Browse Source

XML文件解析器修改

Hcsy 7 years ago
parent
commit
5ba426a11f

+ 129 - 0
UAS_XmlAnalysor/BaseUtil.cs

@@ -0,0 +1,129 @@
+using System;
+using System.IO;
+using System.Xml;
+
+namespace UAS_XmlAnalysor
+{
+    class BaseUtil
+    {
+        public static void CreateXml(string iSN, string iTestResult)
+        {
+            //创建XML文档
+            FileStream fcaches = new FileStream(iSN ,FileMode.OpenOrCreate, FileAccess.ReadWrite);
+            fcaches.Close();
+            FileInfo info = new FileInfo(iSN);
+            if (info.Length == 0)
+            {
+                XmlDocument doc = new XmlDocument();
+                //创建类型声明节点  
+                XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
+                doc.AppendChild(node);
+                //创建根节点  
+                XmlElement xeRoot = doc.CreateElement("CacheInf");
+                doc.AppendChild(xeRoot);
+                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(Form1.CachePath, settings);
+                doc.Load(reader);
+                //先得到根节点
+                XmlNode rootNode = doc.SelectSingleNode("CacheInf");
+                //再由根节点去找制定的节点
+                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(Form1.CachePath, settings);
+                doc.Load(reader);
+                //先得到根节点
+                XmlNode rootNode = doc.SelectSingleNode("CacheInf");
+                //再由根节点去找制定的节点
+                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(Form1.CachePath);
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+       
+            }
+        }
+    }
+}

File diff suppressed because it is too large
+ 774 - 47
UAS_XmlAnalysor/DataHelper.cs


+ 65 - 63
UAS_XmlAnalysor/Form1.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.label4 = new System.Windows.Forms.Label();
             this.Master = new System.Windows.Forms.ComboBox();
             this.AutoStart = new System.Windows.Forms.CheckBox();
+            this.ma_code = new System.Windows.Forms.TextBox();
+            this.MakeCode_lable = new System.Windows.Forms.Label();
             ((System.ComponentModel.ISupportInitialize)(this.XmlWatcher)).BeginInit();
             this.SuspendLayout();
             // 
@@ -57,10 +57,10 @@
             // StartWatch
             // 
             this.StartWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.StartWatch.Location = new System.Drawing.Point(193, 320);
-            this.StartWatch.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.StartWatch.Location = new System.Drawing.Point(145, 256);
+            this.StartWatch.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.StartWatch.Name = "StartWatch";
-            this.StartWatch.Size = new System.Drawing.Size(85, 35);
+            this.StartWatch.Size = new System.Drawing.Size(64, 28);
             this.StartWatch.TabIndex = 0;
             this.StartWatch.Text = "开始监控";
             this.StartWatch.UseVisualStyleBackColor = true;
@@ -70,10 +70,10 @@
             // 
             this.StopWatch.Enabled = false;
             this.StopWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.StopWatch.Location = new System.Drawing.Point(332, 320);
-            this.StopWatch.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.StopWatch.Location = new System.Drawing.Point(249, 256);
+            this.StopWatch.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.StopWatch.Name = "StopWatch";
-            this.StopWatch.Size = new System.Drawing.Size(85, 35);
+            this.StopWatch.Size = new System.Drawing.Size(64, 28);
             this.StopWatch.TabIndex = 1;
             this.StopWatch.Text = "停止监控";
             this.StopWatch.UseVisualStyleBackColor = true;
@@ -83,28 +83,29 @@
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(36, 174);
+            this.label1.Location = new System.Drawing.Point(27, 139);
+            this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(107, 25);
+            this.label1.Size = new System.Drawing.Size(84, 20);
             this.label1.TabIndex = 2;
             this.label1.Text = "监控文件夹";
             // 
             // FolderPath
             // 
             this.FolderPath.Enabled = false;
-            this.FolderPath.Location = new System.Drawing.Point(149, 174);
-            this.FolderPath.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.FolderPath.Location = new System.Drawing.Point(112, 139);
+            this.FolderPath.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.FolderPath.Name = "FolderPath";
-            this.FolderPath.Size = new System.Drawing.Size(292, 25);
+            this.FolderPath.Size = new System.Drawing.Size(220, 21);
             this.FolderPath.TabIndex = 3;
             // 
             // ChooseFolder
             // 
             this.ChooseFolder.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ChooseFolder.Location = new System.Drawing.Point(461, 174);
-            this.ChooseFolder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.ChooseFolder.Location = new System.Drawing.Point(346, 139);
+            this.ChooseFolder.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.ChooseFolder.Name = "ChooseFolder";
-            this.ChooseFolder.Size = new System.Drawing.Size(104, 30);
+            this.ChooseFolder.Size = new System.Drawing.Size(78, 24);
             this.ChooseFolder.TabIndex = 6;
             this.ChooseFolder.Text = "选择文件夹";
             this.ChooseFolder.UseVisualStyleBackColor = true;
@@ -112,20 +113,20 @@
             // 
             // OperateResult
             // 
-            this.OperateResult.Location = new System.Drawing.Point(595, 14);
-            this.OperateResult.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.OperateResult.Location = new System.Drawing.Point(446, 11);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.OperateResult.Name = "OperateResult";
-            this.OperateResult.Size = new System.Drawing.Size(280, 336);
+            this.OperateResult.Size = new System.Drawing.Size(211, 270);
             this.OperateResult.TabIndex = 7;
             this.OperateResult.Text = "";
             // 
             // Clean
             // 
             this.Clean.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Clean.Location = new System.Drawing.Point(699, 359);
-            this.Clean.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.Clean.Location = new System.Drawing.Point(524, 287);
+            this.Clean.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.Clean.Name = "Clean";
-            this.Clean.Size = new System.Drawing.Size(75, 30);
+            this.Clean.Size = new System.Drawing.Size(56, 24);
             this.Clean.TabIndex = 8;
             this.Clean.Text = "清除";
             this.Clean.UseVisualStyleBackColor = true;
