From 5241a8f6377dfd1618610dd15fd05ed6f51c8ba2 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期三, 16 十二月 2020 11:19:45 +0800
Subject: [PATCH] 1. 添加默认流程和默认产品功能 2. 修改批量建立检测项功能

---
 src/Bro.UI.Config/MenuForms/FrmOperation.Designer.cs   |  157 +++++++--------
 src/Bro.Common.Model/Helper/SettingHelper.cs           |  208 +++++++++++---------
 src/Bro.UI.Config/MenuForms/FrmOperation.resx          |    4 
 src/Bro.UI.Config/MenuForms/FrmOperation.cs            |  106 ++--------
 src/Bro.Process/ProcessControl.cs                      |    1 
 src/Bro.M071.Process/M071Models.cs                     |   27 ++
 src/Bro.M071.Process/UI/M071_PatchInsertMeasurement.cs |   61 +++--
 7 files changed, 275 insertions(+), 289 deletions(-)

diff --git a/src/Bro.Common.Model/Helper/SettingHelper.cs b/src/Bro.Common.Model/Helper/SettingHelper.cs
index 99f93c2..f22e684 100644
--- a/src/Bro.Common.Model/Helper/SettingHelper.cs
+++ b/src/Bro.Common.Model/Helper/SettingHelper.cs
@@ -7,95 +7,145 @@
 
 namespace Bro.Common.Helper
 {
-    public class SettingHelper
+    public static class SettingHelper
     {
         const string SETTINGFILE = "Setting.json";
-        const string PROPERTY_PRODUCTIONCODES = "ProductionCodes";
-        const string PROPERTY_CONFIGPATH = "ConfigPath";
-        const string PROPERTY_PROCESSCODES = "ProcessCodes";
-        const string PROPERTY_DESCRIPTION = "Description";
-        const string PROPERTY_ICONPATH = "IconPath";
 
-        static string ConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE);
-        //static JObject data = null;
-        //static JObject Data
-        //{
-        //    get
-        //    {
-        //        if (File.Exists(ConfigPath))
-        //        {
-        //            using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8))
-        //            {
-        //                string dataStr = reader.ReadToEnd();
-        //                data = JsonConvert.DeserializeObject<JObject>(dataStr);
-        //            }
-        //        }
-        //        return data;
-        //    }
-        //}
+        public static SettingInfo SettingInfo = null;
+        static string SettingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE);
 
-        public static JObject GetSettingData()
+        static SettingHelper()
         {
-            JObject settingData = null;
-            if (File.Exists(ConfigPath))
+            if (File.Exists(SettingPath))
             {
-                using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8))
+                using (StreamReader reader = new StreamReader(SettingPath, System.Text.Encoding.UTF8))
                 {
                     string dataStr = reader.ReadToEnd();
-                    settingData = JsonConvert.DeserializeObject<JObject>(dataStr);
+                    SettingInfo = JsonConvert.DeserializeObject<SettingInfo>(dataStr);
                 }
             }
-            return settingData;
         }
 
         public static List<string> GetProductionCodes()
         {
-            List<string> codes = new List<string>();
-            var Data = GetSettingData();
-            if (Data != null && Data.ContainsKey(PROPERTY_PRODUCTIONCODES))
+            if (SettingInfo.ProductionCodes.Count == 0)
             {
-                codes = Data.Value<JArray>(PROPERTY_PRODUCTIONCODES).ToList().ConvertAll(u => u.ToString());
+                SettingInfo.ProductionCodes.Add("Default");
             }
 
-            if (codes.Count == 0)
+            if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProduction))
             {
-                codes.Add("Default");
+                if (SettingInfo.ProductionCodes.Contains(SettingInfo.DefaultProduction))
+                {
+                    SettingInfo.ProductionCodes.Remove(SettingInfo.DefaultProduction);
+                    SettingInfo.ProductionCodes.Insert(0, SettingInfo.DefaultProduction);
+                }
             }
 
-            return codes;
+            return SettingInfo.ProductionCodes;
         }
 
         public static List<string> GetProcessCodes()
         {
-            List<string> codes = new List<string>();
-            var Data = GetSettingData();
-            if (Data != null && Data.ContainsKey(PROPERTY_PROCESSCODES))
+            if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProcess))
             {
-                codes = Data.Value<JArray>(PROPERTY_PROCESSCODES).ToList().ConvertAll(u => u.ToString());
+                if (SettingInfo.ProcessCodes.Contains(SettingInfo.DefaultProcess))
+                {
+                    SettingInfo.ProcessCodes.Remove(SettingInfo.DefaultProcess);
+                    SettingInfo.ProcessCodes.Insert(0, SettingInfo.DefaultProcess);
+                }
             }
-            return codes;
+
+            return SettingInfo.ProcessCodes;
         }
 
         public static void AddNewProductionCode(string code)
         {
-            var dataTemp = GetSettingData();
-
-            if (!dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES))
+            if (!SettingInfo.ProductionCodes.Contains(code))
             {
-                dataTemp.Add(PROPERTY_PRODUCTIONCODES, new JArray());
+                SettingInfo.ProductionCodes.Add(code);
             }
 
