瀏覽代碼

add save config; SettingForm tabIndex

weijw 5 月之前
父節點
當前提交
cc40705d25
共有 6 個文件被更改,包括 46 次插入15 次删除
  1. 30 3
      ConfigHelper.cs
  2. 2 1
      HomeModule.cs
  3. 1 1
      MainForm.Designer.cs
  4. 1 0
      MainForm.cs
  5. 10 10
      SettingForm.Designer.cs
  6. 2 0
      SettingForm.cs

+ 30 - 3
ConfigHelper.cs

@@ -32,15 +32,16 @@ namespace xicheji
             {
                 ServicePort = xdoc.Root!.Element("Service")?.Attribute("Port")?.Value ?? "9999",
 
-                Server = xdoc.Root!.Element("Platform")?.Attribute("Server")?.Value ?? ""
+                Server = xdoc.Root!.Element("Platform")?.Attribute("Server")?.Value ?? "",
+                UploadInterval = int.Parse(xdoc.Root!.Element("Platform")?.Attribute("ReceiveInterval")?.Value ?? "2"),
             };
 
             var device = xdoc.Root!.Element("Device");
             config.PLCIP = device?.Attribute("IP")?.Value ?? "";
             config.PLCPort = device?.Attribute("Port")?.Value ?? "";
             config.PLCType = Enum.Parse<CpuType>(device?.Attribute("Type")?.Value ?? "S7200");
-            config.PLCMacAddress = device?.Attribute("MacAddress")?.Value ?? "";
             config.PLCReceiveInterval = int.Parse(device?.Attribute("ReceiveInterval")?.Value ?? "2");
+            config.PLCMacAddress = device?.Attribute("MacAddress")?.Value ?? "";
 
             var camera = xdoc.Root!.Element("Camera");
             config.CameraIP = camera?.Attribute("IP")?.Value ?? "";
@@ -75,7 +76,28 @@ namespace xicheji
 
         public static void SaveConfig(Config config)
         {
-            //TODO: 写入xml
+            var xdoc = XDocument.Load(configFileName);
+            var xService = xdoc.Root!.Element("Service");
+            xService?.SetAttributeValue("Port", config.ServicePort);
+
+            var xPlatform = xdoc.Root!.Element("Platform");
+            xPlatform?.SetAttributeValue("Server", config.Server);
+            xPlatform?.SetAttributeValue("UploadInterval", config.UploadInterval);
+
+            var xDevice = xdoc.Root!.Element("Device");
+            xDevice?.SetAttributeValue("IP", config.PLCIP);
+            xDevice?.SetAttributeValue("Port", config.PLCPort);
+            xDevice?.SetAttributeValue("Type", config.PLCType.ToString());
+            xDevice?.SetAttributeValue("ReceiveInterval", config.PLCReceiveInterval);
+            xDevice?.SetAttributeValue("MacAddress", config.PLCMacAddress);
+
+            var xCamera = xdoc.Root!.Element("Camera");
+            xCamera?.SetAttributeValue("IP", config.CameraIP);
+            xCamera?.SetAttributeValue("Port", config.CameraPort);
+            xCamera?.SetAttributeValue("UserName", config.CameraUserName);
+            xCamera?.SetAttributeValue("Password", config.CameraPassword);
+
+            xdoc.Save("config2.xml");
         }
 
         public static Variable? FindVariable(string variableName)
@@ -91,17 +113,22 @@ namespace xicheji
     public class Config
     {
         public string ServicePort { get; set; } = string.Empty;
+
         public string Server { get; set; } = string.Empty;
+        public int UploadInterval { get; internal set; }
+
         public string PLCIP { get; set; } = string.Empty;
         public string PLCPort { get; set; } = string.Empty;
         public CpuType PLCType { get; set; } = CpuType.S7200;
         public string PLCMacAddress { get; set; } = string.Empty;
         public int PLCReceiveInterval { get; set; } = 2;
+
         public string CameraIP { get; set; } = string.Empty;
         public string CameraPort { get; set; } = string.Empty;
         public string CameraUserName { get; set; } = string.Empty;
         public string CameraPassword { get; set; } = string.Empty;
         public string DBName { get; set; } = string.Empty;
+
         public List<Variable> Variables { get; set; } = new();
     }
 

+ 2 - 1
HomeModule.cs

@@ -30,7 +30,7 @@ namespace xicheji
                 var requestRoot = this.Bind<RequestRoot>();
 
                 Program.MainForm.UpdateCar(requestRoot.AlarmInfoPlate.result.PlateResult);
