Forráskód Böngészése

Merge repos.ubtob.net:usoft/mes-client

callm 5 hónapja
szülő
commit
96d2035b2c

+ 10 - 17
UAS_MES_BG/FunctionCode/Make/Make_CollectHLH.cs

@@ -467,27 +467,20 @@ namespace UAS_MES_NEW.Make
                                 response = Encoding.UTF8.GetString(receiveBuffer).TrimEnd('\0');
                                 OperateResult.AppendText($"收到响应: {response}" + "\n");
                                 Dictionary<string, string> hlh = ParseInputString(response);
-                                //                              string a = hlh["1212"];
-                                //                             string b = hlh["1212"];
-
-                                /*dh.ExecuteSql(" insert into hlh(HLH_ID,HLH_INDATE,SPEEDPV1,SPEEDPV2,ZONE1PV_UP,ZONE1PV_DOWN,ZONE2PV_UP,ZONE2PV_DOWN,ZONE3PV_UP,ZONE3PV_DOWN,ZONE4PV_UP,ZONE4PV_DOWN,ZONE5PV_UP,ZONE5PV_DOWN,ZONE6PV_UP,ZONE6PV_DOWN,ZONE7PV_UP,ZONE7PV_DOWN,ZONE8PV_UP,ZONE8PV_DOWN,ZONE9PV_UP,ZONE9PV_DOWN,ZONE10PV_UP,ZONE10PV_DOWN,ZONE11PV_UP,ZONE11PV_DOWN,ZONE12PV_UP,ZONE12PV_DOWN,FAN1_PV,FAN2_PV,FAN3_PV)" +
-                                    " values (hlh_seq.nextval,sysdate,'" + hlh["SPEEDPV1"] + "','" + hlh["SPEEDPV2"] + "' ,'" + hlh["ZONE1PV_UP"] + "','" + hlh["ZONE1PV_DOWN"] + "','" + hlh["ZONE2PV_UP"] + "','" + hlh["ZONE2PV_DOWN"] + "','" + hlh["ZONE3PV_UP"] + "','" + hlh["ZONE3PV_DOWN"] + "','" + hlh["ZONE4PV_UP"] + "'" +
-                                    ",'" + hlh["ZONE4PV_DOWN"] + "','" + hlh["ZONE5PV_UP"] + "','" + hlh["ZONE5PV_DOWN"] + "','" + hlh["ZONE6PV_UP"] + "','" + hlh["ZONE6PV_DOWN"] + "','" + hlh["ZONE7PV_UP"] + "','" + hlh["ZONE7PV_DOWN"] + "','" + hlh["ZONE8PV_UP"] + "','" + hlh["ZONE8PV_DOWN"] + "','" + hlh["ZONE9PV_UP"] + "'" +
-                                    ",'" + hlh["ZONE9PV_DOWN"] + "','" + hlh["ZONE10PV_UP"] + "','" + hlh["ZONE10PV_DOWN"] + "','" + hlh["ZONE11PV_UP"] + "','" + hlh["ZONE11PV_DOWN"] + "','" + hlh["ZONE12PV_UP"] + "','" + hlh["ZONE12PV_DOWN"] + "','" + hlh["FAN1_PV"] + "','" + hlh["FAN2_PV"] + "','" + hlh["FAN3_PV"] + "'  ) ", "insert");*/
-
-                                dh.ExecuteSql($@"insert into hlh(SPEEDPV1,ZONE1PV_UP,ZONE1PV_DOWN,ZONE2PV_UP,Zone2PV_Down,Zone3PV_UP,Zone3PV_Down,
-                                                Zone4PV_UP,Zone4PV_Down,Zone5PV_UP,Zone5PV_Down,Zone6PV_UP,Zone6PV_Down,Zone7PV_UP,Zone7PV_Down,
-                                                Zone8PV_UP,Zone8PV_Down,Fan1_PV,Fan2_PV,Fan3_PV) values 
-                                                ({hlh["SpeedPV"]},{hlh["Zone1PV_UP"]},{hlh["ZONE1PV_DOWN"]},{hlh["ZONE2PV_UP"]},{hlh["Zone2PV_Down"]},{hlh["Zone3PV_UP"]},{hlh["Zone3PV_Down"]},
-                                                 {hlh["Zone4PV_UP"]},{hlh["Zone4PV_Down"]},{hlh["Zone5PV_UP"]},{hlh["Zone5PV_Down,"]},{hlh["Zone6PV_UP"]},{hlh["Zone6PV_Down"]},{hlh["Zone7PV_UP"]},{hlh["Zone7PV_Down"]},
-                                                 {hlh["Zone8PV_UP"]},{hlh["Zone8PV_Down"]},{hlh["Fan1_PV"]},{hlh["Fan2_PV"]},{hlh["Fan3_PV"]})", "insert");
-                            }
 