@@ -134,10 +135,10 @@
             // ChooseBackUpFolder
             // 
             this.ChooseBackUpFolder.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.ChooseBackUpFolder.Location = new System.Drawing.Point(461, 251);
-            this.ChooseBackUpFolder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.ChooseBackUpFolder.Location = new System.Drawing.Point(346, 201);
+            this.ChooseBackUpFolder.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.ChooseBackUpFolder.Name = "ChooseBackUpFolder";
-            this.ChooseBackUpFolder.Size = new System.Drawing.Size(104, 30);
+            this.ChooseBackUpFolder.Size = new System.Drawing.Size(78, 24);
             this.ChooseBackUpFolder.TabIndex = 11;
             this.ChooseBackUpFolder.Text = "选择文件夹";
             this.ChooseBackUpFolder.UseVisualStyleBackColor = true;
@@ -146,47 +147,31 @@
             // BackUpFolderPath
             // 
             this.BackUpFolderPath.Enabled = false;
-            this.BackUpFolderPath.Location = new System.Drawing.Point(149, 251);
-            this.BackUpFolderPath.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.BackUpFolderPath.Location = new System.Drawing.Point(112, 201);
+            this.BackUpFolderPath.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.BackUpFolderPath.Name = "BackUpFolderPath";
-            this.BackUpFolderPath.Size = new System.Drawing.Size(292, 25);
+            this.BackUpFolderPath.Size = new System.Drawing.Size(220, 21);
             this.BackUpFolderPath.TabIndex = 10;
             // 
             // label2
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(36, 251);
+            this.label2.Location = new System.Drawing.Point(27, 201);
+            this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(107, 25);
+            this.label2.Size = new System.Drawing.Size(84, 20);
             this.label2.TabIndex = 9;
             this.label2.Text = "备份文件夹";
             // 
-            // label3
-            // 
-            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;
-            // 
             // label4
             // 
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label4.Location = new System.Drawing.Point(36, 29);
+            this.label4.Location = new System.Drawing.Point(27, 23);
+            this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
             this.label4.Name = "label4";
-            this.label4.Size = new System.Drawing.Size(88, 25);
+            this.label4.Size = new System.Drawing.Size(69, 20);
             this.label4.TabIndex = 14;
             this.label4.Text = "账套选择";
             // 
@@ -194,34 +179,51 @@
             // 
             this.Master.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
             this.Master.FormattingEnabled = true;
-            this.Master.Location = new System.Drawing.Point(149, 29);
-            this.Master.Margin = new System.Windows.Forms.Padding(4);
+            this.Master.Location = new System.Drawing.Point(112, 23);
             this.Master.Name = "Master";
-            this.Master.Size = new System.Drawing.Size(292, 23);
+            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(457, 32);
-            this.AutoStart.Margin = new System.Windows.Forms.Padding(4);
+            this.AutoStart.Location = new System.Drawing.Point(343, 26);
             this.AutoStart.Name = "AutoStart";
-            this.AutoStart.Size = new System.Drawing.Size(119, 19);
+            this.AutoStart.Size = new System.Drawing.Size(96, 16);
             this.AutoStart.TabIndex = 16;
             this.AutoStart.Text = "开机自动启动";
             this.AutoStart.UseVisualStyleBackColor = true;
             this.AutoStart.CheckedChanged += new System.EventHandler(this.AutoStart_CheckedChanged);
             // 
+            // ma_code
+            // 
+            this.ma_code.Location = new System.Drawing.Point(112, 87);
+            this.ma_code.Margin = new System.Windows.Forms.Padding(2);
+            this.ma_code.Name = "ma_code";
+            this.ma_code.Size = new System.Drawing.Size(220, 21);
+            this.ma_code.TabIndex = 20;
+            // 
+            // MakeCode_lable
+            // 
+            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(27, 87);
+            this.MakeCode_lable.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
+            this.MakeCode_lable.Name = "MakeCode_lable";
+            this.MakeCode_lable.Size = new System.Drawing.Size(54, 20);
+            this.MakeCode_lable.TabIndex = 19;
+            this.MakeCode_lable.Text = "工单号";
+            // 
             // Form1
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(887, 395);
+            this.ClientSize = new System.Drawing.Size(665, 316);
+            this.Controls.Add(this.ma_code);
+            this.Controls.Add(this.MakeCode_lable);
             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.ChooseBackUpFolder);
             this.Controls.Add(this.BackUpFolderPath);
             this.Controls.Add(this.label2);
@@ -232,7 +234,7 @@
             this.Controls.Add(this.label1);
             this.Controls.Add(this.StopWatch);
             this.Controls.Add(this.StartWatch);
-            this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
             this.MaximizeBox = false;
             this.Name = "Form1";
             this.Text = "UAS_XML解析器";
@@ -258,11 +260,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.ComboBox Master;
         private System.Windows.Forms.Label label4;
         private System.Windows.Forms.CheckBox AutoStart;
+        private System.Windows.Forms.TextBox ma_code;
+        private System.Windows.Forms.Label MakeCode_lable;
     }
 }
 

+ 167 - 55
UAS_XmlAnalysor/Form1.cs

@@ -3,9 +3,11 @@ using System;
 using System.Collections.Generic;
 using System.Data;
 using System.IO;
+using System.Text;
 using System.Threading;
 using System.Windows.Forms;
 using System.Xml;