-                
+
                 return JsonConvert.SerializeObject(new
                 {
                     Response_AlarmInfoPlate = new
@@ -62,6 +62,7 @@ namespace xicheji
 
     public class Plateresult
     {
+        public int plateid { get; set; } = -1;
         public string license { get; set; }//车牌号字符串,如 “京AAAAAA”
         public string imageFile { get; set; }//识别大图片内容经过base64后的字符串,需要开启发送大图片
         public ColorType colorType { get; set; }

+ 1 - 1
MainForm.Designer.cs

@@ -132,7 +132,7 @@
             lblTime.Anchor = AnchorStyles.Top | AnchorStyles.Right;
             lblTime.AutoSize = true;
             lblTime.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
-            lblTime.Location = new Point(1003, 9);
+            lblTime.Location = new Point(996, 9);
             lblTime.Name = "lblTime";
             lblTime.Size = new Size(124, 21);
             lblTime.TabIndex = 7;

+ 1 - 0
MainForm.cs

@@ -688,6 +688,7 @@ namespace xicheji
         {
             this.Invoke(() =>
             {
+                var plateId = result.plateid;
                 var carNo = result.license;
                 var base64String = result.imageFile;
                 var colorType = result.colorType;

+ 10 - 10
SettingForm.Designer.cs

@@ -64,7 +64,7 @@
             btnOK.Location = new Point(276, 486);
             btnOK.Name = "btnOK";
             btnOK.Size = new Size(75, 23);
-            btnOK.TabIndex = 0;
+            btnOK.TabIndex = 9;
             btnOK.Text = "确定";
             btnOK.UseVisualStyleBackColor = true;
             btnOK.Click += btnOK_Click;
@@ -75,7 +75,7 @@
             btnCancel.Location = new Point(357, 486);
             btnCancel.Name = "btnCancel";
             btnCancel.Size = new Size(75, 23);
-            btnCancel.TabIndex = 1;
+            btnCancel.TabIndex = 10;
             btnCancel.Text = "取消";
             btnCancel.UseVisualStyleBackColor = true;
             btnCancel.Click += btnCancel_Click;
@@ -98,7 +98,7 @@
             txtServer.Location = new Point(90, 22);
             txtServer.Name = "txtServer";
             txtServer.Size = new Size(303, 23);
-            txtServer.TabIndex = 1;
+            txtServer.TabIndex = 0;
             // 
             // label1
             // 
@@ -144,7 +144,7 @@
             nudInterval.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
             nudInterval.Name = "nudInterval";
             nudInterval.Size = new Size(40, 23);
-            nudInterval.TabIndex = 3;
+            nudInterval.TabIndex = 4;
             nudInterval.TextAlign = HorizontalAlignment.Right;
             nudInterval.Value = new decimal(new int[] { 2, 0, 0, 0 });
             // 
@@ -155,7 +155,7 @@
             cboPLCType.Location = new Point(90, 104);
             cboPLCType.Name = "cboPLCType";
             cboPLCType.Size = new Size(303, 25);
-            cboPLCType.TabIndex = 2;
+            cboPLCType.TabIndex = 3;
             // 
             // label4
             // 
@@ -181,7 +181,7 @@
             txtPLCPort.Location = new Point(90, 63);
             txtPLCPort.Name = "txtPLCPort";
             txtPLCPort.Size = new Size(303, 23);
-            txtPLCPort.TabIndex = 1;
+            txtPLCPort.TabIndex = 2;
             // 
             // label3
             // 
@@ -251,7 +251,7 @@
             txtPassword.Location = new Point(90, 142);
             txtPassword.Name = "txtPassword";
             txtPassword.Size = new Size(303, 23);
-            txtPassword.TabIndex = 1;
+            txtPassword.TabIndex = 8;
             // 
             // txtUserName
             // 
@@ -259,7 +259,7 @@
             txtUserName.Location = new Point(90, 102);
             txtUserName.Name = "txtUserName";
             txtUserName.Size = new Size(303, 23);
-            txtUserName.TabIndex = 1;
+            txtUserName.TabIndex = 7;
             // 
             // txtCameraPort
             // 
@@ -267,7 +267,7 @@
             txtCameraPort.Location = new Point(90, 62);
             txtCameraPort.Name = "txtCameraPort";
             txtCameraPort.Size = new Size(303, 23);
-            txtCameraPort.TabIndex = 1;
+            txtCameraPort.TabIndex = 6;
             // 
             // label10
             // 
@@ -284,7 +284,7 @@
             txtCameraIP.Location = new Point(90, 22);
             txtCameraIP.Name = "txtCameraIP";
             txtCameraIP.Size = new Size(303, 23);
-            txtCameraIP.TabIndex = 1;
+            txtCameraIP.TabIndex = 5;
             // 
             // label11
             // 

+ 2 - 0
SettingForm.cs

@@ -51,7 +51,9 @@ namespace xicheji
             {
                 var config = ConfigHelper.GetConfig();
 
+                //config.ServicePort = txtServicePort.Text;
                 config.Server = txtServer.Text;
+                //config.UploadInterval = int.Parse(nudUploadInterval.Value.ToString());
                 config.PLCIP = txtPLCIP.Text;
                 config.PLCPort = txtPLCPort.Text;
                 config.PLCType = Enum.Parse<CpuType>(cboPLCType.Text);