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

1513 строки
64 KiB

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