-            if (dataTemp != null && dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES))
-            {
-                List<string> codes = GetProductionCodes();
-                if (!codes.Contains(code))
-                {
-                    codes.Add(code);
-                }
-                dataTemp[PROPERTY_PRODUCTIONCODES] = new JArray(codes);
+            SaveSettingInfo();
+        }
 
-                string newDataStr = JsonConvert.SerializeObject(dataTemp, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto });
-                using (StreamWriter writer = new StreamWriter(ConfigPath, false, System.Text.Encoding.UTF8))
+        public static string GetConfigFilePath()
+        {
+            return SettingInfo.ConfigPath;
+        }
+
+        public static string GetProgramDescription()
+        {
+            if (string.IsNullOrWhiteSpace(SettingInfo.Description))
+            {
+                SettingInfo.Description = "浼偗妫嚜鍔ㄥ寲鎶�鏈湁闄愬叕鍙�";
+            }
+
+            return SettingInfo.Description;
+        }
+
+        public static string GetProgramIcon()
+        {
+            string iconPath = SettingInfo.IconPath;
+            if (string.IsNullOrWhiteSpace(iconPath) || !File.Exists(iconPath))
+            {
+                iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico");
+            }
+
+            if (!File.Exists(iconPath))
+            {
+                iconPath = "";
+            }
+            return iconPath;
+        }
+
+        #region 淇濆瓨
+        public static void SetDefaultProcess(string processCode)
+        {
+            if (SettingInfo.DefaultProcess != processCode)
+            {
+                SettingInfo.DefaultProcess = processCode;
+                SaveSettingInfo();
+            }
+        }
+
+        public static void SetDefaultProduction(string productionCode)
+        {
+            if (SettingInfo.DefaultProduction != productionCode)
+            {
+                SettingInfo.DefaultProduction = productionCode;
+                SaveSettingInfo();
+            }
+        }
+
+        public static void SetDefault(string processCode,string productionCode)
+        {
+            bool isChanged = false;
+            if (SettingInfo.DefaultProcess != processCode)
+            {
+                isChanged = true;
+                SettingInfo.DefaultProcess = processCode;
+            }
+
+            if (SettingInfo.DefaultProduction != productionCode)
+            {
+                isChanged = true;
+                SettingInfo.DefaultProduction = productionCode;
+            }
+
+            if (isChanged)
+            {
+                SaveSettingInfo();
+            }
+        }
+
+        static object saveLock = new object();
+        private static void SaveSettingInfo()
+        {
+            string newDataStr = JsonConvert.SerializeObject(SettingInfo);
+            lock (saveLock)
+            {
+                using (StreamWriter writer = new StreamWriter(SettingPath, false, System.Text.Encoding.UTF8))
                 {
                     writer.Write(newDataStr);
                     writer.Flush();
@@ -103,46 +153,20 @@
                 }
             }
         }
+        #endregion
+    }
 
-        public static string GetConfigFilePath()
-        {
-            string path = "";
-            var Data = GetSettingData();
-            if (Data != null && Data.ContainsKey(PROPERTY_CONFIGPATH))
-            {
-                path = Data.Value<string>(PROPERTY_CONFIGPATH);
-            }
+    public class SettingInfo
+    {
+        public List<string> ProcessCodes { get; set; } = new List<string>();
+        public List<string> ProductionCodes { get; set; } = new List<string>();
 
-            return path;
-        }
+        public string DefaultProcess { get; set; }
 
-        public static string GetProgramDescription()
-        {
-            string desc = "浼偗妫嚜鍔ㄥ寲鎶�鏈湁闄愬叕鍙�";
-            var Data = GetSettingData();
-            if (Data != null && Data.ContainsKey(PROPERTY_DESCRIPTION))
-            {
-                desc = Data.Value<string>(PROPERTY_DESCRIPTION);
-            }
+        public string DefaultProduction { get; set; }
 
-            return desc;
-        }
-
-        public static string GetProgramIcon()
-        {
-            string iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico");
-
-            if (!File.Exists(iconPath))
-            {
-                iconPath = "";
-            }
-            var Data = GetSettingData();
-            if (Data != null && Data.ContainsKey(PROPERTY_ICONPATH))
-            {
-                iconPath = Data.Value<string>(PROPERTY_ICONPATH);
-            }
-
-            return iconPath;
-        }
+        public string ConfigPath { get; set; }
+        public string Description { get; set; }
+        public string IconPath { get; set; }
     }
 }
diff --git a/src/Bro.M071.Process/M071Models.cs b/src/Bro.M071.Process/M071Models.cs
index 44fa305..ed4c138 100644
--- a/src/Bro.M071.Process/M071Models.cs
+++ b/src/Bro.M071.Process/M071Models.cs
@@ -24,17 +24,31 @@
         [TypeConverter(typeof(KeyNameDictConverter))]
         public string Key { get; set; }
 
