章政 %!s(int64=8) %!d(string=hai) anos
pai
achega
e5524506cb

+ 24 - 24
UAS_AutoPass/AutoAnalysisXml.Designer.cs

@@ -40,11 +40,11 @@
             this.ChooseBackUpFolder = new System.Windows.Forms.Button();
             this.BackUpFolderPath = new System.Windows.Forms.TextBox();
             this.label2 = new System.Windows.Forms.Label();
-            this.label3 = new System.Windows.Forms.Label();
-            this.Source = new System.Windows.Forms.TextBox();
+            this.MakeCode_lable = new System.Windows.Forms.Label();
             this.label4 = new System.Windows.Forms.Label();
             this.Master = new System.Windows.Forms.ComboBox();
             this.AutoStart = new System.Windows.Forms.CheckBox();
+            this.MakeCode = new System.Windows.Forms.TextBox();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             this.SuspendLayout();
             // 
@@ -162,23 +162,15 @@
             this.label2.TabIndex = 9;
             this.label2.Text = "备份文件夹";
             // 
-            // label3
+            // MakeCode_lable
             // 
-            this.label3.AutoSize = true;
-            this.label3.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label3.Location = new System.Drawing.Point(36, 100);
-            this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(88, 25);
-            this.label3.TabIndex = 12;
-            this.label3.Text = "岗位资源";
-            // 
-            // Source
-            // 
-            this.Source.Location = new System.Drawing.Point(149, 99);
-            this.Source.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
-            this.Source.Name = "Source";
-            this.Source.Size = new System.Drawing.Size(292, 25);
-            this.Source.TabIndex = 13;
+            this.MakeCode_lable.AutoSize = true;
+            this.MakeCode_lable.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.MakeCode_lable.Location = new System.Drawing.Point(36, 100);
+            this.MakeCode_lable.Name = "MakeCode_lable";
+            this.MakeCode_lable.Size = new System.Drawing.Size(69, 25);
+            this.MakeCode_lable.TabIndex = 12;
+            this.MakeCode_lable.Text = "工单号";
             // 
             // label4
             // 
@@ -212,16 +204,24 @@
             this.AutoStart.UseVisualStyleBackColor = true;
             this.AutoStart.CheckedChanged += new System.EventHandler(this.AutoStart_CheckedChanged);
             // 
-            // Form1
+            // MakeCode
+            // 
+            this.MakeCode.Location = new System.Drawing.Point(149, 100);
+            this.MakeCode.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.MakeCode.Name = "MakeCode";
+            this.MakeCode.Size = new System.Drawing.Size(292, 25);
+            this.MakeCode.TabIndex = 17;
+            // 
+            // AutoAnalysisXml
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(887, 395);
+            this.Controls.Add(this.MakeCode);
             this.Controls.Add(this.AutoStart);
             this.Controls.Add(this.Master);
             this.Controls.Add(this.label4);
-            this.Controls.Add(this.Source);
-            this.Controls.Add(this.label3);
+            this.Controls.Add(this.MakeCode_lable);
             this.Controls.Add(this.ChooseBackUpFolder);
             this.Controls.Add(this.BackUpFolderPath);
             this.Controls.Add(this.label2);
@@ -234,7 +234,7 @@
             this.Controls.Add(this.StartWatch);
             this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.MaximizeBox = false;
-            this.Name = "Form1";
+            this.Name = "AutoAnalysisXml";
             this.Text = "UAS_XML解析器";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
             this.Load += new System.EventHandler(this.Form1_Load);
@@ -258,11 +258,11 @@
         private System.Windows.Forms.Button ChooseBackUpFolder;
         private System.Windows.Forms.TextBox BackUpFolderPath;
         private System.Windows.Forms.Label label2;
-        private System.Windows.Forms.TextBox Source;
-        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label MakeCode_lable;
         private System.Windows.Forms.ComboBox Master;
         private System.Windows.Forms.Label label4;
         private System.Windows.Forms.CheckBox AutoStart;
+        private System.Windows.Forms.TextBox MakeCode;
     }
 }
 

+ 54 - 53
UAS_AutoPass/AutoAnalysisXml.cs

@@ -7,6 +7,7 @@ using System.Threading;
 using System.Windows.Forms;
 using System.Xml;
 using UAS_AutoPass.ToolClass;
