Browse Source

XML解析器修改

Hcsy 7 years ago
parent
commit
89930f0303
2 changed files with 186 additions and 29 deletions
  1. 28 0
      UAS_XmlAnalysor/DataHelper.cs
  2. 158 29
      UAS_XmlAnalysor/Form1.cs

+ 28 - 0
UAS_XmlAnalysor/DataHelper.cs

@@ -936,6 +936,34 @@ namespace UAS_XmlAnalysor
             return sql;
         }
 
+
+        public void CallProcedure(string ProcedureName, string[] ParamName, ref string[] param)
+        {
+            command = new OracleCommand(ProcedureName);
+            command.Connection = connection;
+            Reconnect(command);
+            command.CommandText = ProcedureName;
+            command.CommandType = CommandType.StoredProcedure;
+            for (int i = 0; i < param.Length; i++)
+            {
+                command.Parameters.Add(new OracleParameter(ParamName[i], OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
+                //command.Parameters.Add(new OracleParameter(ParamName[i], OracleType.VarChar, 200, ParameterDirection.InputOutput, "", DataRowVersion.Default, true, param[i]));
+            }
+            try
+            {
+                command.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+                command.Connection = new OracleConnection(ConnectionStrings);
+                command.Connection.Open();
+                command.ExecuteNonQuery();
+            }
+            for (int i = 0; i < command.Parameters.Count; i++)
+                param[i] = command.Parameters[i].Value.ToString();
+            command.Dispose();
+        }
+
         /// <summary>
         /// 调用存储过程
         /// </summary>

+ 158 - 29
UAS_XmlAnalysor/Form1.cs

@@ -237,7 +237,12 @@ namespace UAS_XmlAnalysor
             List<string> name = new List<string>();
             //获取采集项目的结果
             List<string> result = new List<string>();
-            int name_or_result = 0;
+            string class2name = "";
+            string class3name = "";
+
+            List<string> class2 = new List<string>();
+            //获取采集项目的结果
+            List<string> class3 = new List<string>();
             while (myReader.Read())
             {
                 if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "test" && myReader.IsStartElement())
@@ -245,21 +250,67 @@ namespace UAS_XmlAnalysor
                     test_result = myReader.GetAttribute("test_result");
                     testDate = myReader.GetAttribute("test_date");
                     testTime = myReader.GetAttribute("test_time");
+                    class2name = "";
+                    class3name = "";
                 }
-                if (myReader.NodeType == XmlNodeType.Text)
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "OperatorInput" && myReader.IsStartElement())
                 {
-                    if (name_or_result % 2 == 0)
-                    {
-                        name.Add(myReader.Value);
-                        name_or_result++;
-                    }
-                    else
-                    {
-                        result.Add(myReader.Value);
-                        name_or_result++;
-                    }
+                    class2name = "OperatorInput";
+                    class3name = "";
+                }
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "SelfTest" && myReader.IsStartElement())
+                {
+                    class2name = "SelfTest";
+                    class3name = "";
+                }
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "BlueTooth" && myReader.IsStartElement())
+                {
+                    class2name = "SelfTest";
+                    class3name = "BlueTooth";
+                }
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "wifi" && myReader.IsStartElement())
+                {
+                    class2name = "SelfTest";
+                    class3name = "wifi";
+                }
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "temperature" && myReader.IsStartElement())
+                {
+                    class2name = "SelfTest";
+                    class3name = "temperature";
+                }
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "nightvision" && myReader.IsStartElement())
+                {
+                    class2name = "SelfTest";
+                    class3name = "nightvision";
+                }
+                //if (myReader.NodeType == XmlNodeType.Text)
+                //{
+                //    if (name_or_result % 2 == 0)
+                //    {
+
+                //        name.Add(myReader.Value+" ");
+                //        name_or_result++;
+                //    }
+                //    else
+                //    {
+                //        result.Add(myReader.Value+" ");
+                //        name_or_result++;
+                //        class2.Add(class2name);
+                //        class3.Add(class3name);
+                //    }    
+                //}
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "command_name" && myReader.IsStartElement())
+                {
+                    name.Add(myReader.ReadInnerXml() + " "); 
+                }
+                if (myReader.NodeType == XmlNodeType.Element && myReader.Name == "command_result" && myReader.IsStartElement())
+                {
+                    result.Add(myReader.ReadInnerXml() + " ");
+                    class2.Add(class2name);
+                    class3.Add(class3name);
                 }
             }
