Browse Source

优化日志解析

yhluo 5 months ago
parent
commit
83a640390c

+ 83 - 54
UAS_MES_BG/FunctionCode/Make/Make_ParseLog.Designer.cs

@@ -40,17 +40,20 @@
             this.fileName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.panel1 = new System.Windows.Forms.Panel();
             this.claerBtn = new System.Windows.Forms.Button();
+            this.LockMakeCode = new UAS_MES_NEW.CustomControl.CustomCheckBox.LockCheckBox();
+            this.ma_code = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.MaCodeSearchTextBox();
             this.allParse = new System.Windows.Forms.Button();
             this.label3 = new System.Windows.Forms.Label();
             this.panel2 = new System.Windows.Forms.Panel();
-            this.panel3 = new System.Windows.Forms.Panel();
             this.lstFiles = new System.Windows.Forms.ListBox();
             this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog();
-            this.LockMakeCode = new UAS_MES_NEW.CustomControl.CustomCheckBox.LockCheckBox();
-            this.ma_code = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.MaCodeSearchTextBox();
+            this.panel3 = new System.Windows.Forms.Panel();
+            this.panel4 = new System.Windows.Forms.Panel();
+            this.onWatch = new System.Windows.Forms.Button();
             this.panel1.SuspendLayout();
             this.panel2.SuspendLayout();
             this.panel3.SuspendLayout();
+            this.panel4.SuspendLayout();
             this.SuspendLayout();
             // 
             // Device
@@ -59,7 +62,8 @@
             this.Device.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.Device.FormattingEnabled = true;
             this.Device.Items.AddRange(new object[] {
-            "SPI设备",
+            "劲拓SPI设备",
+            "思泰克SPI设备",
             "AOI设备",
             "印刷机",
             "贴片机"});
@@ -123,9 +127,9 @@
             this.logList.Dock = System.Windows.Forms.DockStyle.Fill;
             this.logList.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.logList.HideSelection = false;
-            this.logList.Location = new System.Drawing.Point(958, 0);
+            this.logList.Location = new System.Drawing.Point(0, 0);
             this.logList.Name = "logList";
-            this.logList.Size = new System.Drawing.Size(346, 492);
+            this.logList.Size = new System.Drawing.Size(326, 530);
             this.logList.TabIndex = 6;
             this.logList.UseCompatibleStateImageBehavior = false;
             this.logList.View = System.Windows.Forms.View.Details;
@@ -149,6 +153,7 @@
             // panel1
             // 
             this.panel1.BackColor = System.Drawing.SystemColors.Control;
+            this.panel1.Controls.Add(this.onWatch);
             this.panel1.Controls.Add(this.claerBtn);
             this.panel1.Controls.Add(this.LockMakeCode);
             this.panel1.Controls.Add(this.ma_code);
@@ -162,14 +167,14 @@
             this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
             this.panel1.Location = new System.Drawing.Point(0, 0);
             this.panel1.Name = "panel1";
-            this.panel1.Size = new System.Drawing.Size(1304, 334);
+            this.panel1.Size = new System.Drawing.Size(1304, 296);
             this.panel1.TabIndex = 7;
             // 
             // claerBtn
             // 
             this.claerBtn.Cursor = System.Windows.Forms.Cursors.Hand;
             this.claerBtn.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.claerBtn.Location = new System.Drawing.Point(978, 151);
+            this.claerBtn.Location = new System.Drawing.Point(391, 231);
             this.claerBtn.Name = "claerBtn";
             this.claerBtn.Size = new System.Drawing.Size(122, 38);
             this.claerBtn.TabIndex = 7;
@@ -177,11 +182,44 @@
             this.claerBtn.UseVisualStyleBackColor = true;
             this.claerBtn.Click += new System.EventHandler(this.claerBtn_Click);
             // 
+            // LockMakeCode
+            // 
+            this.LockMakeCode.AutoSize = true;
+            this.LockMakeCode.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.LockMakeCode.LeaveEvent = false;
+            this.LockMakeCode.Location = new System.Drawing.Point(520, 25);
+            this.LockMakeCode.Margin = new System.Windows.Forms.Padding(4);
+            this.LockMakeCode.Name = "LockMakeCode";
+            this.LockMakeCode.Size = new System.Drawing.Size(72, 28);
+            this.LockMakeCode.TabIndex = 1;
+            this.LockMakeCode.Text = "锁定";
+            this.LockMakeCode.UseVisualStyleBackColor = true;
+            // 
+            // ma_code
+            // 
+            this.ma_code.AllPower = null;
+            this.ma_code.BackColor = System.Drawing.SystemColors.Control;
+            this.ma_code.Caller = null;
+            this.ma_code.Condition = null;
+            this.ma_code.DBTitle = null;
+            this.ma_code.FormName = null;
+            this.ma_code.Location = new System.Drawing.Point(193, 25);
+            this.ma_code.Margin = new System.Windows.Forms.Padding(4);
+            this.ma_code.Name = "ma_code";
+            this.ma_code.Power = null;
+            this.ma_code.ReturnData = null;
+            this.ma_code.SelectField = null;
+            this.ma_code.SetValueField = null;
+            this.ma_code.Size = new System.Drawing.Size(224, 32);
+            this.ma_code.TabIndex = 0;
+            this.ma_code.TableName = null;
+            this.ma_code.TextBoxEnable = true;
+            // 
             // allParse
             // 
             this.allParse.Cursor = System.Windows.Forms.Cursors.Hand;
             this.allParse.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.allParse.Location = new System.Drawing.Point(836, 152);