+using UAS_AutoPass.ToolClass;
 
 namespace UAS_XmlAnalysor
 {
@@ -16,29 +18,62 @@ namespace UAS_XmlAnalysor
 
         DataTable dt;
 
-        Tip form2;
+        Tip tipform;
 
+        /// <summary>
+        /// 用户编号
+        /// </summary>
+        string iusercode;
+        /// <summary>
+        /// 岗位资源
+        /// </summary>
+        string isource;
+
+        /// <summary>
+        /// 线别
+        /// </summary>
+        string ilinecode;
+        /// <summary>
+        /// 不良代码组
+        /// </summary>
+        string ibadgroup;
+        /// <summary>
+        /// 当前工序
+        /// </summary>
+        string istepcode;
+
+        StringBuilder sql = new StringBuilder();
+        DataTable DB;
         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/";
+        private string oErrMessage;
 
         public Form1()
         {
             InitializeComponent();
             StartPosition = FormStartPosition.CenterScreen;
-            form2 = new Tip();
+            tipform = new Tip();
+        }
+
+        public Form1(string iUserName, string iSource)
+        {
+            tipform = new Tip();
+            InitializeComponent();
+            iusercode = iUserName;
+            isource = iSource.ToUpper();
+            StartPosition = FormStartPosition.CenterScreen;
         }
 
         private void Form1_Load(object sender, EventArgs e)
         {
-            form2.Show();
+            tipform.Show();
             CheckForIllegalCrossThreadCalls = false;
             FormBorderStyle = FormBorderStyle.FixedSingle;
             InitDB = new Thread(ConnectDB);
@@ -48,30 +83,35 @@ namespace UAS_XmlAnalysor
             stw.StartPosition = FormStartPosition.CenterScreen;
             stw.ShowDialog();
             List<string> CacheInf = new List<string>();
-            dt = (DataTable)dh.ExecuteSql("select ms_pwd,ma_user,ma_address,ma_inneraddress from master", "select");
-            Master.DataSource = dt;
+            DB = (DataTable)dh.ExecuteSql("select ms_pwd,ma_user,ma_address,ma_inneraddress from master", "select");
+            Master.DataSource = DB;
             Master.DisplayMember = "ma_user";
             Master.ValueMember = "ma_user";
+            //获取缓存信息
             try
             {
-                if (!Directory.Exists(CachePathFolder))
-                    Directory.CreateDirectory(CachePathFolder);
-                XmlReader myReader = XmlReader.Create(CachePath);
-                while (myReader.Read())
+                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 ex) { Console.WriteLine(ex.Message); }
+            for (int i = 0; i < DB.Rows.Count; i++)
+            {
+                if (Master.Text == DB.Rows[i]["ma_user"].ToString())
                 {
-                    if (myReader.NodeType == XmlNodeType.Text)
-                        CacheInf.Add(myReader.Value);
+                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=" + DB.Rows[i]["ma_user"].ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + DB.Rows[i]["ma_inneraddress"].ToString() + ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+                    dh = new DataHelper();
                 }
-                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);
             }
-            catch (Exception) { }
-            StartWatch.PerformClick();
+            //获取岗位资源相关信息
+            dt = (DataTable)dh.ExecuteSql("select sc_linecode,sc_stepcode,st_badgroupcode from source left join step on sc_stepcode=st_code where sc_code='" + isource + "'", "select");
+            if (dt.Rows.Count > 0)
+            {
+                ilinecode = dt.Rows[0]["sc_linecode"].ToString();
+                istepcode = dt.Rows[0]["sc_stepcode"].ToString();
+                ibadgroup = dt.Rows[0]["st_badgroupcode"].ToString();
+            }
         }
 
         private void ConnectDB()
@@ -104,15 +144,15 @@ namespace UAS_XmlAnalysor
                 OperateResult.AppendText("监控文件夹和备份文件夹不能相同\n");
                 return;
             }
-            for (int i = 0; i < dt.Rows.Count; i++)
+            for (int i = 0; i < DB.Rows.Count; i++)
             {
-                if (Master.Text == dt.Rows[i]["ma_user"].ToString())
+                if (Master.Text == DB.Rows[i]["ma_user"].ToString())
                 {
-                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=" + dt.Rows[i]["ma_user"].ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + dt.Rows[i]["ma_inneraddress"].ToString() + ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=" + DB.Rows[i]["ma_user"].ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + DB.Rows[i]["ma_inneraddress"].ToString() + ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
                     dh = new DataHelper();
                 }
             }
-            if (!dh.CheckExist("source", "sc_code='" + Source.Text + "' and sc_statuscode='AUDITED'"))
+            if (!dh.CheckExist("source", "sc_code='" + isource + "' and sc_statuscode='AUDITED'"))
             {
                 OperateResult.AppendText("岗位资源错误或者未审核\n");
                 return;
@@ -120,25 +160,13 @@ namespace UAS_XmlAnalysor
             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("Source", isource);
+            BaseUtil.SetCacheData("Master", Master.Text);
+            BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
+
+
             StartWatch.Enabled = false;
             ChooseFolder.Enabled = false;
             ChooseBackUpFolder.Enabled = false;
@@ -192,11 +220,17 @@ namespace UAS_XmlAnalysor
                     Console.WriteLine(ex.Message);
                 }
             }
+
+            string test_result = "";
+            string oMSID = "";
+            string oErrMessage = "";
+
             string testDate = "";
             string testTime = "";
             XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + e.Name);
             //获取文件名的序列号,如SA123456.xml
             string sncode = e.Name.Split('.')[0];
+            string makecode = "";
             //获取序列号ID最大的工单号
             string iMakeCode = dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode='" + sncode + "' order by ms_id desc").ToString();
             OperateResult.AppendText("读取文件" + e.Name + "\n");
@@ -207,10 +241,11 @@ namespace UAS_XmlAnalysor
             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_result = myReader.GetAttribute("test_result");
+                    testDate = myReader.GetAttribute("test_date");
+                    testTime = myReader.GetAttribute("test_time");
                 }
                 if (myReader.NodeType == XmlNodeType.Text)
                 {
@@ -226,11 +261,88 @@ namespace UAS_XmlAnalysor
                     }
                 }
             }
