版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1560 lines
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. private void 快速调试ToolStripMenuItem_Click(object sender, EventArgs e)
  447. {
  448. DebugTestFrm frm = new DebugTestFrm();
  449. //frm.TopMost = true;
  450. frm.ShowDialog();
  451. }
  452. #endregion
  453. #region 显示图像和消息
  454. private void lstLog_DrawItem(object sender, DrawItemEventArgs e)
  455. {
  456. e.DrawBackground();
  457. if (e.Index < 0) return;
  458. try
  459. {
  460. string str = lstLog.Items[e.Index].ToString();
  461. e.Graphics.DrawString(str.Substring(1), e.Font,
  462. new SolidBrush(str[0] == 'R' ? Color.Red : (str[0] == 'Y' ? Color.Orange : Color.Black)),
  463. e.Bounds);
  464. }
  465. catch(Exception ex)
  466. {
  467. e.Graphics.DrawString(ex.Message, e.Font,
  468. new SolidBrush( Color.Red ),
  469. e.Bounds);
  470. }
  471. }
  472. /// <summary>
  473. /// 异步输出日志
  474. /// </summary>
  475. /// <param name="tag">模板标识</param>
  476. /// <param name="msg">内容</param>
  477. /// <param name="type"></param>
  478. private void AddTextEvent(string tag, string msg, WarningEnum level = WarningEnum.Normal)
  479. {
  480. lock (AddTextLock)
  481. {
  482. if (tag != null && tag != "")
  483. tag = $" - [{tag}]";
  484. var now = DateTime.Now;
  485. msg = now.ToString("HH:mm:ss fff") + tag + " - " + msg;
  486. msg = (level == WarningEnum.Normal ? "B" : level == WarningEnum.Low ? "Y" : "R") + msg;
  487. if (this.lstLog.Items.Count > 1000)
  488. this.lstLog.Items.Clear();
  489. lstLog.Items.Insert(0, msg);
  490. }
  491. }
  492. private void main_running(object sender, MainEventArgs e)
  493. {
  494. ShowMessage(e);
  495. }
  496. private delegate void ShowMessageDelegate(MainEventArgs e);
  497. private void ShowMessage(MainEventArgs e)
  498. {
  499. if (InvokeRequired)
  500. {
  501. ShowMessageDelegate smd = new ShowMessageDelegate(ShowMessage);
  502. this.BeginInvoke(smd, e);
  503. }
  504. else
  505. {
  506. AddTextEvent(e.Tag, e.Message, e.Warning);
  507. }
  508. }
  509. /// <summary>
  510. /// 自动运行流程显示
  511. /// </summary>
  512. /// <param name="sender"></param>
  513. /// <param name="e"></param>
  514. private void auto_runing(object sender, RunEventArgs e)
  515. {
  516. ShowUIEvent(e);
  517. }
  518. private delegate void ShowUIEventDelegate(RunEventArgs e);
  519. Bitmap bmp0;
  520. Bitmap bmp1;
  521. private void ShowUIEvent(RunEventArgs e)
  522. {
  523. if (InvokeRequired)
  524. {
  525. ShowUIEventDelegate smd = new ShowUIEventDelegate(ShowUIEvent);
  526. this.BeginInvoke(smd, e);
  527. }
  528. else
  529. {
  530. try
  531. {
  532. if (e.Cmd == 0) //显示SN和流程
  533. {
  534. this.cbProductSN.Text = e.SN;
  535. if (e.NewStep)
  536. {
  537. this.tabControl1.SelectTab(1);
  538. ShowNewStepProcess(e.StepProcessesList);
  539. }
  540. else
  541. {
  542. this.tabControl1.SelectTab(0);
  543. this.dgvProcess.DataSource = new BindingSource(e.StepProcessesList, null);
  544. }
  545. }
  546. else if (e.Cmd == 1) //显示当前运行步骤
  547. {
  548. this.dgvProcess.Rows[e.StepIndex].Selected = true;
  549. dgvProcess.CurrentCell = dgvProcess.Rows[e.StepIndex].Cells[1];
  550. }
  551. else if (e.Cmd == 2) //显示当前运行步骤 和步骤详情
  552. {
  553. this.dgvProcess.Rows[e.StepIndex].Cells["colValue"].Value = e.Mesg;
  554. }
  555. else if (e.Cmd == 3) //图纸比对结果
  556. {
  557. this.lblCompareResult.Text = (e.CompareResult ? "通过" : $"未通过");
  558. this.lblCompareResultCount.Text = e.Cnt.ToString();
  559. if (!e.CompareResult)
  560. {
  561. this.lblCompareResult.ForeColor = Color.Red;
  562. }
  563. else
  564. this.lblCompareResult.ForeColor = Color.Lime;
  565. }
  566. else if (e.Cmd == 4) //缺陷结果
  567. {
  568. lblDefectResult.Text = "未通过";
  569. lblDefectResultCount.Text = $"总数:{e.Cnt},详细:{e.CompareResultString}";
  570. this.toolTip1.SetToolTip(lblDefectResultCount, lblDefectResultCount.Text);
  571. this.lblDefectResult.Text = (e.CompareResult ? "通过" : "未通过");
  572. if (!e.CompareResult)
  573. {
  574. this.lblDefectResult.ForeColor = Color.Red;
  575. }
  576. else
  577. this.lblDefectResult.ForeColor = Color.Lime;
  578. }
  579. else if (e.Cmd == 5) //加载缺陷小图
  580. {
  581. ;
  582. }
  583. else if (e.Cmd == 6) //显示主图
  584. {
  585. if (e.PicIndex == 0)
  586. {
  587. bmp0 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  588. picScanner0.Image = bmp0;
  589. picScanner0.Refresh();
  590. }
  591. else
  592. {
  593. bmp1 = (Bitmap)CamDev.HImageToBitmap(e.Pic).Clone();
  594. picScanner1.Image = bmp1;
  595. picScanner1.Refresh();
  596. }
  597. }
  598. else if (e.Cmd == 7) //显示测试时间
  599. {
  600. lblTimeLen.Text = "检测时长: " + e.Time.ToString("0.000") + " 秒";
  601. }
  602. else if (e.Cmd == 8) //显示测试时间
  603. {
  604. lblOutput.Text = "当日产量: " + e.Num.ToString("0") + " 个";
  605. }
  606. else if (e.Cmd == 10) //测试结束
  607. {
  608. this.tsbtnStart.Enabled = true;
  609. this.tsbtnStop.Enabled = false;
  610. this.cbOrderCode.Enabled = true;
  611. this.cbProductCode.Enabled = true;
  612. this.cbProductSN.Enabled = true;
  613. }
  614. else if (e.Cmd == 21) //厚度显示
  615. {
  616. double value = Math.Round(e.Value.Average(), 2);
  617. double valueMax = e.Value.Max();
  618. double valueMin = e.Value.Min();
  619. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  620. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  621. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  622. this.lblHeight.Text = Math.Round(value, 2).ToString();
  623. this.lblHeight.ForeColor = color;
  624. this.lblHeightMax.Text = Math.Round(valueMax, 2).ToString();
  625. this.lblHeightMax.ForeColor = colorMax;
  626. this.lblHeightMin.Text = Math.Round(valueMin, 2).ToString();
  627. this.lblHeightMin.ForeColor = colorMin;
  628. }
  629. else if (e.Cmd == 22) //PT显示
  630. {
  631. double value = Math.Round(e.Value.Average(), 4);
  632. double valueMax = e.Value.Max();
  633. double valueMin = e.Value.Min();
  634. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  635. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  636. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  637. this.lblPT.Text = Math.Round(value, 4).ToString();
  638. this.lblPT.ForeColor = color;
  639. this.lblPTMax.Text = Math.Round(valueMax, 4).ToString();
  640. this.lblPTMax.ForeColor = colorMax;
  641. this.lblPTMin.Text = Math.Round(valueMin, 4).ToString();
  642. this.lblPTMin.ForeColor = colorMin;
  643. }
  644. else if (e.Cmd == 23) //线宽显示
  645. {
  646. double value = Math.Round(e.Value.Average(), 2);
  647. double valueMax = e.Value.Max();
  648. double valueMin = e.Value.Min();
  649. Color color = (e.Value_up + e.Value_low > 0 && (value > e.Value_up || value < e.Value_low)) ? Color.Red : Color.White;
  650. Color colorMax = (e.Value_up + e.Value_low > 0 && (valueMax > e.Value_up || valueMax < e.Value_low)) ? Color.Red : Color.White;
  651. Color colorMin = (e.Value_up + e.Value_low > 0 && (valueMin > e.Value_up || valueMin < e.Value_low)) ? Color.Red : Color.White;
  652. this.lblLineWidth.Text = Math.Round(value, 2).ToString();
  653. this.lblLineWidth.ForeColor = color;
  654. this.lblLineWidthMax.Text = Math.Round(valueMax, 2).ToString();
  655. this.lblLineWidthMax.ForeColor = colorMax;
  656. this.lblLineWidthMin.Text = Math.Round(valueMin, 2).ToString();
  657. this.lblLineWidthMin.ForeColor = colorMin;
  658. }
  659. else if (e.Cmd == 30) //新流程 厚度, 张力, pt, 线宽显示
  660. {
  661. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex +1), true);
  662. //滚动条滚动
  663. //int scrollStep = (this.flpProcessStep.VerticalScroll.Maximum / (flpProcessStep.Controls.Count - 1));
  664. this.flpProcessStep.VerticalScroll.Value = e.StepIndex * controls[0].Height > this.flpProcessStep.VerticalScroll.Maximum? this.flpProcessStep.VerticalScroll.Maximum: e.StepIndex * controls[0].Height;
  665. if (!e.ProcessType)
  666. {
  667. NewStepShow newStepShow = controls[0] as NewStepShow;
  668. if (e.Mesg == "镜头变焦")
  669. {
  670. string str1 = e.Value_ave == 0 ? "开启自动聚焦" : "关闭自动聚焦";
  671. string str2 = e.Value_up == 0 ? "自动变倍" : "手动变倍";
  672. string str3 = e.Value_low == 0 ? "自动Z轴聚焦" : "手动Z轴聚焦";
  673. string ShowData = e.Mesg + $"-{str1}-{str2}-{str3}";
  674. newStepShow.StepString = ShowData;
  675. }
  676. if (e.Mesg == "光源设置")
  677. {
  678. string ShowData = e.Mesg + $":通道号:{e.Value_up},亮度:{e.Value_low}";
  679. newStepShow.StepString = ShowData;
  680. }
  681. else
  682. {
  683. newStepShow.StepMax = e.Value_up;
  684. newStepShow.StepMin = e.Value_low;
  685. newStepShow.StepData = e.Value_ave;
  686. if (e.Value !=null && e.Value.Count > 0)
  687. {
  688. string ShowData = e.Mesg + $"1:{e.Value[0]}";
  689. for (int i = 1; i < e.Value.Count; i++)
  690. {
  691. ShowData += $",{e.Mesg}{i + 1}:{e.Value[i]}";
  692. }
  693. newStepShow.StepString = ShowData;
  694. }
  695. else
  696. newStepShow.StepString = e.Mesg;
  697. }
  698. if (e.ProcessSts == 1)
  699. newStepShow.StepStatus = NewStepShow.StepStsEnum.Testing;
  700. else if (e.ProcessSts == 2)
  701. newStepShow.StepStatus = NewStepShow.StepStsEnum.OK;
  702. else if (e.ProcessSts == 3)
  703. newStepShow.StepStatus = NewStepShow.StepStsEnum.NG;
  704. else if (e.ProcessSts == 0)
  705. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  706. else if (e.ProcessSts == 4)
  707. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  708. }
  709. else
  710. {
  711. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  712. newStepShowDef.StepString = e.Mesg;
  713. if (e.ProcessSts == 1)
  714. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Testing;
  715. else if (e.ProcessSts == 2)
  716. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.OK;
  717. else if (e.ProcessSts == 3)
  718. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.NG;
  719. else if (e.ProcessSts == 0)
  720. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  721. else if (e.ProcessSts == 4)
  722. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Error;
  723. if (e.Value_ave == 0)
  724. {
  725. newStepShowDef.StepSizeData = (int)e.Value_up;
  726. if (e.Value_up > 0)
  727. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.NG;
  728. else if (e.Value_up < 0)
  729. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  730. else if (e.Value_up == 0)
  731. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.OK;
  732. else
  733. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.Error;
  734. }
  735. else
  736. {
  737. if (e.Value_low == 0)
  738. newStepShowDef.StepDefectData = (int)e.Value_low;
  739. else if (e.Value_low > 0)
  740. newStepShowDef.StepDefectData = newStepShowDef.StepDefectData + (int)e.Value_low;
  741. //if (e.Value_low > 0)
  742. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.NG;
  743. //else if (e.Value_low < 0)
  744. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  745. //else if ((e.Value_low == 0)&&(e.Value_up == 0))
  746. // newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.OK;
  747. if ((e.Value_up == -1) && (e.Value_low == -1))
  748. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Error;
  749. else if (e.Value_up == 1)
  750. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Testing;
  751. else if (e.Value_up == 0)
  752. {
  753. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.Done;
  754. newStepShowDef.StepDefectData = (int)e.Value_low;
  755. }
  756. }
  757. }
  758. }
  759. else if (e.Cmd == 31) //忽略流程 厚度, 张力, pt, 线宽显示
  760. {
  761. Control[] controls = flpProcessStep.Controls.Find("Step_" + (e.StepIndex + 1), true);
  762. if (controls != null)
  763. {
  764. if (!e.ProcessType)
  765. {
  766. NewStepShow newStepShow = controls[0] as NewStepShow;
  767. newStepShow.StepMax = 0;
  768. newStepShow.StepMin = 0;
  769. newStepShow.StepData = 0;
  770. string ShowData = e.Mesg;
  771. newStepShow.StepString = ShowData;
  772. if (e.ProcessSts == 4)
  773. newStepShow.StepStatus = NewStepShow.StepStsEnum.Error;
  774. else
  775. newStepShow.StepStatus = NewStepShow.StepStsEnum.Skip;
  776. }
  777. else
  778. {
  779. NewStepShowDefect newStepShowDef = controls[0] as NewStepShowDefect;
  780. newStepShowDef.StepStatus = NewStepShowDefect.StepStsEnum.Skip;
  781. newStepShowDef.StepDefectData = -1;
  782. newStepShowDef.StepDefectSts = NewStepShowDefect.StepResultEnum.None;
  783. newStepShowDef.StepSizeData = -1;
  784. newStepShowDef.StepSizeSts = NewStepShowDefect.StepResultEnum.None;
  785. newStepShowDef.StepString = "未启用或被禁用";
  786. newStepShowDef.StepString = e.Mesg;
  787. }
  788. }
  789. }
  790. Application.DoEvents();
  791. }
  792. catch { }
  793. }
  794. }
  795. void ShowNewStepProcess(List<StepProcess> list)
  796. {
  797. flpProcessStep.Controls.Clear();
  798. int index = 0;
  799. int splitWidth = 5;
  800. foreach (StepProcess stepProcess in list)
  801. {
  802. index++;
  803. if (stepProcess.ProcessCode != "SizeAndDefect")
  804. {
  805. NewStepShow newStepShow = new NewStepShow();
  806. newStepShow.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  807. newStepShow.StepName = stepProcess.ProcessName;
  808. newStepShow.StepIndex = index;
  809. newStepShow.StepMax = 0;
  810. newStepShow.StepMin = 0;
  811. newStepShow.StepData = 0;
  812. newStepShow.StepString = "";
  813. newStepShow.StepStatus = NewStepShow.StepStsEnum.Wait;
  814. newStepShow.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  815. newStepShow.Name = "Step_" + index;
  816. flpProcessStep.Controls.Add(newStepShow);
  817. }
  818. else
  819. {
  820. NewStepShowDefect newStepShowDefect = new NewStepShowDefect();
  821. newStepShowDefect.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  822. newStepShowDefect.StepName = stepProcess.ProcessName;
  823. newStepShowDefect.StepIndex = index;
  824. bool opensize = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenSize");
  825. newStepShowDefect.StepSizeSts = opensize ? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  826. newStepShowDefect.StepSizeData = -1;
  827. bool opendefect = JObject.Parse(stepProcess.ProcessParams).Value<bool>("OpenDefect");
  828. newStepShowDefect.StepDefectSts = opendefect? NewStepShowDefect.StepResultEnum.Wait: NewStepShowDefect.StepResultEnum.None;
  829. newStepShowDefect.StepDefectData = -1;
  830. newStepShowDefect.StepString = "";
  831. newStepShowDefect.StepStatus = NewStepShowDefect.StepStsEnum.Wait;
  832. newStepShowDefect.Margin = new Padding(splitWidth, splitWidth, 0, 0);
  833. newStepShowDefect.Name = "Step_" + index;
  834. flpProcessStep.Controls.Add(newStepShowDefect);
  835. }
  836. }
  837. }
  838. /// <summary>
  839. /// 缺陷小图多图显示
  840. /// </summary>
  841. /// <param name="sender"></param>
  842. /// <param name="e"></param>
  843. private void auto_ShowMoreImg(object sender, ImgEventArgs e)
  844. {
  845. ShowImgEvent(e);
  846. }
  847. private delegate void ShowImgEventDelegate(ImgEventArgs e);
  848. private void ShowImgEvent(ImgEventArgs e)
  849. {
  850. if (InvokeRequired)
  851. {
  852. ShowImgEventDelegate smd = new ShowImgEventDelegate(ShowImgEvent);
  853. this.BeginInvoke(smd, e);
  854. }
  855. else
  856. {
  857. //Task<int> tt = new Task<int>(() =>
  858. //{
  859. //lock (AddPicLock)
  860. {
  861. //加载缺陷小图
  862. //纵向显示
  863. int imgWidth = this.pnlBmpList.ClientSize.Width - 50;
  864. int imgHeight = (int)((e.Bitmaps[0].Height * 1.0f / e.Bitmaps[0].Width) * imgWidth + 0.5);
  865. int splitWidth = 20;
  866. int pnlWidth = this.pnlBmpList.ClientSize.Width;
  867. int index = (int)this.gboxDefectList.Tag;
  868. //横向显示
  869. //int imgHeight = this.pnlBmpList.Height - 50;
  870. //int imgWidth = (int)((e.Bitmaps[0].Width * 1.0f / e.Bitmaps[0].Height) * imgHeight + 0.5);
  871. //int splitWidth = 20;
  872. //int pnlWidth = this.pnlBmpList.Height;
  873. //int index = (int)this.gboxDefectList.Tag;
  874. int len = e.Info.Count();
  875. int range = 100;
  876. int uselen = len > 100 ? 100 : len;
  877. for (int x = 0; x < uselen / range + 1; x++)
  878. {
  879. for (int i = 0; i < (x < (uselen / range) ? range : uselen % range); i++)
  880. {
  881. foreach (var item in e.Info[(x * range + i)]) //单个info[x] = {"1":[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]}
  882. {
  883. //统计缺陷类型
  884. SysMgr.Instance.countDefectClass(item.Value);//[["92.7542","80.85799","99.54083","86.05363","dk","0.52"]]
  885. //
  886. PictureBox picbox = new PictureBox();
  887. picbox.Width = imgWidth;
  888. picbox.Height = imgHeight;
  889. picbox.Image = (Bitmap)e.Bitmaps[(x * range + i)].Clone();
  890. picbox.Name = "imgDefect_" + index;
  891. picbox.Tag = item.Key + "," + e.X + "," + e.Y;
  892. picbox.Click += new EventHandler(defectBmpBox_Click);
  893. picbox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  894. picbox.BorderStyle = BorderStyle.FixedSingle;
  895. //picbox.Margin = new Padding((pnlWidth - picbox.Height) / 2, splitWidth, 0, 0);
  896. picbox.Margin = new Padding((pnlWidth - picbox.Width) / 2, splitWidth, 0, 0);
  897. picbox.MouseHover += simpleTip_MouseHover;
  898. picbox.Visible = true;
  899. //this.Invoke(new MethodInvoker(() =>
  900. // {
  901. this.pnlBmpList.Controls.Add(picbox);
  902. //this.Refresh();
  903. //this.dgvProcess.Refresh();
  904. //this.lstLog.Refresh();
  905. //this.statusStrip1.Refresh();
  906. // }));
  907. break;
  908. }
  909. //
  910. index++;
  911. //Thread.Sleep(10);
  912. //Application.DoEvents();
  913. }
  914. //Application.DoEvents();
  915. //this.Invoke(new MethodInvoker(() =>
  916. //{
  917. //this.Refresh();
  918. pnlBmpList.VerticalScroll.Value = pnlBmpList.VerticalScroll.Maximum;
  919. //}));
  920. //Thread.Sleep(10);
  921. }
  922. //this.Invoke(new MethodInvoker(() =>
  923. //{
  924. //this.gboxDefectList.Tag = len + (int)this.gboxDefectList.Tag;
  925. this.gboxDefectList.Tag = index;
  926. this.gboxDefectList.Text = $"缺陷图像:{index} 张";
  927. }
  928. //}));
  929. //return 0;
  930. // });
  931. // tt.Start();
  932. // await tt;
  933. }
  934. }
  935. #endregion
  936. #region 工具栏
  937. private void tsbtnImpStop_Click(object sender, EventArgs e)
  938. {
  939. SysMgr.Instance.LedPause();
  940. AddTextEvent("急停", "手动急停", WarningEnum.High);
  941. SysMgr.Instance.StatusMgr.GotoWarning( WarningEnum.High, "急停", "手动急停");
  942. SysMgr.Instance.SendStatus();
  943. SysMgr.Instance.EmergencyStop();
  944. }
  945. private void tsbOpenLight_Click(object sender, EventArgs e)
  946. {
  947. if (this.tsbOpenLight.Text == "开灯")
  948. {
  949. SysMgr.Instance.OpenFloodlight(true);
  950. this.tsbOpenLight.Text = "关灯";
  951. }
  952. else
  953. {
  954. SysMgr.Instance.OpenFloodlight(false);
  955. this.tsbOpenLight.Text = "开灯";
  956. }
  957. }
  958. private void tsbtnStart_Click(object sender, EventArgs e)
  959. {
  960. if (!SysMgr.Instance.IsRuning)
  961. {
  962. //低报警自动复位
  963. if(SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  964. {
  965. if (SysMgr.Instance.StatusMgr.Warning == WarningEnum.Low)
  966. {
  967. SysMgr.Instance.StatusMgr.ClearWarning();
  968. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  969. }
  970. }
  971. //提示正在报警中
  972. if (SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Warning)
  973. {
  974. FrmDialog.ShowDialog(this, "系统报警中!无法启动运行!", "警告", false);
  975. return;
  976. }
  977. this.Cursor = Cursors.WaitCursor;
  978. System.Windows.Forms.Application.DoEvents();
  979. if (SysMgr.Instance.StatusMgr.Status != SystemStsEnum.Pause)
  980. {
  981. ResetUI(false);
  982. AddTextEvent("运行", $"启动自动检测流程");
  983. this.lstLog.Refresh();
  984. if (SysMgr.Instance.StartRun(this, this.cbOrderCode.Text, (int)this.numDefectCnt.Value, this.cbProductCode.Text, this.cbProductSN.Text))
  985. {
  986. this.tsbtnStop.Enabled = true;
  987. this.tsbtnStart.Enabled = false;
  988. //锁定信息
  989. this.cbOrderCode.Enabled = false;
  990. this.cbProductCode.Enabled = false;
  991. this.cbProductSN.Enabled = false;
  992. //记录开始运行时间
  993. RunStartTime.Restart();
  994. }
  995. }
  996. else //暂停状态开始
  997. {
  998. if (SysMgr.Instance.ReStartRun())
  999. {
  1000. this.tsbtnStop.Enabled = true;
  1001. this.tsbtnStart.Enabled = false;
  1002. }
  1003. }
  1004. this.Cursor = Cursors.Default;
  1005. }
  1006. }
  1007. private void tsbtnStop_Click(object sender, EventArgs e)
  1008. {
  1009. AddTextEvent("暂停", "手动暂停");
  1010. this.tsbtnStart.Enabled = true;
  1011. SysMgr.Instance.StatusMgr.GotoPause();
  1012. SysMgr.Instance.SendStatus();
  1013. SysMgr.Instance.LedPause();
  1014. //this.tsbtnStart.Enabled = true;
  1015. }
  1016. private void tsbtnReset_Click(object sender, EventArgs e)
  1017. {
  1018. if (SystemIsRun())
  1019. {
  1020. DialogResult dr = DialogResult.Cancel;
  1021. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统?", "警告", true);
  1022. if (dr == DialogResult.OK)
  1023. {
  1024. this.tsbtnStart.Enabled = true;
  1025. this.tsbtnStop.Enabled = false;
  1026. Task.Factory.StartNew(() =>
  1027. {
  1028. SysMgr.Instance.LedRset(true);
  1029. SysMgr.Instance.GotoReadyPosAndIO();
  1030. SysMgr.Instance.LedRset(false);
  1031. });
  1032. ResetUI(true);
  1033. //AddTextEvent("复位", "复位完成");
  1034. }
  1035. }
  1036. }
  1037. private void tsbtnWarning_Click(object sender, EventArgs e)
  1038. {
  1039. if(SysMgr.Instance.StatusMgr.Warning != WarningEnum.Normal)
  1040. {
  1041. AddTextEvent("清除", "手动清除报警");
  1042. SysMgr.Instance.StatusMgr.ClearWarning();
  1043. SysMgr.Instance.LedReady();
  1044. if (SysMgr.Instance.IsAuto)
  1045. SysMgr.Instance.StatusMgr.GotoPause();
  1046. else
  1047. SysMgr.Instance.StatusMgr.GotoNormalStandby();
  1048. SysMgr.Instance.SendStatus();
  1049. }
  1050. }
  1051. private void tsbGoHome_Click(object sender, EventArgs e)
  1052. {
  1053. if (SystemIsRun())
  1054. {
  1055. DialogResult dr = DialogResult.Cancel;
  1056. dr = FrmDialog.ShowDialog(this, "确定要复位当前系统所有硬件位置?", "警告", true);
  1057. if (dr == DialogResult.OK)
  1058. {
  1059. this.tsbtnStart.Enabled = true;
  1060. this.tsbtnStop.Enabled = false;
  1061. this.Cursor = Cursors.WaitCursor;
  1062. System.Windows.Forms.Application.DoEvents();
  1063. Task.Factory.StartNew(() =>
  1064. {
  1065. SysMgr.Instance.LedRset(true);
  1066. SysMgr.Instance.AllResetAndGoHome();
  1067. SysMgr.Instance.LedRset(false);
  1068. });
  1069. this.Cursor = Cursors.Default;
  1070. }
  1071. }
  1072. }
  1073. //缺陷+比对与图纸查看
  1074. private void tsbtnDefectImage_Click(object sender, EventArgs e)
  1075. {
  1076. try
  1077. {
  1078. string gbxBmpPath = "";
  1079. Order temp_order = null;
  1080. if (SysMgr.Instance.GetDefectDistribution(out gbxBmpPath, out temp_order))
  1081. {
  1082. //
  1083. ToolStripButton btn = sender as ToolStripButton;
  1084. DefectImageShowFrm frm = new DefectImageShowFrm(gbxBmpPath , temp_order, string.IsNullOrEmpty(btn.Tag.ToString()) ? 0 : Convert.ToInt32(btn.Tag.ToString()));
  1085. frm.Show();
  1086. }
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
  1091. }
  1092. }
  1093. #endregion
  1094. #region 小图操作
  1095. private void defectBmpBox_Click(object sender, EventArgs e)
  1096. {
  1097. PictureBox picbox = sender as PictureBox;
  1098. if (SysMgr.Instance.IsAuto || SysMgr.Instance.StatusMgr.Status == SystemStsEnum.Auto)//检测中
  1099. {
  1100. //只查看
  1101. AddTextEvent("查看", $"运行中查看缺陷{SysMgr.Instance.IsAuto} - {SysMgr.Instance.StatusMgr.Status}");
  1102. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls, Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]));
  1103. frm.ShowDialog(this);
  1104. }
  1105. else//完成
  1106. {
  1107. AddTextEvent("查看", $"查看缺陷{ConfMgr.Instance.SysConfigParams.OpenDefectSanp}");
  1108. ImageShowFrm frm = new ImageShowFrm(this.pnlBmpList.Controls,
  1109. Convert.ToInt32(picbox.Name.Split(new char[] { '_' })[1]), ConfMgr.Instance.SysConfigParams.OpenDefectSanp);
  1110. frm.ShowDialog(this);
  1111. }
  1112. }
  1113. private void simpleTip_MouseHover(object sender, EventArgs e)
  1114. {
  1115. PictureBox pb = sender as PictureBox;
  1116. // 创建the ToolTip
  1117. ToolTip toolTip1 = new ToolTip();
  1118. // 设置显示样式
  1119. toolTip1.AutoPopDelay = 5000;//提示信息的可见时间
  1120. toolTip1.InitialDelay = 500;//事件触发多久后出现提示
  1121. toolTip1.ReshowDelay = 500;//指针从一个控件移向另一个控件时,经过多久才会显示下一个提示框
  1122. toolTip1.ShowAlways = true;//是否显示提示框
  1123. // 设置伴随的对象.
  1124. toolTip1.SetToolTip(pb, pb.Name + "[" +pb.Tag.ToString() + "]");//设置提示按钮和提示内容
  1125. }
  1126. #endregion
  1127. #region 时钟捕获
  1128. GetPN pn = new GetPN();
  1129. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  1130. {
  1131. while (backgroundWorkerDo)
  1132. {
  1133. try
  1134. {
  1135. this.Invoke(new MethodInvoker(() =>
  1136. {
  1137. this.tsslLoginTime.Text = $" 当前时间:{DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss")}";
  1138. }));
  1139. //检测按钮和实时状态
  1140. if (SysMgr.Instance.IsInit)
  1141. {
  1142. bool sts = SysMgr.Instance.WarningShowLed(DisEnableBuzz);
  1143. if (sts)
  1144. {
  1145. this.Invoke(new MethodInvoker(() =>
  1146. {
  1147. this.tsbtnStart.Enabled = true;
  1148. this.tsbtnStop.Enabled = false;
  1149. }));
  1150. }
  1151. int stsno = 0;
  1152. stsno = SysMgr.Instance.ButtonIOTrg(DisEnableDoor);
  1153. if (stsno == 1)
  1154. {
  1155. this.Invoke(new MethodInvoker(() =>
  1156. {
  1157. tsbtnStart_Click(null, null);
  1158. }));
  1159. }
  1160. else if (stsno == 2)
  1161. {
  1162. this.Invoke(new MethodInvoker(() =>
  1163. {
  1164. this.tsbtnStart.Enabled = true;
  1165. }));
  1166. SysMgr.Instance.LedPause();
  1167. }
  1168. else if (stsno == 3)
  1169. {
  1170. this.Invoke(new MethodInvoker(() =>
  1171. {
  1172. tsbtnReset_Click(null, null);
  1173. }));
  1174. }
  1175. else if (stsno == 4) //老流程张力读取
  1176. {
  1177. TensionResult tensionResult;
  1178. if (SysMgr.Instance.TensionGetValue(out tensionResult) >= 0)
  1179. {
  1180. this.Invoke(new MethodInvoker(() =>
  1181. {
  1182. this.lblTension.Text = Math.Round(tensionResult.value, 2).ToString();
  1183. this.lblTension.ForeColor = tensionResult.color;
  1184. this.lblTensionMax.Text = Math.Round(tensionResult.valueMax, 2).ToString();
  1185. this.lblTensionMax.ForeColor = tensionResult.colorMax;
  1186. this.lblTensionMin.Text = Math.Round(tensionResult.valueMin, 2).ToString();
  1187. this.lblTensionMin.ForeColor = tensionResult.colorMin;
  1188. }));
  1189. }
  1190. }
  1191. else if (stsno == 5) //新流程张力读取
  1192. {
  1193. //this.Invoke(new MethodInvoker(() =>
  1194. //{
  1195. // tsbtnReset_Click(null, null);
  1196. //}));
  1197. }
  1198. //显示实际位置
  1199. this.Invoke(new MethodInvoker(() =>
  1200. {
  1201. tsAxisState.Text = SysMgr.Instance.GetAxisPos();
  1202. }));
  1203. }
  1204. if (pn.P(SysMgr.Instance.IsRuning))
  1205. {
  1206. //继续计时
  1207. RunStartTime.Start();
  1208. }
  1209. if (pn.N(SysMgr.Instance.IsRuning))
  1210. {
  1211. //停止计时
  1212. RunStartTime.Stop();
  1213. }
  1214. if (SysMgr.Instance.IsRuning)
  1215. {
  1216. //实时显示
  1217. RunStartTime.Stop();
  1218. this.Invoke(new MethodInvoker(() =>
  1219. {
  1220. tslabelTime.Text = "实时测试:" + ((double)RunStartTime.ElapsedMilliseconds / 1000.0).ToString("0.000") + "s";
  1221. //this.Refresh();
  1222. }));
  1223. RunStartTime.Start();
  1224. }
  1225. Thread.Sleep(100);
  1226. }
  1227. catch { }
  1228. }
  1229. }
  1230. /// <summary>
  1231. /// 信号上升沿下降沿捕获
  1232. /// </summary>
  1233. class GetPN
  1234. {
  1235. bool _P = false;
  1236. bool _N = false;
  1237. /// <summary>
  1238. /// 判断上升沿
  1239. /// </summary>
  1240. /// <param name="Value"></param>
  1241. /// <returns></returns>
  1242. public bool P(bool Value)
  1243. {
  1244. if (Value && !_P)
  1245. {
  1246. _P = true;
  1247. return true;
  1248. }
  1249. if (!Value)
  1250. _P = false;
  1251. return false;
  1252. }
  1253. /// <summary>
  1254. /// 判断下降沿
  1255. /// </summary>
  1256. /// <param name="Value"></param>
  1257. /// <returns></returns>
  1258. public bool N(bool Value)
  1259. {
  1260. if (!Value && _N)
  1261. {
  1262. _N = false;
  1263. return true;
  1264. }
  1265. if (Value)
  1266. _N = true;
  1267. return false;
  1268. }
  1269. }
  1270. #endregion
  1271. #region 料号和产品编码选择
  1272. private void txtProductCode_DoubleClick(object sender, EventArgs e)
  1273. {
  1274. string pdtName = SysMgr.Instance.SelectProduct();
  1275. if (!string.IsNullOrWhiteSpace(pdtName))
  1276. this.cbProductCode.Text = pdtName;
  1277. }
  1278. private void txtProductCode_TextChanged(object sender, EventArgs e)
  1279. {
  1280. }
  1281. private void txtProductSN_DoubleClick(object sender, EventArgs e)
  1282. {
  1283. InputFrm frm = new InputFrm(null, "请输入网版编码:");
  1284. if (frm.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(frm.inputData))
  1285. {
  1286. this.cbProductSN.Text = frm.inputData;
  1287. }
  1288. else
  1289. {
  1290. this.cbProductSN.Text = "";
  1291. }
  1292. }
  1293. private string[] pdtlistData;
  1294. private string[] snlistData;
  1295. private void LoadPdtList(List<string> list)
  1296. {
  1297. this.cbProductCode.Items.Clear();
  1298. this.pdtlistData = list.ToArray();
  1299. cbProductCode.Items.AddRange(pdtlistData);//比使用DataSource速度要快一些
  1300. cbProductCode.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1301. cbProductCode.KeyDown += CobList_KeyDown;
  1302. this.cbProductCode.Text = "";
  1303. cbProductCode.Focus();
  1304. cbProductCode.SelectAll();
  1305. }
  1306. private void LoadSNList(List<string> list)
  1307. {
  1308. this.cbProductSN.Items.Clear();
  1309. this.snlistData = list.ToArray();
  1310. cbProductSN.Items.AddRange(snlistData);//比使用DataSource速度要快一些
  1311. //cbProductSN.TextUpdate += cobList_TextUpdate;//重新绑定事件
  1312. cbProductSN.KeyDown += CobList_KeyDown;
  1313. this.cbProductSN.Text = "";
  1314. cbProductSN.Focus();
  1315. cbProductSN.SelectAll();
  1316. }
  1317. private void CobList_KeyDown(object sender, KeyEventArgs e)
  1318. {
  1319. ComboBox ctrl = sender as ComboBox;
  1320. if (e.KeyCode == Keys.Enter)
  1321. {
  1322. if (ctrl.Items.Count == 1)
  1323. ctrl.Text = ctrl.Items[0].ToString();
  1324. }
  1325. }
  1326. private void cobList_TextUpdate(object sender, EventArgs e)
  1327. {
  1328. ComboBox ctrl = sender as ComboBox;
  1329. if (ctrl.Text != null)
  1330. {
  1331. string str = ctrl.Text; //获取cb_material控件输入内
  1332. //清空combobox
  1333. ctrl.DataSource = null;
  1334. ctrl.Items.Clear();
  1335. string[] workOrderFiltered;
  1336. if (ctrl.Name == "cbProductCode")
  1337. workOrderFiltered = pdtlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1338. else
  1339. workOrderFiltered = snlistData.Where(x => x.IndexOf(str, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();//忽略大小写
  1340. ctrl.Items.AddRange(workOrderFiltered);//比使用DataSource速度要快一些
  1341. // 不存在符合条件时
  1342. //设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1343. ctrl.Cursor = Cursors.Default; //保持鼠标指针原来状态,有时候鼠标指针会被下拉框覆盖,所以要进行一次设置
  1344. if (workOrderFiltered.Length > 0)
  1345. {
  1346. if (!ctrl.DroppedDown)
  1347. ctrl.DroppedDown = true; // 自动弹出下拉框
  1348. }
  1349. ctrl.SelectionStart = str.Length; // 设置光标位置,若不设置:光标位置始终保持在第一列,造成输入关键词的倒序排列
  1350. }
  1351. }
  1352. #endregion
  1353. #region 界面变化
  1354. private void MainFrm_SizeChanged(object sender, EventArgs e)
  1355. {
  1356. if (this.WindowState == FormWindowState.Maximized)
  1357. {
  1358. this.WindowState = FormWindowState.Normal;
  1359. this.Top = 0;
  1360. this.Left = 0;
  1361. this.Width = SystemInformation.WorkingArea.Width;
  1362. this.Height = SystemInformation.WorkingArea.Height;
  1363. }
  1364. }
  1365. private void tsmSysUserMgr_Click(object sender, EventArgs e)
  1366. {
  1367. }
  1368. private void tabPage1_Resize(object sender, EventArgs e)
  1369. {
  1370. int allWidth = this.tabPage1.Width;
  1371. this.flpnlResultData.Width = allWidth;
  1372. kanban1.Width = kanban2.Width = kanban3.Width = kanban4.Width = kanban5.Width = kanban6.Width = (flpnlResultData.Width - 30) / 6;
  1373. tabControl1.Region = new Region(new RectangleF(this.tabPage1.Left, this.tabPage1.Top, this.tabPage1.Width, this.tabPage1.Height));
  1374. }
  1375. private void tabPage2_Resize(object sender, EventArgs e)
  1376. {
  1377. int allWidth = this.tabPage2.Width;
  1378. tabControl1.Region = new Region(new RectangleF(this.tabPage2.Left, this.tabPage2.Top, this.tabPage2.Width, this.tabPage2.Height));
  1379. }
  1380. private void MainFrm_Paint(object sender, PaintEventArgs e)
  1381. {
  1382. this.tsbtnReset.Visible = ConfMgr.Instance.SysConfigParams.ShowResetBtn;
  1383. this.chkBuzzer.Visible = ConfMgr.Instance.SysConfigParams.ShowBuzz;
  1384. this.chkDoorSensor.Visible = ConfMgr.Instance.SysConfigParams.ShowDoorAlm;
  1385. this.tsbtnDefectImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1386. this.tsbtnSizeImage.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1387. toolStripSeparator7.Visible = ConfMgr.Instance.SysConfigParams.ShowDistribution;
  1388. this.tsbCC.Visible = ConfMgr.Instance.SysConfigParams.ShowSizeBtn;
  1389. this.tsbQX.Visible = ConfMgr.Instance.SysConfigParams.ShowDefectBtn;
  1390. toolStripSeparator8.Visible = ConfMgr.Instance.SysConfigParams.ShowSizeBtn || ConfMgr.Instance.SysConfigParams.ShowDefectBtn;
  1391. }
  1392. private void flpProcessStep_SizeChanged(object sender, EventArgs e)
  1393. {
  1394. int splitWidth = 5;
  1395. foreach (Control item in this.flpProcessStep.Controls)
  1396. {
  1397. item.Width = flpProcessStep.Width - splitWidth * 2 - 30;
  1398. }
  1399. this.flpProcessStep.Refresh();
  1400. this.gpbProcessList.Refresh();
  1401. }
  1402. private void cbProductSN_MouseDoubleClick(object sender, MouseEventArgs e)
  1403. {
  1404. this.cbProductSN.Text = "";
  1405. this.cbProductSN.Select();
  1406. }
  1407. #endregion
  1408. }
  1409. }