+            this.allParse.Location = new System.Drawing.Point(230, 232);
             this.allParse.Name = "allParse";
             this.allParse.Size = new System.Drawing.Size(122, 38);
             this.allParse.TabIndex = 5;
@@ -201,23 +239,14 @@
             // 
             // panel2
             // 
-            this.panel2.Controls.Add(this.logList);
+            this.panel2.Controls.Add(this.panel4);
             this.panel2.Controls.Add(this.panel3);
             this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.panel2.Location = new System.Drawing.Point(0, 334);
+            this.panel2.Location = new System.Drawing.Point(0, 296);
             this.panel2.Name = "panel2";
-            this.panel2.Size = new System.Drawing.Size(1304, 492);
+            this.panel2.Size = new System.Drawing.Size(1304, 530);
             this.panel2.TabIndex = 8;
             // 
-            // panel3
-            // 
-            this.panel3.Controls.Add(this.lstFiles);
-            this.panel3.Dock = System.Windows.Forms.DockStyle.Left;
-            this.panel3.Location = new System.Drawing.Point(0, 0);
-            this.panel3.Name = "panel3";
-            this.panel3.Size = new System.Drawing.Size(958, 492);
-            this.panel3.TabIndex = 7;
-            // 
             // lstFiles
             // 
             this.lstFiles.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -225,45 +254,42 @@
             this.lstFiles.ItemHeight = 18;
             this.lstFiles.Location = new System.Drawing.Point(0, 0);
             this.lstFiles.Name = "lstFiles";
-            this.lstFiles.Size = new System.Drawing.Size(958, 492);
+            this.lstFiles.Size = new System.Drawing.Size(978, 530);
             this.lstFiles.TabIndex = 0;
             // 
             // openFileDialog2
             // 
             this.openFileDialog2.FileName = "openFileDialog2";
             // 
-            // LockMakeCode
-            // 
-            this.LockMakeCode.AutoSize = true;
-            this.LockMakeCode.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.LockMakeCode.LeaveEvent = false;
-            this.LockMakeCode.Location = new System.Drawing.Point(520, 25);
-            this.LockMakeCode.Margin = new System.Windows.Forms.Padding(4);
-            this.LockMakeCode.Name = "LockMakeCode";
-            this.LockMakeCode.Size = new System.Drawing.Size(72, 28);
-            this.LockMakeCode.TabIndex = 1;
-            this.LockMakeCode.Text = "锁定";
-            this.LockMakeCode.UseVisualStyleBackColor = true;
-            // 
-            // ma_code
+            // panel3
             // 
-            this.ma_code.AllPower = null;
-            this.ma_code.BackColor = System.Drawing.SystemColors.Control;
-            this.ma_code.Caller = null;
-            this.ma_code.Condition = null;
-            this.ma_code.DBTitle = null;
-            this.ma_code.FormName = null;
-            this.ma_code.Location = new System.Drawing.Point(193, 25);
-            this.ma_code.Margin = new System.Windows.Forms.Padding(4);
-            this.ma_code.Name = "ma_code";
-            this.ma_code.Power = null;
-            this.ma_code.ReturnData = null;
-            this.ma_code.SelectField = null;
-            this.ma_code.SetValueField = null;
-            this.ma_code.Size = new System.Drawing.Size(224, 32);
-            this.ma_code.TabIndex = 0;
-            this.ma_code.TableName = null;
-            this.ma_code.TextBoxEnable = true;
+            this.panel3.Controls.Add(this.logList);
+            this.panel3.Dock = System.Windows.Forms.DockStyle.Right;
+            this.panel3.Location = new System.Drawing.Point(978, 0);
+            this.panel3.Name = "panel3";
+            this.panel3.Size = new System.Drawing.Size(326, 530);
+            this.panel3.TabIndex = 1;
+            // 
+            // panel4
+            // 
+            this.panel4.Controls.Add(this.lstFiles);
+            this.panel4.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.panel4.Location = new System.Drawing.Point(0, 0);
+            this.panel4.Name = "panel4";
+            this.panel4.Size = new System.Drawing.Size(978, 530);
+            this.panel4.TabIndex = 2;
+            // 
+            // onWatch
+            // 
+            this.onWatch.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.onWatch.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.onWatch.Location = new System.Drawing.Point(66, 232);
+            this.onWatch.Name = "onWatch";
+            this.onWatch.Size = new System.Drawing.Size(122, 38);
+            this.onWatch.TabIndex = 8;
+            this.onWatch.Text = "开启解析";
+            this.onWatch.UseVisualStyleBackColor = true;
+            this.onWatch.Click += new System.EventHandler(this.onWatch_Click);
             // 
             // Make_ParseLog
             // 