-            string date = testDate + " " + testTime;
+            string test_date = testDate + " " + testTime;
+            string status = "";
+            string errmessage = "";
+            bool NoteAlready = false;
+            LogicHandler.GetMakeInfo(sncode, out makecode, out status, out errmessage);
+            if (ma_code.Text != makecode && makecode != "" && ma_code.Text != "" && status != "2")
+            {
+                string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号" + sncode + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                //如果选择不切换赋值当前界面工单
+                if (ChangeMakeCode != "Yes")
+                {
+                    makecode = ma_code.Text;
+                }
+                else
+                {
+                    NoteAlready = true;
+                }
+            }
+            if (LogicHandler.CheckStepSNAndMacode(iMakeCode, isource, sncode, iusercode, out iMakeCode, out oMSID, out oErrMessage))
+            {
+                if (!NoteAlready)
+                {
+                    if (makecode != ma_code.Text && ma_code.Text != "")
+                    {
+                        string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                        //如果选择不切换赋值当前界面工单
+                        if (ChangeMakeCode == "Yes")
+                        {
+                            ma_code.Text = makecode;
+                        }
+                        else
+                        {
+                            OperateResult.AppendText(">>请重新采集序列号\n");
+                            tipform.startthread("请重新采集序列号", test_result);
+                            return;
+                        }
+                    }
+                }
+                //获取序列号ID最大的工单
+                dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_id from makeserial where ms_sncode='" + sncode + "' order by ms_id desc", "select");
+                if (dt.Rows.Count > 0)
+                {
+                    ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
+                    makecode = dt.Rows[0]["ms_makecode"].ToString();
+                    switch (test_result)
+                    {
+                        case "OK":
+                            if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", test_result, iusercode, out oErrMessage))
+                            {
+                                OperateResult.AppendText(oErrMessage + "\n");
+                                tipform.startthread(oErrMessage, test_result);
+                                return;
+                            }
+                            tipform.startthread("序列号 " + sncode + "通过检测", test_result);
+                            break;
+                        case "NG":
+                            //RecordBadInfo(sncode, makecode, e.Name, "", badcode.ToArray(), badlocation.ToArray());
+                            ////所有的序列号均采集为良品
+                            //if (!LogicHandler.SetTestNGDetail(sncode, makecode, iusercode, isource, test_result, out oErrMessage))
+                            //{
+                            //    OperateResult.AppendText(oErrMessage + "\n");
+                            //    tipform.startthread(oErrMessage, test_result);
+                            //    return;
+                            //}
+                            tipform.startthread("序列号 " + sncode + "未通过检测", test_result);
+                            break;
+                        default:
+                            break;
+                    }
+                    LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, e.Name, test_result == "NG" ? "1" : "0", "0");
+                }
+            }
+            else
+            {
+                OperateResult.AppendText(oErrMessage + "\n");
+                tipform.startthread(oErrMessage, "NG");
+                return;
+            }
             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'))";
+            sql += "'" + sncode + "',:std_subclass1,:std_testresult, sysdate,'" + isource + "',to_char(to_date('" + testDate + "','YYYY/MM/DD'), 'YYYYMMDD'),";
+            sql += "to_char(to_date('" + testTime + "','hh24:mi:ss'), 'hh24miss'),to_date('" + test_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);
@@ -244,14 +356,14 @@ namespace UAS_XmlAnalysor
                         {
                             file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name);
                             OperateResult.AppendText("成功解析文件" + e.Name + "\n");
-                            form2.startthread(e.Name);
+                            //tipform.startthread(e.Name);
                             break;
                         }
                         else if (!File.Exists(BackUpFolderPath.Text + @"\" + e.Name.Split('.')[0] + "(" + i + ")" + "." + e.Name.Split('.')[1]))
                         {
                             file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name.Split('.')[0] + "(" + i + ")" + "." + e.Name.Split('.')[1]);
                             OperateResult.AppendText("成功解析文件" + e.Name + "\n");
-                            form2.startthread(e.Name);
+                            //tipform.startthread(e.Name);
                             break;
                         }
                     }
@@ -266,7 +378,6 @@ namespace UAS_XmlAnalysor
         private void StopWatch_Click(object sender, EventArgs e)
         {
             XmlWatcher.EnableRaisingEvents = false;
-            Source.Enabled = true;
             StartWatch.Enabled = true;
             ChooseFolder.Enabled = true;
             ChooseBackUpFolder.Enabled = true;
@@ -320,5 +431,6 @@ namespace UAS_XmlAnalysor
         {
             SetAutoRun();
         }
+ 
     }
 }

+ 44 - 9
UAS_XmlAnalysor/Form2.Designer.cs