+        [Category("榛樿閰嶇疆")]
+        [Description("鏄惁榛樿灏哄閰嶇疆")]
+        public bool IsDefault { get; set; } = false;
+
+        //[Category("浣嶇疆閰嶇疆")]
+        //[Description("鍗曢敭鍦ㄩ敭鐩樺钩闈㈠浘涓婄殑浣嶇疆鏄剧ず")]
+        //public RectangleF KeyRect { get; set; } = new RectangleF(0, 0, 0, 0);
+
         [Category("浣嶇疆閰嶇疆")]
-        [Description("鍗曢敭鍦ㄩ敭鐩樺钩闈㈠浘涓婄殑浣嶇疆鏄剧ず")]
-        public Rectangle KeyRect { get; set; } = new Rectangle();
+        [Description("鍗曢敭宸︿笂瑙掑潗鏍�")]
+        [TypeConverter(typeof(ComplexObjectConvert))]
+        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
+        public CustomizedPoint KeyPosition { get; set; } = new CustomizedPoint();
+
+        [Category("浣嶇疆閰嶇疆")]
+        [Description("鍗曢敭灏哄")]
+        public SizeF KeySize { get; set; } = new SizeF();
 
         [Category("浣嶇疆閰嶇疆")]
         [Description("鍗曢敭涔嬪悗闂撮殭浣嶇疆")]
-        public Rectangle IntervalRect { get; set; } = new Rectangle();
+        public SizeF IntervalSize { get; set; } = new SizeF();
 
         public string GetDisplayText()
         {
-            return $"{Key}:{KeyRect.X},{KeyRect.Y},{KeyRect.Width},{KeyRect.Height}";
+            return $"{(IsDefault ? "Default" : Key)}:{KeyPosition.X},{KeyPosition.Y},{KeySize.Width},{KeySize.Height}";
         }
     }
 
@@ -70,6 +84,11 @@
         [Description("妫�娴嬬畻娉曡矾寰�")]
         [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
         public string AlgorithemPath { get; set; }
+
+        [Category("鏄剧ず閰嶇疆")]
+        [Description("鏄剧ず鍖哄煙澶у皬")]
+        [DisplayName("鏍囩澶у皬")]
+        public Size DisplayRect { get; set; }
     }
 
     public class KeyResult : IComplexDisplay
diff --git a/src/Bro.M071.Process/UI/M071_PatchInsertMeasurement.cs b/src/Bro.M071.Process/UI/M071_PatchInsertMeasurement.cs
index 59f538a..b67f13c 100644
--- a/src/Bro.M071.Process/UI/M071_PatchInsertMeasurement.cs
+++ b/src/Bro.M071.Process/UI/M071_PatchInsertMeasurement.cs
@@ -43,7 +43,7 @@
             btnInsertMeasurement.Enabled = false;
             btnInsertMeasurement.Text = "鐢熸垚涓�傘�傘��";
 
-            string measureType = cboMeasureType.Text;
+            MeasureType measureType = cboMeasureType.SelectedItem as MeasureType;
             string startKey = cboStartKey.Text;
             string endKey = cboEndKey.Text;
 
@@ -56,7 +56,7 @@
             btnInsertMeasurement.Text = "鐢熸垚妫�娴嬮」";
         }
 