@@ -281,6 +307,7 @@
             this.panel1.PerformLayout();
             this.panel2.ResumeLayout(false);
             this.panel3.ResumeLayout(false);
+            this.panel4.ResumeLayout(false);
             this.ResumeLayout(false);
 
         }
@@ -296,7 +323,6 @@
         private System.Windows.Forms.ListView logList;
         private System.Windows.Forms.Panel panel1;
         private System.Windows.Forms.Panel panel2;
-        private System.Windows.Forms.Panel panel3;
         private System.Windows.Forms.ColumnHeader time;
         private System.Windows.Forms.ColumnHeader fileName;
         private System.Windows.Forms.ColumnHeader sn;
@@ -307,5 +333,8 @@
         private System.Windows.Forms.OpenFileDialog openFileDialog2;
         private System.Windows.Forms.ListBox lstFiles;
         private System.Windows.Forms.Button claerBtn;
+        private System.Windows.Forms.Panel panel4;
+        private System.Windows.Forms.Panel panel3;
+        private System.Windows.Forms.Button onWatch;
     }
 }

+ 196 - 217
UAS_MES_BG/FunctionCode/Make/Make_ParseLog.cs

@@ -35,6 +35,9 @@ namespace UAS_MES_NEW.Make
         {
             InitializeComponent();
         }
+
+        FileSystemWatcher watcher = new FileSystemWatcher();
+
         LogStringBuilder sql = new LogStringBuilder();
         DataTable Dbfind;
         DataTable dt;
@@ -44,10 +47,18 @@ namespace UAS_MES_NEW.Make
 
         string SN, omakeCode, oMsid, oErrorMessage = "";
         string equiType = "";
+        List<string> fileList = new List<string>();
         private void Make_ParseLog_Load(object sender, EventArgs e)
         {
             dh = SystemInf.dh;
 
+            fileList.Add("D:\\MES"); // 劲拓SPI
+            fileList.Add("D:\\EYSPI\\DataExport\\Res"); // 思泰克SPI
+            fileList.Add("E:\\MES_TEXT_PATH");  // AOI 
+            fileList.Add("C:\\GKGPrintTemp");   // GKG印刷机
+            fileList.Add("");
+
+
             //设置锁定工单
             LockMakeCode.GetMakeCodeCtl(ma_code);
             ma_code.SetLockCheckBox(LockMakeCode);
@@ -78,7 +89,7 @@ namespace UAS_MES_NEW.Make
 
         private void Device_SelectedIndexChanged(object sender, EventArgs e)
         {
-            if (Device.SelectedIndex == 3)
+            if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2)
             {
                 ma_code.Enabled = false;
                 txtPath.Focus();
@@ -91,15 +102,57 @@ namespace UAS_MES_NEW.Make
                 MessageBox.Show(this.ParentForm, "请选择工单", "提示");
                 return;
             }
+
+            txtPath.Text = fileList[Device.SelectedIndex];
             txtPath.Focus();
             txtPath.SelectAll();
+            ma_code.Enabled = true;
+            txtPath.Enabled = false;
+        }
+
+        private void Choose_Click(object sender, EventArgs e)
+        {
+            FolderBrowserDialog dialog = new FolderBrowserDialog();
+            switch (Device.SelectedIndex)
+            {
+                case 0:
+                    dialog.Description = "请选择读取劲拓SPI设备文件夹";
+                    currFileType = "txt";
+                    equiType = "SPI";
+                    break;
+                case 1:
+                    dialog.Description = "请选择读取思泰克SPI设备文件夹";
+                    currFileType = "csv";
+                    equiType = "SPI";
+                    break;
+                case 2:
+                    dialog.Description = "请选择读取AOI设备文本文件";
+                    currFileType = "txt";
+                    equiType = "AOI";
+                    break;
+                case 3:
+                    dialog.Description = "请选择读取印刷机设备的文本文件夹";
+                    currFileType = "csv";
+                    equiType = "印刷机";
+                    break;
+                case 4:
+                    dialog.Description = "请选择读取贴片机的文本文件夹";
+                    currFileType = "xml";
+                    equiType = "贴片机";
+                    break;
+            }
+            if (dialog.ShowDialog() == DialogResult.OK)
+            {
+                txtPath.Text = dialog.SelectedPath;
+                txtPath.Enabled = false;
+                Device.Enabled = false;
+            }
         }
 
         private void claerBtn_Click(object sender, EventArgs e)
         {
             lstFiles.Items.Clear();
         }