+using BenQGuru.eMES.DLLService;
 
 namespace UAS_AutoPass
 {
@@ -17,15 +18,21 @@ namespace UAS_AutoPass
 
         DataTable dt;
 
+        MESHelper helper = new MESHelper();
+
+        string iusercode;
+
+        string isource;
+
         Thread InitDB;
         /// <summary>
         /// 缓存的文件
         /// </summary>
-        string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
+        public static string CachePath = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/Cache.xml";
         /// <summary>
         /// 缓存的文件夹
         /// </summary>
-        string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
+        public static string CachePathFolder = Environment.GetEnvironmentVariable("windir").Substring(0, 1) + @":/UAS_MES/XmlAnalysor/";
 
         public AutoAnalysisXml()
         {
@@ -33,6 +40,14 @@ namespace UAS_AutoPass
             StartPosition = FormStartPosition.CenterScreen;
         }
 
+        public AutoAnalysisXml(string iUserName, string iSource)
+        {
+            InitializeComponent();
+            iusercode = iUserName;
+            isource = iSource;
+            StartPosition = FormStartPosition.CenterScreen;
+        }
+
         private void Form1_Load(object sender, EventArgs e)
         {
             CheckForIllegalCrossThreadCalls = false;
@@ -50,24 +65,12 @@ namespace UAS_AutoPass
             Master.ValueMember = "ma_user";
             try
             {
-                if (!Directory.Exists(CachePathFolder))
-                    Directory.CreateDirectory(CachePathFolder);
-                XmlReader myReader = XmlReader.Create(CachePath);
-                while (myReader.Read())
-                {
-                    if (myReader.NodeType == XmlNodeType.Text)
-                        CacheInf.Add(myReader.Value);
-                }
-                myReader.Close();
-                string[] Info = CacheInf.ToArray();
-                FolderPath.Text = Info[0];
-                BackUpFolderPath.Text = Info[1];
-                Source.Text = Info[2];
-                Master.Text = Info[3];
-                AutoStart.Checked = (Info[4] == "True" ? true : false);
+                FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
+                BackUpFolderPath.Text = BaseUtil.GetCacheData("BackUpFolderPath").ToString();
+                Master.Text = BaseUtil.GetCacheData("Master").ToString();
+                AutoStart.Checked = (bool)BaseUtil.GetCacheData("AutoStart");
             }
-            catch (Exception) { }
-            StartWatch.PerformClick();
+            catch (Exception ex) { Console.WriteLine(ex.Message); }
         }
 
         private void ConnectDB()
@@ -108,35 +111,21 @@ namespace UAS_AutoPass
                     dh = new DataHelper();
                 }
             }
-            if (!dh.CheckExist("source", "sc_code='" + Source.Text + "' and sc_statuscode='AUDITED'"))
+            if (!dh.CheckExist("make", "ma_statuscode='STARTED' and ma_code='" + MakeCode.Text + "'"))
             {
-                OperateResult.AppendText("岗位资源错误或者未审核\n");
+                OperateResult.AppendText("工单不存在或者未下放\n");
                 return;
             }
             XmlWatcher.Path = FolderPath.Text;
             XmlWatcher.Filter = "*.xml";
             XmlWatcher.EnableRaisingEvents = true;
-            try
-            {
-                File.Delete(CachePath);
-            }
-            catch (Exception) { }
-            XmlDocument xmlDoc = new XmlDocument();
-            //创建类型声明节点  
-            XmlNode node = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "");
-            xmlDoc.AppendChild(node);
-            //创建根节点  
-            XmlElement xeRoot = xmlDoc.CreateElement("CacheInf");
-            xmlDoc.AppendChild(xeRoot);
-            CreateNode(xmlDoc, xeRoot, "FolderPath", FolderPath.Text);
-            CreateNode(xmlDoc, xeRoot, "BackUpFolderPath", BackUpFolderPath.Text);
-            CreateNode(xmlDoc, xeRoot, "Source", Source.Text);
-            CreateNode(xmlDoc, xeRoot, "Master", Master.Text);
-            CreateNode(xmlDoc, xeRoot, "AutoStart", AutoStart.Checked.ToString());
-            xmlDoc.Save(CachePath);
-            Source.Enabled = false;
+            BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
+            BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
+            BaseUtil.SetCacheData("Master", Master.Text);
+            BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
             StartWatch.Enabled = false;
             ChooseFolder.Enabled = false;
+            MakeCode.Enabled = false;
             ChooseBackUpFolder.Enabled = false;
             StopWatch.Enabled = true;
             OperateResult.AppendText("开始执行监控\n");
@@ -188,8 +177,10 @@ namespace UAS_AutoPass
                     Console.WriteLine(ex.Message);
                 }
             }
