From e69865a1a3739740201bac8782b721da35d49923 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期一, 25 一月 2021 18:45:28 +0800
Subject: [PATCH] 1. gocator添加重试和清理缓存操作 2. gts板卡调整监听频率 3. 记录产品数据使用filsstream避免程序崩溃影响

---
 src/Bro.M071.Process/UI/M071_MainForm.cs |  135 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 120 insertions(+), 15 deletions(-)

diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index e875fd6..c92a0ec 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -1,13 +1,16 @@
 锘縰sing Bro.Common.Base;
 using Bro.Common.Helper;
 using Bro.UI.Model.Winform;
+using Bro.UI.Model.Winform.UI;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.IO;
 using System.Linq;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using static Bro.Common.Helper.EnumHelper;
@@ -40,6 +43,12 @@
                    cvImage.SetScreenSize();
                    cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle;
                    cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle;
+
+                   timer1.Enabled = true;
+
+                   btnReset.Text = $"澶嶄綅锛堥暱鎸墈Config.FullResetRequiredDuration}绉掑ぇ澶嶄綅锛�";
+
+                   lblCT.Text = tsslError.Text = "";
                };
         }
 
@@ -86,6 +95,8 @@
                            item.Tag = u.Id;
                            lvMeasures.Items.Add(item);
                        });
+
+                       lblOperator.Text = string.IsNullOrWhiteSpace(Process_M071.OperatorCode) ? "NotLogin" : Process_M071.OperatorCode;
                    }));
             }
             catch (Exception ex)
@@ -113,6 +124,9 @@
 
             Process_M071.OnElementUpdated -= Process_M071_OnElementUpdated;
             Process_M071.OnElementUpdated += Process_M071_OnElementUpdated;
+
+            Process_M071.OnCheckHintUpload = OnCheckHintUpload;
+            Process_M071.OnOperatorLogin = OnOperatorLogin;
         }
 
         private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -135,6 +149,27 @@
         {
             tscEditLocation.Visible = tsmiShowEditor.Checked;
             tscEditLocation.BringToFront();
+        }
+
+        private void tsmiRefreshLabels_Click(object sender, EventArgs e)
+        {
+            cvImage.Elements.Clear();
+            lvMeasures.Items.Clear();
+
+            Config.MeasurementUnitCollection.ForEach(u =>
+            {
+                if (!u.IsEnabled)
+                    return;
+
+                var ele = new KeyIndicator(u.Id, u.DisplayLocation);
+                cvImage.Elements.Add(ele);
+
+                ListViewItem item = new ListViewItem(u.GetDisplayText());
+                item.Tag = u.Id;
+                lvMeasures.Items.Add(item);
+            });
+
+            this.Invalidate();
         }
         #endregion
 
