瀏覽代碼

指令写入和bug

yhluo 5 月之前
父節點
當前提交
1e10bd15ad
共有 2 個文件被更改,包括 140 次插入38 次删除
  1. 28 28
      UAS_MES_BG/FunctionCode/Make/Make_ParseLog.Designer.cs
  2. 112 10
      UAS_MES_BG/FunctionCode/Make/Make_ParseLog.cs

+ 28 - 28
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
@@ -171,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;
@@ -248,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;
@@ -258,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);
@@ -271,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
             // 
@@ -307,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);
 
         }

+ 112 - 10
UAS_MES_BG/FunctionCode/Make/Make_ParseLog.cs

@@ -26,6 +26,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,7 +37,7 @@ namespace UAS_MES_NEW.Make
             InitializeComponent();
         }
 
-        FileSystemWatcher watcher = new FileSystemWatcher();
+        FileSystemWatcher watcher;
 
         LogStringBuilder sql = new LogStringBuilder();
         DataTable Dbfind;
@@ -48,6 +49,9 @@ namespace UAS_MES_NEW.Make
         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;
@@ -59,6 +63,18 @@ namespace UAS_MES_NEW.Make
             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);
@@ -108,6 +124,33 @@ namespace UAS_MES_NEW.Make
                 MessageBox.Show(this.ParentForm, "请选择工单", "提示");
                 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;
+            }
 
             txtPath.Text = fileList[Device.SelectedIndex];
             txtPath.Focus();
@@ -157,6 +200,7 @@ namespace UAS_MES_NEW.Make
                 txtPath.Text = dialog.SelectedPath;
                 txtPath.Enabled = false;
                 Device.Enabled = false;
+                watcher.EnableRaisingEvents = false;
             }
         }
 
@@ -228,25 +272,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)
@@ -254,7 +358,6 @@ namespace UAS_MES_NEW.Make
                 MessageBox.Show(this.ParentForm, ex.Message, "警告");
             }
         }
-        
 
         private void OnFileCreated(object sender, FileSystemEventArgs e)
         {
@@ -1154,7 +1257,6 @@ namespace UAS_MES_NEW.Make
             }
         }
 
-       
 
         private class PrinterData
         {