+                                string field = "", value = "";
+                                foreach (KeyValuePair<string, string> kvp in hlh)
+                                {
+                                    field += ","+ kvp.Key;
+                                    value += "," + $"'{kvp.Value}'";
 
+                                }
+                                //OperateResult.AppendText($"接收消息: {field}\n{value}");
 
+                                dh.ExecuteSql($@"insert into hlh(hlh_id,hlh_indate {field}) values 
+                                                (hlh_seq.nextval,sysdate {value})", "insert");
+                            }
                         }
-
-
                     }
                 }
             }

+ 31 - 30
UAS_MES_BG/FunctionCode/Make/Make_ParseLog.Designer.cs

@@ -39,21 +39,21 @@
             this.time = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.fileName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.panel1 = new System.Windows.Forms.Panel();
+            this.onWatch = new System.Windows.Forms.Button();
             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.panel4 = new System.Windows.Forms.Panel();
             this.lstFiles = new System.Windows.Forms.ListBox();
-            this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog();
             this.panel3 = new System.Windows.Forms.Panel();
-            this.panel4 = new System.Windows.Forms.Panel();
-            this.onWatch = new System.Windows.Forms.Button();
+            this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog();
             this.panel1.SuspendLayout();
             this.panel2.SuspendLayout();
-            this.panel3.SuspendLayout();
             this.panel4.SuspendLayout();
+            this.panel3.SuspendLayout();
             this.SuspendLayout();
             // 
             // Device
@@ -65,8 +65,9 @@
             "劲拓SPI设备",
             "思泰克SPI设备",
             "AOI设备",
-            "印刷机",
-            "贴片机"});
+            "GKG印刷机",
+            "贴片机",
+            "JUKI贴片机"});
             this.Device.Location = new System.Drawing.Point(193, 88);
             this.Device.Name = "Device";
             this.Device.Size = new System.Drawing.Size(328, 32);
@@ -170,6 +171,18 @@
             this.panel1.Size = new System.Drawing.Size(1304, 296);
             this.panel1.TabIndex = 7;
             // 
+            // 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);
+            // 
             // claerBtn
             // 
             this.claerBtn.Cursor = System.Windows.Forms.Cursors.Hand;
@@ -247,6 +260,15 @@
             this.panel2.Size = new System.Drawing.Size(1304, 530);
             this.panel2.TabIndex = 8;
             // 
+            // 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;
+            // 
             // lstFiles
             // 
             this.lstFiles.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -257,10 +279,6 @@
             this.lstFiles.Size = new System.Drawing.Size(978, 530);
             this.lstFiles.TabIndex = 0;
             // 
-            // openFileDialog2
-            // 
-            this.openFileDialog2.FileName = "openFileDialog2";
-            // 
             // panel3
             // 
             this.panel3.Controls.Add(this.logList);
@@ -270,26 +288,9 @@
             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
+            // openFileDialog2
             // 
-            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);
+            this.openFileDialog2.FileName = "openFileDialog2";
             // 
             // Make_ParseLog
             // 
