From 78994d1c8243018f6e37717e3ea0a0297d491bd8 Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期五, 10 七月 2020 13:10:24 +0800
Subject: [PATCH] 标签显示和列表联动修改

---
 src/Bro.M071.Process/UI/M071_MainForm.cs             |   40 +++++++++++++
 src/Bro.UI.Model.Winform/UI/CanvasImage.cs           |    2 
 src/Bro.M071.Process/M071Process.cs                  |    7 +
 src/Bro.M071.Process/UI/M071_ShortcutFrm.Designer.cs |   16 +++++
 src/Bro.M071.Process/UI/M071_ShortcutFrm.cs          |   12 +++-
 src/Bro.UI.Model.Winform/UI/Canvas.cs                |   17 ++++-
 src/Bro.UI.Model.Winform/ElementBase.cs              |    3 
 src/Bro.M071.Process/UI/M071_MainForm.Designer.cs    |   10 +++
 src/Bro.UI.Config/MenuForms/FrmOperation.cs          |   29 ++++++---
 src/Bro.M071.Process/M071Config.cs                   |    5 +
 src/Bro.M071.Process/UI/KeyIndicator.cs              |    7 +-
 11 files changed, 122 insertions(+), 26 deletions(-)

diff --git a/src/Bro.M071.Process/M071Config.cs b/src/Bro.M071.Process/M071Config.cs
index f2b54c1..b0944f2 100644
--- a/src/Bro.M071.Process/M071Config.cs
+++ b/src/Bro.M071.Process/M071Config.cs
@@ -101,5 +101,10 @@
         [Category("灞忚斀閰嶇疆")]
         [Description("true锛氱姝㈡墜鍔ㄨ緭鍏ユ潯鐮� false锛氬厑璁告墜鍔ㄨ緭鍏ユ潯鐮�")]
         public bool IsBarcodeManulInputBlocked { get; set; } = true;
+
+        [Category("MES璁剧疆")]
+        [Description("true锛氭暟鎹笂浼犺嚦MES false锛氭暟鎹笉涓婁紶")]
+        [ReadOnly(true)]
+        public bool IsEnableMESUpload { get; set; } = false;
     }
 }
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 6b0702d..7f239ef 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -378,6 +378,9 @@
                 var measurementUnitResultAndKeyUnitDataSet = GetMeasurementUnitResultAndKeyUnitData(pMeasure);
 
                 //MES杈撳嚭 todo
+                if (Config.IsEnableMESUpload)
+                { 
+                }
 
                 //Excel鎶ヨ〃杈撳嚭 锛堝崟涓骇鍝佺殑excel瀵煎嚭锛�
                 ExportProductionExcel(measurementUnitResultAndKeyUnitDataSet);
@@ -460,7 +463,7 @@
                     measurementUnitResult.ProductionMeasurementRecordsId = productionMeasurementRecords.ID;
                     measurementUnitResult.MeasurementName = MeasurementUnitResult.Name;
                     measurementUnitResult.MeasurementType = MeasurementUnitResult.MeasureType;
-                    measurementUnitResult.MeasurementValue = "";
+                    measurementUnitResult.MeasurementValue = MeasurementUnitResult.Spec.ActualValue.ToString();
                     measurementUnitResult.MeasurementResult = MeasurementUnitResult.Spec.MeasureResult.Value ? "OK" : "NG";
 
                     measurementUnitResults.Add(measurementUnitResult);
@@ -521,7 +524,7 @@
                 excelExportDto.WorksheetDataTable[excelExportDto.Worksheets[1]] = ExcelExportHelper.ListToDataTable(measurementUnitResultAndKeyUnitDataSet.MeasurementUnitResultList, measurementUnitResultColumns); ;
 
                 byte[] filecontent = ExcelExportHelper.ExportExcel(excelExportDto, false);