@@ -29,6 +29,9 @@
         private void InitializeComponent()
         {
             this.label1 = new System.Windows.Forms.Label();
+            this.checkBox1 = new System.Windows.Forms.CheckBox();
+            this.panel1 = new System.Windows.Forms.Panel();
+            this.panel1.SuspendLayout();
             this.SuspendLayout();
             // 
             // label1
@@ -37,33 +40,65 @@
             this.label1.BackColor = System.Drawing.SystemColors.Menu;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.label1.ForeColor = System.Drawing.Color.Black;
-            this.label1.Location = new System.Drawing.Point(75, 18);
+            this.label1.Location = new System.Drawing.Point(13, 10);
+            this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label1.MaximumSize = new System.Drawing.Size(400, 0);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(0, 21);
+            this.label1.Size = new System.Drawing.Size(0, 27);
             this.label1.TabIndex = 0;
             // 
+            // checkBox1
+            // 
+            this.checkBox1.AutoSize = true;
+            this.checkBox1.BackColor = System.Drawing.SystemColors.Menu;
+            this.checkBox1.Font = new System.Drawing.Font("宋体", 7.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.checkBox1.ForeColor = System.Drawing.Color.Black;
+            this.checkBox1.Location = new System.Drawing.Point(13, 68);
+            this.checkBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.checkBox1.Name = "checkBox1";
+            this.checkBox1.Size = new System.Drawing.Size(107, 17);
+            this.checkBox1.TabIndex = 1;
+            this.checkBox1.Text = "是否自动隐藏";
+            this.checkBox1.UseVisualStyleBackColor = false;
+            this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
+            // 
+            // panel1
+            // 
+            this.panel1.Controls.Add(this.checkBox1);
+            this.panel1.Controls.Add(this.label1);
+            this.panel1.Location = new System.Drawing.Point(3, 0);
+            this.panel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
+            this.panel1.Name = "panel1";
+            this.panel1.Size = new System.Drawing.Size(413, 91);
+            this.panel1.TabIndex = 2;
+            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
+            this.panel1.MouseEnter += new System.EventHandler(this.Form2_MouseEnter);
+            this.panel1.MouseLeave += new System.EventHandler(this.Form2_MouseLeave);
+            // 
             // Tip
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.SystemColors.Menu;
-            this.ClientSize = new System.Drawing.Size(312, 59);
-            this.Controls.Add(this.label1);
+            this.ClientSize = new System.Drawing.Size(416, 98);
+            this.Controls.Add(this.panel1);
             this.ForeColor = System.Drawing.Color.White;
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
             this.Name = "Tip";
             this.Text = "Form2";
             this.TopMost = true;
             this.Load += new System.EventHandler(this.Form2_Load);
-            this.MouseEnter += new System.EventHandler(this.Form2_MouseEnter);
-            this.MouseLeave += new System.EventHandler(this.Form2_MouseLeave);
-            this.ResumeLayout(false);
-            this.PerformLayout();
+            this.panel1.ResumeLayout(true);
+            this.panel1.PerformLayout();
+            this.ResumeLayout(true);
 
         }
 
         #endregion
 
         private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.CheckBox checkBox1;
+        private System.Windows.Forms.Panel panel1;
     }
 }

+ 41 - 17
UAS_XmlAnalysor/Form2.cs

@@ -1,10 +1,6 @@
 using System;
-using System.Collections.Generic;
 using System.ComponentModel;
-using System.Data;
 using System.Drawing;
-using System.Linq;
-using System.Text;
 using System.Threading;
 using System.Windows.Forms;
 
@@ -29,9 +25,14 @@ namespace UAS_XmlAnalysor
             label1.Text = DateTime.Now.ToString();
         }
 
-        public void startthread(string filename)
+        public void startthread(string filename,string type)
         {
-            label1.Text = filename+"解析完成";
+            label1.Text = filename;
+            if(type  == "OK")
+            label1.ForeColor = System.Drawing.Color.Green;
+            if(type == "NG")
+            label1.ForeColor = System.Drawing.Color.Red;
+                  
             //thread.Start();
             using (BackgroundWorker bw = new BackgroundWorker())
             {
@@ -47,9 +48,12 @@ namespace UAS_XmlAnalysor
         }
         private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
         {
-            aa();
-            Thread.Sleep(500);
-            bb();
+            if (checkBox1.Checked)
+            {
+                aa();
+                Thread.Sleep(2000);
+                bb();
+            }
         }
         public void aa()
         {
@@ -98,17 +102,37 @@ namespace UAS_XmlAnalysor
 
         private void Form2_MouseLeave(object sender, EventArgs e)
         {
-            if (this.Left <= Screen.PrimaryScreen.WorkingArea.Width - 10 && state == 0)
+            if (checkBox1.Checked)
             {
-                state = 1;
-                int t = this.Left;
-                for (int i = t; i < Screen.PrimaryScreen.WorkingArea.Width - 10; i=i+2)
+                Panel p = sender as Panel;
+                //如果Mouse Leave,则清除背景图,否则不处理
+                Point mousePoint = p.PointToClient(Control.MousePosition);
+                if (!p.ClientRectangle.Contains(mousePoint))
                 {
-                    this.Left = i;
-                    Application.DoEvents();
+                    if (this.Left <= Screen.PrimaryScreen.WorkingArea.Width - 10 && state == 0)
+                    {
+                        state = 1;
+                        int t = this.Left;
+                        for (int i = t; i < Screen.PrimaryScreen.WorkingArea.Width - 10; i = i + 2)
+                        {
+                            this.Left = i;
+                            Application.DoEvents();
+                        }
+                        state = 0;
+                    }
                 }
-                state = 0;
-            }
+            }      
+        }
+
+        private void panel1_Paint(object sender, PaintEventArgs e)
+        {
+
+        }
+
+        private void checkBox1_CheckedChanged(object sender, EventArgs e)
+        {
+            if (!checkBox1.Checked)
+                aa();  
         }
     }
 }

+ 222 - 0
UAS_XmlAnalysor/LogicHandler.cs