-        private async Task<string> PatchInsertMeasurement(string measureType, string startKey, string endKey)
+        private async Task<string> PatchInsertMeasurement(MeasureType measureType, string startKey, string endKey)
         {
             return await Task.Run(() =>
              {
@@ -64,7 +64,6 @@
                  int endIndex = Config.KeyNameCollection.IndexOf(endKey);
 
                  KeyLocation startRect = Config.KeyLocationCollection.FirstOrDefault(u => u.Key == startKey);
-                 //KeyLocation endRect = Config.KeyLocationCollection.FirstOrDefault(u => u.Key == endKey);
                  if (startRect == null)
                  {
                      return $"鏈厤缃畕(startRect == null ? startKey : "")}鐨勬樉绀轰綅缃�";
@@ -75,22 +74,31 @@
                      return "璧峰閿笉鑳藉皬浜庣粨鏉熼敭";
                  }
 
-                 switch (measureType)
+                 RectangleF curKeyRect = new RectangleF((float)startRect.KeyPosition.X, (float)startRect.KeyPosition.Y, startRect.KeySize.Width, startRect.KeySize.Height);
+                 KeyLocation curKey = null;
+
+                 switch (measureType.Code)
                  {
                      case "Slant":
                          {
                              for (int i = startIndex; i <= endIndex; i++)
                              {
-                                 int curKeyEdge_X = (i - startIndex + 1) * (startRect.KeyRect.Width + startRect.IntervalRect.Width) + startRect.KeyRect.X - startRect.IntervalRect.Width;
+                                 curKey = Config.KeyLocationCollection.FirstOrDefault(u => u.Key == Config.KeyNameCollection[i]);
+                                 if (curKey == null)
+                                 {
+                                     curKey = Config.KeyLocationCollection.FirstOrDefault(u => u.IsDefault);
+                                 }
 
-                                 int lableX = (curKeyEdge_X + curKeyEdge_X - startRect.KeyRect.Width - 25) / 2;
-                                 int lable_Up_Y = startRect.KeyRect.Y + (startRect.KeyRect.Height - 25) / 2;
+                                 int lableX = (int)((curKeyRect.X + curKeyRect.X + curKey.KeySize.Width - measureType.DisplayRect.Width) / 2.0);
+                                 int lable_Up_Y = (int)(startRect.KeyPosition.Y + (startRect.KeySize.Height - measureType.DisplayRect.Height) / 2.0);
 
                                  MeasurementUnit mUnitUp = new MeasurementUnit();
-                                 mUnitUp.MeasureType = measureType;
+                                 mUnitUp.MeasureType = measureType.Code;
                                  mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "All" });
-                                 mUnitUp.DisplayLocation = new Rectangle(lableX, lable_Up_Y, 25, 25);
+                                 mUnitUp.DisplayLocation = new Rectangle(lableX, lable_Up_Y, measureType.DisplayRect.Width, measureType.DisplayRect.Height);
                                  Config.MeasurementUnitCollection.Add(mUnitUp);
+
+                                 curKeyRect.Offset(curKey.KeySize.Width + curKey.IntervalSize.Width, 0);
                              }
                          }
                          break;
@@ -98,39 +106,44 @@
                          {
                              for (int i = startIndex; i < endIndex; i++)
                              {
-                                 int curKeyEdge_X = (i - startIndex + 1) * (startRect.KeyRect.Width + startRect.IntervalRect.Width) + startRect.KeyRect.X - startRect.IntervalRect.Width;
-                                 int nextKeyStart_X = curKeyEdge_X + startRect.IntervalRect.Width;
+                                 curKey = Config.KeyLocationCollection.FirstOrDefault(u => u.Key == Config.KeyNameCollection[i]);
+                                 if (curKey == null)
+                                 {
+                                     curKey = Config.KeyLocationCollection.FirstOrDefault(u => u.IsDefault);
+                                 }
 
-                                 int lableX = (curKeyEdge_X + nextKeyStart_X - 25) / 2;
-                                 int lable_Up_Y = startRect.KeyRect.Y + 4;
-                                 int lable_Down_y = startRect.KeyRect.Y + startRect.KeyRect.Height - 4 - 12;
+                                 int lableX = (int)((curKeyRect.X + curKey.KeySize.Width + curKeyRect.X + curKey.KeySize.Width + curKey.IntervalSize.Width - measureType.DisplayRect.Width) / 2.0);
+                                 int lable_Up_Y = (int)startRect.KeyPosition.Y + 4;
+                                 int lable_Down_y = (int)(startRect.KeyPosition.Y + startRect.KeySize.Height - 4 - measureType.DisplayRect.Height);
 
                                  MeasurementUnit mUnitUp = new MeasurementUnit();
-                                 mUnitUp.MeasureType = measureType;
+                                 mUnitUp.MeasureType = measureType.Code;
                                  mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z2" });
                                  mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i + 1], KeyResultId = "Z1" });
-                                 mUnitUp.DisplayLocation = new Rectangle(lableX, lable_Up_Y, 25, 12);
+                                 mUnitUp.DisplayLocation = new Rectangle(lableX, lable_Up_Y, measureType.DisplayRect.Width, measureType.DisplayRect.Height);
                                  Config.MeasurementUnitCollection.Add(mUnitUp);
 
                                  MeasurementUnit mUnitDown = new MeasurementUnit();
-                                 mUnitDown.MeasureType = measureType;
+                                 mUnitDown.MeasureType = measureType.Code;
                                  mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z4" });
                                  mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i + 1], KeyResultId = "Z3" });
-                                 mUnitDown.DisplayLocation = new Rectangle(lableX, lable_Down_y, 25, 12);
+                                 mUnitDown.DisplayLocation = new Rectangle(lableX, lable_Down_y, measureType.DisplayRect.Width, measureType.DisplayRect.Height);
                                  Config.MeasurementUnitCollection.Add(mUnitDown);