-                string dir = Path.Combine(Config.ImageSaveFolder, DateTime.Now.ToString("yyyyMMdd"));
+                string dir = Path.Combine(Config.ResultDataSaveFolder, DateTime.Now.ToString("yyyyMMdd"));
                 if (!Directory.Exists(dir))
                 {
                     Directory.CreateDirectory(dir);
diff --git a/src/Bro.M071.Process/UI/KeyIndicator.cs b/src/Bro.M071.Process/UI/KeyIndicator.cs
index ec6d69b..8d43b6b 100644
--- a/src/Bro.M071.Process/UI/KeyIndicator.cs
+++ b/src/Bro.M071.Process/UI/KeyIndicator.cs
@@ -139,17 +139,18 @@
 
         public override bool IsMouseCanStretchBottom(Point p)
         {
-            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width / 2)) < 10 && Math.Abs(p.Y - DisplayRect.Y - DisplayRect.Height) < 10;
+
+            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width / 2)) < (DisplayRect.Width / 3) && Math.Abs(p.Y - DisplayRect.Y - DisplayRect.Height) < (DisplayRect.Height / 3);
         }
 
         public override bool IsMouseCanStretchRight(Point p)
         {
-            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < 10 && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height / 2)) < 10;
+            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < (DisplayRect.Width / 3) && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height / 2)) < (DisplayRect.Height / 3);
         }
 
         public override bool IsMouseCanStretchRightLowerCorner(Point p)
         {
-            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < 10 && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height)) < 10;
+            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < (DisplayRect.Width / 3) && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height)) < (DisplayRect.Height / 3);
         }
 
         int x, y = 0;
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
index a7e2e8d..abd460f 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.Designer.cs
@@ -44,6 +44,7 @@
             this.btnCancelEdit = new System.Windows.Forms.Button();
             this.splitContainer1 = new System.Windows.Forms.SplitContainer();
             this.lvMeasures = new System.Windows.Forms.ListView();
+            this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.propGridKeyIndicator = new System.Windows.Forms.PropertyGrid();
             this.btnStartMeasure = new System.Windows.Forms.Button();
             this.btnReset = new System.Windows.Forms.Button();
@@ -228,6 +229,9 @@
             // 
             // lvMeasures
             // 
+            this.lvMeasures.BackColor = System.Drawing.SystemColors.Control;
+            this.lvMeasures.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+            this.columnHeader1});
             this.lvMeasures.Dock = System.Windows.Forms.DockStyle.Fill;
             this.lvMeasures.Font = new System.Drawing.Font("Tahoma", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World, ((byte)(134)));
             this.lvMeasures.FullRowSelect = true;
@@ -241,6 +245,11 @@
             this.lvMeasures.View = System.Windows.Forms.View.List;
             this.lvMeasures.SelectedIndexChanged += new System.EventHandler(this.lvMeasures_SelectedIndexChanged);
             this.lvMeasures.DoubleClick += new System.EventHandler(this.lvMeasures_DoubleClick);
+            // 
+            // columnHeader1
+            // 
+            this.columnHeader1.Text = "妫�娴嬫爣绛�";
+            this.columnHeader1.Width = 181;
             // 
             // propGridKeyIndicator
             // 
@@ -333,5 +342,6 @@
         private System.Windows.Forms.Label lblCT;
         private System.Windows.Forms.Button btnStartMeasure;
         private System.Windows.Forms.Button btnReset;
+        private System.Windows.Forms.ColumnHeader columnHeader1;
     }
 }
\ No newline at end of file
diff --git a/src/Bro.M071.Process/UI/M071_MainForm.cs b/src/Bro.M071.Process/UI/M071_MainForm.cs
index 938e116..7f507bc 100644
--- a/src/Bro.M071.Process/UI/M071_MainForm.cs
+++ b/src/Bro.M071.Process/UI/M071_MainForm.cs
@@ -38,6 +38,8 @@
                    await Task.Delay(300);
 
                    cvImage.SetScreenSize();
+                   cvImage.OnElementChangedHandle -= CvImage_OnElementChangedHandle;
+                   cvImage.OnElementChangedHandle += CvImage_OnElementChangedHandle;
                };
         }
 
@@ -119,10 +121,45 @@
         #endregion
 
         #region 鏍囩缂栬緫鍖�
+        private async void CvImage_OnElementChangedHandle(Common.Interface.IShapeElement ele)
+        {
+            this.Invoke(new Action(() =>
+            {
+                if (ele is KeyIndicator indicator)
+                {
+                    if (indicator.State == ElementState.Selected)
+                    {
+                        foreach (ListViewItem item in lvMeasures.Items)
+                        {
+                            if (item.Tag.ToString() == indicator.ID)
+                            {
+                                item.Selected = true;
+
+                                lvMeasures.EnsureVisible(item.Index);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }));
+
+            await Task.Delay(100);
+        }
+
         private void lvMeasures_SelectedIndexChanged(object sender, EventArgs e)
         {
             if (lvMeasures.SelectedItems.Count <= 0)
                 return;
+
+            foreach (ListViewItem item in lvMeasures.Items)
+            {
+                item.BackColor = SystemColors.Control;
+            }
+
+            foreach (ListViewItem item in lvMeasures.SelectedItems)
+            {
+                item.BackColor = Color.Orange;
+            }
 
             var ele = cvImage.Elements.FirstOrDefault(u => u.ID == lvMeasures.SelectedItems[0].Tag.ToString());
             propGridKeyIndicator.SelectedObject = ele;
@@ -167,11 +204,12 @@
             if (lvMeasures.SelectedItems.Count <= 0)
                 return;
 
+            cvImage.Elements.ToList().ForEach(u => u.State = ElementState.Normal);
             var ele = cvImage.Elements.FirstOrDefault(u => u.ID == lvMeasures.SelectedItems[0].Tag.ToString());
             if (ele != null)
             {
                 ele.State = ElementState.Selected;
-                cvImage.Invalidate();
+                //cvImage.Invalidate();
             }
         }
         #endregion
diff --git a/src/Bro.M071.Process/UI/M071_ShortcutFrm.Designer.cs b/src/Bro.M071.Process/UI/M071_ShortcutFrm.Designer.cs
index eca6a77..3a1c2ce 100644
--- a/src/Bro.M071.Process/UI/M071_ShortcutFrm.Designer.cs
+++ b/src/Bro.M071.Process/UI/M071_ShortcutFrm.Designer.cs
@@ -34,6 +34,7 @@
             this.chkBlockBeep = new System.Windows.Forms.CheckBox();
             this.chkManualInputForbidden = new System.Windows.Forms.CheckBox();
             this.btnLightSwitch = new System.Windows.Forms.Button();
+            this.chkEnableMESUpload = new System.Windows.Forms.CheckBox();
             this.flowLayoutPanel1.SuspendLayout();
             this.SuspendLayout();
             // 
@@ -43,6 +44,7 @@
             this.flowLayoutPanel1.Controls.Add(this.chkBlockSafetyBeam);
             this.flowLayoutPanel1.Controls.Add(this.chkBlockBeep);
             this.flowLayoutPanel1.Controls.Add(this.chkManualInputForbidden);
+            this.flowLayoutPanel1.Controls.Add(this.chkEnableMESUpload);
             this.flowLayoutPanel1.Controls.Add(this.btnLightSwitch);
             this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
             this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
@@ -96,13 +98,24 @@
             // 
             // btnLightSwitch
             // 
-            this.btnLightSwitch.Location = new System.Drawing.Point(419, 3);
+            this.btnLightSwitch.Location = new System.Drawing.Point(543, 3);
             this.btnLightSwitch.Name = "btnLightSwitch";
             this.btnLightSwitch.Size = new System.Drawing.Size(75, 36);
             this.btnLightSwitch.TabIndex = 5;
             this.btnLightSwitch.Text = "鏃ュ厜鐏紑鍏�";
             this.btnLightSwitch.UseVisualStyleBackColor = true;
             this.btnLightSwitch.Click += new System.EventHandler(this.btnLightSwitch_Click);
+            // 
+            // chkEnableMESUpload
+            // 
+            this.chkEnableMESUpload.AutoSize = true;
+            this.chkEnableMESUpload.Location = new System.Drawing.Point(419, 3);
+            this.chkEnableMESUpload.Name = "chkEnableMESUpload";
+            this.chkEnableMESUpload.Size = new System.Drawing.Size(118, 17);
+            this.chkEnableMESUpload.TabIndex = 6;
+            this.chkEnableMESUpload.Text = "鍚敤MES鏁版嵁涓婁紶";
+            this.chkEnableMESUpload.UseVisualStyleBackColor = true;
+            this.chkEnableMESUpload.CheckedChanged += new System.EventHandler(this.chkEnableMESUpload_CheckedChanged);
             // 
             // M071_ShortcutFrm
             // 
@@ -126,5 +139,6 @@
         private System.Windows.Forms.CheckBox chkBlockBeep;
         private System.Windows.Forms.CheckBox chkManualInputForbidden;
         private System.Windows.Forms.Button btnLightSwitch;
+        private System.Windows.Forms.CheckBox chkEnableMESUpload;
     }
 }
\ No newline at end of file
diff --git a/src/Bro.M071.Process/UI/M071_ShortcutFrm.cs b/src/Bro.M071.Process/UI/M071_ShortcutFrm.cs
index d5961a9..01c11b7 100644
--- a/src/Bro.M071.Process/UI/M071_ShortcutFrm.cs
+++ b/src/Bro.M071.Process/UI/M071_ShortcutFrm.cs
@@ -29,8 +29,8 @@
         M071Config Config => Process?.IConfig as M071Config;
         M071Process Process_M071 => Process as M071Process;
 
-        protected override bool IsLogin 
-        { 
+        protected override bool IsLogin
+        {
             get => base.IsLogin;
             set
             {
@@ -42,7 +42,7 @@
                     {
                         this.Invoke(new Action(() =>
                         {
-                            chkBlockSafetyBeam.Enabled = chkBlockSaftyDoor.Enabled = IsLogin;
+                            chkEnableMESUpload.Enabled = chkBlockSafetyBeam.Enabled = chkBlockSaftyDoor.Enabled = IsLogin;
                         }));
                     }
                 });
@@ -63,6 +63,7 @@
                         chkBlockSafetyBeam.Checked = Config.IsSafetyBeamBlocked;
                         chkBlockSaftyDoor.Checked = Config.IsSafetyDoorBlocked;
                         chkManualInputForbidden.Checked = Config.IsBarcodeManulInputBlocked;
+                        chkEnableMESUpload.Checked = Config.IsEnableMESUpload;
                     }));
                 }
             });
