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

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