+            myReader.Close();
             string test_date = testDate + " " + testTime;
             string status = "";
             string errmessage = "";
@@ -278,11 +329,11 @@ namespace UAS_XmlAnalysor
                     NoteAlready = true;
                 }
             }
-            if (LogicHandler.CheckStepSNAndMacode(makecode, isource, sncode, iusercode, out makecode, out oMSID, out oErrMessage))
+            if (CheckRoutePassed(sncode,isource, makecode,out oErrMessage))
             {
                 if (!NoteAlready)
                 {
-                    if (makecode != ma_code.Text && ma_code.Text != "")
+                    if (makecode != ma_code.Text && ma_code.Text != "" && status != "")
                     {
                         string ChangeMakeCode = MessageBox.Show(this.ParentForm, "序列号所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
                         //如果选择不切换赋值当前界面工单
@@ -299,32 +350,42 @@ namespace UAS_XmlAnalysor
                     }
                 }
                 //获取序列号ID最大的工单
-                dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_id from makeserial where ms_sncode='" + sncode + "' order by ms_id desc", "select");
+                dt = (DataTable)dh.ExecuteSql("select ms_status,ms_makecode,ms_id,ms_craftcode,ms_prodcode from makeserial where ms_sncode='" + sncode + "' order by ms_id desc", "select");
                 if (dt.Rows.Count > 0)
                 {
+                    string ms_status = dt.Rows[0]["ms_status"].ToString();
+                    string ms_craftcode = dt.Rows[0]["ms_craftcode"].ToString();
+                    string ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
                     ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
                     makecode = dt.Rows[0]["ms_makecode"].ToString();
                     switch (test_result)
                     {
                         case "OK":
+                            if (ms_status == "3")
+                            {
+                                string nextstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id=cd_crid ", "cd_nextstepcode", "cr_code='" + ms_craftcode + "' and cr_prodcode='" + ms_prodcode + "' and cd_stepcode='" + istepcode + "'").ToString();
+                                dh.UpdateByCondition("makeserial", "ms_status=1,ms_nextstepcode='" + nextstepcode + "'", "ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'");
+                                dh.UpdateByCondition("makebad", "mb_status=-1", "mb_sncode='" + sncode + "' and mb_makecode='" + makecode + "'");
+                            }
+
                             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);
+                            tipform.startthread("序列号 " + sncode + "通过检测,OK", 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);
+                            RecordBadInfo(sncode, makecode, e.Name, "");
+                            //所有的序列号均采集为良品
+                            if (!LogicHandler.SetTestNGDetail(sncode, makecode, iusercode, isource, test_result, out oErrMessage))
+                            {
+                                OperateResult.AppendText(oErrMessage + "\n");
+                                tipform.startthread(oErrMessage, test_result);
+                                return;
+                            }
+                            tipform.startthread("序列号 " + sncode + "未通过检测,NG", test_result);
                             break;
                         default:
                             break;
@@ -338,12 +399,11 @@ namespace UAS_XmlAnalysor
                 tipform.startthread(oErrMessage, "NG");
                 return;
             }
-            string sql = "insert into STEPTESTDETAIL(std_id,std_makecode,std_sn,std_subclass1,std_testresult,std_indate,";
+            string sql = "insert into STEPTESTDETAIL(std_id,std_makecode,std_sn,std_subclass1,std_subclass2,std_subclass3,std_testresult,std_indate,";
             sql += "std_rescode,std_testdate,std_testtime,std_date) values(STEPTESTDETAIL_seq.nextval, '" + makecode + "', ";
-            sql += "'" + sncode + "',:std_subclass1,:std_testresult, sysdate,'" + isource + "',to_char(to_date('" + testDate + "','YYYY/MM/DD'), 'YYYYMMDD'),";
+            sql += "'" + sncode + "',:std_subclass1,:std_subclass2,:std_subclass3,: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();
+            dh.BatchInsert(sql, new string[] { "std_subclass1", "std_subclass2", "std_subclass3", "std_testresult" }, name.ToArray(), class2.ToArray(), class3.ToArray(),result.ToArray());
             FileInfo file = new FileInfo(FolderPath.Text + @"\" + e.Name);
             if (file.Exists)
             {
@@ -405,6 +465,27 @@ namespace UAS_XmlAnalysor
 
         }
 
+        private void RecordBadInfo(string sncode, string makecode, string filename, string combine)
+        {
+            string ID = dh.GetSEQ("makebad_seq");
+            sql.Clear();
+            sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
+            sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_status,mb_badremark) select "+ ID + "");
+            sql.Append(",ma_code,ms_code,ms_sncode,'" + iusercode + "',sysdate,'" + istepcode + "','" + isource + "',");
+            sql.Append("'','" + ibadgroup + "','','0','' from make left join makeSerial on ms_makecode=ma_code ");
+            sql.Append("where ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'");
+            dh.ExecuteSql(sql.ToString(),"insert");
+            sql.Clear();
+            sql.Append("update makebad set mb_badname=(select DISTINCT bc_name from badcode where bc_code=mb_badcode),mb_bgname=(select DISTINCT bg_name from badgroup where bg_code=mb_bgcode) ");
+            sql.Append("where mb_id="+ ID + "");
+            dh.ExecuteSql(sql.ToString(), "insert");
+            //记录判断日志
+            if (dh.getFieldDataByCondition("source", "sc_scantype", "sc_code='" + isource + "'").ToString() == "REJUCE")
+            {
+                LogicHandler.AutoPassJudge(sncode, makecode, isource, filename, ilinecode, combine);
+            }
+        }
+
         private void ChooseBackUpFolder_Click(object sender, EventArgs e)
         {
             FolderBrowserDialog folder = new FolderBrowserDialog();
@@ -430,5 +511,53 @@ namespace UAS_XmlAnalysor
         {
             SetAutoRun();
         }
+
+
+
+
+        public bool CheckRoutePassed(string iSN, string iResCode,string makecode, out string oErrMessage)
+        {
+            if (iSN == "")
+            {
+                oErrMessage = "SN不能为空";
+                return false;
+            }
+            oErrMessage = "";
+            string[] param = new string[] { ma_code.Text == "" ? makecode : ma_code.Text, iResCode, iSN, iusercode, "", "", oErrMessage };
+            string[] ParamName = new string[] { "v_i_macode", "v_i_sourcecode", "v_i_sncode", "v_i_usercode", "v_o_macode", "v_o_msid", "v_o_errmsg" };
+            dh.CallProcedure("CS_CHECKSTEPSNANDMACODE", ParamName, ref param);
+            oErrMessage = param[6];
+            DataTable dt = (DataTable)dh.ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_id=(  select max(ms_id) from makeserial where ms_sncode  in ( select '" + iSN + "' from dual union select sn from makesnrelation where beforesn='" + iSN + "' and sn<>' '  union select beforesn from makesnrelation where sn='" + iSN + "' and beforesn<>' '))", "select");
+            string ms_status = "";
+            string ms_stepcode = "";
+            string ms_nextstepcode = "";
+            if (dt.Rows.Count > 0)
+            {
+                ms_status = dt.Rows[0]["ms_status"].ToString();
+                ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
+                ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
+            }
+            string stepcode = GetStepCodeBySource(iResCode);
+            if (ms_nextstepcode != "" && ms_nextstepcode != stepcode)
+            {
+                oErrMessage = "当前序列号下一工序" + ms_nextstepcode;
+                return false;
+            }
+            if (oErrMessage == "" || oErrMessage == null || oErrMessage == "null" || (ms_status == "3" && stepcode == ms_stepcode))
+            {
+                if (ms_status == "3")
+                {
+                    oErrMessage = "";
+                }
+                return true;
+            }
+            else
+                return false;
+        }
+
+        private string GetStepCodeBySource(string Source)
+        {
+            return dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
+        }
     }
 }