@@ -306,8 +307,8 @@
             this.panel1.ResumeLayout(false);
             this.panel1.PerformLayout();
             this.panel2.ResumeLayout(false);
-            this.panel3.ResumeLayout(false);
             this.panel4.ResumeLayout(false);
+            this.panel3.ResumeLayout(false);
             this.ResumeLayout(false);
 
         }

+ 316 - 36
UAS_MES_BG/FunctionCode/Make/Make_ParseLog.cs

@@ -1,4 +1,5 @@
 using BarTender;
+using DevExpress.Utils.OAuth.Provider;
 using DevExpress.Xpo.Logger;
 using DevExpress.XtraEditors.Controls;
 using DevExpress.XtraExport;
@@ -11,6 +12,7 @@ using System.Data;
 using System.Drawing;
 using System.IO;
 using System.Linq;
+using System.Net;
 using System.Security;
 using System.Security.AccessControl;
 using System.Security.Principal;
@@ -26,6 +28,7 @@ using UAS_MES_NEW.DataOperate;
 using UAS_MES_NEW.Entity;
 using UAS_MES_NEW.PublicMethod;
 using static DevExpress.Xpo.DB.DataStoreLongrunnersWatch;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
 
 namespace UAS_MES_NEW.Make
 {
@@ -36,18 +39,21 @@ namespace UAS_MES_NEW.Make
             InitializeComponent();
         }
 
-        FileSystemWatcher watcher = new FileSystemWatcher();
+        FileSystemWatcher watcher;
 
         LogStringBuilder sql = new LogStringBuilder();
         DataTable Dbfind;
         DataTable dt;
 
         DataHelper dh;
-        string currFileType = "";
+        string currFileType = "",equiType = "";
 
         string SN, omakeCode, oMsid, oErrorMessage = "";
-        string equiType = "";
         List<string> fileList = new List<string>();
+
+        Timer formsTimer;
+        string outXmlFilePath;
+
         private void Make_ParseLog_Load(object sender, EventArgs e)
         {
             dh = SystemInf.dh;
@@ -56,8 +62,21 @@ namespace UAS_MES_NEW.Make
             fileList.Add("D:\\EYSPI\\DataExport\\Res"); // 思泰克SPI
             fileList.Add("E:\\MES_TEXT_PATH");  // AOI 
             fileList.Add("C:\\GKGPrintTemp");   // GKG印刷机
-            fileList.Add("");
-
+            fileList.Add("");   // 贴片机
+            fileList.Add("D:\\JANETSSC\\SMT\\MachineMonitoring");   // JUKI贴片机
+
+            formsTimer = new Timer();
+            formsTimer.Interval = 10000;
+            formsTimer.Tick += timer1_Tick;
+            //outXmlFilePath = "C:\\Users\\MI\\Desktop\\贴片机\\outLogs";
+            outXmlFilePath = "D:\\JANETSSR";
+
+            watcher = new FileSystemWatcher();
+            watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
+            watcher.Created += OnFileCreated;
+            /*watcher.Changed += OnFileChanged;
+            watcher.Deleted += OnFileChanged;
+            watcher.Renamed += OnFileChanged;*/
 
             //设置锁定工单
             LockMakeCode.GetMakeCodeCtl(ma_code);
@@ -89,8 +108,40 @@ namespace UAS_MES_NEW.Make
 
         private void Device_SelectedIndexChanged(object sender, EventArgs e)
         {
-            if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2)
+            if (Device.SelectedIndex == -1) return;
+
+            switch (Device.SelectedIndex)
+            {
+                case 0:
+                    currFileType = "txt";
+                    equiType = "SPI";
+                    break;
+                case 1:
+                    currFileType = "csv";
+                    equiType = "SPI";
+                    break;
+                case 2:
+                    currFileType = "txt";
+                    equiType = "AOI";
+                    break;
+                case 3:
+                    currFileType = "csv";
+                    equiType = "印刷机";
+                    break;
+                case 4:
+                    currFileType = "xml";
+                    equiType = "贴片机";
+                    break;
+                case 5:
+                    currFileType = "xml";
+                    equiType = "贴片机";
+                    break;
+            }
+
+            if (Device.SelectedIndex == 4 || Device.SelectedIndex == 2 || Device.SelectedIndex == 5)
             {
+                txtPath.Text = fileList[Device.SelectedIndex];
+                ma_code.Text = "";
                 ma_code.Enabled = false;
                 txtPath.Focus();
                 txtPath.SelectAll();
@@ -99,6 +150,7 @@ namespace UAS_MES_NEW.Make
             if (string.IsNullOrEmpty(ma_code.Text))
             {
                 Device.SelectedIndex = -1;
+                txtPath.Text = "";
                 MessageBox.Show(this.ParentForm, "请选择工单", "提示");
                 return;
             }
@@ -140,12 +192,18 @@ namespace UAS_MES_NEW.Make
                     currFileType = "xml";
                     equiType = "贴片机";
                     break;
+                case 5:
+                    dialog.Description = "请选择读取JUKI贴片机的文本文件夹";
+                    currFileType = "xml";
+                    equiType = "贴片机";
+                    break;
             }
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 txtPath.Text = dialog.SelectedPath;
                 txtPath.Enabled = false;
                 Device.Enabled = false;
+                watcher.EnableRaisingEvents = false;
             }
         }
 
