瀏覽代碼

自动解析文件占用BUG

callm 3 年之前
父節點
當前提交
abdf121df2
共有 2 個文件被更改,包括 55 次插入46 次删除
  1. 53 46
      UAS_AutoPass/AutoAnalysisXml.cs
  2. 2 0
      UAS_AutoPass/ToolClass/BaseUtil.cs

+ 53 - 46
UAS_AutoPass/AutoAnalysisXml.cs

@@ -157,7 +157,7 @@ namespace UAS_AutoPass
                 }
             }
             //存在工单必须是已下放状态
-            if (!dh.CheckExist("make", "ma_statuscode='STARTED' and ma_code='" + ma_code.Text + "'") && ma_code.Text != ""&&Device.Text=="AOI设备")
+            if (!dh.CheckExist("make", "ma_statuscode='STARTED' and ma_code='" + ma_code.Text + "'") && ma_code.Text != "" && Device.Text == "AOI设备")
             {
                 OperateResult.AppendText("工单不存在或者未下放\n");
                 return;
@@ -227,15 +227,15 @@ namespace UAS_AutoPass
             List<string> badcode = new List<string>();
             List<string> badlocation = new List<string>();
             List<string> badprod = new List<string>();
-            StreamReader sR = File.OpenText(FileName);
-
-            string[] data1 = null;
-            while ((nextLine = sR.ReadLine()) != null)
-            {
-                data1 = nextLine.Split(';');
-            }
             if (Device.Text == "AOI设备")
             {
+                StreamReader sR = File.OpenText(FileName);
+
+                string[] data1 = null;
+                while ((nextLine = sR.ReadLine()) != null)
+                {
+                    data1 = nextLine.Split(';');
+                }
                 string SoftVersion = data1[0];
                 List<string[]> dic = new List<string[]>();
                 List<string> sndata = new List<string>();
@@ -407,31 +407,31 @@ namespace UAS_AutoPass
                             LogicHandler.AutoPassLog(SN, isource, makecode, Day + Time, istepcode, ilinecode, SoftVersion, Result == "NG" ? "-1" : "0", "0", MissTest, TotalPart, NGPart);
                             FileName = FileName.Substring(FileName.LastIndexOf(@"\") + 1);
                             FileInfo file = new FileInfo(FolderPath.Text + @"\" + FileName);
-                            //if (file.Exists)
-                            //{
-                            //    try
-                            //    {
-                            //        for (int i = 1; i <= 20; i++)
-                            //        {
-                            //            if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName))
-                            //            {
-                            //                file.MoveTo(BackUpFolderPath.Text + @"\" + FileName);
-                            //                OperateResult.AppendText("成功解析文件" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + FileName + "\n");
-                            //                break;
-                            //            }
-                            //            else if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]))
-                            //            {
-                            //                file.MoveTo(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]);
-                            //                OperateResult.AppendText("成功解析文件" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + FileName + "\n");
-                            //                break;
-                            //            }
-                            //        }
-                            //    }
-                            //    catch (Exception ex)
-                            //    {
-                            //        OperateResult.AppendText(FileName + ex.Message + "\n");
-                            //    }
-                            //}
+                            if (file.Exists)
+                            {
+                                try
+                                {
+                                    for (int i = 1; i <= 20; i++)
+                                    {
+                                        if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName))
+                                        {
+                                            file.MoveTo(BackUpFolderPath.Text + @"\" + FileName);
+                                            OperateResult.AppendText("成功解析文件" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + FileName + "\n");
+                                            break;
+                                        }
+                                        else if (!File.Exists(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]))
+                                        {
+                                            file.MoveTo(BackUpFolderPath.Text + @"\" + FileName.Split('.')[0] + "(" + i + ")" + "." + FileName.Split('.')[1]);
+                                            OperateResult.AppendText("成功解析文件" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + FileName + "\n");
+                                            break;
+                                        }
+                                    }
+                                }
+                                catch (Exception ex)
+                                {
+                                    OperateResult.AppendText(FileName + ex.Message + "\n");
+                                }
+                            }
                         }
                     }
                     else
@@ -444,21 +444,28 @@ namespace UAS_AutoPass
             }
             else if (Device.Text == "选焊设备")
             {
-                Dictionary<string, string> dic = new Dictionary<string, string>();
-                BaseUtil.GetWriteInfo(FileName, out dic);
-                string sql = "insert into AOITESTDETAIL(atd_id,atd_makecode,atd_indate,";
-                string sql1 = " values(AOITESTDETAIL_seq.nextval,'" + ma_code.Text + "',sysdate,";
-                foreach (var item in dic)
+                try
                 {
-                    sql += item.Key + ",";
-                    if (item.Key.Contains("starttime") || item.Key.Contains("endtime"))
-                        sql1 += "to_date('" + item.Value + "','yyyy/mm/dd hh24:mi:ss'),";
-                    else
-                        sql1 += "'" + item.Value + "',";
+                    Dictionary<string, string> dic = new Dictionary<string, string>();
+                    BaseUtil.GetWriteInfo(FileName, out dic);
+                    string sql = "insert into AOITESTDETAIL(atd_id,atd_makecode,atd_indate,";
+                    string sql1 = " values(AOITESTDETAIL_seq.nextval,'" + ma_code.Text + "',sysdate,";
+                    foreach (var item in dic)
+                    {
+                        sql += item.Key + ",";
+                        if (item.Key.Contains("starttime") || item.Key.Contains("endtime"))
+                            sql1 += "to_date('" + item.Value + "','dd/mm/yyyy hh24:mi:ss'),";
+                        else
+                            sql1 += "'" + item.Value + "',";
+                    }
+                    sql = sql.Substring(0, sql.Length - 1) + ")" + sql1.Substring(0, sql1.Length - 1) + ")";
+                    dh.ExecuteSql(sql, "insert");
+                    OperateResult.AppendText("解析成功:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n");
+                }
+                catch (Exception e)
+                {
+                    OperateResult.AppendText("解析失败:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n" + FileName + "\n" + e.Message + "\n");
                 }
-
-                sql = sql.Substring(0, sql.Length - 1) + ")" + sql1.Substring(0, sql1.Length - 1) + ")";
-                dh.ExecuteSql(sql, "insert");
             }
         }
         /// <summary>

+ 2 - 0
UAS_AutoPass/ToolClass/BaseUtil.cs

@@ -138,6 +138,8 @@ namespace UAS_AutoPass.ToolClass
                 string str = sr.ReadLine();
                 txt += str + "\n";
             }
+            sr.Close();
+            sr.Dispose();
             Dic.Add("atd_sncode", FilePath.Substring(FilePath.LastIndexOf("\\") + 1).Replace(".txt", ""));
             Dic.Add("atd_software", Regex.Match(txt, "Program Name,\\S+").Value.Replace("Program Name,", ""));
             Dic.Add("atd_pot", Regex.Match(txt, "Board Segment,\\S+").Value.Replace("Board Segment,", ""));