@@ -0,0 +1,222 @@
+using System.Collections.Generic;
+using System.Data;
+using System.Text;
+using UAS_XmlAnalysor;
+
+namespace UAS_XmlAnalysor
+{
+    class LogicHandler
+    {
+        public LogicHandler() { }
+
+        public static DataHelper dh = new DataHelper();
+        //用于拼接SQL
+        static StringBuilder sql = new StringBuilder();
+        //用于存放批量执行的SQL
+        static List<string> sqls = new List<string>();
+
+        public static bool CheckStepSNAndMacode(string iMakeCode, string iSourceCode, string iSN, string iUserCode, out string oMakeCode, out string oMsID, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            oMakeCode = "";
+            oMsID = "";
+            string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, oMakeCode, oMsID, oErrorMessage };
+            dh.CallProcedure("CS_CHECKSTEPSNANDMACODE", ref param);
+            oMakeCode = param[4];
+            oMsID = param[5];
+            oErrorMessage = param[6];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+
+        public static void AutoPassLog(string iSN, string iSource, string iMakeCode, string iDate, string iStepCode, string iLineCode, string iFileName, string iIFNG,string iIFAutoSN)
+        {
+            sql.Clear();
+            sql.Append("insert into AUTOSCANLOG(as_id,as_indate,as_testdate,as_sourcecode,as_stepcode,");
+            sql.Append("as_linecode,as_makecode,as_sncode,as_filename,as_ifng,as_autosn)values(AUTOSCANLOG_seq.nextval,");
+            sql.Append("sysdate,to_date('" + iDate + "','yyyy-mm-dd,hh24:mi:ss'),'" + iSource + "','" + iStepCode + "','" + iLineCode + "','" + iMakeCode + "',");
+            sql.Append("'" + iSN + "','" + iFileName + "','" + iIFNG + "','"+iIFAutoSN+"')");
+            dh.ExecuteSql(sql.ToString(), "select");
+        }
+
+        /// <summary>
+        /// 获取工单的最近一条执行记录
+        /// </summary>
+        /// <param name="iSnCode"></param>
+        /// <param name="oMakeCode"></param>
+        /// <param name="oErrorMessage"></param>
+        /// <returns></returns>
+        public static bool GetMakeInfo(string iSnCode, out string oMakeCode, out string oStatus, out string oErrorMessage)
+        {
+            //取MakeProcess表中的执行记录ID最大的一个工单的号码
+            oMakeCode = "";
+            oErrorMessage = "";
+            oStatus = "";
+            DataTable dt = dh.getFieldsDataByCondition("MakeSerial", new string[] { "ms_makecode", "ms_status" }, "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + iSnCode + "')");
+            if (dt.Rows.Count > 0)
+            {
+                oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
+                oStatus = dt.Rows[0]["ms_status"].ToString();
+            }
+            if (oMakeCode != "")
+                return true;
+            else
+            {
+                oErrorMessage = "序列号:" + iSnCode + " 未归属工单";
+                return false;
+            }
+        }
+
+        public static void AutoPassJudge(string iSN, string iMakeCode, string iSource, string iFileName, string iLineCode, string iCombine)
+        {
+            //插入不良判断记录
+            sql.Clear();
+            sql.Append("insert into AUTOSCAN_REJUDGE(asr_id,asr_indate,asr_filename,asr_combinecode,asr_sourcecode,");
+            sql.Append("asr_linecode,asr_makecode,asr_sncode) values(AUTOSCAN_REJUDGE_seq.nextval,sysdate,");
+            sql.Append("'" + iFileName + "','" + iCombine + "','" + iSource + "','" + iLineCode + "','" + iMakeCode + "','" + iSN + "')");
+            dh.ExecuteSql(sql.ToString(), "insert");
+        }
+
+        public static bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string SQL = "select em_code from employee where upper(em_code)=:UserName and em_password =:PassWord";
+            DataTable dt;
+            dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode.ToUpper(), iPassWord);
+            if (dt.Rows.Count > 0)
+                return true;
+            else
+            {
+                oErrorMessage = "用户名或者密码不正确!";
+                return false;
+            }
+        }
+
+        public static bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserCode, string iSourceCode, string iResult, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string StepCode = "";
+            string StepName = "";
+            if (iResult == "" || iResult == null)
+                iResult = "检查未通过";
+            GetStepCodeAndNameBySource(iSourceCode, ref StepCode, ref StepName);
+            //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
+            //如果存在送检批号则进行删除
+            if (dh.CheckExist("oqcbatchdetail", "obd_sncode='" + iSnCode + "'"))
+            {
+                string checkno = dh.getFieldDataByCondition("oqcbatchdetail", "obd_checkno", "obd_sncode='" + iSnCode + "'").ToString();
+                dh.ExecuteSql("delete from oqcbatchdetail where obd_sncode='" + iSnCode + "'", "delete");
+                dh.ExecuteSql("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + checkno + "'", "update");
+            }
+            //之前保存的不良就不再调用
+            DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "ms_stepcode", "nvl(ms_ifrework,0)ms_ifrework" }, "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
+            if (dt.Rows.Count > 0)
+            {
+                string ifrework = dt.Rows[0]["ms_ifrework"].ToString();
+                string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
+                if (ms_stepcode == StepCode)
+                {
+                    if (ifrework == "0")
+                        dh.UpdateByCondition("makeserial", "ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
+                    else
+                        dh.UpdateByCondition("makeserial", "ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
+                }
+                else
+                {
+                    if (ifrework == "0")
+                        dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_status=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "' ");
+                    else
+                        dh.UpdateByCondition("makeserial", "ms_nextstepcode='',ms_paststep = ms_paststep ||'," + StepCode + "',ms_reworkstatus=3", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
+                    SetStepResult(iMakeCode, iSourceCode, iSnCode, "不良采集", iResult, iUserCode, out oErrorMessage);
+                }
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 获取步骤代码和名称
+        /// </summary>
+        /// <param name="Source"></param>
+        /// <param name="StepCode"></param>
+        /// <param name="StepName"></param>
+        private static void GetStepCodeAndNameBySource(string Source, ref string StepCode, ref string StepName)
+        {
+            DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
+            if (dt.Rows.Count > 0)
+            {
+                StepCode = dt.Rows[0]["sc_stepcode"].ToString();
+                StepName = dt.Rows[0]["sc_stepname"].ToString();
+            }
+        }
+
+        public static bool CheckUserAndResourcePassed(string iUserCode, string iSourceCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            iUserCode = iUserCode.ToUpper();
+            iSourceCode = iSourceCode.ToUpper();
+            string SQL = "select em_code,em_type from employee where upper(em_code)=:UserName ";
+            DataTable dt;
+            dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode);
+            if (dt.Rows.Count > 0)
+            {
+                string em_type = dt.Rows[0]["em_type"].ToString();
+                if (iSourceCode == "")
+                {
+                    oErrorMessage = "岗位资源不允许为空";
+                    return false;
+                }
+                if (em_type == "admin")
+                {
+                    if (dh.CheckExist("Source", "upper(sc_code)='" + iSourceCode + "' and sc_statuscode='AUDITED'"))
+                    {
+                        return true;
+                    }
+                    else
+                    {
+                        oErrorMessage = "岗位资源编号错误或者未审核!";
+                        return false;
+                    }
+                }
+                else
+                {
+                    dt = dh.getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "upper(ur_resourcecode) ur_resourcecode" }, "upper(eg_emcode)= '" + iUserCode + "' and sc_statuscode='AUDITED'");
+                    //如果存在该编号
+                    if (dt.Rows.Count > 0)
+                    {
+                        //判断如果多个岗位资源存在,用户输入的只要在其中就行
+                        for (int i = 0; i < dt.Rows.Count; i++)
+                        {
+                            if (dt.Rows[i]["ur_resourcecode"].ToString() == iSourceCode)
+                                return true;
+                        }
+                        oErrorMessage = "用户不处于当前资源所属分组!";
+                    }
+                    else
+                        oErrorMessage = "岗位资源编号错误或者未审核!";
+                }
+            }
+            else
+                oErrorMessage = "用户不存在!";
+            return false;
+        }
+
+        public static bool SetStepResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
+        {
+            return CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
+        }
+
+        public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrorMessage };
+            dh.CallProcedure("CS_SETSTEPRESULT", ref param);
+            oErrorMessage = param[5];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+    }
+}

