Parcourir la source

记录日期参数

章政 il y a 7 ans
Parent
commit
3ac197d9aa

+ 3 - 0
UAS_XmlAnalysor/App.config

@@ -25,6 +25,9 @@
             <setting name="Master" serializeAs="String">
                 <value />
             </setting>
+            <setting name="AutoStart" serializeAs="String">
+                <value>False</value>
+            </setting>
         </UAS_XmlAnalysor.Properties.Settings>
     </userSettings>
 </configuration>

+ 13 - 0
UAS_XmlAnalysor/Form1.Designer.cs

@@ -44,6 +44,7 @@
             this.Source = new System.Windows.Forms.TextBox();
             this.label4 = new System.Windows.Forms.Label();
             this.Master = new System.Windows.Forms.ComboBox();
+            this.AutoStart = new System.Windows.Forms.CheckBox();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             this.SuspendLayout();
             // 
@@ -201,11 +202,22 @@
             this.Master.Size = new System.Drawing.Size(220, 20);
             this.Master.TabIndex = 15;
             // 
+            // AutoStart
+            // 
+            this.AutoStart.AutoSize = true;
+            this.AutoStart.Location = new System.Drawing.Point(343, 26);
+            this.AutoStart.Name = "AutoStart";
+            this.AutoStart.Size = new System.Drawing.Size(96, 16);
+            this.AutoStart.TabIndex = 16;
+            this.AutoStart.Text = "开机自动启动";
+            this.AutoStart.UseVisualStyleBackColor = true;
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(665, 316);
+            this.Controls.Add(this.AutoStart);
             this.Controls.Add(this.Master);
             this.Controls.Add(this.label4);
             this.Controls.Add(this.Source);
@@ -248,6 +260,7 @@
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.ComboBox Master;
         private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.CheckBox AutoStart;
     }
 }
 

+ 43 - 6
UAS_XmlAnalysor/Form1.cs

@@ -1,4 +1,5 @@
-using System;
+using Microsoft.Win32;
+using System;
 using System.Collections.Generic;
 using System.Data;
 using System.IO;
@@ -55,11 +56,36 @@ namespace UAS_XmlAnalysor
             Properties.Settings.Default.BackUpFolderPath = BackUpFolderPath.Text;
             Properties.Settings.Default.Source = Source.Text;
             Properties.Settings.Default.Master = Master.Text;
+            Properties.Settings.Default.AutoStart = AutoStart.Checked;
             Properties.Settings.Default.Save();
             Source.Enabled = false;
+            StartWatch.Enabled = false;
+            SetAutoRun();
             OperateResult.AppendText("开始执行监控\n");
         }
 
+        public void SetAutoRun()
+        {
+            if (AutoStart.Checked) //设置开机自启动  
+            {
+                string path = Application.ExecutablePath;
+                RegistryKey rk = Registry.LocalMachine;
+                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
+                rk2.SetValue("UAS_XML解析器.exe", path);
+                rk2.Close();
+                rk.Close();
+            }
+            else //取消开机自启动  
+            {
+                string path = Application.ExecutablePath;
+                RegistryKey rk = Registry.LocalMachine;
+                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
+                rk2.DeleteValue("UAS_XML解析器.exe", false);
+                rk2.Close();
+                rk.Close();
+            }
+        }
+
         private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
         {
             while (true)
@@ -73,18 +99,24 @@ namespace UAS_XmlAnalysor
                     }
                     System.Threading.Thread.Sleep(500);
                 }
-                catch (Exception)
-                {
-                }
+                catch (Exception) { }
             }
+            string testDate = "";
+            string testTime = "";
             XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + e.Name);
             string sncode = e.Name.Split('.')[0];
+            string iMakeCode = dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode='" + sncode + "'").ToString();
             OperateResult.AppendText("读取文件" + e.Name + "\n");
             List<string> name = new List<string>();
             List<string> result = new List<string>();
             int name_or_result = 0;
             while (myReader.Read())
             {
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test")
+                {
+                    testDate = myReader.GetAttribute(1);
+                    testTime = myReader.GetAttribute(0);
+                }
                 if (myReader.NodeType == XmlNodeType.Text)
                 {
                     if (name_or_result % 2 == 0)
@@ -99,7 +131,11 @@ namespace UAS_XmlAnalysor
                     }
                 }
             }
-            string sql = "insert into STEPTESTDETAIL(std_id,std_sn,std_subclass1,std_testresult,std_date,std_rescode) values (STEPTESTDETAIL_seq.nextval,'" + sncode + "',:std_subclass1,:std_testresult,sysdate,'" + Source.Text + "')";
+            string date = testDate + " " + testTime;
+            string sql = "insert into STEPTESTDETAIL(std_id,std_makecode,std_sn,std_subclass1,std_testresult,std_indate,";
+            sql += "std_rescode,std_testdate,std_testtime,std_date) values(STEPTESTDETAIL_seq.nextval, '" + iMakeCode + "', ";
+            sql += "'" + sncode + "',:std_subclass1,:std_testresult, sysdate,'" + Source.Text + "',to_char(to_date('"+testDate+"','YYYY/MM/DD'), 'YYYYMMDD'),";
+            sql += "to_char(to_date('"+testTime+ "','hh24:mi:ss'), 'hh24miss'),to_date('"+ date + "','YYYY/MM/DD hh24:mi:ss'))";
             dh.BatchInsert(sql, new string[] { "std_subclass1", "std_testresult" }, name.ToArray(), result.ToArray());
             myReader.Close();
             FileInfo file = new FileInfo(FolderPath.Text + @"\" + e.Name);
@@ -111,7 +147,7 @@ namespace UAS_XmlAnalysor
                 }
                 catch (Exception ex)
                 {
-                    OperateResult.AppendText(e.Name + ex.Message+"\n");
+                    OperateResult.AppendText(e.Name + ex.Message + "\n");
                 }
             }
         }
@@ -120,6 +156,7 @@ namespace UAS_XmlAnalysor
         {
             XmlWatcher.EnableRaisingEvents = false;
             Source.Enabled = true;
+            StartWatch.Enabled = true;
             OperateResult.AppendText("停止执行监控\n");
         }
 

+ 12 - 0
UAS_XmlAnalysor/Properties/Settings.Designer.cs

@@ -82,5 +82,17 @@ namespace UAS_XmlAnalysor.Properties {
                 this["Master"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        public bool AutoStart {
+            get {
+                return ((bool)(this["AutoStart"]));
+            }
+            set {
+                this["AutoStart"] = value;
+            }
+        }
     }
 }

+ 3 - 0
UAS_XmlAnalysor/Properties/Settings.settings

@@ -17,5 +17,8 @@
     <Setting Name="Master" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     </Setting>
+    <Setting Name="AutoStart" Type="System.Boolean" Scope="User">
+      <Value Profile="(Default)">False</Value>
+    </Setting>
   </Settings>
 </SettingsFile>