-            string testDate = "";
-            string testTime = "";
+            string test_date = "";
+            string test_result = "";
+            string test_sn = "";
+            string imageurl = "";
             XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + e.Name);
             //获取文件名的序列号,如SA123456.xml
             string sncode = e.Name.Split('.')[0];
@@ -203,10 +194,12 @@ namespace UAS_AutoPass
             int name_or_result = 0;
             while (myReader.Read())
             {
-                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test")
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test" && myReader.IsStartElement())
                 {
-                    testDate = myReader.GetAttribute(1);
-                    testTime = myReader.GetAttribute(0);
+                    test_sn = myReader.GetAttribute("test_sn");
+                    test_result = myReader.GetAttribute("test_result");
+                    test_date = myReader.GetAttribute("test_date");
+                    imageurl = myReader.GetAttribute("imgurl");
                 }
                 if (myReader.NodeType == XmlNodeType.Text)
                 {
@@ -222,13 +215,21 @@ namespace UAS_AutoPass
                     }
                 }
             }
-            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();
+            string ErrMessage = "";
+            if (helper.GoMo(MakeCode.Text, sncode, isource, out ErrMessage))
+            {
+                if (!helper.SetStepFinish(MakeCode.Text, isource, sncode, "自动过站采集", test_result, iusercode, "自动过站不良", out ErrMessage))
+                {
+                    OperateResult.AppendText(ErrMessage + "\n");
+                    return;
+                }
+            }
+            else
+            {
+                OperateResult.AppendText(ErrMessage + "\n");
+                return;
+            }
             FileInfo file = new FileInfo(FolderPath.Text + @"\" + e.Name);
             if (file.Exists)
             {
@@ -260,8 +261,8 @@ namespace UAS_AutoPass
         private void StopWatch_Click(object sender, EventArgs e)
         {
             XmlWatcher.EnableRaisingEvents = false;
-            Source.Enabled = true;
             StartWatch.Enabled = true;
+            MakeCode.Enabled = true;
             ChooseFolder.Enabled = true;
             ChooseBackUpFolder.Enabled = true;
             StopWatch.Enabled = false;
@@ -315,4 +316,4 @@ namespace UAS_AutoPass
             SetAutoRun();
         }
     }
-}
+}

+ 1 - 0
UAS_AutoPass/Login.Designer.cs

@@ -113,6 +113,7 @@
             this.Controls.Add(this.UserName_lable);
             this.Name = "Login";
             this.Text = "Login";
+            this.Load += new System.EventHandler(this.Login_Load);
             this.ResumeLayout(false);
             this.PerformLayout();
 

+ 10 - 1
UAS_AutoPass/Login.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Windows.Forms;
 using BenQGuru.eMES.DLLService;
+using UAS_AutoPass.ToolClass;
 
 namespace UAS_AutoPass
 {
@@ -19,12 +20,20 @@ namespace UAS_AutoPass
             string ErrMessage = "";
             if (helper.CheckUserAndResourcePassed(UserName.Text, Source.Text, PassWord.Text, out ErrMessage))
             {
-                AutoAnalysisXml xml = new AutoAnalysisXml();
+                BaseUtil.SetCacheData("UserName", UserName.Text);
+                BaseUtil.SetCacheData("Source", Source.Text);
+                AutoAnalysisXml xml = new AutoAnalysisXml(UserName.Text, Source.Text);
                 Hide();
                 xml.ShowDialog();
                 Close();
             }
             else MessageBox.Show(ErrMessage);
         }
+
+        private void Login_Load(object sender, EventArgs e)
+        {
+            UserName.Text = BaseUtil.GetCacheData("UserName").ToString();
+            Source.Text = BaseUtil.GetCacheData("Source").ToString();
+        }
     }
 }

+ 17 - 4
UAS_AutoPass/Program.cs

@@ -4,6 +4,7 @@ using System.IO;
 using System.Security.Principal;
 using System.Text;
 using System.Windows.Forms;