+
+                                 curKeyRect.Offset(curKey.KeySize.Width + curKey.IntervalSize.Width, 0);
                              }
                          }
                          break;
                      case "RowAlignment":
                          {
-                             int start_X = startRect.KeyRect.X + startRect.KeyRect.Width / 3;
-                             int end_X = (startRect.KeyRect.Width + startRect.IntervalRect.Width) * (endIndex - startIndex) + startRect.KeyRect.X + startRect.KeyRect.Width * 2 / 3;
+                             int start_X = (int)(startRect.KeyPosition.X + startRect.KeySize.Width / 3.0);
+                             int end_X = (int)((startRect.KeySize.Width + startRect.IntervalSize.Width) * (endIndex - startIndex) + startRect.KeyPosition.X + startRect.KeySize.Width * 2.0 / 3.0);
 
-                             int lable_Up_Y = startRect.KeyRect.Y - 6;
-                             int lable_Down_Y = startRect.KeyRect.Y + startRect.KeyRect.Height - 6;
+                             int lable_Up_Y = (int)startRect.KeyPosition.Y - 6;
+                             int lable_Down_Y = (int)(startRect.KeyPosition.Y + startRect.KeySize.Height - 6);
 
                              MeasurementUnit mUnitUp = new MeasurementUnit();
-                             mUnitUp.MeasureType = measureType;
+                             mUnitUp.MeasureType = measureType.Code;
                              for (int i = startIndex; i < endIndex; i++)
                              {
                                  mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z2" });
@@ -141,7 +154,7 @@
                              Config.MeasurementUnitCollection.Add(mUnitUp);
 
                              MeasurementUnit mUnitDown = new MeasurementUnit();
-                             mUnitDown.MeasureType = measureType;
+                             mUnitDown.MeasureType = measureType.Code;
                              for (int i = startIndex; i < endIndex; i++)
                              {
                                  mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z4" });
diff --git a/src/Bro.Process/ProcessControl.cs b/src/Bro.Process/ProcessControl.cs
index 8a4c27f..359e771 100644
--- a/src/Bro.Process/ProcessControl.cs
+++ b/src/Bro.Process/ProcessControl.cs
@@ -45,7 +45,6 @@
 
         #region Event
         public event Action<string, Bitmap, string> OnBitmapOutput;
-        //public event Action<string, object> OnObjectOutput;
         public Action<DateTime, Exception> OnExceptionOccured { get; set; }
         public event Action<DeviceState> OnProcessStateChanged;
         public event Action<DateTime, string, string> OnLog;
diff --git a/src/Bro.UI.Config/MenuForms/FrmOperation.Designer.cs b/src/Bro.UI.Config/MenuForms/FrmOperation.Designer.cs
index 6e021e7..8377642 100644
--- a/src/Bro.UI.Config/MenuForms/FrmOperation.Designer.cs
+++ b/src/Bro.UI.Config/MenuForms/FrmOperation.Designer.cs
@@ -31,39 +31,71 @@
             this.components = new System.ComponentModel.Container();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmOperation));
             this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+            this.btnStart = new System.Windows.Forms.Button();
+            this.imgList = new System.Windows.Forms.ImageList(this.components);
             this.plProcess = new System.Windows.Forms.Panel();
             this.cboProcessCode = new System.Windows.Forms.ComboBox();
             this.lblProcessCode = new System.Windows.Forms.Label();
+            this.btnLoad = new System.Windows.Forms.Button();
+            this.imgListLoad = new System.Windows.Forms.ImageList(this.components);
             this.plProduct = new System.Windows.Forms.Panel();
             this.cboProductionCode = new System.Windows.Forms.ComboBox();
             this.lblProductionCode = new System.Windows.Forms.Label();
-            this.plOperation = new System.Windows.Forms.Panel();
-            this.btnStart = new System.Windows.Forms.Button();
-            this.imgList = new System.Windows.Forms.ImageList(this.components);
-            this.btnLoad = new System.Windows.Forms.Button();
-            this.imgListLoad = new System.Windows.Forms.ImageList(this.components);
             this.tableLayoutPanel1.SuspendLayout();
             this.plProcess.SuspendLayout();
             this.plProduct.SuspendLayout();
-            this.plOperation.SuspendLayout();
             this.SuspendLayout();
             // 
             // tableLayoutPanel1
             // 
             this.tableLayoutPanel1.ColumnCount = 1;
             this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
-            this.tableLayoutPanel1.Controls.Add(this.plProcess, 0, 0);
-            this.tableLayoutPanel1.Controls.Add(this.plProduct, 0, 1);
-            this.tableLayoutPanel1.Controls.Add(this.plOperation, 0, 2);
+            this.tableLayoutPanel1.Controls.Add(this.btnStart, 0, 7);
+            this.tableLayoutPanel1.Controls.Add(this.plProcess, 0, 1);
+            this.tableLayoutPanel1.Controls.Add(this.btnLoad, 0, 5);
+            this.tableLayoutPanel1.Controls.Add(this.plProduct, 0, 3);
             this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
             this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
+            this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(15, 3, 15, 3);
             this.tableLayoutPanel1.Name = "tableLayoutPanel1";
-            this.tableLayoutPanel1.RowCount = 3;
+            this.tableLayoutPanel1.RowCount = 9;
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F));
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F));
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F));
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 5F));
             this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
             this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
-            this.tableLayoutPanel1.Size = new System.Drawing.Size(184, 214);
+            this.tableLayoutPanel1.Size = new System.Drawing.Size(184, 427);
             this.tableLayoutPanel1.TabIndex = 0;
