版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

1553 строки
66 KiB

  1. using CCWin;
  2. using CCWin.SkinControl;
  3. using HalconDotNet;
  4. using HZH_Controls.Forms;
  5. using MaiMuAOI.Properties;
  6. using MaiMuAOI.SysCtrl;
  7. using MaiMuAOI.SysUI.DefectPicShow;
  8. using MaiMuAOI.SysUI.Load;
  9. using MaiMuAOI.SysUI.ProcessStep;
  10. using MaiMuAOI.SysUI.ProcessStep.Ctrl;
  11. using MaiMuAOI.SysUI.ProductAndStep;
  12. using MaiMuAOI.SysUI.SysSet;
  13. using MaiMuAOI.SysUI.Web;
  14. using MaiMuAOI.UI.SysSet;
  15. using MaiMuControl.Device;
  16. using MaiMuControl.Device.CamDev;
  17. using MaiMuControl.Device.IOCardDev;
  18. using MaiMuControl.SysStatusMgr.StatusMgr;
  19. using Models;
  20. using Newtonsoft.Json.Linq;
  21. using OpenCvSharp;
  22. using ProductionControl;
  23. using System;
  24. using System.Collections.Generic;
  25. using System.ComponentModel;
  26. using System.Data;
  27. using System.Diagnostics;
  28. using System.Drawing;
  29. using System.Drawing.Imaging;
  30. using System.Linq;
  31. using System.Text;
  32. using System.Threading;
  33. using System.Threading.Tasks;
  34. using System.Windows.Forms;
  35. using static MaiMuAOI.SysCtrl.SysMgr;
  36. namespace MaiMuAOI
  37. {
  38. public partial class MainFrm : Form
  39. {
  40. private Service.ProductService svcProduct = new Service.ProductService();
  41. object AddTextLock = new object();
  42. object AddPicLock = new object();
  43. bool backgroundWorkerDo;
  44. bool DisEnableBuzz;
  45. bool DisEnableDoor;
  46. private Stopwatch RunStartTime = new Stopwatch();
  47. public MainFrm()
  48. {
  49. InitializeComponent();
  50. this.uiTitel1.FatherForm = this;
  51. this.uiTitel1.UserMenuStrip = this.menuStrip1;
  52. this.uiTitel1.ShowContrlBox(true, true, true);
  53. this.uiTitel1.ShowMenu();
  54. this.DoubleBuffered = true;//设置本窗体
  55. SetStyle(ControlStyles.UserPaint, true);
  56. SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
  57. SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
  58. SysMgr.Instance.MainRuning += main_running;
  59. SysMgr.Instance.AutoRuning += auto_runing;
  60. SysMgr.Instance.AutoShowImg += auto_ShowMoreImg;
  61. //显示行号与列宽度自动调整
  62. dgvProcess.RowHeadersVisible = true;
  63. dgvProcess.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
  64. dgvProcess.RowPostPaint += (sender, e) =>
  65. {
  66. SysMgr.showRowNum_onDataGrid_RowPostPaint(this.dgvProcess, sender, e);
  67. };
  68. dgvProcess.DefaultCellStyle.ForeColor = System.Drawing.Color.Black;
  69. this.lblTimeLen.Top = toolStrip1.Top + 10;
  70. this.lblTimeLen.Left = toolStrip1.Width - 300;
  71. this.lblOutput.Top = toolStrip1.Top + 10 + lblTimeLen.Height + 5;
  72. this.lblOutput.Left = toolStrip1.Width - 300;
  73. this.chkBuzzer.Top = toolStrip1.Top + 20;
  74. this.chkDoorSensor.Top = toolStrip1.Top + 20;
  75. }
  76. #region 私有方法
  77. /// <summary>
  78. /// 初始化
  79. /// </summary>
  80. /// <returns></returns>
  81. private bool InitSystem()
  82. {
  83. //进入初始化,初始化失败则中断
  84. InitFrm initFrm = new InitFrm();
  85. initFrm.ShowDialog();
  86. if (initFrm.DialogResult == DialogResult.OK)
  87. {
  88. //初始化成功
  89. }
  90. else
  91. {
  92. initFrm.Dispose();
  93. return false;
  94. }
  95. initFrm.Dispose();
  96. return true;
  97. }
  98. /// <summary>
  99. /// 系统是否在运行
  100. /// </summary>
  101. /// <returns></returns>
  102. private bool SystemIsRun()
  103. {
  104. if (SysMgr.Instance.IsRuning)
  105. {
  106. FrmDialog.ShowDialog(this, "设备正在运行中!", "警告", false);
  107. //MessageBox.Show("设备正在运行中!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  108. return false;
  109. }
  110. return true;
  111. }
  112. private void ClearDefectBmps()
  113. {
  114. this.pnlBmpList.Controls.Clear();
  115. this.gboxDefectList.Text = $"缺陷图像";
  116. this.gboxDefectList.Tag = 0;
  117. this.lblDefectAddTag.Text = "";
  118. this.lblDefectAddTag.Tag = 0;
  119. }
  120. private void ResetUI(bool clearSN)
  121. {
  122. //保持产品名称和料号
  123. //txtProductName.Text = txtProductCode.Text = txtProductSN.Text = "";
  124. if(clearSN)
  125. cbProductSN.Text = "";
  126. lblTension.ForeColor = Color.White;
  127. lblTension.Text = "0.00";
  128. lblTensionMax.Text = "0.00";
  129. lblTensionMin.Text = "0.00";
  130. lblHeight.ForeColor = Color.White;
  131. lblHeight.Text = "0.00";
  132. lblHeightMax.Text = "0.00";
  133. lblHeightMin.Text = "0.00";
  134. lblLineWidth.ForeColor = Color.White;
  135. lblLineWidth.Text = "0.00";
  136. lblLineWidthMax.Text = "0.00";
  137. lblLineWidthMin.Text = "0.00";
  138. lblPT.ForeColor = Color.White;
  139. lblPT.Text = "0.00";
  140. lblPTMax.Text = "0.00";
  141. lblPTMin.Text = "0.00";
  142. lblCompareResult.ForeColor = Color.White;
  143. lblCompareResult.Text = "无";
  144. //lblCompareCount.Text = "未通过:";
  145. lblDefectResult.ForeColor = Color.White;
  146. lblDefectResult.Text = "无";
  147. lblDefectResultCount.Text = "无";
  148. this.dgvProcess.DataSource = null;
  149. this.dgvProcess.DataSource = null;
  150. this.lstLog.Items.Clear();
  151. this.ClearDefectBmps();
  152. this.flpProcessStep.Controls.Clear();
  153. this.picScanner0.Image = null;
  154. picScanner0.Refresh();
  155. this.picScanner1.Image = null;
  156. picScanner1.Refresh();
  157. this.tsbtnStop.Enabled = false;
  158. this.cbOrderCode.Enabled = true;
  159. this.cbProductCode.Enabled = true;
  160. this.cbProductSN.Enabled = true;
  161. lblTimeLen.Text = "检测时长: 0 秒";
  162. tslabelTime.Text = "实时测试:0.00s";
  163. int daout = 0;
  164. if(ConfMgr.Instance.GetDailyOutput(out daout))
  165. {
  166. lblOutput.Text = $"当日产量: {daout} 个";
  167. }
  168. MainFrm_Paint(null, null);
  169. this.Refresh();
  170. }
  171. private void UserRightCheck()
  172. {
  173. this.tsmStepMgr.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Step);
  174. this.tsmPdtMgr.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Product);
  175. this.tsmSysDataFind.Visible = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Statistics);
  176. this.tsmUserList.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.User);
  177. this.tsmUserRight.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Role);
  178. if(this.tsmUserList.Enabled == false && this.tsmUserRight.Enabled == false)
  179. this.tsmSysUserMgr.Visible = false;
  180. else
  181. this.tsmSysUserMgr.Visible = true;
  182. this.tsmDebug.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.Debug);
  183. this.tsmSysSet.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.ParamsSetting);
  184. this.tsmSysPoints.Enabled = SysMgr.Instance.UserMgr.RightControl(MaiMuControl.SysStatusMgr.UserMgr.UserRightEnum.ParamsSetting);
  185. if (this.tsmDebug.Enabled == false && this.tsmSysSet.Enabled == false)
  186. this.stmSysSet.Visible = false;
  187. else
  188. this.stmSysSet.Visible = true;
  189. }
  190. #endregion
  191. private void MainFrm_Load(object sender, EventArgs e)
  192. {
  193. //登入
  194. if (SysMgr.Instance.LoginSystem())
  195. {
  196. //登入成功
  197. if (InitSystem())
  198. {
  199. this.Cursor = Cursors.WaitCursor;
  200. //this.WindowState = FormWindowState.Normal;
  201. this.Top = 0;
  202. this.Left = 0;
  203. this.Width = SystemInformation.WorkingArea.Width;
  204. this.Height = SystemInformation.WorkingArea.Height;
  205. //this.WindowState = FormWindowState.Maximized;
  206. this.splitContainer1.SplitterDistance = this.Width / 3;
  207. ResetUI(true);
  208. this.Show();
  209. this.dgvProcess.AutoGenerateColumns = false;
  210. this.tsslLoginInfo.Text = $"操作员:{SysMgr.Instance.UserMgr.LoginUser.Code}({SysMgr.Instance.UserMgr.LoginUser.Name})";
  211. //this.tsslLoginTime.Text = $" 登录时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm")}";
  212. this.statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
  213. this.tsslLoginTime.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
  214. this.tsslLoginInfo.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
  215. this.tsAxisState.Text = "";
  216. //设置流程卡显示
  217. this.tabControl1.SelectTab(0);
  218. //this.tabControl1.SelectTab(1);
  219. //更新数据库格式
  220. Service.InitDB.initDB();
  221. //权限判断
  222. UserRightCheck();
  223. //开启后台
  224. //timer1.Enabled = true;
  225. backgroundWorkerDo = true;
  226. backgroundWorker1.RunWorkerAsync();
  227. //s_BackWorker = true;
  228. //backgroundWorker.RunWorkerAsync();
  229. //开启web服务器
  230. SysMgr.Instance.InitWebServer();
  231. //开启云端连接
  232. SysMgr.Instance.InitCloudConnect();
  233. //开启产品服务
  234. SysMgr.Instance.InitPdtService();
  235. //开启处理事件反馈
  236. SysMgr.Instance.InitDefectEvent();
  237. //加载产品料号
  238. SysMgr.Instance.LoadProductCodeList();
  239. //加载产品选择
  240. LoadPdtList(SysMgr.Instance.ProductCodeList);
  241. LoadSNList(SysMgr.Instance.ProductSNList);
  242. this.Cursor = Cursors.Default;
  243. //运行前检测磁盘空间
  244. SysMgr.CheckDisk(this);
  245. }
  246. else
  247. {
  248. Application.Exit();
  249. }
  250. }
  251. else
  252. {
  253. Application.Exit();
  254. }
  255. }
  256. private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
  257. {
  258. backgroundWorkerDo = false;
  259. Thread.Sleep(300);
  260. if (SystemIsRun())
  261. {
  262. DialogResult dr = DialogResult.Cancel;
  263. if (SysMgr.Instance.IsInit)
  264. {
  265. dr = FrmDialog.ShowDialog(this, "确定要退出当前系统?", "警告", true);
  266. }
  267. else
  268. dr = DialogResult.OK;
  269. if (dr == DialogResult.Cancel)
  270. {
  271. e.Cancel = true;
  272. }
  273. else
  274. {
  275. Thread.Sleep(300);
  276. if (SysMgr.Instance.IsInit)
  277. SysMgr.Instance.Close();
  278. //SysMgr.Instance.MainRuning -= main_running;
  279. }
  280. }
  281. else
  282. e.Cancel = true;
  283. }
  284. #region 主界面
  285. private void toolStrip1_Paint(object sender, PaintEventArgs e)
  286. {
  287. if ((sender as ToolStrip).RenderMode == ToolStripRenderMode.System)
  288. {
  289. Rectangle rect = new Rectangle(0, 0, this.toolStrip1.Width, this.toolStrip1.Height - 2);
  290. e.Graphics.SetClip(rect);
  291. }
  292. }
  293. private void chkBuzzer_CheckedChanged(object sender, EventArgs e)
  294. {
  295. DisEnableBuzz = chkBuzzer.Checked;
  296. }
  297. private void chkDoorSensor_CheckedChanged(object sender, EventArgs e)
  298. {
  299. DisEnableDoor = chkDoorSensor.Checked;
  300. }
  301. private void MainFrm_Shown(object sender, EventArgs e)
  302. {
  303. }
  304. private void tsbCC_Click(object sender, EventArgs e)
  305. {
  306. if(this.tsbCC.Text == "尺寸启用")
  307. {
  308. this.tsbCC.Text = "尺寸禁用";
  309. this.tsbCC.Image = Resources.ccClose;
  310. SysMgr.Instance.SetSizeEnable(false);
  311. }
  312. else
  313. {
  314. this.tsbCC.Text = "尺寸启用";
  315. this.tsbCC.Image = Resources.ccOpen;
  316. SysMgr.Instance.SetSizeEnable(true);
  317. }
  318. }
  319. private void tsbQX_Click(object sender, EventArgs e)
  320. {
  321. if (this.tsbQX.Text == "缺陷启用")
  322. {
  323. this.tsbQX.Text = "缺陷禁用";
  324. this.tsbQX.Image = Resources.qxClose;
  325. SysMgr.Instance.SetDefectEnable(false);
  326. }
  327. else
  328. {
  329. this.tsbQX.Text = "缺陷启用";
  330. this.tsbQX.Image = Resources.qxOpen;
  331. SysMgr.Instance.SetDefectEnable(true);
  332. }
  333. }
  334. #endregion
  335. #region 菜单按钮
  336. private void tsmSysSet_Click(object sender, EventArgs e)
  337. {
  338. if (SystemIsRun())
  339. {
  340. SysMgr.Instance.StatusMgr.GotoSetParams();
  341. SysMgr.Instance.SendStatus();
  342. SysSetFrm frm = new SysSetFrm();
  343. frm.ShowDialog();
  344. MainFrm_Paint(null, null);
  345. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  346. SysMgr.Instance.SendStatus();
  347. }
  348. }
  349. private void tsmUserRight_Click(object sender, EventArgs e)
  350. {
  351. SysMgr.Instance.UserPermissiomMgr();
  352. }
  353. private void tsmUserList_Click(object sender, EventArgs e)
  354. {
  355. SysMgr.Instance.UserListMgr();
  356. }
  357. private void tsmDebug_Click(object sender, EventArgs e)
  358. {
  359. if (SystemIsRun())
  360. {
  361. SysMgr.Instance.StatusMgr.GotoDebug();
  362. SysMgr.Instance.SendStatus();
  363. SysDebugFrm frm = new SysDebugFrm();
  364. frm.ShowDialog();
  365. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  366. SysMgr.Instance.SendStatus();
  367. }
  368. }
  369. private void tsmSysPoints_Click(object sender, EventArgs e)
  370. {
  371. if (SystemIsRun())
  372. {
  373. SysMgr.Instance.StatusMgr.GotoSetParams();
  374. SysMgr.Instance.SendStatus();
  375. SysPointsFrm frm = new SysPointsFrm();
  376. frm.ShowDialog();
  377. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  378. SysMgr.Instance.SendStatus();
  379. }
  380. }
  381. private void tsmSysDataFind_Click(object sender, EventArgs e)
  382. {
  383. //WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B",
  384. // "http://127.0.0.1:" + ConfMgr.Instance.SysConfigParams.HttpServerPort.ToString() + "/static/index.html#/");
  385. //WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B");
  386. //frm.WindowState = FormWindowState.Maximized;
  387. //frm.Show();
  388. }
  389. private void web数据查询ToolStripMenuItem_Click(object sender, EventArgs e)
  390. {
  391. WebFrm frm = new WebFrm("查询统计", $"reportRecordSN?CustomerVer=B");
  392. frm.WindowState = FormWindowState.Maximized;
  393. frm.Show();
  394. }
  395. private void 本地数据库查询ToolStripMenuItem_Click(object sender, EventArgs e)
  396. {
  397. DataQueryFrm frm = new DataQueryFrm();
  398. frm.WindowState = FormWindowState.Maximized;
  399. frm.Show();
  400. }
  401. private void 系统管理ToolStripMenuItem_Click(object sender, EventArgs e)
  402. {
  403. if (SystemIsRun())
  404. {
  405. ProductListFrm frm = new ProductListFrm();
  406. frm.ShowDialog();
  407. //加载产品料号
  408. SysMgr.Instance.LoadProductCodeList();
  409. //加载产品选择
  410. LoadPdtList(SysMgr.Instance.ProductCodeList);
  411. }
  412. }
  413. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  414. {
  415. if (SystemIsRun())
  416. {
  417. StepListFrm frm = new StepListFrm();
  418. frm.ShowDialog();
  419. }
  420. }
  421. private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
  422. {
  423. this.Close();
  424. }
  425. private void tsmInfoUS_Click(object sender, EventArgs e)
  426. {
  427. SysInfoFrm frm = new SysInfoFrm();
  428. frm.ShowDialog();
  429. }
  430. private void tsmReadLog_Click(object sender, EventArgs e)
  431. {
  432. SysLogFrm frm = new SysLogFrm();
  433. frm.ShowDialog();
  434. }
  435. private void tsmHelpInfo_Click(object sender, EventArgs e)
  436. {
  437. //MessageBox.Show(SysUpdata.Updata, "更新信息");
  438. SysUpdataInfoFrm frm = new SysUpdataInfoFrm(SysUpdata.Updata);
  439. frm.ShowDialog();
  440. }
  441. private void tsmSoftFile_Click(object sender, EventArgs e)
  442. {
  443. string fileName = ConfMgr.Instance.SpecificationPath;//输入打开文件路径
  444. Process.Start(fileName);//使用process进程打开
  445. }
  446. #endregion
  447. #region 显示图像和消息
  448. private void lstLog_DrawItem(object sender, DrawItemEventArgs e)
  449. {
  450. e.DrawBackground();
  451. if (e.Index < 0) return;
  452. try
  453. {
  454. string str = lstLog.Items[e.Index].ToString();
  455. e.Graphics.DrawString(str.Substring(1), e.Font,
  456. new SolidBrush(str[0] == 'R' ? Color.Red : (str[0] == 'Y' ? Color.Orange : Color.Black)),
  457. e.Bounds);
  458. }
  459. catch(Exception ex)
  460. {
  461. e.Graphics.DrawString(ex.Message, e.Font,
  462. new SolidBrush( Color.Red ),
  463. e.Bounds);
  464. }
  465. }
  466. /// <summary>
  467. /// 异步输出日志
  468. /// </summary>
  469. /// <param name="tag">模板标识</param>
  470. /// <param name="msg">内容</param>
  471. /// <param name="type"></param>
  472. private void AddTextEvent(string tag, string msg, WarningEnum level = WarningEnum.Normal)
  473. {
  474. lock (AddTextLock)
  475. {
  476. if (tag != null && tag != "")
  477. tag = $" - [{tag}]";
  478. var now = DateTime.Now;
  479. msg = now.ToString("HH:mm:ss fff") + tag + " - " + msg;
  480. msg = (level == WarningEnum.Normal ? "B" : level == WarningEnum.Low ? "Y" : "R") + msg;
  481. if (this.lstLog.Items.Count > 1000)
  482. this.lstLog.Items.Clear();
  483. lstLog.Items.Insert(0, msg);
  484. }
  485. }
  486. private void main_running(object sender, MainEventArgs e)
  487. {
  488. ShowMessage(e);
  489. }
  490. private delegate void ShowMessageDelegate(MainEventArgs e);
  491. private void ShowMessage(MainEventArgs e)
  492. {
  493. if (InvokeRequired)
  494. {
  495. ShowMessageDelegate smd = new ShowMessageDelegate(ShowMessage);
  496. this.BeginInvoke(smd, e);
  497. }
  498. else
  499. {
  500. AddTextEvent(e.Tag, e.Message, e.Warning);
  501. }
  502. }
  503. /// <summary>
  504. /// 自动运行流程显示
  505. /// </summary>
  506. /// <param name="sender"></param>
  507. /// <param name="e"></param>
  508. private void auto_runing(object sender, RunEventArgs e)
  509. {
  510. ShowUIEvent(e);
  511. }
  512. private delegate void ShowUIEventDelegate(RunEventArgs e);
  513. Bitmap bmp0;
  514. Bitmap bmp1;
  515. private void ShowUIEvent(RunEventArgs e)
  516. {
  517. if (InvokeRequired)
  518. {
  519. ShowUIEventDelegate smd = new ShowUIEventDelegate(ShowUIEvent);
  520. this.BeginInvoke(smd, e);
  521. }
  522. else
  523. {
  524. try
  525. {
  526. if (e.Cmd == 0) //显示SN和流程
  527. {
  528. this.cbProductSN.Text = e.SN;
  529. if (e.NewStep)
  530. {
  531. this.tabControl1.SelectTab(1);
  532. ShowNewStepProcess(e.StepProcessesList);
  533. }
  534. else
  535. {
  536. this.tabControl1.SelectTab(0);
  537. this.dgvProcess.DataSource = new BindingSource(e.StepProcessesList, null);
  538. }
  539. }
  540. else if (e.Cmd == 1) //显示当前运行步骤
  541. {
  542. this.dgvProcess.Rows[e.StepIndex].Selected = true;
  543. dgvProcess.CurrentCell = dgvProcess.Rows[e.StepIndex].Cells[1];
  544. }
  545. else if (e.Cmd == 2) //显示当前运行步骤 和步骤详情
  546. {
  547. this.dgvProcess.Rows[e.StepIndex].Cells["colValue"].Value = e.Mesg;
  548. }
  549. else if (e.Cmd == 3) //图纸比对结果
  550. {
  551. this.lblCompareResult.Text = (e.CompareResult ? "通过" : $"未通过");
  552. this.lblCompareResultCount.Text = e.Cnt.ToString();
  553. if (!e.CompareResult)
  554. {
  555. this.lblCompareResult.ForeColor = Color.Red;
  556. }
  557. else
  558. this.lblCompareResult.ForeColor = Color.Lime;
  559. }
  560. else if (e.Cmd == 4) //缺陷结果
  561. {
  562. lblDefectResult.Text = "未通过";
  563. lblDefectResultCount.Text = $"总数:{e.Cnt},详细:{e.CompareResultString}";
  564. this.toolTip1.SetToolTip(lblDefectResultCount, lblDefectResultCount.Text);
  565. this.lblDefectResult.Text = (e.CompareResult ? "通过" : "未通过");
  566. if (!e.CompareResult)
  567. {
  568. this.lblDefectResult.ForeColor = Color.Red;
  569. }
  570. else
  571. this.lblDefectResult.ForeColor = Color.Lime;
  572. }
  573. else if (e.Cmd == 5) //加载缺陷小图
  574. {
  575. ;
  576. }
  577. else if (e.Cmd == 6) //显示主图
  578. {
  579. if (e.PicIndex == 0)
  580. {
  581. bmp0 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  582. picScanner0.Image = bmp0;
  583. picScanner0.Refresh();
  584. }
  585. else
  586. {
  587. bmp1 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  588. picScanner1.Image = bmp1;
  589. picScanner1.Refresh();
  590. }
  591. }
  592. else if (e.Cmd == 7) //显示测试时间
  593. {
  594. lblTimeLen.Text = "检测时长: " + e.Time.ToString("0.000") + " 秒";
  595. }
  596. else if (e.Cmd == 8) //显示测试时间
  597. {
  598. lblOutput.Text = "当日产量: " + e.Num.ToString("0") + " 个";
  599. }
  600. else if (e.Cmd == 10) //测试结束
  601. {
  602. this.tsbtnStart.Enabled = true;
  603. this.tsbtnStop.Enabled = false;
  604. this.cbOrderCode.Enabled = true;
  605. this.cbProductCode.Enabled = true;
  606. this.cbProductSN.Enabled = true;
  607. }
  608. else if (e.Cmd == 21) //厚度显示
  609. {
  610. double value = Math.Round(e.Value.Average(), 2);
  611. double valueMax = e.Value.Max();
  612. double valueMin = e.Value.Min();
  613. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  614. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  615. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  616. this.lblHeight.Text = Math.Round(value, 2).ToString();
  617. this.lblHeight.ForeColor = color;
  618. this.lblHeightMax.Text = Math.Round(valueMax, 2).ToString();
  619. this.lblHeightMax.ForeColor = colorMax;
  620. this.lblHeightMin.Text = Math.Round(valueMin, 2).ToString();
  621. this.lblHeightMin.ForeColor = colorMin;
  622. }
  623. else if (e.Cmd == 22) //PT显示
  624. {
  625. double value = Math.Round(e.Value.Average(), 4);
  626. double valueMax = e.Value.Max();
  627. double valueMin = e.Value.Min();
  628. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  629. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  630. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  631. this.lblPT.Text = Math.Round(value, 4).ToString();
  632. this.lblPT.ForeColor = color;
  633. this.lblPTMax.Text = Math.Round(valueMax, 4).ToString();
  634. this.lblPTMax.ForeColor = colorMax;
  635. this.lblPTMin.Text = Math.Round(valueMin, 4).ToString();
  636. this.lblPTMin.ForeColor = colorMin;
  637. }
  638. else if (e.Cmd == 23) //线宽显示
  639. {
  640. double value = Math.Round(e.Value.Average(), 2);
  641. double valueMax = e.Value.Max();
  642. double valueMin = e.Value.Min();
  643. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  644. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  645. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  646. this.lblLineWidth.Text = Math.Round(value, 2).ToString();
  647. this.lblLineWidth.ForeColor = color;
  648. this.lblLineWidthMax.Text = Math.Round(valueMax, 2).ToString();
  649. this.lblLineWidthMax.ForeColor = colorMax;
  650. this.lblLineWidthMin.Text = Math.Round(valueMin, 2).ToString();
  651. this.lblLineWidthMin.ForeColor = colorMin;
  652. }
  653. else if (e.Cmd == 30) //新流程 厚度, 张力, pt, 线宽显示
  654. {
  655. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex +1), true);
  656. //滚动条滚动
  657. //int scrollStep = (this.flpProcessStep.VerticalScroll.Maximum / (flpProcessStep.Controls.Count - 1));
  658. this.flpProcessStep.VerticalScroll.Value = e.StepIndex * controls[0].Height > this.flpProcessStep.VerticalScroll.Maximum? this.flpProcessStep.VerticalScroll.Maximum: e.StepIndex * controls[0].Height;
  659. if (!e.ProcessType)
  660. {
  661. NewStepShow newStepShow = controls[0] as NewStepShow;
  662. if (e.Mesg == "镜头变焦")
  663. {
  664. string str1 = e.Value_ave == 0 ? "开启自动聚焦" : "关闭自动聚焦";
  665. string str2 = e.Value_up == 0 ? "自动变倍" : "手动变倍";
  666. string str3 = e.Value_low == 0 ? "自动Z轴聚焦" : "手动Z轴聚焦";
  667. string ShowData = e.Mesg + $"-{str1}-{str2}-{str3}";
  668. newStepShow.StepString = ShowData;
  669. }
  670. if (e.Mesg == "光源设置")
  671. {
  672. string ShowData = e.Mesg + $":通道号:{e.Value_up},亮度:{e.Value_low}";
  673. newStepShow.StepString = ShowData;
  674. }
  675. else
  676. {
  677. newStepShow.StepMax = e.Value_up;
  678. newStepShow.StepMin = e.Value_low;
  679. newStepShow.StepData = e.Value_ave;
  680. if (e.Value !=null && e.Value.Count > 0)
  681. {
  682. string ShowData = e.Mesg + $"1:{e.Value[0]}";
  683. for (int i = 1; i < e.Value.Count; i++)
  684. {
  685. ShowData += $",{e.Mesg}{i + 1}:{e.Value[i]}";
  686. }
  687. newStepShow.StepString = ShowData;
  688. }
  689. else
  690. newStepShow.StepString = e.Mesg;
  691. }
  692. if (e.ProcessSts == 1)
  693. newStepShow.StepStatus = NewStepShow.StepStsEnum.Testing;
  694. else if (e.ProcessSts == 2)
  695. newStepShow.StepStatus = NewStepShow.StepStsEnum.OK;
  696. else if (e.ProcessSts == 3)
  697. newStepShow.StepStatus = NewStepShow.StepStsEnum.NG;
  698. else if (e.ProcessSts == 0)
  699. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  700. else if (e.ProcessSts == 4)
  701. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  702. }
  703. else
  704. {
  705. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  706. newStepShowDef.StepString = e.Mesg;
  707. if (e.ProcessSts == 1)
  708. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Testing;
  709. else if (e.ProcessSts == 2)
  710. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.OK;
  711. else if (e.ProcessSts == 3)
  712. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.NG;
  713. else if (e.ProcessSts == 0)
  714. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  715. else if (e.ProcessSts == 4)
  716. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Error;
  717. if (e.Value_ave == 0)
  718. {
  719. newStepShowDef.StepSizeData = (int)e.Value_up;
  720. if (e.Value_up > 0)
  721. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.NG;
  722. else if (e.Value_up < 0)
  723. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  724. else if (e.Value_up == 0)
  725. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.OK;
  726. else
  727. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.Error;
  728. }
  729. else
  730. {
  731. if (e.Value_low == 0)
  732. newStepShowDef.StepDefectData = (int)e.Value_low;
  733. else if (e.Value_low > 0)
  734. newStepShowDef.StepDefectData = newStepShowDef.StepDefectData + (int)e.Value_low;
  735. //if (e.Value_low > 0)
  736. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.NG;
  737. //else if (e.Value_low < 0)
  738. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  739. //else if ((e.Value_low == 0)&&(e.Value_up == 0))
  740. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.OK;
  741. if ((e.Value_up == -1) && (e.Value_low == -1))
  742. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Error;
  743. else if (e.Value_up == 1)
  744. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Testing;
  745. else if (e.Value_up == 0)
  746. {
  747. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Done;
  748. newStepShowDef.StepDefectData = (int)e.Value_low;
  749. }
  750. }
  751. }
  752. }
  753. else if (e.Cmd == 31) //忽略流程 厚度, 张力, pt, 线宽显示
  754. {
  755. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex + 1), true);
  756. if (controls != null)
  757. {
  758. if (!e.ProcessType)
  759. {
  760. NewStepShow newStepShow = controls[0] as NewStepShow;
  761. newStepShow.StepMax = 0;
  762. newStepShow.StepMin = 0;
  763. newStepShow.StepData = 0;
  764. string ShowData = e.Mesg;
  765. newStepShow.StepString = ShowData;
  766. if (e.ProcessSts == 4)
  767. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  768. else
  769. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  770. }
  771. else
  772. {
  773. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  774. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  775. newStepShowDef.StepDefectData = -1;
  776. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  777. newStepShowDef.StepSizeData = -1;
  778. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  779. newStepShowDef.StepString = "未启用或被禁用";
  780. newStepShowDef.StepString = e.Mesg;
  781. }
  782. }
  783. }
  784. Application.DoEvents();
  785. }
  786. catch { }
  787. }
  788. }
  789. void ShowNewStepProcess(List<StepProcess> list)
  790. {
  791. flpProcessStep.Controls.Clear();
  792. int index = 0;
  793. int splitWidth = 5;
  794. foreach (StepProcess stepProcess in list)
  795. {
  796. index++;
  797. if (stepProcess.ProcessCode != "SizeAndDefect")
  798. {
  799. NewStepShow newStepShow = new NewStepShow();
  800. newStepShow.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  801. newStepShow.StepName = stepProcess.ProcessName;
  802. newStepShow.StepIndex = index;
  803. newStepShow.StepMax = 0;
  804. newStepShow.StepMin = 0;
  805. newStepShow.StepData = 0;
  806. newStepShow.StepString = "";
  807. newStepShow.StepStatus = NewStepShow.StepStsEnum.Wait;
  808. newStepShow.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  809. newStepShow.Name = "Step_" + index;
  810. flpProcessStep.Controls.Add(newStepShow);
  811. }
  812. else
  813. {
  814. NewStepShowDefect newStepShowDefect = new NewStepShowDefect();
  815. newStepShowDefect.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  816. newStepShowDefect.StepName = stepProcess.ProcessName;
  817. newStepShowDefect.StepIndex = index;
  818. bool opensize = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenSize");
  819. newStepShowDefect.StepSizeSts = opensize ? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  820. newStepShowDefect.StepSizeData = -1;
  821. bool opendefect = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenDefect");
  822. newStepShowDefect.StepDefectSts = opendefect? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  823. newStepShowDefect.StepDefectData = -1;
  824. newStepShowDefect.StepString = "";
  825. newStepShowDefect.StepStatus = NewStepShowDefect.StepStsEnum.Wait;
  826. newStepShowDefect.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  827. newStepShowDefect.Name = "Step_" + index;
  828. flpProcessStep.Controls.Add(newStepShowDefect);
  829. }
  830. }
  831. }
  832. /// <summary>
  833. /// 缺陷小图多图显示
  834. /// </summary>
  835. /// <param name="sender"></param>
  836. /// <param name="e"></param>
  837. private void auto_ShowMoreImg(object sender, ImgEventArgs e)
  838. {
  839. ShowImgEvent(e);
  840. }
  841. private delegate void ShowImgEventDelegate(ImgEventArgs e);
  842. private void ShowImgEvent(ImgEventArgs e)
  843. {
  844. if (InvokeRequired)
  845. {
  846. ShowImgEventDelegate smd = new ShowImgEventDelegate(ShowImgEvent);
  847. this.BeginInvoke(smd, e);
  848. }
  849. else
  850. {
  851. //Task<int> tt = new Task<int>(() =>
  852. //{
  853. //lock (AddPicLock)
  854. {
  855. //加载缺陷小图
  856. //纵向显示
  857. int imgWidth = this.pnlBmpList.ClientSize.Width - 50;
  858. int imgHeight = (int)((e.Bitmaps[0].Height * 1.0f / e.Bitmaps[0].Width) * imgWidth + 0.5);
  859. int splitWidth = 20;
  860. int pnlWidth = this.pnlBmpList.ClientSize.Width;
  861. int index = (int)this.gboxDefectList.Tag;
  862. //横向显示
  863. //int imgHeight = this.pnlBmpList.Height - 50;
  864. //int imgWidth = (int)((e.Bitmaps[0].Width * 1.0f / e.Bitmaps[0].Height) * imgHeight + 0.5);
  865. //int splitWidth = 20;
  866. //int pnlWidth = this.pnlBmpList.Height;
  867. //int index = (int)this.gboxDefectList.Tag;
  868. int len = e.Info.Count();
  869. int range = 100;
  870. int uselen = len > 100 ? 100 : len;
  871. for (int x = 0; x < uselen / range + 1; x++)
  872. {
  873. for (int i = 0; i < (x < (uselen / range) ? range : uselen % range); i++)
  874. {
  875. foreach (var item in e.Info[(x * range + i)]) //单个info[x] = {"1":[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]}
  876. {
  877. //统计缺陷类型
  878. SysMgr.Instance.countDefectClass(item.Value);//[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]
  879. //
  880. PictureBox picbox = new PictureBox();
  881. picbox.Width = imgWidth;
  882. picbox.Height = imgHeight;
  883. picbox.Image = (Bitmap)e.Bitmaps[(x * range + i)].Clone();
  884. picbox.Name = "imgDefect_" + index;
  885. picbox.Tag = item.Key + "," + e.X + "," + e.Y;
  886. picbox.Click += new EventHandler(defectBmpBox_Click);
  887. picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  888. picbox.BorderStyle = BorderStyle.FixedSingle;
  889. //picbox.Margin = new Padding((pnlWidth - picbox.Height) / 2, splitWidth, 0, 0);
  890. picbox.Margin = new Padding((pnlWidth - picbox.Width) / 2, splitWidth, 0, 0);
  891. picbox.MouseHover += simpleTip_MouseHover;
  892. picbox.Visible = true;
  893. //this.Invoke(new MethodInvoker(() =>
  894. // {
  895. this.pnlBmpList.Controls.Add(picbox);
  896. //this.Refresh();
  897. //this.dgvProcess.Refresh();
  898. //this.lstLog.Refresh();
  899. //this.statusStrip1.Refresh();
  900. // }));
  901. break;
  902. }
  903. //
  904. index++;
  905. //Thread.Sleep(10);
  906. //Application.DoEvents();
  907. }
  908. //Application.DoEvents();
  909. //this.Invoke(new MethodInvoker(() =>
  910. //{
  911. //this.Refresh();
  912. pnlBmpList.VerticalScroll.Value = pnlBmpList.VerticalScroll.Maximum;
  913. //}));
  914. //Thread.Sleep(10);
  915. }
  916. //this.Invoke(new MethodInvoker(() =>
  917. //{
  918. //this.gboxDefectList.Tag = len + (int)this.gboxDefectList.Tag;
  919. this.gboxDefectList.Tag = index;
  920. this.gboxDefectList.Text = $"缺陷图像:{index} 张";
  921. }
  922. //}));
  923. //return 0;
  924. // });
  925. // tt.Start();
  926. // await tt;
  927. }
  928. }
  929. #endregion
  930. #region 工具栏
  931. private void tsbtnImpStop_Click(object sender, EventArgs e)
  932. {
  933. SysMgr.Instance.LedPause();
  934. AddTextEvent("急停", "手动急停", WarningEnum.High);
  935. SysMgr.Instance.StatusMgr.GotoWarning( WarningEnum.High, "急停", "手动急停");
  936. SysMgr.Instance.SendStatus();
  937. SysMgr.Instance.EmergencyStop();
  938. }
  939. private void tsbOpenLight_Click(object sender, EventArgs e)
  940. {
  941. if (this.tsbOpenLight.Text == "开灯")
  942. {
  943. SysMgr.Instance.OpenFloodlight(true);
  944. this.tsbOpenLight.Text = "关灯";
  945. }
  946. else
  947. {
  948. SysMgr.Instance.OpenFloodlight(false);
  949. this.tsbOpenLight.Text = "开灯";
  950. }
  951. }
  952. private void tsbtnStart_Click(object sender, EventArgs e)
  953. {
  954. if (!SysMgr.Instance.IsRuning)
  955. {
  956. //低报警自动复位
  957. if(SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  958. {
  959. if (SysMgr.Instance.StatusMgr.Warning == WarningEnum.Low)
  960. {
  961. SysMgr.Instance.StatusMgr.ClearWarning();
  962. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  963. }
  964. }
  965. //提示正在报警中
  966. if (SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  967. {
  968. FrmDialog.ShowDialog(this, "系统报警中!无法启动运行!", "警告", false);
  969. return;
  970. }
  971. this.Cursor = Cursors.WaitCursor;
  972. System.Windows.Forms.Application.DoEvents();
  973. if (SysMgr.Instance.StatusMgr.Status != SystemStsEnum.Pause)
  974. {
  975. ResetUI(false);
  976. AddTextEvent("运行", $"启动自动检测流程");
  977. this.lstLog.Refresh();
  978. if (SysMgr.Instance.StartRun(this, this.cbOrderCode.Text, (int)this.numDefectCnt.Value, this.cbProductCode.Text, this.cbProductSN.Text))
  979. {
  980. this.tsbtnStop.Enabled = true;
  981. this.tsbtnStart.Enabled = false;
  982. //锁定信息
  983. this.cbOrderCode.Enabled = false;
  984. this.cbProductCode.Enabled = false;
  985. this.cbProductSN.Enabled = false;
  986. //记录开始运行时间
  987. RunStartTime.Restart();
  988. }
  989. }
  990. else //暂停状态开始
  991. {
  992. if (SysMgr.Instance.ReStartRun())
  993. {
  994. this.tsbtnStop.Enabled = true;
  995. this.tsbtnStart.Enabled = false;
  996. }
  997. }
  998. this.Cursor = Cursors.Default;
  999. }
  1000. }
  1001. private void tsbtnStop_Click(object sender, EventArgs e)
  1002. {
  1003. AddTextEvent("暂停", "手动暂停");
  1004. this.tsbtnStart.Enabled = true;
  1005. SysMgr.Instance.StatusMgr.GotoPause();
  1006. SysMgr.Instance.SendStatus();
  1007. SysMgr.Instance.LedPause();
  1008. //this.tsbtnStart.Enabled = true;
  1009. }
  1010. private void tsbtnReset_Click(object sender, EventArgs e)
  1011. {
  1012. if (SystemIsRun())
  1013. {
  1014. DialogResult dr = DialogResult.Cancel;
  1015. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统?", "警告", true);
  1016. if (dr == DialogResult.OK)
  1017. {
  1018. this.tsbtnStart.Enabled = true;
  1019. this.tsbtnStop.Enabled = false;
  1020. Task.Factory.StartNew(() =>
  1021. {
  1022. SysMgr.Instance.LedRset(true);
  1023. SysMgr.Instance.GotoReadyPosAndIO();
  1024. SysMgr.Instance.LedRset(false);
  1025. });
  1026. ResetUI(true);
  1027. //AddTextEvent("复位", "复位完成");
  1028. }
  1029. }
  1030. }
  1031. private void tsbtnWarning_Click(object sender, EventArgs e)
  1032. {
  1033. if(SysMgr.Instance.StatusMgr.Warning != WarningEnum.Normal)
  1034. {
  1035. AddTextEvent("清除", "手动清除报警");
  1036. SysMgr.Instance.StatusMgr.ClearWarning();
  1037. SysMgr.Instance.LedReady();
  1038. if (SysMgr.Instance.IsAuto)
  1039. SysMgr.Instance.StatusMgr.GotoPause();
  1040. else
  1041. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  1042. SysMgr.Instance.SendStatus();
  1043. }
  1044. }
  1045. private void tsbGoHome_Click(object sender, EventArgs e)
  1046. {
  1047. if (SystemIsRun())
  1048. {
  1049. DialogResult dr = DialogResult.Cancel;
  1050. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统所有硬件位置?", "警告", true);
  1051. if (dr == DialogResult.OK)
  1052. {
  1053. this.tsbtnStart.Enabled = true;
  1054. this.tsbtnStop.Enabled = false;
  1055. this.Cursor = Cursors.WaitCursor;
  1056. System.Windows.Forms.Application.DoEvents();
  1057. Task.Factory.StartNew(() =>
  1058. {
  1059. SysMgr.Instance.LedRset(true);
  1060. SysMgr.Instance.AllResetAndGoHome();
  1061. SysMgr.Instance.LedRset(false);
  1062. });
  1063. this.Cursor = Cursors.Default;
  1064. }
  1065. }
  1066. }
  1067. //缺陷+比对与图纸查看
  1068. private void tsbtnDefectImage_Click(object sender, EventArgs e)
  1069. {
  1070. try
  1071. {
  1072. string gbxBmpPath = "";
  1073. Order temp_order = null;
  1074. if (SysMgr.Instance.GetDefectDistribution(out gbxBmpPath, out temp_order))
  1075. {
  1076. //
  1077. ToolStripButton btn = sender as ToolStripButton;
  1078. DefectImageShowFrm frm = new DefectImageShowFrm(gbxBmpPath , temp_order, string.IsNullOrEmpty(btn.Tag.ToString()) ? 0 : Convert.ToInt32(btn.Tag.ToString()));
  1079. frm.Show();
  1080. }
  1081. }
  1082. catch (Exception ex)
  1083. {
  1084. MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
  1085. }
  1086. }
  1087. #endregion
  1088. #region 小图操作
  1089. private void defectBmpBox_Click(object sender, EventArgs e)
  1090. {
  1091. PictureBox picbox = sender as PictureBox;
  1092. if (SysMgr.Instance.IsAuto || SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Auto)//检测中
  1093. {
  1094. //只查看
  1095. AddTextEvent("查看", $"运行中查看缺陷{SysMgr.Instance.IsAuto} - {SysMgr.Instance.StatusMgr.Status}");
  1096. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1097. frm.ShowDialog(this);
  1098. }
  1099. else//完成
  1100. {
  1101. AddTextEvent("查看", $"查看缺陷{ConfMgr.Instance.SysConfigParams.OpenDefectSanp}");
  1102. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls,
  1103. Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]), ConfMgr.Instance.SysConfigParams.OpenDefectSanp);
  1104. frm.ShowDialog(this);
  1105. }
  1106. }
  1107. private void simpleTip_MouseHover(object sender, EventArgs e)
  1108. {
  1109. PictureBox pb = sender as PictureBox;
  1110. // 创建the ToolTip
  1111. ToolTip toolTip1 = new ToolTip();
  1112. // 设置显示样式
  1113. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  1114. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  1115. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1116. toolTip1.ShowAlways = true;//是否显示提示框
  1117. // 设置伴随的对象.
  1118. toolTip1.SetToolTip(pb, pb.Name + "[" +pb.Tag.ToString() + "]");//设置提示按钮和提示内容
  1119. }
  1120. #endregion
  1121. #region 时钟捕获
  1122. GetPN pn = new GetPN();
  1123. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  1124. {
  1125. while (backgroundWorkerDo)
  1126. {
  1127. try
  1128. {
  1129. this.Invoke(new MethodInvoker(() =>
  1130. {
  1131. this.tsslLoginTime.Text = $" 当前时间:{DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss")}";
  1132. }));
  1133. //检测按钮和实时状态
  1134. if (SysMgr.Instance.IsInit)
  1135. {
  1136. bool sts = SysMgr.Instance.WarningShowLed(DisEnableBuzz);
  1137. if (sts)
  1138. {
  1139. this.Invoke(new MethodInvoker(() =>
  1140. {
  1141. this.tsbtnStart.Enabled = true;
  1142. this.tsbtnStop.Enabled = false;
  1143. }));
  1144. }
  1145. int stsno = 0;
  1146. stsno = SysMgr.Instance.ButtonIOTrg(DisEnableDoor);
  1147. if (stsno == 1)
  1148. {
  1149. this.Invoke(new MethodInvoker(() =>
  1150. {
  1151. tsbtnStart_Click(null, null);
  1152. }));
  1153. }
  1154. else if (stsno == 2)
  1155. {
  1156. this.Invoke(new MethodInvoker(() =>
  1157. {
  1158. this.tsbtnStart.Enabled = true;
  1159. }));
  1160. SysMgr.Instance.LedPause();
  1161. }
  1162. else if (stsno == 3)
  1163. {
  1164. this.Invoke(new MethodInvoker(() =>
  1165. {
  1166. tsbtnReset_Click(null, null);
  1167. }));
  1168. }
  1169. else if (stsno == 4) //老流程张力读取
  1170. {
  1171. TensionResult tensionResult;
  1172. if (SysMgr.Instance.TensionGetValue(out tensionResult) >= 0)
  1173. {
  1174. this.Invoke(new MethodInvoker(() =>
  1175. {
  1176. this.lblTension.Text = Math.Round(tensionResult.value, 2).ToString();
  1177. this.lblTension.ForeColor = tensionResult.color;
  1178. this.lblTensionMax.Text = Math.Round(tensionResult.valueMax, 2).ToString();
  1179. this.lblTensionMax.ForeColor = tensionResult.colorMax;
  1180. this.lblTensionMin.Text = Math.Round(tensionResult.valueMin, 2).ToString();
  1181. this.lblTensionMin.ForeColor = tensionResult.colorMin;
  1182. }));
  1183. }
  1184. }
  1185. else if (stsno == 5) //新流程张力读取
  1186. {
  1187. //this.Invoke(new MethodInvoker(() =>
  1188. //{
  1189. // tsbtnReset_Click(null, null);
  1190. //}));
  1191. }
  1192. //显示实际位置
  1193. this.Invoke(new MethodInvoker(() =>
  1194. {
  1195. tsAxisState.Text = SysMgr.Instance.GetAxisPos();
  1196. }));
  1197. }
  1198. if (pn.P(SysMgr.Instance.IsRuning))
  1199. {
  1200. //继续计时
  1201. RunStartTime.Start();
  1202. }
  1203. if (pn.N(SysMgr.Instance.IsRuning))
  1204. {
  1205. //停止计时
  1206. RunStartTime.Stop();
  1207. }
  1208. if (SysMgr.Instance.IsRuning)
  1209. {
  1210. //实时显示
  1211. RunStartTime.Stop();
  1212. this.Invoke(new MethodInvoker(() =>
  1213. {
  1214. tslabelTime.Text = "实时测试:" + ((double)RunStartTime.ElapsedMilliseconds / 1000.0).ToString("0.000") + "s";
  1215. //this.Refresh();
  1216. }));
  1217. RunStartTime.Start();
  1218. }
  1219. Thread.Sleep(100);
  1220. }
  1221. catch { }
  1222. }
  1223. }
  1224. /// <summary>
  1225. /// 信号上升沿下降沿捕获
  1226. /// </summary>
  1227. class GetPN
  1228. {
  1229. bool _P = false;
  1230. bool _N = false;
  1231. /// <summary>
  1232. /// 判断上升沿
  1233. /// </summary>
  1234. /// <param name="Value"></param>
  1235. /// <returns></returns>
  1236. public bool P(bool Value)
  1237. {
  1238. if (Value && !_P)
  1239. {
  1240. _P = true;
  1241. return true;
  1242. }
  1243. if (!Value)
  1244. _P = false;
  1245. return false;
  1246. }
  1247. /// <summary>
  1248. /// 判断下降沿
  1249. /// </summary>
  1250. /// <param name="Value"></param>
  1251. /// <returns></returns>
  1252. public bool N(bool Value)
  1253. {
  1254. if (!Value && _N)
  1255. {
  1256. _N = false;
  1257. return true;
  1258. }
  1259. if (Value)
  1260. _N = true;
  1261. return false;
  1262. }
  1263. }
  1264. #endregion
  1265. #region 料号和产品编码选择
  1266. private void txtProductCode_DoubleClick(object sender, EventArgs e)
  1267. {
  1268. string pdtName = SysMgr.Instance.SelectProduct();
  1269. if (!string.IsNullOrWhiteSpace(pdtName))
  1270. this.cbProductCode.Text = pdtName;
  1271. }
  1272. private void txtProductCode_TextChanged(object sender, EventArgs e)
  1273. {
  1274. }
  1275. private void txtProductSN_DoubleClick(object sender, EventArgs e)
  1276. {
  1277. InputFrm frm = new InputFrm(null, "请输入网版编码:");
  1278. if (frm.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(frm.inputData))
  1279. {
  1280. this.cbProductSN.Text = frm.inputData;
  1281. }
  1282. else
  1283. {
  1284. this.cbProductSN.Text = "";
  1285. }
  1286. }
  1287. private string[] pdtlistData;
  1288. private string[] snlistData;
  1289. private void LoadPdtList(List<string> list)
  1290. {
  1291. this.cbProductCode.Items.Clear();
  1292. this.pdtlistData = list.ToArray();
  1293. cbProductCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
  1294. cbProductCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1295. cbProductCode.KeyDown += CobList_KeyDown;
  1296. this.cbProductCode.Text = "";
  1297. cbProductCode.Focus();
  1298. cbProductCode.SelectAll();
  1299. }
  1300. private void LoadSNList(List<string> list)
  1301. {
  1302. this.cbProductSN.Items.Clear();
  1303. this.snlistData = list.ToArray();
  1304. cbProductSN.Items.AddRange(snlistData);//比使用DataSource速度要快一些
  1305. //cbProductSN.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1306. cbProductSN.KeyDown += CobList_KeyDown;
  1307. this.cbProductSN.Text = "";
  1308. cbProductSN.Focus();
  1309. cbProductSN.SelectAll();
  1310. }
  1311. private void CobList_KeyDown(object sender, KeyEventArgs e)
  1312. {
  1313. ComboBox ctrl = sender as ComboBox;
  1314. if (e.KeyCode == Keys.Enter)
  1315. {
  1316. if (ctrl.Items.Count == 1)
  1317. ctrl.Text = ctrl.Items[0].ToString();
  1318. }
  1319. }
  1320. private void cobList_TextUpdate(object sender, EventArgs e)
  1321. {
  1322. ComboBox ctrl = sender as ComboBox;
  1323. if (ctrl.Text != null)
  1324. {
  1325. string str = ctrl.Text; //获取cb_material控件输入内
  1326. //清空combobox
  1327. ctrl.DataSource = null;
  1328. ctrl.Items.Clear();
  1329. string[] workOrderFiltered;
  1330. if (ctrl.Name == "cbProductCode")
  1331. workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1332. else
  1333. workOrderFiltered = snlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1334. ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些
  1335. // 不存在符合条件时
  1336. //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1337. ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
  1338. if (workOrderFiltered.Length > 0)
  1339. {
  1340. if (!ctrl.DroppedDown)
  1341. ctrl.DroppedDown = true; // 自动弹出下拉框
  1342. }
  1343. ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1344. }
  1345. }
  1346. #endregion
  1347. #region 界面变化
  1348. private void MainFrm_SizeChanged(object sender, EventArgs e)
  1349. {
  1350. if (this.WindowState == FormWindowState.Maximized)
  1351. {
  1352. this.WindowState = FormWindowState.Normal;
  1353. this.Top = 0;
  1354. this.Left = 0;
  1355. this.Width = SystemInformation.WorkingArea.Width;
  1356. this.Height = SystemInformation.WorkingArea.Height;
  1357. }
  1358. }
  1359. private void tsmSysUserMgr_Click(object sender, EventArgs e)
  1360. {
  1361. }
  1362. private void tabPage1_Resize(object sender, EventArgs e)
  1363. {
  1364. int allWidth = this.tabPage1.Width;
  1365. this.flpnlResultData.Width = allWidth;
  1366. kanban1.Width = kanban2.Width = kanban3.Width = kanban4.Width = kanban5.Width = kanban6.Width = (flpnlResultData.Width - 30) / 6;
  1367. tabControl1.Region = new Region(new RectangleF(this.tabPage1.Left, this.tabPage1.Top, this.tabPage1.Width, this.tabPage1.Height));
  1368. }
  1369. private void tabPage2_Resize(object sender, EventArgs e)
  1370. {
  1371. int allWidth = this.tabPage2.Width;
  1372. tabControl1.Region = new Region(new RectangleF(this.tabPage2.Left, this.tabPage2.Top, this.tabPage2.Width, this.tabPage2.Height));
  1373. }
  1374. private void MainFrm_Paint(object sender, PaintEventArgs e)
  1375. {
  1376. this.tsbtnReset.Visible = ConfMgr.Instance.SysConfigParams.ShowResetBtn;
  1377. this.chkBuzzer.Visible = ConfMgr.Instance.SysConfigParams.ShowBuzz;
  1378. this.chkDoorSensor.Visible = ConfMgr.Instance.SysConfigParams.ShowDoorAlm;
  1379. this.tsbtnDefectImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1380. this.tsbtnSizeImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1381. toolStripSeparator7.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1382. this.tsbCC.Visible = ConfMgr.Instance.SysConfigParams.ShowSizeBtn;
  1383. this.tsbQX.Visible = ConfMgr.Instance.SysConfigParams.ShowDefectBtn;
  1384. toolStripSeparator8.Visible = ConfMgr.Instance.SysConfigParams.ShowSizeBtn || ConfMgr.Instance.SysConfigParams.ShowDefectBtn;
  1385. }
  1386. private void flpProcessStep_SizeChanged(object sender, EventArgs e)
  1387. {
  1388. int splitWidth = 5;
  1389. foreach (Control item in this.flpProcessStep.Controls)
  1390. {
  1391. item.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  1392. }
  1393. this.flpProcessStep.Refresh();
  1394. this.gpbProcessList.Refresh();
  1395. }
  1396. private void cbProductSN_MouseDoubleClick(object sender, MouseEventArgs e)
  1397. {
  1398. this.cbProductSN.Text = "";
  1399. this.cbProductSN.Select();
  1400. }
  1401. #endregion
  1402. }
  1403. }