版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

1506 wiersze
64 KiB

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