+ 61 - 61
UAS_XmlAnalysor/Login.Designer.cs

@@ -28,92 +28,92 @@
         /// </summary>
         private void InitializeComponent()
         {
-            this.label1 = new System.Windows.Forms.Label();
-            this.label2 = new System.Windows.Forms.Label();
             this.UserName = new System.Windows.Forms.TextBox();
+            this.UserName_lable = new System.Windows.Forms.Label();
             this.PassWord = new System.Windows.Forms.TextBox();
-            this.label3 = new System.Windows.Forms.Label();
+            this.PassWord_label = new System.Windows.Forms.Label();
             this.Source = new System.Windows.Forms.TextBox();
-            this.LoginButton = new System.Windows.Forms.Button();
+            this.Source_label = new System.Windows.Forms.Label();
+            this.CheckLogin = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
-            // label1
-            // 
-            this.label1.AutoSize = true;
-            this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(145, 70);
-            this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(58, 21);
-            this.label1.TabIndex = 0;
-            this.label1.Text = "用户名";
-            // 
-            // label2
-            // 
-            this.label2.AutoSize = true;
-            this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label2.Location = new System.Drawing.Point(145, 121);
-            this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(42, 21);
-            this.label2.TabIndex = 1;
-            this.label2.Text = "密码";
-            // 
             // UserName
             // 
-            this.UserName.Location = new System.Drawing.Point(231, 71);
+            this.UserName.Location = new System.Drawing.Point(206, 53);
             this.UserName.Name = "UserName";
-            this.UserName.Size = new System.Drawing.Size(174, 21);
-            this.UserName.TabIndex = 2;
+            this.UserName.Size = new System.Drawing.Size(163, 25);
+            this.UserName.TabIndex = 5;
+            // 
+            // UserName_lable
+            // 
+            this.UserName_lable.AutoSize = true;
+            this.UserName_lable.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.UserName_lable.Location = new System.Drawing.Point(122, 51);
+            this.UserName_lable.Name = "UserName_lable";
+            this.UserName_lable.Size = new System.Drawing.Size(72, 27);
+            this.UserName_lable.TabIndex = 4;
+            this.UserName_lable.Text = "用户名";
             // 
             // PassWord
             // 
-            this.PassWord.Location = new System.Drawing.Point(231, 122);
+            this.PassWord.Location = new System.Drawing.Point(206, 110);
             this.PassWord.Name = "PassWord";
             this.PassWord.PasswordChar = '*';
-            this.PassWord.Size = new System.Drawing.Size(174, 21);
-            this.PassWord.TabIndex = 3;
+            this.PassWord.Size = new System.Drawing.Size(163, 25);
+            this.PassWord.TabIndex = 7;
             // 
-            // label3
+            // PassWord_label
             // 
-            this.label3.AutoSize = true;
-            this.label3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label3.Location = new System.Drawing.Point(145, 171);
-            this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(74, 21);
-            this.label3.TabIndex = 4;
-            this.label3.Text = "岗位资源";
+            this.PassWord_label.AutoSize = true;
+            this.PassWord_label.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.PassWord_label.Location = new System.Drawing.Point(122, 108);
+            this.PassWord_label.Name = "PassWord_label";
+            this.PassWord_label.Size = new System.Drawing.Size(52, 27);
+            this.PassWord_label.TabIndex = 6;
+            this.PassWord_label.Text = "密码";
             // 
             // Source
             // 
-            this.Source.Location = new System.Drawing.Point(231, 171);
+            this.Source.Location = new System.Drawing.Point(206, 169);
             this.Source.Name = "Source";
-            this.Source.Size = new System.Drawing.Size(174, 21);
-            this.Source.TabIndex = 5;
+            this.Source.Size = new System.Drawing.Size(163, 25);
+            this.Source.TabIndex = 9;
+            // 
+            // Source_label
+            // 
+            this.Source_label.AutoSize = true;
+            this.Source_label.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Source_label.Location = new System.Drawing.Point(122, 169);
+            this.Source_label.Name = "Source_label";
+            this.Source_label.Size = new System.Drawing.Size(52, 27);
+            this.Source_label.TabIndex = 8;
+            this.Source_label.Text = "资源";
             // 
-            // LoginButton
+            // CheckLogin
             // 
-            this.LoginButton.Location = new System.Drawing.Point(245, 232);
-            this.LoginButton.Name = "LoginButton";
-            this.LoginButton.Size = new System.Drawing.Size(75, 23);
-            this.LoginButton.TabIndex = 6;
-            this.LoginButton.Text = "登陆";
-            this.LoginButton.UseVisualStyleBackColor = true;
-            this.LoginButton.Click += new System.EventHandler(this.LoginButton_Click);
+            this.CheckLogin.Location = new System.Drawing.Point(220, 224);
+            this.CheckLogin.Name = "CheckLogin";
+            this.CheckLogin.Size = new System.Drawing.Size(75, 30);
+            this.CheckLogin.TabIndex = 10;
+            this.CheckLogin.Text = "登陆";
+            this.CheckLogin.UseVisualStyleBackColor = true;
+            this.CheckLogin.Click += new System.EventHandler(this.CheckLogin_Click);
             // 
             // Login
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(561, 294);
-            this.Controls.Add(this.LoginButton);
+            this.ClientSize = new System.Drawing.Size(508, 286);
+            this.Controls.Add(this.CheckLogin);
             this.Controls.Add(this.Source);
-            this.Controls.Add(this.label3);
+            this.Controls.Add(this.Source_label);
             this.Controls.Add(this.PassWord);
+            this.Controls.Add(this.PassWord_label);
             this.Controls.Add(this.UserName);
-            this.Controls.Add(this.label2);
-            this.Controls.Add(this.label1);
-            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
+            this.Controls.Add(this.UserName_lable);
             this.Name = "Login";
-            this.Text = "登陆";
+            this.Text = "Login";
+            this.Load += new System.EventHandler(this.Login_Load);
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -121,12 +121,12 @@
 
         #endregion
 
-        private System.Windows.Forms.Label label1;
-        private System.Windows.Forms.Label label2;
         private System.Windows.Forms.TextBox UserName;
+        private System.Windows.Forms.Label UserName_lable;
         private System.Windows.Forms.TextBox PassWord;
-        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label PassWord_label;
         private System.Windows.Forms.TextBox Source;
-        private System.Windows.Forms.Button LoginButton;
+        private System.Windows.Forms.Label Source_label;
+        private System.Windows.Forms.Button CheckLogin;
     }
 }

