From 8bd46da0c9fbfe39a65d75b1d85692d8783f5905 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期三, 15 九月 2021 10:50:54 +0800
Subject: [PATCH] 现场修改

---
 src/Bro.M071.Process/UI/M071_MainForm.cs |   80 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index 4893258..8849ca7 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -7,8 +7,10 @@
 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;
@@ -22,6 +24,9 @@
         M071Config Config => Process?.IConfig as M071Config;
         M071Process Process_M071 => Process as M071Process;
 
+        System.Threading.Timer _refreshUITimer = null;
+
+
         public M071_MainForm()
         {
             InitializeComponent();
@@ -34,6 +39,7 @@
 
             tscEditLocation.Visible = tsmiShowEditor.Checked = false;
 
+            _refreshUITimer = new System.Threading.Timer(OnRefreshUI, null, -1, -1);
             this.Load += async (s, e) =>
                {
                    await Task.Delay(300);
@@ -42,7 +48,7 @@
                    cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle;
                    cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle;
 
-                   timer1.Enabled = true;
+                   //timer1.Enabled = true;
 
                    btnReset.Text = $"澶嶄綅锛堥暱鎸墈Config.FullResetRequiredDuration}绉掑ぇ澶嶄綅锛�";
 
@@ -117,6 +123,9 @@
             Process_M071.OnFullResetDone -= Process_M071_FullResetDone;
             Process_M071.OnFullResetDone += Process_M071_FullResetDone;
 
+            Process_M071.OnResetDone -= Process_M071_ResetDone;
+            Process_M071.OnResetDone += Process_M071_ResetDone;
+
             Config.PropertyChanged -= Config_PropertyChanged;
             Config.PropertyChanged += Config_PropertyChanged;
 
@@ -125,6 +134,14 @@
 
             Process_M071.OnCheckHintUpload = OnCheckHintUpload;
             Process_M071.OnOperatorLogin = OnOperatorLogin;
+        }
+
+        private void Process_M071_ResetDone()
+        {
+            lblCT.BeginInvoke(new Action(() =>
+            {
+                lblCT.Text = "";
+            }));
         }
 
         private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -266,6 +283,12 @@
         #endregion
 
         #region 鏍囩缁撴灉鏄剧ず
+
+        private void OnRefreshUI(object state)
+        {
+            cvImage.Invoke(new Action(() => Refresh()));
+        }
+
         private async void Process_M071_OnElementUpdated(Common.Interface.IShapeElement obj)
         {
             //this.Invoke(new Action(() =>
@@ -294,7 +317,8 @@
                     (ele as KeyIndicator).Text = keyIndicator.Text;
                     (ele as KeyIndicator).ResultState = keyIndicator.ResultState;
 
-                    this.Invalidate();
+                    //this.Invalidate();
+                    _refreshUITimer.Change(1000, -1);
                 }));
             }
 
@@ -316,6 +340,10 @@
             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)
@@ -516,7 +544,7 @@
 
         private void timer1_Tick(object sender, EventArgs e)
         {
-            cvImage.Refresh();
+            //cvImage.Refresh();
         }
 
         private void lblOperator_DoubleClick(object sender, EventArgs e)
@@ -557,5 +585,51 @@
                 }));
             });
         }
+
+        bool isStart = true;
+        private void button1_Click(object sender, EventArgs e)
+        {
+            Task.Run(async () =>
+            {
+                try
+                {
+                    for (int j = 0; j < 10000; j++)
+                    {
+                        int i = 0;
+
+                        if (isStart)
+                        {
+                            cvImage.Elements.ToList().ForEach(ele =>
+                            {
+                                if (ele is KeyIndicator indicator)
+                                {
+                                    indicator.Text = "";
+                                    indicator.ResultState = null;
+                                }
+                            });
+                        }
+                        else
+                        {
+                            cvImage.Elements.ToList().ForEach(ele =>
+                            {
+                                if (ele is KeyIndicator indicator)
+                                {
+                                    indicator.Text = (i++).ToString();
+                                    indicator.ResultState = true;
+                                }
+                            });
+                        }
+                        isStart = !isStart;
+                        cvImage.BeginInvoke(new Action(() => Refresh()));
+                        LogAsync(DateTime.Now, $"UI Refresh {j}", "");
+                        await Task.Delay(300);
+                    }
+                }
+                catch (Exception ex)
+                {
+                }
+
+            });
+        }
     }
 }

--
Gitblit v1.8.0