+            // 
+            // btnStart
+            // 
+            this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.btnStart.AutoSize = true;
+            this.btnStart.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.btnStart.Font = new System.Drawing.Font("瀹嬩綋", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.btnStart.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
+            this.btnStart.ImageIndex = 0;
+            this.btnStart.ImageList = this.imgList;
+            this.btnStart.Location = new System.Drawing.Point(3, 132);
+            this.btnStart.Name = "btnStart";
+            this.btnStart.Size = new System.Drawing.Size(178, 35);
+            this.btnStart.TabIndex = 1;
+            this.btnStart.Text = "  鍚�  鍔�";
+            this.btnStart.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
+            this.btnStart.UseVisualStyleBackColor = true;
+            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
+            // 
+            // imgList
+            // 
+            this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
+            this.imgList.TransparentColor = System.Drawing.Color.Transparent;
+            this.imgList.Images.SetKeyName(0, "start_32px.png");
+            this.imgList.Images.SetKeyName(1, "stop_32px.png");
             // 
             // plProcess
             // 
@@ -71,7 +103,7 @@
             this.plProcess.Controls.Add(this.cboProcessCode);
             this.plProcess.Controls.Add(this.lblProcessCode);
             this.plProcess.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.plProcess.Location = new System.Drawing.Point(3, 3);
+            this.plProcess.Location = new System.Drawing.Point(3, 8);
             this.plProcess.Name = "plProcess";
             this.plProcess.Size = new System.Drawing.Size(178, 29);
             this.plProcess.TabIndex = 0;
@@ -90,11 +122,36 @@
             // lblProcessCode
             // 
             this.lblProcessCode.AutoSize = true;
-            this.lblProcessCode.Location = new System.Drawing.Point(4, 11);
+            this.lblProcessCode.Location = new System.Drawing.Point(4, 8);
             this.lblProcessCode.Name = "lblProcessCode";
             this.lblProcessCode.Size = new System.Drawing.Size(67, 13);
             this.lblProcessCode.TabIndex = 0;
             this.lblProcessCode.Text = "娴佺▼浠g爜锛�";
+            // 
+            // btnLoad
+            // 
+            this.btnLoad.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.btnLoad.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.btnLoad.Font = new System.Drawing.Font("瀹嬩綋", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.btnLoad.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
+            this.btnLoad.ImageKey = "load_32px.png";
+            this.btnLoad.ImageList = this.imgListLoad;
+            this.btnLoad.Location = new System.Drawing.Point(3, 86);
+            this.btnLoad.Name = "btnLoad";
+            this.btnLoad.Size = new System.Drawing.Size(178, 35);
+            this.btnLoad.TabIndex = 0;
+            this.btnLoad.Text = "  杞�  鍏�";
+            this.btnLoad.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
+            this.btnLoad.UseMnemonic = false;
+            this.btnLoad.UseVisualStyleBackColor = false;
+            this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
+            // 
+            // imgListLoad
+            // 
+            this.imgListLoad.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgListLoad.ImageStream")));
+            this.imgListLoad.TransparentColor = System.Drawing.Color.Transparent;
+            this.imgListLoad.Images.SetKeyName(0, "load_32px.png");
             // 
             // plProduct
             // 
@@ -102,7 +159,7 @@
             this.plProduct.Controls.Add(this.cboProductionCode);
             this.plProduct.Controls.Add(this.lblProductionCode);
             this.plProduct.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.plProduct.Location = new System.Drawing.Point(3, 38);
+            this.plProduct.Location = new System.Drawing.Point(3, 48);
             this.plProduct.Name = "plProduct";
             this.plProduct.Size = new System.Drawing.Size(178, 27);
             this.plProduct.TabIndex = 1;
@@ -121,79 +178,16 @@
             // lblProductionCode
             // 
             this.lblProductionCode.AutoSize = true;
-            this.lblProductionCode.Location = new System.Drawing.Point(4, 9);
+            this.lblProductionCode.Location = new System.Drawing.Point(4, 6);
             this.lblProductionCode.Name = "lblProductionCode";
             this.lblProductionCode.Size = new System.Drawing.Size(67, 13);
             this.lblProductionCode.TabIndex = 0;
             this.lblProductionCode.Text = "浜у搧浠g爜锛�";
             // 
-            // plOperation
-            // 
-            this.plOperation.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
-            | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-            this.plOperation.Controls.Add(this.btnStart);
-            this.plOperation.Controls.Add(this.btnLoad);
-            this.plOperation.Location = new System.Drawing.Point(3, 71);
-            this.plOperation.Name = "plOperation";
-            this.plOperation.Size = new System.Drawing.Size(178, 140);
-            this.plOperation.TabIndex = 2;
-            // 
-            // btnStart
-            // 
-            this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-            this.btnStart.AutoSize = true;
-            this.btnStart.Cursor = System.Windows.Forms.Cursors.Hand;
-            this.btnStart.Font = new System.Drawing.Font("瀹嬩綋", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnStart.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
-            this.btnStart.ImageIndex = 0;
-            this.btnStart.ImageList = this.imgList;
-            this.btnStart.Location = new System.Drawing.Point(10, 82);
-            this.btnStart.Name = "btnStart";
-            this.btnStart.Size = new System.Drawing.Size(150, 35);
-            this.btnStart.TabIndex = 1;
-            this.btnStart.Text = "  鍚�  鍔�";
-            this.btnStart.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
-            this.btnStart.UseVisualStyleBackColor = true;
-            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
-            // 
-            // imgList
-            // 
-            this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
-            this.imgList.TransparentColor = System.Drawing.Color.Transparent;
-            this.imgList.Images.SetKeyName(0, "start_32px.png");
-            this.imgList.Images.SetKeyName(1, "stop_32px.png");
-            // 
-            // btnLoad
-            // 
-            this.btnLoad.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
-            | System.Windows.Forms.AnchorStyles.Right)));
-            this.btnLoad.Cursor = System.Windows.Forms.Cursors.Hand;
-            this.btnLoad.Font = new System.Drawing.Font("瀹嬩綋", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.btnLoad.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
-            this.btnLoad.ImageKey = "load_32px.png";
-            this.btnLoad.ImageList = this.imgListLoad;
-            this.btnLoad.Location = new System.Drawing.Point(10, 24);
-            this.btnLoad.Name = "btnLoad";
-            this.btnLoad.Size = new System.Drawing.Size(150, 35);
-            this.btnLoad.TabIndex = 0;
-            this.btnLoad.Text = "  杞�  鍏�";
-            this.btnLoad.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
-            this.btnLoad.UseMnemonic = false;
-            this.btnLoad.UseVisualStyleBackColor = false;
-            this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
-            // 
-            // imgListLoad
-            // 
-            this.imgListLoad.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgListLoad.ImageStream")));
-            this.imgListLoad.TransparentColor = System.Drawing.Color.Transparent;
-            this.imgListLoad.Images.SetKeyName(0, "load_32px.png");
-            // 
             // FrmOperation
             // 
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
-            this.ClientSize = new System.Drawing.Size(184, 214);
+            this.ClientSize = new System.Drawing.Size(184, 427);
             this.Controls.Add(this.tableLayoutPanel1);
             this.Name = "FrmOperation";
             this.Text = "FrmOperation";
@@ -204,8 +198,6 @@
             this.plProcess.PerformLayout();
             this.plProduct.ResumeLayout(false);
             this.plProduct.PerformLayout();
-            this.plOperation.ResumeLayout(false);
-            this.plOperation.PerformLayout();
             this.ResumeLayout(false);
 
         }