-
         private void allParse_Click(object sender, EventArgs e)
         {
             if (string.IsNullOrEmpty(ma_code.Text))
@@ -123,13 +176,13 @@ namespace UAS_MES_NEW.Make
             string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
             if (txtFiles.Length == 0)
             {
-                LogMessage($"当前没有{currFileType.ToUpper()}文件");
+                LogMessage($"当前{txtPath.Text},没有{currFileType.ToUpper()}格式文件");
                 return;
             }
             RefreshFileList();
         }
 
-        private void Choose_Click(object sender, EventArgs e)
+        private void onWatch_Click(object sender, EventArgs e)
         {
             if (string.IsNullOrEmpty(ma_code.Text))
             {
@@ -143,115 +196,48 @@ namespace UAS_MES_NEW.Make
                 MessageBox.Show(this.ParentForm, "请选择设备", "提示");
                 return;
             }
-            if (!String.IsNullOrEmpty(txtPath.Text))
+            if (String.IsNullOrEmpty(txtPath.Text))
             {
                 txtPath.Focus();
                 txtPath.SelectAll();
+                return;
             }
             try
             {
-                FolderBrowserDialog dialog = new FolderBrowserDialog();
-                switch (Device.SelectedIndex)
-                {
-                    case 0:
-                        dialog.Description = "请选择读取SPI设备文件夹";
-                        currFileType = "txt";
-                        equiType = "SPI";
-                        break;
-                    case 1:
-                        dialog.Description = "请选择读取AOI设备文本文件";
-                        currFileType = "txt";
-                        equiType = "AOI";
-                        break;
-                    case 2:
-                        dialog.Description = "请选择读取印刷机设备的文本文件夹";
-                        currFileType = "csv";
-                        equiType = "印刷机";
-                        break;
-                    case 3:
-                        dialog.Description = "请选择读取贴片机的文本文件夹";
-                        currFileType = "xml";
-                        equiType = "贴片机";
-                        break;
-                }
-                if (dialog.ShowDialog() == DialogResult.OK)
-                {
-                    txtPath.Text = dialog.SelectedPath;
-                    txtPath.Enabled = false;
-                    Device.Enabled = false;
-                    var watcher = new FileSystemWatcher(txtPath.Text);
-                    if (equiType == "SPI")
-                    {
-                        var txtFiles = Directory.GetFiles(txtPath.Text, "*.txt");
-                        var csvFiles = Directory.GetFiles(txtPath.Text, "*.csv");
-                        currFileType = txtFiles.Length > csvFiles.Length ? "txt" : "csv";
-                        watcher.Filter = $"*.{currFileType}";
-                    }
-                    else
-                    {
-                        watcher.Filter = $"*.{currFileType}";
-                    }
-                        
-                    watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
-                    watcher.Created += OnFileCreated;
-                    /*watcher.Changed += OnFileChanged;
-                    watcher.Deleted += OnFileChanged;
-                    watcher.Renamed += OnFileChanged;*/
-                    watcher.EnableRaisingEvents = true;
-                }
                 #region
-                /*OpenFileDialog dialog = new OpenFileDialog();
-                dialog.Multiselect = true;//该值确定是否可以选择多个文件
-                dialog.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
-                switch (Device.SelectedIndex)
-                {
-                    case 0:
-                        dialog.Title = "请选择读取SPI设备文件夹";
-                        dialog.Filter = "All files (*.*)|*.*";
-                        break;
-                    case 1:
-                        dialog.Title = "请选择读取AOI设备文本文件";
-                        dialog.Filter = "All files (*.*)|*.*";
-                        break;
-                    case 2:
-                        dialog.Title = "请选择读取印刷机设备的文本文件夹";
-                        dialog.Filter = "文本文件 (*.xml)|*.xml|All files (*.*)|*.*";
-                        break;
-                }
-                
-                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
-                {
-                    txtPath.Text = dialog.FileName;
-                    dialog.Dispose();
-                    ListViewItem item = new ListViewItem();
-                    int count = logList.Items.Count;
-                    item.Text = (++count).ToString();
-                    item.SubItems.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
-                    item.SubItems.Add(txtPath.Text);
-                    logList.Items.Add(item);
-                }
+                /* 识别文件类型
+                var txtFiles = Directory.GetFiles(txtPath.Text, "*.txt");
+                var csvFiles = Directory.GetFiles(txtPath.Text, "*.csv");
+                currFileType = txtFiles.Length > csvFiles.Length ? "txt" : "csv";
+                watcher.Filter = $"*.{currFileType}";*/
+                #endregion
+
+                watcher.Path = txtPath.Text;
+                watcher.Filter = $"*.{currFileType}";
+                watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
+                watcher.Created += OnFileCreated;
+                /*watcher.Changed += OnFileChanged;
+                watcher.Deleted += OnFileChanged;
+                watcher.Renamed += OnFileChanged;*/
 
-                if (Device.SelectedIndex == 0) // SPI
+                if (onWatch.Text == "开启解析")
                 {
-                    ParseLogInsert(txtPath.Text);
-                    Console.WriteLine();
+                    watcher.EnableRaisingEvents = true;
+                    onWatch.Text = "关闭解析";
                 }
-                else if (Device.SelectedIndex == 1) // AOI
+                else
                 {
-
+                    watcher.EnableRaisingEvents = false;
+                    watcher.Dispose();
+                    onWatch.Text = "开启解析";
                 }
-                else if (Device.SelectedIndex == 2) // 印刷机
-                {
-                    PrinterData xmlData = ReadWithXmlReader(txtPath.Text);
-                    Console.WriteLine();
-                }*/
-                #endregion
             }
             catch (Exception ex)
             {
                 MessageBox.Show(this.ParentForm, ex.Message, "警告");
             }
         }
