Browse Source

修改解析不同文件的方式

callm 5 years ago
parent
commit
ca8b1fb810
1 changed files with 50 additions and 29 deletions
  1. 50 29
      UAS_AutoPass/AutoAnalysisXml.cs

+ 50 - 29
UAS_AutoPass/AutoAnalysisXml.cs

@@ -103,7 +103,7 @@ namespace UAS_AutoPass
             {
                 if (Master.Text == DB.Rows[i]["ma_user"].ToString())
                 {
-                    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)));";
+                    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=117.25.180.218)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
                     dh = new DataHelper();
                 }
             }
@@ -151,9 +151,8 @@ namespace UAS_AutoPass
             {
                 if (Master.Text == DB.Rows[i]["ma_user"].ToString())
                 {
-                    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();
-                    LogicHandler.dh = new DataHelper();
+                    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=117.25.180.218)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+                    LogicHandler.dh = dh = new DataHelper();
                 }
             }
             //存在工单必须是已下放状态
@@ -163,7 +162,7 @@ namespace UAS_AutoPass
                 return;
             }
             XmlWatcher.Path = FolderPath.Text;
-            XmlWatcher.Filter = "*.xml";
+            XmlWatcher.Filter = "*.txt";
             XmlWatcher.EnableRaisingEvents = true;
             //设置缓存数据
             BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
@@ -204,14 +203,44 @@ namespace UAS_AutoPass
                     Console.WriteLine(ex.Message);
                 }
             }
+            Console.WriteLine(e.FullPath.Substring(e.FullPath.LastIndexOf(".") + 1));
+            switch (e.FullPath.Substring(e.FullPath.LastIndexOf(".")+1))
+            {
+                case "xml":
+                    XmlHandleProcess(e.FullPath);
+                    break;
+                case "txt":
+                    TxtHandleProcess(e.FullPath);
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        /// </summary>
+        private void TxtHandleProcess(string FileName)
+        {
+            StreamReader sr = new StreamReader(FileName, Encoding.Default);
+            String line;
+            while ((line = sr.ReadLine()) != null)
+            {
+                Console.WriteLine(line.ToString());
+            }
+        }
+
+        /// <summary>
+        /// 使用进程处理文件,避免界面假死
+        /// </summary>
+        private void XmlHandleProcess(string FileName)
+        {
             string test_date = "";
             string test_result = "";
             string test_sn = "";
             string imageurl = "";
             string oMSID = "";
             string oErrMessage = "";
-            XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + e.Name);
-            OperateResult.AppendText("读取文件" + e.Name + "\n");
+            XmlReader myReader = XmlReader.Create(FolderPath.Text + @"\" + FileName);
+            OperateResult.AppendText("读取文件" + FileName + "\n");
             //获取采集的项目名称
             List<string> badcode = new List<string>();
             //获取采集项目的结果
@@ -251,7 +280,7 @@ namespace UAS_AutoPass
             }
             myReader.Close();
             //获取文件名的序列号,如SA123456.xml,如果开头为-表示无条码需要自动获取
-            string sncode = e.Name.Substring(0, 1) == "-" ? "" : e.Name.Split('.')[0];
+            string sncode = FileName.Substring(0, 1) == "-" ? "" : FileName.Split('.')[0];
             string makecode = "";
             //获取序列号ID最大的工单号,所有序列号都测试为良品
             if (sncode == "")
@@ -273,15 +302,15 @@ namespace UAS_AutoPass
                     return;
                 }
                 //-2-NG2017/10/2514:46:29.xml取第二位版号
-                string combinecode = e.Name.Substring(1, 1);
+                string combinecode = FileName.Substring(1, 1);
                 if (LogicHandler.CheckStepSNAndMacode(ma_code.Text == "" ? makecode : ma_code.Text, isource, sncode, iusercode, out makecode, out oMSID, out oErrMessage))
                 {
                     //插入日志
-                    LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, e.Name, test_result == "NG" ? "-1" : "0", "-1");
+                    LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, FileName, test_result == "NG" ? "-1" : "0", "-1");
                     //如果是不良品记录日志,用于测试采集判负
                     if (test_result == "NG")
                     {
-                        RecordBadInfo(sncode, makecode, e.Name, combinecode, badcode.ToArray(), badlocation.ToArray());
+                        RecordBadInfo(sncode, makecode, FileName, combinecode, badcode.ToArray(), badlocation.ToArray());
                     }
                     if (!LogicHandler.SetStepResult(makecode, isource, sncode, "自动过站采集", "OK", iusercode, out oErrMessage))
                     {
@@ -355,7 +384,7 @@ namespace UAS_AutoPass
                                 tipform.startthread("序列号 " + sncode + "通过检测", test_result);
                                 break;
                             case "NG":
-                                RecordBadInfo(sncode, makecode, e.Name, "", badcode.ToArray(), badlocation.ToArray());
+                                RecordBadInfo(sncode, makecode, FileName, "", badcode.ToArray(), badlocation.ToArray());
                                 //所有的序列号均采集为良品
                                 if (!LogicHandler.SetTestNGDetail(sncode, makecode, iusercode, isource, test_result, out oErrMessage))
                                 {
@@ -368,7 +397,7 @@ namespace UAS_AutoPass
                             default:
                                 break;
                         }
-                        LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, e.Name, test_result == "NG" ? "1" : "0", "0");
+                        LogicHandler.AutoPassLog(sncode, isource, makecode, test_date, istepcode, ilinecode, FileName, test_result == "NG" ? "1" : "0", "0");
                     }
                 }
                 else
@@ -378,42 +407,34 @@ namespace UAS_AutoPass
                     return;
                 }
             }
-            FileInfo file = new FileInfo(FolderPath.Text + @"\" + e.Name);
+            FileInfo file = new FileInfo(FolderPath.Text + @"\" + FileName);
             if (file.Exists)
             {
                 try
                 {
                     for (int i = 1; i <= 20; i++)
                     {
-                        if (!File.Exists(BackUpFolderPath.Text + @"\" + e.Name))
+                        if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName))
                         {
-                            file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name);
-                            OperateResult.AppendText("成功解析文件" + e.Name + "\n");
+                            file.MoveTo(BackUpFolderPath.Text + @"\" + FileName);
+                            OperateResult.AppendText("成功解析文件" + FileName + "\n");
                             break;
                         }
-                        else if (!File.Exists(BackUpFolderPath.Text + @"\" + e.Name.Split('.')[0] + "(" + i + ")" + "." + e.Name.Split('.')[1]))
+                        else if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]))
                         {
-                            file.MoveTo(BackUpFolderPath.Text + @"\" + e.Name.Split('.')[0] + "(" + i + ")" + "." + e.Name.Split('.')[1]);
-                            OperateResult.AppendText("成功解析文件" + e.Name + "\n");
+                            file.MoveTo(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]);
+                            OperateResult.AppendText("成功解析文件" + FileName + "\n");
                             break;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
-                    OperateResult.AppendText(e.Name + ex.Message + "\n");
+                    OperateResult.AppendText(FileName + ex.Message + "\n");
                 }
             }
         }
 
-        /// <summary>
-        /// 使用进程处理文件,避免界面假死
-        /// </summary>
-        private void XmlHandleProcess()
-        {
-
-        }
-
         private void RecordBadInfo(string sncode, string makecode, string filename, string combine, string[] badcode, string[] badlocation)
         {
             string[] ID = dh.GetSEQ("makebad_seq", badcode.Length);