@@ -215,7 +207,6 @@
         private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
         private System.Windows.Forms.Panel plProcess;
         private System.Windows.Forms.Panel plProduct;
-        private System.Windows.Forms.Panel plOperation;
         private System.Windows.Forms.ComboBox cboProcessCode;
         private System.Windows.Forms.Label lblProcessCode;
         private System.Windows.Forms.ComboBox cboProductionCode;
diff --git a/src/Bro.UI.Config/MenuForms/FrmOperation.cs b/src/Bro.UI.Config/MenuForms/FrmOperation.cs
index 455f1aa..43152d5 100644
--- a/src/Bro.UI.Config/MenuForms/FrmOperation.cs
+++ b/src/Bro.UI.Config/MenuForms/FrmOperation.cs
@@ -27,22 +27,6 @@
 
             LoadProcessCode();
             LoadProductionCode();
-
-            //Task.Run(() =>
-            //{
-            //    Thread.Sleep(1000);
-
-            //    if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
-            //    {
-            //        LoadProcess();
-            //        _isFirstLoad = false;
-            //    }
-            //});
-            //if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
-            //{
-            //    LoadProcess();
-            //    _isFirstLoad = false;
-            //}
         }
 
         #region Load Codes
@@ -71,7 +55,7 @@
                 pCodes = systemProcessCodes;
             }
 