@@ -94,5 +95,10 @@
             isLightOn = !isLightOn;
             Process_M071.SwitchLight(isLightOn);
         }
+
+        private void chkEnableMESUpload_CheckedChanged(object sender, EventArgs e)
+        {
+            Config.IsEnableMESUpload = chkEnableMESUpload.Checked;
+        }
     }
 }
diff --git a/src/Bro.UI.Config/MenuForms/FrmOperation.cs b/src/Bro.UI.Config/MenuForms/FrmOperation.cs
index 025c4fb..e1c128c 100644
--- a/src/Bro.UI.Config/MenuForms/FrmOperation.cs
+++ b/src/Bro.UI.Config/MenuForms/FrmOperation.cs
@@ -28,16 +28,21 @@
             LoadProcessCode();
             LoadProductionCode();
 
-            Task.Run(() =>
-            {
-                Thread.Sleep(1000);
+            //Task.Run(() =>
+            //{
+            //    Thread.Sleep(1000);
 
-                if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
-                {
-                    LoadProcess();
-                    _isFirstLoad = false;
-                }
-            });
+            //    if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
+            //    {
+            //        LoadProcess();
+            //        _isFirstLoad = false;
+            //    }
+            //});
+            //if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
+            //{
+            //    LoadProcess();
+            //    _isFirstLoad = false;
+            //}
         }
 
         #region Load Codes
@@ -128,6 +133,12 @@
 
         private void FrmOperation_Load(object sender, System.EventArgs e)
         {
+            if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
+            {
+                LoadProcess();
+                _isFirstLoad = false;
+            }
+
             btnStart.Enabled = true;
         }
 
diff --git a/src/Bro.UI.Model.Winform/ElementBase.cs b/src/Bro.UI.Model.Winform/ElementBase.cs
index 899ff14..c0feb9d 100644
--- a/src/Bro.UI.Model.Winform/ElementBase.cs
+++ b/src/Bro.UI.Model.Winform/ElementBase.cs
@@ -190,9 +190,8 @@
                 if (state != value)
                 {
                     ElementState preState = state;
-                    state = value;
+                    Set(ref state, value);
                     EventRouter.ChangeElementsMouseState?.Invoke(this, preState, state);
-
                     switch (state)
                     {
                         case ElementState.MouseHover:
diff --git a/src/Bro.UI.Model.Winform/UI/Canvas.cs b/src/Bro.UI.Model.Winform/UI/Canvas.cs
index 16ae7be..9b7102f 100644
--- a/src/Bro.UI.Model.Winform/UI/Canvas.cs
+++ b/src/Bro.UI.Model.Winform/UI/Canvas.cs
@@ -237,7 +237,7 @@
             {
                 ele.IsEnabled = e.CheckedState;
             }
-            OnElementChanged();
+            OnElementChanged(null);
         }
 
         private void dgElements_SelectionChanged(object sender, EventArgs e)
@@ -270,7 +270,7 @@
 
         private void Elements_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
         {
-            OnElementChanged();
+            OnElementChanged(null);
 
             foreach (IShapeElement ele in Elements)
             {
@@ -281,14 +281,17 @@
 
         private void Ele_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
-            OnElementChanged();
+            OnElementChanged(sender as IShapeElement);
         }
 
-        private void OnElementChanged()
+        private void OnElementChanged(IShapeElement ele)
         {
+            if (ele != null)
+                OnElementChangedHandle?.Invoke(ele);
+
             if (InvokeRequired)
             {
-                Invoke(new Action(() => OnElementChanged()));
+                Invoke(new Action(() => OnElementChanged(ele)));
             }
             else
             {
@@ -543,5 +546,9 @@
             }
         }
         #endregion
+
+        #region 浜嬩欢
+        public event Action<IShapeElement> OnElementChangedHandle;
+        #endregion
     }
 }
diff --git a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
index 0de094a..3bd6941 100644
--- a/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
+++ b/src/Bro.UI.Model.Winform/UI/CanvasImage.cs
@@ -358,6 +358,8 @@
                     MouseState = MouseState.Normal;
                 }
             }
+
+            this.Invalidate();
         }
         #endregion
 

--
Gitblit v1.8.0