@@ -155,10 +213,13 @@ namespace UAS_MES_NEW.Make
         }
         private void allParse_Click(object sender, EventArgs e)
         {
-            if (string.IsNullOrEmpty(ma_code.Text))
+            if (Device.SelectedIndex == 0 || Device.SelectedIndex == 1 || Device.SelectedIndex == 3)
             {
-                MessageBox.Show(this.ParentForm, "请选择工单", "提示");
-                return;
+                if (string.IsNullOrEmpty(ma_code.Text))
+                {
+                    MessageBox.Show(this.ParentForm, "请选择工单", "提示");
+                    return;
+                }
             }
             if (Device.SelectedIndex == -1)
             {
@@ -176,7 +237,7 @@ namespace UAS_MES_NEW.Make
             string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
             if (txtFiles.Length == 0)
             {
-                LogMessage($"当前{txtPath.Text},没有{currFileType.ToUpper()}格式文件");
+                LogMessage($"当前{txtPath.Text},没有{equiType}设备{currFileType.ToUpper()}文件");
                 return;
             }
             RefreshFileList();
@@ -184,10 +245,13 @@ namespace UAS_MES_NEW.Make
 
         private void onWatch_Click(object sender, EventArgs e)
         {
-            if (string.IsNullOrEmpty(ma_code.Text))
+            if (Device.SelectedIndex == 0 || Device.SelectedIndex == 1 || Device.SelectedIndex == 3)
             {
-                MessageBox.Show(this.ParentForm, "请选择工单", "提示");
-                return;
+                if (string.IsNullOrEmpty(ma_code.Text))
+                {
+                    MessageBox.Show(this.ParentForm, "请选择工单", "提示");
+                    return;
+                }
             }
             if (Device.SelectedIndex == -1)
             {
@@ -211,25 +275,85 @@ namespace UAS_MES_NEW.Make
                 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 (onWatch.Text == "开启解析")
                 {
                     watcher.EnableRaisingEvents = true;
                     onWatch.Text = "关闭解析";
+
+                    if (Device.SelectedIndex == 5) // JUKI贴片机
+                    {
+                        formsTimer.Start();
+                    }
                 }
                 else
                 {
                     watcher.EnableRaisingEvents = false;
-                    watcher.Dispose();
+                    //watcher.Dispose();
                     onWatch.Text = "开启解析";
+                    formsTimer.Stop();
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(this.ParentForm, ex.Message, "警告");
+            }
+        }
+
+        private void timer1_Tick(object sender, EventArgs e)
+        {
+            try
+            {
+                sql.Clear();
+                sql.Append($@"SELECT dd_date,dd_name,dd_status,dd_id FROM devicedata WHERE dd_status = 0");
+                dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
+                if (dt.Rows.Count > 0)
+                {
+                    string currentDate = DateTime.Now.ToString("yyyyMMddHHmmss");
+                    XmlWriterSettings settings = new XmlWriterSettings
+                    {
+                        Indent = true,
+                        Encoding = System.Text.Encoding.UTF8
+                    };
+                    foreach (DataRow dr in dt.Rows)
+                    {
+                        var hasFileAry = Directory.GetFiles(outXmlFilePath, $"*.{currFileType}");
+                        string xmlName;
+                        if (hasFileAry.Length > 0)
+                        {
+                            var lastFile = Directory.GetFiles(outXmlFilePath).Select(f => new FileInfo(f))
+                                            .Where(f => f.CreationTime.Date == DateTime.Today)
+                                            .OrderByDescending(f => f.CreationTime).FirstOrDefault().Name;
+
+                            string seqNumStr = lastFile.Substring(lastFile.Length - 7, 3);
+                            string fileSeqNum = (int.Parse(seqNumStr) + 1).ToString().PadLeft(seqNumStr.Length, '0'); ;
+                            xmlName = $"1.08_{currentDate}_{currentDate}{fileSeqNum}.xml";
+                        }
+                        else
+                        {
+                            xmlName = $"1.08_{currentDate}_{currentDate}001.xml";
+                        }
+                        string fullPath = Path.Combine(outXmlFilePath, xmlName);
+
+                        using (XmlWriter writer = XmlWriter.Create(fullPath, settings))
+                        {
+                            writer.WriteStartDocument();
+                            writer.WriteStartElement("RequestTotalProductionInfo");
+                            writer.WriteAttributeString("MachineName", dr["dd_name"].ToString());
+                            writer.WriteEndElement();
+                            writer.WriteEndDocument();
+                        }
+                        if (File.Exists(fullPath))
+                        {
+                            File.ReadAllText(fullPath);
+                        }
+
+                        sql.Clear();
+                        sql.Append($"UPDATE devicedata SET dd_status = -1 WHERE dd_name = '{dr["dd_name"].ToString()}'");
+                        dh.ExecuteSql(sql.GetString(), "update");
+                    }
                 }
             }
             catch (Exception ex)
@@ -237,7 +361,6 @@ namespace UAS_MES_NEW.Make
                 MessageBox.Show(this.ParentForm, ex.Message, "警告");
             }
         }
-        
 
         private void OnFileCreated(object sender, FileSystemEventArgs e)
         {
@@ -278,14 +401,62 @@ namespace UAS_MES_NEW.Make
                 {
                     foreach (string file in txtFiles)
                     {
+                        if (!File.Exists(file))
+                        {
+                            LogMessage($"文件不存在: {file}");
+                        }
+
+
                         if (Device.SelectedIndex == 0) // 劲拓SPI
                         {
-                            string fileType = Path.GetExtension(file).ToLower();
                             ParseLogInsert(file);
                         }
                         else if (Device.SelectedIndex == 1) // 思泰克SPI
                         {
-                            List<SpiData> csvData;
+                            string fileName = Path.GetFileName(file);
+                            string[] lines = File.ReadAllLines(file, Encoding.GetEncoding("GB2312"));
+
+                            //string modelName = lines[1].Split(',')[0];
+                            //string lineNumber = lines[1].Split(',')[1];
+                            //string boardStatus = lines[2].Split(',')[1];
+                            SN = lines[4].Split(',')[16];
+                            if (string.IsNullOrEmpty(SN))
+                            {
+                                LogMessage($"文件: {file},无SN信息");
+                                continue;
+                            }
+                            LogMessage($"文件: {file},开始上传");
+                            if (UploadFileToFtp(file))
+                            {
+                                dh.ExecuteSql($@"insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class,std_testresult) 
+                                                    select STEPTESTDETAIL_seq.nextval,'{SN}','{ma_code.Text}',sysdate,'思泰克SPI',
+                                                    'http://112.48.67.154:8088/ftp/mes/TestData/{DateTime.Now.ToString("yyyyMMdd")}/{Path.GetFileName(file)}.xml' from dual", "insert");
+                                
+                                string xmlContent = File.ReadAllText(file);
+                                if (ConsoleLog(xmlContent, file))
+                                {
+                                    File.Delete(file);
+                                }
+                            }
+
+                            /*if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, SN, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
+                            {
+                                if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, SN, "日志解析", "OK", User.UserCode, out oErrorMessage))
+                                {
+                                    
+                                }
+                                else
+                                {
+                                    LogMessage(">>" + oErrorMessage + "\n");
+                                }
+                            }
+                            else
+                            {
+                                LogMessage(">>" + oErrorMessage + "\n");
+                            }*/
+
+                            #region // 20250630 M 调整对接方式 
+                            /*List<SpiData> csvData; 
                             //csvData = ParseCsvFile(file);
                             csvData = ParseCsvFile<SpiData>(file, MapToSpiData);
 
@@ -359,7 +530,8 @@ namespace UAS_MES_NEW.Make
                             if (ConsoleLog(xmlContent, file))
                             {
                                 File.Delete(file);
-                            }
+                            }*/
+                            #endregion
                         }
                         else if (Device.SelectedIndex == 2) // AOI
                         {
@@ -439,7 +611,7 @@ namespace UAS_MES_NEW.Make
                             if (priMacData.Count == 0)
                             {
                                 LogMessage($"文件: {file},读取记录 {priMacData.Count} 条");
-                                return;
+                                continue;
                             }
 
                             sql.Clear();
@@ -450,7 +622,7 @@ namespace UAS_MES_NEW.Make
                                             std_value15,std_value16,
                                             STD_TESTRESULT,std_value18,std_value19,std_value20,std_value21,
                                             std_rescode)
-                                            (select steptestdetail_seq.nextval,:BarCode,'{ma_code.Text}',to_date(:TimeStamp,'yyyy-mm-dd hh24:mi:ss'),:FileName,:ProgramRunning,
+                                            (select steptestdetail_seq.nextval,:BarCode,'{ma_code.Text}',to_date(:TimeStamp,'yyyy-mm-dd hh24:mi:ss'),'印刷机',:ProgramRunning,
                                             :CycleTime,:DSPIResult2,:PrintSpeed,:FrontSQGPress,:RearSQGPress,:PrintMode,
                                             :SnapOffDistance,:SnapOffSpeed,:SnapOffDelay,:SQGUpSpeed,:SQGDownSpeed,
                                             :SQGUpFirst,:SQGHeightAtSnapOff,:CleaningAfterLastBoard,:CleaningFrequency,:CleaningSpeed,
@@ -459,13 +631,13 @@ namespace UAS_MES_NEW.Make
                                             '{User.UserSourceCode}' from dual)");
 
                             dh.BatchInsert(sql.GetString(),
-                                new string[] { "BarCode", "TimeStamp", "FileName","ProgramRunning",
+                                new string[] { "BarCode", "TimeStamp","ProgramRunning",
                                     "CycleTime","DSPIResult_2","PrintSpeed","FrontSQGPress","RearSQGPress","PrintMode",
                                     "SnapOffDistance","SnapOffSpeed","SnapOffDelay","SQGUpSpeed","SQGDownSpeed",
                                     "SQGUpFirst","SQGHeightAtSnapOff","CleaningAfterLastBoard","CleaningFrequency","CleaningSpeed",
                                     "CleaningType","AddSPMode",
                                     "PrintDirection","PCBSize","TableUpX","TableUpY1","TableUpY2"},
-                                BarCode.ToArray(), TimeStamp.ToArray(), FileName.ToArray(), ProgramRunning.ToArray(),
+                                BarCode.ToArray(), TimeStamp.ToArray(), ProgramRunning.ToArray(),
                                 CycleTime.ToArray(), DSPIResult_2.ToArray(), PrintSpeed.ToArray(), FrontSQGPress.ToArray(), RearSQGPress.ToArray(), PrintMode.ToArray(),
                                 SnapOffDistance.ToArray(), SnapOffSpeed.ToArray(), SnapOffDelay.ToArray(), SQGUpSpeed.ToArray(), SQGDownSpeed.ToArray(),
                                 SQGUpFirst.ToArray(), SQGHeightAtSnapOff.ToArray(), CleaningAfterLastBoard.ToArray(), CleaningFrequency.ToArray(), CleaningSpeed.ToArray(),
@@ -479,18 +651,18 @@ namespace UAS_MES_NEW.Make
                                 File.Delete(file);
                             }
                         }
-                        else if (Device.SelectedIndex == 4) // 贴片机
+                        else if (Device.SelectedIndex == 4 || Device.SelectedIndex == 5) // 贴片机
                         {
-                            if (!File.Exists(file))
+                            if (Device.SelectedIndex == 5 && !file.Contains("TotalProduction"))
                             {
-                                LogMessage($"文件不存在: {file}");
+                                continue;
                             }
                             string xmlContent = File.ReadAllText(file);
                             var xmlList = ParseXml(xmlContent);
                             if (xmlList.Count == 0)
                             {
                                 LogMessage($"文件: {file},读取记录 {xmlList.Count} 条");
-                                return;
+                                continue;
                             }
 
                             List<string> param = new List<string>() { };
@@ -532,7 +704,7 @@ namespace UAS_MES_NEW.Make
                             }
                             sql.Clear();
                             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 " +
+                                "select productsmtlocation_seq.nextval," + ps_id + ",:letArr, :ReelNo,:ReelNo,:Station,BD_BASEQTY,'A' 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());
@@ -553,6 +725,99 @@ namespace UAS_MES_NEW.Make
             }
         }
 
+        public bool UploadFileToFtp(string localFilePath)
+        {
+            string ftpServer = "ftp://10.8.0.208:21/mes/TestData/";
+            string username = "vsftpd";
+            string password = "vsftpd3cd79018fl";
+
+            string currentDate = DateTime.Now.ToString("yyyyMMdd");
+
+            string ftpFullPath = $"{ftpServer.TrimEnd('/')}/{currentDate}";
+            string outResult = CreateFtpDirectoryIfNotExists(ftpFullPath, username, password);
+            if (outResult.Substring(0, 2) == "NG")
+            {
+                LogMessage(outResult);
+                return false;
+            }
+
+            string remoteFileName = Path.GetFileName(localFilePath);
+            string uri = $"{ftpFullPath}/{remoteFileName}";
+
+            try
+            {
+                var request = (FtpWebRequest)WebRequest.Create(uri);
+                request.Method = WebRequestMethods.Ftp.UploadFile;
+                request.Credentials = new NetworkCredential(username, password);
+                request.UsePassive = true;
+                request.UseBinary = true;
+                request.KeepAlive = false;
+
+                using (var fileStream = File.OpenRead(localFilePath))
+                using (var requestStream = request.GetRequestStream())
+                {
+                    byte[] buffer = new byte[4096];
+                    int bytesRead;
+                    while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
+                    {
+                        requestStream.Write(buffer, 0, bytesRead);
+                    }
+                }
+
+                using (var response = (FtpWebResponse)request.GetResponse())
+                {
+                    LogMessage($"文件: {localFilePath}上传成功,状态{response.StatusDescription}");
+                    return true;
+                }
+            }
+            catch (WebException ex)
+            {
+                if (ex.Response is FtpWebResponse response)
+                {
+                    LogMessage($"FTP 错误码: {(int)response.StatusCode} - {response.StatusDescription}");
+                }
+                else
+                {
+                    LogMessage("Web异常: " + ex.Message);
+                }
+                return false;
+            }
+            catch (Exception ex)
+            {
+                LogMessage($"上传失败: " + ex.Message);
+                return false;
+            }
+        }
+
+        private string CreateFtpDirectoryIfNotExists(string ftpDirectoryPath, string username, string password)
+        {
+            try
+            {
+                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpDirectoryPath);
+                request.Method = WebRequestMethods.Ftp.MakeDirectory;
+                request.Credentials = new NetworkCredential(username, password);
+                request.UsePassive = true;
+                request.UseBinary = true;
+                request.KeepAlive = false;
+
+                using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
+                {
+                    return "OK,目录创建成功: " + response.StatusDescription;
+                }
+            }
+            catch (WebException ex)
+            {
+                if (ex.Response is FtpWebResponse response && response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
+                {
+                    return "OK,目录已存在: " + response.StatusDescription;
+                }
+                else
+                {
+                    return "NG,创建目录时发生错误: " + ex.Message;
+                }
+            }
+        }
+
         private void ParseLogInsert(string PathName)
         {
             try
@@ -569,18 +834,33 @@ namespace UAS_MES_NEW.Make
                 {
                     if (string.IsNullOrEmpty(item)) continue;
                     string[] currItem = item.Split(',');
-                    string res = "";
+                    string res = "",wo = "";
                     if(equiType == "SPI")
                     {
                         res = currItem[1];
+                        wo = ma_code.Text;
                     }
                     else if (equiType == "AOI")
                     {
                         res = currItem[3];
+
+                        sql.Clear();
+                        sql.Append($"SELECT a.li_code,b.dl_macode FROM line_ipaoi a, deviceline b WHERE a.ipaddress = '{currItem[2]}' AND a.li_code = b.dl_linecode");
+                        dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
+                        if (dt.Rows.Count > 0)
+                        {
+                            wo = dt.Rows[0]["dd_name"].ToString();
+                        }
+                        else
+                        {
+                            LogMessage($"IP:{currItem[2]},无对应线体工单");
+                            return;
+                        }
                     }
                     Log itemLog = new Log()
                     {
                         SN = currItem[0],
+                        work_order = wo,
                         Result = res,
                         Details = equiType == "SPI" ? currItem[1] : currItem[3]
                     };
@@ -636,7 +916,7 @@ namespace UAS_MES_NEW.Make
                     }
 
                     param.Add(item.SN);
-                    param.Add(ma_code.Text ?? omakeCode);
+                    param.Add(item.work_order);
                     if (item.Result == "PASS")
                     {
                         param.Add(item.Result);
@@ -952,6 +1232,7 @@ namespace UAS_MES_NEW.Make
 
         private class Log
         {
+            public string work_order {  get; set; }
             public string SN { set; get; }
             public string Result { set; get; }
             /*public List<NgData> Details { set; get; }*/
@@ -1129,7 +1410,6 @@ namespace UAS_MES_NEW.Make
             }
         }
 
-       
 
         private class PrinterData
         {

+ 3 - 0
UAS_MES_BG/Login.cs

@@ -55,6 +55,8 @@ namespace UAS_MES_NEW
             //显示上次用户登录的用户名,将输入框定位到密码
             UserName.Text = BaseUtil.GetCacheData("LastLoginUser").ToString();
             Source.Text = BaseUtil.GetCacheData("LastLoginResource").ToString();
+            PassWord.Text = BaseUtil.GetCacheData("LastLoginPassword").ToString();
+
             if (UserName.Text != "")
                 PassWord.Select();
             else
@@ -171,6 +173,7 @@ namespace UAS_MES_NEW
             BaseUtil.SetCacheData("LastLoginUser", UserName.Text);
             BaseUtil.SetCacheData("LastLoginSob", DB.Text);
             BaseUtil.SetCacheData("LastLoginResource", Source.Text);
+            BaseUtil.SetCacheData("LastLoginPassword", PassWord.Text);
         }
 
         private void ForGetPwd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)