@@ -235,6 +270,23 @@
         #region 鏍囩缁撴灉鏄剧ず
         private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj)
         {
+            //this.Invoke(new Action(() =>
+            //{
+            //    if (obj is KeyIndicator keyIndicator)
+            //    {
+            //        var ele = cvImage.Elements.FirstOrDefault(u => u.ID == keyIndicator.ID);
+
+            //        //(ele as KeyIndicator).Text = keyIndicator.Text;
+            //        //(ele as KeyIndicator).ResultState = keyIndicator.ResultState;
+            //        if (ele != null)
+            //        {
+            //            ele = keyIndicator;
+            //        }
+
+            //        this.Invalidate();
+            //    }                
+            //}));
+
             if (obj is KeyIndicator keyIndicator)
             {
                 this.Invoke(new Action(() =>
@@ -263,10 +315,18 @@
             {
                 _barcode += keyStr.ToUpper();
             }
+            else if (keyStr.Length == 2 && keyStr.StartsWith("D"))
+            {
+                _barcode += keyStr.Substring(1).ToUpper();
+            }
+            else if (keyStr.StartsWith("NumPad"))
+            {
+                _barcode += keyStr.Replace("NumPad", "");
+            }
 
             if (e.KeyValue == 13)
             {
-                txtBarcode.Text = _barcode;
+                Process_M071.BarCode = txtBarcode.Text = _barcode;
                 _barcode = "";
             }
 
@@ -278,7 +338,7 @@
 
         private void txtBarcode_TextChanged(object sender, EventArgs e)
         {
-            Process_M071.BarCode = txtBarcode.Text.Trim();
+            //Process_M071.BarCode = txtBarcode.Text.Trim();
         }
 
         private void M071_MainForm_OnClearBarcode()
@@ -292,7 +352,7 @@
         {
             if (lblMachineState.IsHandleCreated)
             {
-                lblMachineState.BeginInvoke(new Action(() =>
+                lblMachineState.Invoke(new Action(() =>
                 {
                     switch (state)
                     {
@@ -303,7 +363,6 @@
 
                             btnStartMeasure.Text = "寮�濮嬫祴閲�";
                             btnStartMeasure.Enabled = false;
-                            btnStartMeasure.BackColor = Color.Red;
                             break;
                         case MachineState.Pause:
                             btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Yellow;
@@ -312,25 +371,22 @@
 
                             btnStartMeasure.Text = "缁х画娴嬮噺";
                             btnStartMeasure.Enabled = true;
-                            btnStartMeasure.BackColor = Color.Lime;
                             break;
                         case MachineState.Ready:
                             btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
-                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.White;
+                            btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.Black;
                             lblMachineState.Text = "灏辩华";
-                            
+
                             btnStartMeasure.Text = "寮�濮嬫祴閲�";
                             btnStartMeasure.Enabled = true;
-                            btnStartMeasure.BackColor = Color.Lime;
                             break;
                         case MachineState.Running:
-                            btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Lime;
+                            btnStartMeasure.BackColor = lblMachineState.BackColor = Color.Transparent;
                             btnStartMeasure.ForeColor = lblMachineState.ForeColor = Color.DarkGreen;
                             lblMachineState.Text = "杩愯";
 
                             btnStartMeasure.Text = "鏆傚仠娴嬮噺";
                             btnStartMeasure.Enabled = true;
-                            btnStartMeasure.BackColor = Color.Lime;
                             break;
                         case MachineState.Unknown:
                             btnStartMeasure.BackColor = lblMachineState.BackColor = SystemColors.Control;
@@ -338,7 +394,6 @@
                             lblMachineState.Text = "鏈煡";
 
                             btnStartMeasure.Enabled = false;
-                            btnStartMeasure.BackColor = Color.Red;
                             break;
                     }
                 }));
@@ -368,11 +423,17 @@
                     lblProductionState.ForeColor = Color.White;
                     lblProductionState.Text = "OK";
                 }
-                else
+                else if (result == 0)
                 {
                     lblProductionState.BackColor = Color.Red;
                     lblProductionState.ForeColor = Color.White;
                     lblProductionState.Text = "NG";
+                }
+                else
+                {
+                    lblProductionState.BackColor = Color.White;
+                    lblProductionState.ForeColor = Color.Red;
+                    lblProductionState.Text = "NA";
                 }
 
                 //btnStartMeasure.Text = "寮�濮嬫祴閲�";
@@ -424,11 +485,11 @@
             }
             else if (btnStartMeasure.Text == "缁х画娴嬮噺")
             {
-                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 0 } }, null, null);
+                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 10 } }, null, null);
             }
             else
             {
-                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 1 } }, null, null);
+                Process_M071.SwitchJobStatus(new OperationConfigBase() { InputPara = new List<int>() { 11 } }, null, null);
             }
         }
 
@@ -450,7 +511,7 @@
                 Process_M071.Reset(null, null, null);
             }
 
-            Process_M071.ResetTimer.Change(1000 * 5, -1);
+            Process_M071.ResetTimer.Change(1000 * Config.FullResetRequiredDuration, -1);
         }
 
         private void btnReset_MouseUp(object sender, MouseEventArgs e)
@@ -458,5 +519,49 @@
             Process_M071.ResetTimer.Change(-1, -1);
         }
         #endregion
+
+        private void timer1_Tick(object sender, EventArgs e)
+        {
+            cvImage.Refresh();
+        }
+
+        private void lblOperator_DoubleClick(object sender, EventArgs e)
+        {
+            InputWindow inputFrm = new InputWindow("璇疯緭鍏ユ搷浣滃憳宸ュ彿");
+            if (inputFrm.ShowDialog() == DialogResult.OK)
+            {
+                Process_M071.OperatorCode = inputFrm.Input;
+            }
+        }
+
+        private void OnOperatorLogin(string operatorCode)
+        {
+            this.Invoke(new Action(() =>
+            {
+                lblOperator.Text = operatorCode;
+            }));
+        }
+
+        private async void OnCheckHintUpload(string hintMsg, bool isAlarm)
+        {
+            await Task.Run(() =>
+            {
+                this.Invoke(new Action(() =>
+                {
+                    if (!string.IsNullOrWhiteSpace(hintMsg))
+                    {
+                        stStripHint.Visible = true;
+                        tsslError.Text = hintMsg;
+
+                        tsslError.BackColor = isAlarm ? Color.Red : Color.Green;
+                    }
+                    else
+                    {
+                        stStripHint.Visible = false;
+                        tsslError.Text = "";
+                    }
+                }));
+            });
+        }
     }
 }

--
Gitblit v1.8.0