-            if (pCodes.Count == 1 && pCodes[0] == "")
+            if (pCodes.Count == 1)
             {
                 plProcess.Visible = false;
                 _processCode = pCodes[0];
@@ -79,12 +63,21 @@
             }
             else
             {
-                pCodes.Remove("");
+                pCodes.RemoveAll(p => string.IsNullOrWhiteSpace(p));
             }
 
             if (pCodes.Count > 1)
             {
                 plProcess.Visible = true;
+
+                //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProcess))
+                //{
+                //    if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProcess))
+                //    {
+                //        pCodes.Remove(SettingHelper.SettingInfo.DefaultProcess);
+                //        pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProcess);
+                //    }
+                //}
 
                 cboProcessCode.SelectedIndexChanged -= cboProcessCode_SelectedIndexChanged;
                 UIHelper.SetCombo(cboProcessCode, pCodes, "", "");
@@ -109,6 +102,16 @@
             if (pCodes.Count > 1)
             {
                 plProduct.Visible = true;
+
+                //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProduction))
+                //{
+                //    if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProduction))
+                //    {
+                //        pCodes.Remove(SettingHelper.SettingInfo.DefaultProduction);
+                //        pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProduction);
+                //    }
+                //}
+
                 cboProductionCode.SelectedIndexChanged -= cboProductionCode_SelectedIndexChanged;
                 UIHelper.SetCombo(cboProductionCode, pCodes, "", "");
                 cboProductionCode.SelectedIndexChanged += cboProductionCode_SelectedIndexChanged;
@@ -133,12 +136,6 @@
 
         private void FrmOperation_Load(object sender, System.EventArgs e)
         {
-            //if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad)
-            //{
-            //    LoadProcess();
-            //    _isFirstLoad = false;
-            //}
-
             btnStart.Enabled = true;
         }
 
@@ -148,6 +145,8 @@
 
             LogAsync(DateTime.Now, "杞藉叆娴佺▼");
             LoadProcess();
+
+            SettingHelper.SetDefault(_processCode, _productionCode);
         }
 
         bool isStart = true;
@@ -161,11 +160,8 @@
 
             btnStart.Enabled = false;
 
-            //Task.Run(() =>
-            //{
             try
             {
-                //if (Process.ProcessState != EnumHelper.DeviceState.DSOpen)
                 if (isStart)
                 {
                     await ProcessOperation(true);
@@ -183,10 +179,8 @@
             }
             finally
             {
-                //this.BeginInvoke(new Action(() => btnStart.Enabled = true));
                 btnStart.Enabled = true;
             }
-            //});
         }
 
         string _currentProcssCode = "";
@@ -204,7 +198,6 @@
                     return;
                 }
 
-                //Process.OnProcessStateChanged += Process_OnProcessStateChanged;
                 Process.OnLog -= Process_OnLog;
                 Process.OnLog += Process_OnLog;
 
@@ -222,80 +215,27 @@
             LogAsync(dt, prefix, msg);
         }
 
-        //private void Process_OnProcessStateChanged(EnumHelper.DeviceState state)
-        //{
-        //    try
-        //    {
-        //        if (InvokeRequired)
-        //        {
-        //            this.Invoke(new Action<EnumHelper.DeviceState>(Process_OnProcessStateChanged), state);
-        //        }
-        //        else
-        //        {
-        //            try
-        //            {
-        //                btnStart.Enabled = true;
-
-        //                switch (state)
-        //                {
-        //                    case EnumHelper.DeviceState.DSOpen:
-        //                        btnStart.Text = "  鍋�  姝�";
-        //                        btnStart.ImageIndex = 1;
-        //                        btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen);
-
-        //                        btnLoad.Enabled = false;
-        //                        break;
-        //                    case EnumHelper.DeviceState.DSClose:
-        //                        btnStart.Text = "  鍚�  鍔�";
-        //                        btnStart.ImageIndex = 0;
-        //                        btnStart.BackColor = SystemColors.Control;
-
-        //                        btnLoad.Enabled = true;
-        //                        break;
-        //                    default:
-        //                        break;
-        //                }
-
-        //                this.Refresh();
-        //            }
-        //            catch (Exception ex)
-        //            {
-        //            }
-        //        }
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //    }
-        //}
-
         private async Task ProcessOperation(bool isStart)
         {
             if (isStart)
             {
                 await Task.Run(() => Process.Open());
 
-                //this.BeginInvoke(new Action(() =>
-                //{
                 btnStart.Text = "  鍋�  姝�";
                 btnStart.ImageIndex = 1;
                 btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen);
 
                 btnLoad.Enabled = false;
-                //}));
-
             }
             else
             {
                 await Task.Run(() => Process.Close());
 
-                //this.BeginInvoke(new Action(() =>
-                //{
                 btnStart.Text = "  鍚�  鍔�";
                 btnStart.ImageIndex = 0;
                 btnStart.BackColor = SystemColors.Control;
 
                 btnLoad.Enabled = true;
-                //}));
             }
         }
     }
diff --git a/src/Bro.UI.Config/MenuForms/FrmOperation.resx b/src/Bro.UI.Config/MenuForms/FrmOperation.resx
index d3a1d92..33117b6 100644
--- a/src/Bro.UI.Config/MenuForms/FrmOperation.resx
+++ b/src/Bro.UI.Config/MenuForms/FrmOperation.resx
@@ -125,7 +125,7 @@
         AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
         LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
         ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADm
-        CgAAAk1TRnQBSQFMAgEBAgEAAfgBAAH4AQABGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
+        CgAAAk1TRnQBSQFMAgEBAgEAARABAQEQAQEBGAEAARgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
         AwABYAMAARgDAAEBAQABCAYAAQkYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
         AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
         AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
@@ -182,7 +182,7 @@
         AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
         LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
         ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD4
-        CAAAAk1TRnQBSQFMAwEBAAH4AQAB+AEAARgBAAEYAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
+        CAAAAk1TRnQBSQFMAwEBAAEQAQEBEAEBARgBAAEYAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
         AWADAAEYAwABAQEAAQgGAAEJGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEA
         AfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEA
         AYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFm

--
Gitblit v1.8.0