Browse Source

样品类型和厂商如果在列表中没有则添加到配置文件中。

@wang_qi0307 5 năm trước cách đây
mục cha
commit
eed0c9cd6f
1 tập tin đã thay đổi với 51 bổ sung6 xóa
  1. 51 6
      HOZProject/FormUnitControl.cs

+ 51 - 6
HOZProject/FormUnitControl.cs

@@ -39,6 +39,10 @@ namespace HOZProject
         private int st_flag = 0;
 
         WebResult wr = new WebResult("127.0.0.1", "18080");
+
+        String[] sT;
+        String[] firms;
+        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         #endregion
 
         #region 构造函数
@@ -1418,6 +1422,36 @@ namespace HOZProject
 
             
             cfm.Save(@"E:\test.cfg");
+
+            List<String> _sT = sT.ToList();
+            if(_sT.IndexOf(cbbWYP.Text)<0)
+            {
+                _sT.Add(cbbWYP.Text);
+                sT = _sT.ToArray();
+                string wsT = "";
+                for(int i=0;i<sT.Length;i++)
+                {
+                    wsT += sT[i] + ",";
+                }
+                wsT = wsT.Substring(0, wsT.Length - 1);
+                config.AppSettings.Settings["Sample_Type"].Value = wsT;
+            }
+            List<String> _firms = firms.ToList();
+            if (_firms.IndexOf(cbbWCS.Text) < 0)
+            {
+                _firms.Add(cbbWCS.Text);
+                firms = _firms.ToArray();
+                string wFirms = "";
+                for (int i = 0; i < firms.Length; i++)
+                {
+                    wFirms += firms[i] + ",";
+                }
+                wFirms = wFirms.Substring(0, wFirms.Length - 1);
+                config.AppSettings.Settings["Firm"].Value = wFirms;
+            }
+            config.Save(ConfigurationSaveMode.Modified);
+            ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件   
+            reloadconfig();
         }
 
         private void btnReadConfig_Click(object sender, EventArgs e)
@@ -1440,22 +1474,33 @@ namespace HOZProject
         }
 
         private void FormUnitControl_Load(object sender, EventArgs e)
+        {
+            reloadconfig();
+            cbbWYP.SelectedIndex = 0;
+
+            cbbWCS.SelectedIndex = 0;
+
+            cbbWXZ.SelectedIndex = 0;
+        }
+
+        private void reloadconfig()
         {
             String sample_Type = ConfigurationManager.AppSettings["Sample_Type"];
             String firm = ConfigurationManager.AppSettings["Firm"];
-            String[] sT = sample_Type.Split(',');
-            for(int i=0;i<sT.Length;i++)
+            sT = sample_Type.Split(',');
+            cbbWYP.Items.Clear();
+            for (int i = 0; i < sT.Length; i++)
             {
                 cbbWYP.Items.Add(sT[i]);
             }
-            cbbWYP.SelectedIndex = 0;
-            String[] firms = firm.Split(',');
+            
+            firms = firm.Split(',');
+            cbbWCS.Items.Clear();
             for (int i = 0; i < firms.Length; i++)
             {
                 cbbWCS.Items.Add(firms[i]);
             }
-            cbbWCS.SelectedIndex = 0;
-            cbbWXZ.SelectedIndex = 0;
+            
         }
     }
 }