+using System.Xml;
 
 namespace UAS_AutoPass
 {
@@ -19,18 +20,30 @@ namespace UAS_AutoPass
             {
                 WindowsIdentity identity = WindowsIdentity.GetCurrent();
                 WindowsPrincipal principal = new WindowsPrincipal(identity);
-
                 string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
                 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                 //处理UI线程异常
                 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                 //处理非UI线程异常
                 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
-
+                if (!Directory.Exists(AutoAnalysisXml.CachePathFolder))
+                    Directory.CreateDirectory(AutoAnalysisXml.CachePathFolder);
+                FileStream fcaches = new FileStream(AutoAnalysisXml.CachePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                fcaches.Close();
+                FileInfo info = new FileInfo(AutoAnalysisXml.CachePath);
+                if (info.Length == 0)
+                {
+                    XmlDocument doc = new XmlDocument();
+                    //创建类型声明节点  
+                    XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
+                    doc.AppendChild(node);
+                    //创建根节点  
+                    XmlElement xeRoot = doc.CreateElement("cacheInfo");
+                    doc.AppendChild(xeRoot);
+                    doc.Save(AutoAnalysisXml.CachePath);
+                }
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
-                if (!Directory.Exists(sysdisc + @":\Cache"))
-                    Directory.CreateDirectory(sysdisc + @":\Cache");
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                     Application.Run(new Login());
                 else

+ 102 - 1
UAS_AutoPass/ToolClass/BaseUtil.cs

@@ -1,4 +1,5 @@
-using System.IO;
+using System;
+using System.IO;
 using System.Xml;
 
 namespace UAS_AutoPass.ToolClass
@@ -23,5 +24,105 @@ namespace UAS_AutoPass.ToolClass
                 doc.Save(iSN + ".xml");
             }
         }
+
+        public static object GetCacheData(string ParamName)
+        {
+            try
+            {
+                object returnData = null;
+                //根据地址读取xml文件
+                XmlDocument doc = new XmlDocument();
+                XmlReaderSettings settings = new XmlReaderSettings();
+                //忽略文档里面的注释
+                settings.IgnoreComments = true;
+                XmlReader reader = XmlReader.Create(AutoAnalysisXml.CachePath, settings);
+                doc.Load(reader);
+                //先得到根节点
+                XmlNode rootNode = doc.SelectSingleNode("cacheInfo");
+                //再由根节点去找制定的节点
+                XmlNodeList nodeList = rootNode.ChildNodes;
+                foreach (XmlNode node in nodeList)
+                {
+                    //找到了这个节点名字
+                    if (node.Name == ParamName)
+                    {
+                        //返回节点的内容
+                        switch (((XmlElement)node).GetAttribute("Type"))
+                        {
+                            case "System.String":
+                                returnData = node.InnerText;
+                                break;
+                            case "System.Int32":
+                                returnData = int.Parse(node.InnerText);
+                                break;
+                            case "System.Boolean":
+                                returnData = node.InnerText == "True" ? true : false;
+                                break;
+                            default:
+                                break;
+                        }
+                        break;
+                    }
+                }
+                //关闭reader
+                reader.Close();
+                if (returnData == null)
+                    return "";
+                else
+                    return returnData;
+            }
+            catch (Exception)
+            {
+                return "";
+            }
+        }
+
+        public static void SetCacheData(string ParamName, object Value)
+        {
+            try
+            {
+                //根据地址读取xml文件
+                XmlDocument doc = new XmlDocument();
+                XmlReaderSettings settings = new XmlReaderSettings();
+                //忽略文档里面的注释
+                settings.IgnoreComments = true;
+                XmlReader reader = XmlReader.Create(AutoAnalysisXml.CachePath, settings);
+                doc.Load(reader);
+                //先得到根节点
+                XmlNode rootNode = doc.SelectSingleNode("cacheInfo");
+                //再由根节点去找制定的节点
+                XmlNodeList nodeList = rootNode.ChildNodes;
+                bool flag = false;
+                foreach (XmlNode node in nodeList)
+                {
+                    //找到了这个节点名字
+                    if (node.Name == ParamName)
+                    {
+                        //就直接赋值
+                        node.InnerText = Value.ToString();
+                        flag = true;
+                    }
+                }
+                //如果没有该节点,就创建节点保存结果
+                if (!flag)
+                {
+                    //创建节点
+                    XmlElement newNode = doc.CreateElement(ParamName);
+                    XmlAttribute attr = doc.CreateAttribute("Type");
+                    attr.InnerText = Value.GetType().ToString();
+                    newNode.InnerText = Value.ToString();
+                    newNode.SetAttributeNode(attr);
+                    //讲新建的节点挂到根节点上
+                    rootNode.AppendChild(newNode);
+                }
+                //关闭Reader
+                reader.Close();
+                doc.Save(AutoAnalysisXml.CachePath);
+            }
+            catch (Exception)
+            {
+
+            }
+        }
     }
 }