+ 44 - 0
UAS_XmlAnalysor/Login.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Windows.Forms;
+
+namespace UAS_XmlAnalysor
+{
+    public partial class Login : Form
+    {
+
+        public Login()
+        {
+            StartPosition = FormStartPosition.CenterScreen;
+            InitializeComponent();
+        }
+
+        private void CheckLogin_Click(object sender, EventArgs e)
+        {
+            string ErrMessage = "";
+            if (LogicHandler.CheckUserLogin(UserName.Text, PassWord.Text, out ErrMessage))
+            {
+                if (LogicHandler.CheckUserAndResourcePassed(UserName.Text, Source.Text, out ErrMessage))
+                {
+                    BaseUtil.SetCacheData("UserName", UserName.Text);
+                    BaseUtil.SetCacheData("Source", Source.Text);
+                    Form1 xml = new Form1(UserName.Text, Source.Text);
+                    Hide();
+                    xml.ShowDialog();
+                    Close();
+                }
+                else MessageBox.Show(ErrMessage);
+            }
+            else MessageBox.Show(ErrMessage);
+        }
+
+        private void Login_Load(object sender, EventArgs e)
+        {
+            UserName.Text = BaseUtil.GetCacheData("UserName").ToString();
+            Source.Text = BaseUtil.GetCacheData("Source").ToString();
+            if (UserName.Text != "")
+            {
+                PassWord.Focus();
+            }
+        }
+    }
+}

+ 120 - 0
UAS_XmlAnalysor/Login.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 19 - 1
UAS_XmlAnalysor/Program.cs

@@ -7,6 +7,7 @@ using System.Security.Principal;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using System.Xml;
 
 namespace UAS_XmlAnalysor
 {
@@ -29,13 +30,30 @@ namespace UAS_XmlAnalysor
                 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                 //处理非UI线程异常
                 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+                //创建存储登录信息的文件
+                if (!Directory.Exists(Form1.CachePathFolder))
+                    Directory.CreateDirectory(Form1.CachePathFolder);
+                FileStream fcaches = new FileStream(Form1.CachePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                fcaches.Close();
+                FileInfo info = new FileInfo(Form1.CachePath);
+                if (info.Length == 0)
+                {
+                    XmlDocument doc = new XmlDocument();
+                    //创建类型声明节点  
+                    XmlNode node = doc.CreateXmlDeclaration("1.0", "utf-8", "");
+                    doc.AppendChild(node);
+                    //创建根节点  
+                    XmlElement xeRoot = doc.CreateElement("CacheInf");
+                    doc.AppendChild(xeRoot);
+                    doc.Save(Form1.CachePath);
+                }
 
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
                 if (!Directory.Exists(sysdisc + @":\Cache"))
                     Directory.CreateDirectory(sysdisc + @":\Cache");
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
-                    Application.Run(new Form1());
+                    Application.Run(new Login());
                 else
                 {
                     //创建启动对象

+ 11 - 0
UAS_XmlAnalysor/UAS_XmlAnalysor.csproj

@@ -89,6 +89,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="BaseUtil.cs" />
     <Compile Include="DataHelper.cs" />
     <Compile Include="Form1.cs">
       <SubType>Form</SubType>
@@ -108,6 +109,13 @@
     <Compile Include="LoadingCircle.Designer.cs">
       <DependentUpon>LoadingCircle.cs</DependentUpon>
     </Compile>
+    <Compile Include="LogicHandler.cs" />
+    <Compile Include="Login.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Login.Designer.cs">
+      <DependentUpon>Login.cs</DependentUpon>
+    </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="SetLoadingWindow.cs">
@@ -122,6 +130,9 @@
     <EmbeddedResource Include="Form2.resx">
       <DependentUpon>Form2.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="Login.resx">
+      <DependentUpon>Login.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>

Some files were not shown because too many files changed in this diff