+        
 
         private void OnFileCreated(object sender, FileSystemEventArgs e)
         {
@@ -270,7 +256,7 @@ namespace UAS_MES_NEW.Make
         {
             if (lstFiles.InvokeRequired)
             {
-                //lstFiles.Invoke(new Action(RefreshFileList));
+                lstFiles.Invoke(new Action(RefreshFileList));
                 lstFiles.BeginInvoke(new Action(RefreshFileList));
                 return;
             }
@@ -292,53 +278,58 @@ namespace UAS_MES_NEW.Make
                 {
                     foreach (string file in txtFiles)
                     {
-                        if (Device.SelectedIndex == 0) // SPI
+                        if (Device.SelectedIndex == 0) // 劲拓SPI
                         {
                             string fileType = Path.GetExtension(file).ToLower();
+                            ParseLogInsert(file);
+                        }
+                        else if (Device.SelectedIndex == 1) // 思泰克SPI
+                        {
                             List<SpiData> csvData;
-                            if (fileType == ".txt") // 劲拓
+                            //csvData = ParseCsvFile(file);
+                            csvData = ParseCsvFile<SpiData>(file, MapToSpiData);
+
+                            List<string> Barcode = new List<string>();
+                            List<string> Date = new List<string>();
+
+                            List<string> AreaPercent = new List<string>();
+                            List<string> Height = new List<string>();
+                            List<string> VolumePercent = new List<string>();
+                            List<string> XOffset = new List<string>();
+                            List<string> YOffset = new List<string>();
+                            List<string> PadSizeX = new List<string>();
+                            List<string> PadSizeY = new List<string>();
+                            List<string> Area = new List<string>();
+                            List<string> HeightPercent = new List<string>();
+                            List<string> Volume = new List<string>();
+                            List<string> Result = new List<string>();
+
+                            foreach (var item in csvData)
                             {
-                                ParseLogInsert(file);
+                                Barcode.Add(item.Barcode);
+                                Date.Add(item.Date);
+                                Result.Add(item.Result);
+
+                                AreaPercent.Add(item.AreaPercent);
+                                Height.Add(item.Height);
+                                VolumePercent.Add(item.VolumePercent);
+                                XOffset.Add(item.XOffset);
+                                YOffset.Add(item.YOffset);
+                                PadSizeX.Add(item.PadSizeX);
+                                PadSizeY.Add(item.PadSizeY);
+                                Area.Add(item.Area);
+                                HeightPercent.Add(item.HeightPercent);
+                                Volume.Add(item.Volume);
                             }
-                            else if (fileType == ".csv") // 思泰克 ?
+
+                            if (csvData.Count == 0)
                             {
-                                //csvData = ParseCsvFile(file);
-                                csvData = ParseCsvFile<SpiData>(file, MapToSpiData);
-
-                                List<string> Barcode = new List<string>();
-                                List<string> Date = new List<string>();
-
-                                List<string> AreaPercent = new List<string>();
-                                List<string> Height = new List<string>();
-                                List<string> VolumePercent = new List<string>();
-                                List<string> XOffset = new List<string>();
-                                List<string> YOffset = new List<string>();
-                                List<string> PadSizeX = new List<string>();
-                                List<string> PadSizeY = new List<string>();
-                                List<string> Area = new List<string>();
-                                List<string> HeightPercent = new List<string>();
-                                List<string> Volume = new List<string>();
-                                List<string> Result = new List<string>();
-
-                                foreach (var item in csvData)
-                                {
-                                    Barcode.Add(item.Barcode);
-                                    Date.Add(item.Date);
-                                    Result.Add(item.Result);
-
-                                    AreaPercent.Add(item.AreaPercent);
-                                    Height.Add(item.Height);
-                                    VolumePercent.Add(item.VolumePercent);
-                                    XOffset.Add(item.XOffset);
-                                    YOffset.Add(item.YOffset);
-                                    PadSizeX.Add(item.PadSizeX);
-                                    PadSizeY.Add(item.PadSizeY);
-                                    Area.Add(item.Area);
-                                    HeightPercent.Add(item.HeightPercent);
-                                    Volume.Add(item.Volume);
-                                }
-                                sql.Clear();
-                                sql.Append($@"INSERT INTO steptestdetail (std_id,std_sn,std_makecode,
+                                LogMessage($"文件: {file},读取记录 {csvData.Count} 条");
+                                return;
+                            }
+
+                            sql.Clear();
+                            sql.Append($@"INSERT INTO steptestdetail (std_id,std_sn,std_makecode,
                                                     std_testresult,std_class,std_actualvalue,
                                                     std_rescode,STD_SUBCLASS1,STD_VALUE1,
                                                     STD_VALUE2,STD_VALUE3,STD_VALUE4,
@@ -351,29 +342,30 @@ namespace UAS_MES_NEW.Make
                                                     :YOffset,:PadSizeX,:PadSizeY,
                                                     :Area,:HeightPercent,:Volume from dual)");
 
-                                dh.BatchInsert(sql.GetString(), 
-                                    new string[] { "Barcode", "Result", "AreaPercent",
+                            dh.BatchInsert(sql.GetString(),
+                                new string[] { "Barcode", "Result", "AreaPercent",
                                         "Height" ,"VolumePercent","XOffset",
                                         "YOffset","PadSizeX","PadSizeY",
                                         "Area","HeightPercent","Volume"},
-                                    Barcode.ToArray(), Result.ToArray(), AreaPercent.ToArray(),
-                                    Height.ToArray(), VolumePercent.ToArray(), XOffset.ToArray(),
-                                    YOffset.ToArray(), PadSizeX.ToArray(), PadSizeY.ToArray(),
-                                    Area.ToArray(), HeightPercent.ToArray(), Volume.ToArray());
+                                Barcode.ToArray(), Result.ToArray(), AreaPercent.ToArray(),
+                                Height.ToArray(), VolumePercent.ToArray(), XOffset.ToArray(),
+                                YOffset.ToArray(), PadSizeX.ToArray(), PadSizeY.ToArray(),
+                                Area.ToArray(), HeightPercent.ToArray(), Volume.ToArray());
+
 
+                            LogMessage($"文件: {file},共{csvData.Count}条记录,已解析");
 
-                                string xmlContent = File.ReadAllText(file);
-                                if (ConsoleLog(xmlContent, file))
-                                {
-                                    File.Delete(file);
-                                }
+                            string xmlContent = File.ReadAllText(file);
+                            if (ConsoleLog(xmlContent, file))
+                            {
+                                File.Delete(file);
                             }
                         }
-                        else if (Device.SelectedIndex == 1) // AOI
+                        else if (Device.SelectedIndex == 2) // AOI
                         {
                             ParseLogInsert(file);
                         }
-                        else if (Device.SelectedIndex == 2) // 印刷机 ?
+                        else if (Device.SelectedIndex == 3) // 印刷机 ?
                         {
                             List<PrintData> priMacData;
                             priMacData = ParseCsvFile<PrintData>(file, MapToPriMacData);
@@ -444,6 +436,11 @@ namespace UAS_MES_NEW.Make
                                 TableUpY1.Add(item.TableUpY1);
                                 TableUpY2.Add(item.TableUpY2);
                             }
+                            if (priMacData.Count == 0)
+                            {
+                                LogMessage($"文件: {file},读取记录 {priMacData.Count} 条");
+                                return;
+                            }
 
                             sql.Clear();
                             sql.Append($@"INSERT INTO steptestdetail (std_id,std_sn,std_makecode,STD_TESTTIME,STD_CLASS,STD_SUBCLASS1,
@@ -475,13 +472,14 @@ namespace UAS_MES_NEW.Make
                                 CleaningType.ToArray(), AddSPMode.ToArray(),
                                 PrintDirection.ToArray(), PCBSize.ToArray(), TableUpX.ToArray(), TableUpY1.ToArray(), TableUpY2.ToArray());
 
+                            LogMessage($"文件: {file},共{priMacData.Count}条记录,已解析");
                             string xmlContent = File.ReadAllText(file);
                             if (ConsoleLog(xmlContent, file))
                             {
                                 File.Delete(file);
                             }
                         }
-                        else if (Device.SelectedIndex == 3) // 贴片机
+                        else if (Device.SelectedIndex == 4) // 贴片机
                         {
                             if (!File.Exists(file))
                             {
@@ -489,10 +487,12 @@ namespace UAS_MES_NEW.Make
                             }
                             string xmlContent = File.ReadAllText(file);
                             var xmlList = ParseXml(xmlContent);
-                            if (ConsoleLog(xmlContent, file))
+                            if (xmlList.Count == 0)
                             {
-                                File.Delete(file);
+                                LogMessage($"文件: {file},读取记录 {xmlList.Count} 条");
+                                return;
                             }
+
                             List<string> param = new List<string>() { };
                             string PS_CODE = "";
                             LogicHandler.GetSerialNumByCaller("Make!ParseLog", out PS_CODE);
@@ -520,11 +520,11 @@ namespace UAS_MES_NEW.Make
                             {
                                 ps_id = dh.GetSEQ("productsmt_seq");
                                 dh.ExecuteSql("insert into productsmt(ps_id,ps_prodcode,ps_status,ps_statuscode,PS_LINECODE,PS_CODE)" +
-                                    "values('" + ps_id + "','" + Part_ + "','在录入','ENTERING','"+ lineId + "','"+ PS_CODE + "')", "insert");
+                                    "values('" + ps_id + "','" + Part_ + "','在录入','ENTERING','" + lineId + "','" + PS_CODE + "')", "insert");
                             }
                             else
                             {
-                                ps_id = dh.getFieldDataByCondition("productsmt", "ps_id", "ps_prodcode='"+Part_+"'").ToString();
+                                ps_id = dh.getFieldDataByCondition("productsmt", "ps_id", "ps_prodcode='" + Part_ + "'").ToString();
                             }
                             if (dh.getRowCount("productsmtlocation", "PSL_PSID=" + ps_id) > 0)
                             {
@@ -534,16 +534,22 @@ namespace UAS_MES_NEW.Make
                             sql.Append("insert into productsmtlocation(PSL_ID, PSL_PSID, PSL_DETNO, PSL_PRODCODE, PSL_REPCODE, PSL_LOCATION, PSL_BASEQTY, PSL_TABLE)" +
                                 "select productsmtlocation_seq.nextval," + ps_id + ",:letArr, :ReelNo,:ReelNo,:Station,BD_BASEQTY,'' from bom@ERP " +
                                 "left join bomdetail@ERP on bo_id=bd_bomid where bo_mothercode='" + Part_ + "' and BD_SONCODE=:ReelNo");
-                            dh.BatchInsert(sql.GetString(), new string[] {"letArr", "ReelNo", "ReelNo", "Station", "ReelNo" },
-                                letNo.ToArray(),ReelNo.ToArray(), ReelNo.ToArray(), Station.ToArray(), ReelNo.ToArray());
-                            Console.WriteLine();
+                            dh.BatchInsert(sql.GetString(), new string[] { "letArr", "ReelNo", "ReelNo", "Station", "ReelNo" },
+                                letNo.ToArray(), ReelNo.ToArray(), ReelNo.ToArray(), Station.ToArray(), ReelNo.ToArray());
+
+                            LogMessage($"文件: {file},已解析生成站位表");
+
+                            if (ConsoleLog(xmlContent, file))
+                            {
+                                File.Delete(file);
+                            }
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
-                LogMessage($"刷新文件列表时出错: {ex.Message}");
+                LogMessage($"Error: 解析文件列表失败: {ex.Message}");
             }
         }
 
@@ -559,46 +565,18 @@ namespace UAS_MES_NEW.Make
                 List<Log> logArr = new List<Log>() { };
                 string[] lines = restOfStream.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                 int fileNum = string.IsNullOrEmpty(lines[lines.Length - 1]) ? lines.Length - 1 : lines.Length;
-                LogMessage($"文件夹{PathName},共{fileNum}条记录");
                 foreach (var item in lines)
                 {
                     if (string.IsNullOrEmpty(item)) continue;
                     string[] currItem = item.Split(',');
                     string res = "";
-                    /*List<NgData> data = new List<NgData>();*/
                     if(equiType == "SPI")
                     {
-                        if (currItem[1] != "PASS")
-                        {
-                            res = "NG";
-                            #region
-                            /*string[] NgArr = currItem[1].Split(';');
-                            foreach (var ngItem in NgArr)
-                            {
-                                string[] ngItemArr = ngItem.Split('*');
-                                List<string> ngItemLocal = ngItemArr[1].Split('&').ToList();
-                                NgData ngData = new NgData { 
-                                    Code = ngItemArr[0], 
-                                    Local = ngItemLocal
-                                };
-                                data.Add(ngData);
-                            }*/
-                            #endregion
-                        }
-                        else
-                        {
-                            res = "PASS";
-                        }
-                    }else if (equiType == "AOI")
+                        res = currItem[1];
+                    }
+                    else if (equiType == "AOI")
                     {
-                        if (currItem[3] != "PASS")
-                        {
-                            res = "NG";
-                        }
-                        else
-                        {
-                            res = "PASS";
-                        }
+                        res = currItem[3];
                     }
                     Log itemLog = new Log()
                     {
@@ -608,8 +586,8 @@ namespace UAS_MES_NEW.Make
                     };
                     logArr.Add(itemLog);
 
-                    LogMessage($"已解析: {currItem[0]}");
                 }
+                LogMessage($"文件: {PathName},共{fileNum}条记录,已解析");
                 InsertDb(logArr, PathName);
 
                 File.WriteAllText(PathName, string.Empty);
@@ -620,7 +598,7 @@ namespace UAS_MES_NEW.Make
             }
             catch (Exception ex)
             {
-                MessageBox.Show(this.ParentForm, ex.Message, "警告");
+                LogMessage($"Error: 文件 {PathName}, {ex.Message}");
             }
         }
 
@@ -628,32 +606,10 @@ namespace UAS_MES_NEW.Make
         {
             try
             {
-                int type = Device.SelectedIndex;
                 StringBuilder sql = new StringBuilder();
                 List<string> param = new List<string>() { };
                 foreach (var item in logs)
                 {
-                    param.Add(item.SN);
-                    param.Add(ma_code.Text);
-                    if (item.Result == "PASS")
-                    {
-                        param.Add(item.Result);
-                    }
-                    else
-                    {
-                        param.Add(item.Result);
-                    }
-                    param.Add(equiType);
-                    param.Add(item.Details);
-                    param.Add(User.UserCode);
-                    param.Add(User.UserSourceCode);
-                    param.Add(User.UserLineCode);
-                    string res = "";
-                    param.Add(res);
-                    string[] paramList = param.ToArray();
-                    dh.CallProcedure("cs_insert_testrejects", ref paramList);
-                    param.Clear();
-
                     if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, item.SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
                     {
                         if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, item.SN, "日志解析", "OK", User.UserCode, out oErrorMessage))
@@ -678,6 +634,27 @@ namespace UAS_MES_NEW.Make
                     {
                         LogMessage(">>" + oErrorMessage + "\n");
                     }
+
+                    param.Add(item.SN);
+                    param.Add(ma_code.Text ?? omakeCode);
+                    if (item.Result == "PASS")
+                    {
+                        param.Add(item.Result);
+                    }
+                    else
+                    {
+                        param.Add(item.Result);
+                    }
+                    param.Add(equiType);
+                    param.Add(item.Details);
+                    param.Add(User.UserCode);
+                    param.Add(User.UserSourceCode);
+                    param.Add(User.UserLineCode);
+                    string res = "";
+                    param.Add(res);
+                    string[] paramList = param.ToArray();
+                    dh.CallProcedure("cs_insert_testrejects", ref paramList);
+                    param.Clear();
                 }
             }
             catch (Exception ex)
@@ -831,14 +808,14 @@ namespace UAS_MES_NEW.Make
                 /*Encoding fileEncoding = DetectFileEncoding(filePath);*/
                 string[] lines = File.ReadAllLines(filePath, Encoding.GetEncoding("GB2312"));
 
-                if (lines.Length < 4) return dataList;
-
                 for (int i = 1; i < lines.Length; i++)
                 {
                     if (string.IsNullOrWhiteSpace(lines[i])) continue;
 
                     if (equiType == "SPI")
                     {
+                        if (lines.Length < 4) return dataList;
+
                         string modelName = lines[1].Split(',')[0];
                         string lineNumber = lines[1].Split(',')[1];
                         string boardStatus = lines[2].Split(',')[1];
@@ -1152,6 +1129,8 @@ namespace UAS_MES_NEW.Make
             }
         }
 
+       
+
         private class PrinterData
         {
             public string SN { get; set; }