浏览代码

add设备对接

yhluo 1 月之前
父节点
当前提交
af354dbfc9

+ 294 - 0
UAS_MES_HYSX/FunctionCode/Make/Make_ParseLog.Designer.cs

@@ -0,0 +1,294 @@
+namespace UAS_MES_NEW.Make
+{
+    partial class Make_ParseLog
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.Device = new System.Windows.Forms.ComboBox();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.txtPath = new System.Windows.Forms.TextBox();
+            this.Choose = new System.Windows.Forms.Button();
+            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
+            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.lstOk = new System.Windows.Forms.ListBox();
+            this.lstFiles = new System.Windows.Forms.ListBox();
+            this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog();
+            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+            this.panel1.SuspendLayout();
+            this.tableLayoutPanel1.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // Device
+            // 
+            this.Device.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.Device.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Device.FormattingEnabled = true;
+            this.Device.Items.AddRange(new object[] {
+            "AOI设备",
+            "CCD相机"});
+            this.Device.Location = new System.Drawing.Point(193, 88);
+            this.Device.Name = "Device";
+            this.Device.Size = new System.Drawing.Size(387, 39);
+            this.Device.TabIndex = 2;
+            this.Device.SelectedIndexChanged += new System.EventHandler(this.Device_SelectedIndexChanged);
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.Location = new System.Drawing.Point(61, 92);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(101, 30);
+            this.label1.TabIndex = 0;
+            this.label1.Text = "设备类型";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label2.Location = new System.Drawing.Point(61, 154);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(123, 30);
+            this.label2.TabIndex = 4;
+            this.label2.Text = "文件夹路径";
+            // 
+            // txtPath
+            // 
+            this.txtPath.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.txtPath.Location = new System.Drawing.Point(193, 154);
+            this.txtPath.Name = "txtPath";
+            this.txtPath.Size = new System.Drawing.Size(387, 35);
+            this.txtPath.TabIndex = 3;
+            // 
+            // Choose
+            // 
+            this.Choose.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.Choose.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.Choose.Location = new System.Drawing.Point(601, 155);
+            this.Choose.Name = "Choose";
+            this.Choose.Size = new System.Drawing.Size(122, 38);
+            this.Choose.TabIndex = 4;
+            this.Choose.Text = "选择";
+            this.Choose.UseVisualStyleBackColor = true;
+            this.Choose.Click += new System.EventHandler(this.Choose_Click);
+            // 
+            // openFileDialog1
+            // 
+            this.openFileDialog1.FileName = "openFileDialog1";
+            this.openFileDialog1.RestoreDirectory = true;
+            // 
+            // 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);
+            this.panel1.Controls.Add(this.allParse);
+            this.panel1.Controls.Add(this.label3);
+            this.panel1.Controls.Add(this.Device);
+            this.panel1.Controls.Add(this.label1);
+            this.panel1.Controls.Add(this.Choose);
+            this.panel1.Controls.Add(this.label2);
+            this.panel1.Controls.Add(this.txtPath);
+            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, 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;
+            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(391, 231);
+            this.claerBtn.Name = "claerBtn";
+            this.claerBtn.Size = new System.Drawing.Size(122, 38);
+            this.claerBtn.TabIndex = 7;
+            this.claerBtn.Text = "清除";
+            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(523, 30);
+            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.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            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(320, 42);
+            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(230, 232);
+            this.allParse.Name = "allParse";
+            this.allParse.Size = new System.Drawing.Size(122, 38);
+            this.allParse.TabIndex = 5;
+            this.allParse.Text = "批量解析";
+            this.allParse.UseVisualStyleBackColor = true;
+            this.allParse.Click += new System.EventHandler(this.allParse_Click);
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label3.Location = new System.Drawing.Point(61, 26);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(101, 30);
+            this.label3.TabIndex = 6;
+            this.label3.Text = "归属工单";
+            // 
+            // lstOk
+            // 
+            this.lstOk.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.lstOk.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
+            this.lstOk.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.lstOk.FormattingEnabled = true;
+            this.lstOk.ItemHeight = 22;
+            this.lstOk.Location = new System.Drawing.Point(655, 3);
+            this.lstOk.Name = "lstOk";
+            this.lstOk.Size = new System.Drawing.Size(646, 524);
+            this.lstOk.TabIndex = 1;
+            // 
+            // lstFiles
+            // 
+            this.lstFiles.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.lstFiles.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
+            this.lstFiles.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.lstFiles.FormattingEnabled = true;
+            this.lstFiles.ItemHeight = 22;
+            this.lstFiles.Location = new System.Drawing.Point(3, 3);
+            this.lstFiles.Name = "lstFiles";
+            this.lstFiles.Size = new System.Drawing.Size(646, 524);
+            this.lstFiles.TabIndex = 0;
+            this.lstFiles.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lstFiles_DrawItem);
+            // 
+            // openFileDialog2
+            // 
+            this.openFileDialog2.FileName = "openFileDialog2";
+            // 
+            // tableLayoutPanel1
+            // 
+            this.tableLayoutPanel1.ColumnCount = 2;
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+            this.tableLayoutPanel1.Controls.Add(this.lstOk, 1, 0);
+            this.tableLayoutPanel1.Controls.Add(this.lstFiles, 0, 0);
+            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 296);
+            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+            this.tableLayoutPanel1.RowCount = 1;
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
+            this.tableLayoutPanel1.Size = new System.Drawing.Size(1304, 530);
+            this.tableLayoutPanel1.TabIndex = 8;
+            // 
+            // Make_ParseLog
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.SystemColors.Window;
+            this.ClientSize = new System.Drawing.Size(1304, 826);
+            this.Controls.Add(this.tableLayoutPanel1);
+            this.Controls.Add(this.panel1);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
+            this.Name = "Make_ParseLog";
+            this.Text = "Make_ParseLog";
+            this.Load += new System.EventHandler(this.Make_ParseLog_Load);
+            this.panel1.ResumeLayout(false);
+            this.panel1.PerformLayout();
+            this.tableLayoutPanel1.ResumeLayout(false);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.ComboBox Device;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.TextBox txtPath;
+        private System.Windows.Forms.Button Choose;
+        private System.Windows.Forms.OpenFileDialog openFileDialog1;
+        private System.Windows.Forms.Panel panel1;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Button allParse;
+        private CustomControl.TextBoxWithIcon.MaCodeSearchTextBox ma_code;
+        private CustomControl.CustomCheckBox.LockCheckBox LockMakeCode;
+        private System.Windows.Forms.OpenFileDialog openFileDialog2;
+        private System.Windows.Forms.ListBox lstFiles;
+        private System.Windows.Forms.Button claerBtn;
+        private System.Windows.Forms.Button onWatch;
+        private System.Windows.Forms.ListBox lstOk;
+        private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+    }
+}

+ 638 - 0
UAS_MES_HYSX/FunctionCode/Make/Make_ParseLog.cs

@@ -0,0 +1,638 @@
+using DevExpress.Utils.CodedUISupport;
+using HslCommunication;
+using NPOI.SS.Formula.Functions;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Web.Services.Description;
+using System.Windows.Forms;
+using UAS_MES_NEW.CustomControl.ButtonUtil;
+using UAS_MES_NEW.DataOperate;
+using UAS_MES_NEW.Entity;
+using UAS_MES_NEW.PublicMethod;
+
+namespace UAS_MES_NEW.Make
+{
+    public partial class Make_ParseLog : Form
+    {
+        public Make_ParseLog()
+        {
+            InitializeComponent();
+        }
+
+        FileSystemWatcher watcher;
+
+        LogStringBuilder sql = new LogStringBuilder();
+        DataTable Dbfind;
+        DataTable dt;
+
+        DataHelper dh;
+        string currFileType = "", equiType = "";
+
+        string SN, omakeCode, oMsid, oErrorMessage = "";
+        List<string> fileList = new List<string>();
+
+        Timer ChangeWoTimer;
+
+        private void Make_ParseLog_Load(object sender, EventArgs e)
+        {
+            dh = SystemInf.dh;
+            Choose.Enabled = false;
+            fileList.Add("C:\\Users\\MI\\Desktop");
+
+            ChangeWoTimer = new Timer();
+            ChangeWoTimer.Interval = 30000;
+            ChangeWoTimer.Tick += ChangeWoFunc;
+
+            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);
+            ma_code.SetLockCheckBox(LockMakeCode);
+            //工单号放大镜配置
+            ma_code.TableName = "make left join product on ma_prodcode=pr_code";
+            ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
+            ma_code.FormName = Name;
+            ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
+            ma_code.Condition = "ma_statuscode='STARTED'";
+            ma_code.DbChange += Ma_code_DbChange;
+        }
+
+        private void Ma_code_DbChange(object sender, EventArgs e)
+        {
+            Dbfind = ma_code.ReturnData;
+            BaseUtil.SetFormValue(this.Controls, Dbfind);
+            //获取工单的其他信息
+            sql.Clear();
+            sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
+            sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
+            sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
+            dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
+            if (dt.Rows.Count > 0)
+            {
+                BaseUtil.SetFormValue(this.Controls, dt);
+            }
+        }
+
+        private void Device_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            if (Device.SelectedIndex == -1) return;
+
+            switch (Device.SelectedIndex)
+            {
+                case 0:
+                    currFileType = "Txt";
+                    equiType = "AOI";
+                    ChangeWoTimer.Start();
+                    break;
+                case 1:
+                    currFileType = "jpg";
+                    equiType = "CCD";
+                    ChangeWoTimer.Stop();
+                    break;
+            }
+            if (string.IsNullOrEmpty(ma_code.Text))
+            {
+                Device.SelectedIndex = -1;
+                txtPath.Text = "";
+                MessageBox.Show(this.ParentForm, "请选择工单", "提示");
+                return;
+            }
+
+            txtPath.Text = fileList[Device.SelectedIndex];
+            txtPath.Focus();
+            txtPath.SelectAll();
+            ma_code.Enabled = true;
+            Choose.Enabled = true;
+            txtPath.Enabled = false;
+        }
+
+        private void Choose_Click(object sender, EventArgs e)
+        {
+            using (var dialog = new FolderBrowserDialog())
+            {
+                if (dialog.ShowDialog() == DialogResult.OK)
+                {
+                    txtPath.Text = dialog.SelectedPath;
+                    txtPath.Enabled = false;
+                    Device.Enabled = false;
+                    watcher.EnableRaisingEvents = false;
+                }
+            }
+        }
+
+        private void claerBtn_Click(object sender, EventArgs e)
+        {
+            lstFiles.Items.Clear();
+        }
+
+        private void allParse_Click(object sender, EventArgs e)
+        {
+            if (Device.SelectedIndex == 0)
+            {
+                if (string.IsNullOrEmpty(ma_code.Text))
+                {
+                    MessageBox.Show(this.ParentForm, "请选择工单", "提示");
+                    return;
+                }
+            }
+            if (Device.SelectedIndex == -1)
+            {
+                Device.Focus();
+                Device.SelectAll();
+                MessageBox.Show(this.ParentForm, "请选择设备", "提示");
+                return;
+            }
+            if (String.IsNullOrEmpty(txtPath.Text))
+            {
+                txtPath.Focus();
+                txtPath.SelectAll();
+                MessageBox.Show(this.ParentForm, "请选择解析路径", "提示");
+                return;
+            }
+            string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
+            if (txtFiles.Length == 0)
+            {
+                LogMessage(0, $"当前{txtPath.Text},没有{equiType}设备输出的{currFileType.ToLower()}文件");
+                return;
+            }
+            RefreshFileList();
+        }
+
+        private void onWatch_Click(object sender, EventArgs e)
+        {
+            if (Device.SelectedIndex == 0)
+            {
+                if (string.IsNullOrEmpty(ma_code.Text))
+                {
+                    MessageBox.Show(this.ParentForm, "请选择工单", "提示");
+                    return;
+                }
+            }
+            if (Device.SelectedIndex == -1)
+            {
+                Device.Focus();
+                Device.SelectAll();
+                MessageBox.Show(this.ParentForm, "请选择设备", "提示");
+                return;
+            }
+            if (String.IsNullOrEmpty(txtPath.Text))
+            {
+                txtPath.Focus();
+                txtPath.SelectAll();
+                MessageBox.Show(this.ParentForm, "请选择解析路径", "提示");
+                return;
+            }
+            try
+            {
+                watcher.Path = txtPath.Text;
+                watcher.Filter = $"*.{currFileType}";
+                if (onWatch.Text == "开启解析")
+                {
+                    watcher.EnableRaisingEvents = true;
+                    onWatch.Text = "关闭解析";
+                }
+                else
+                {
+                    watcher.EnableRaisingEvents = false;
+                    onWatch.Text = "开启解析";
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(this.ParentForm, ex.Message, "警告");
+            }
+        }
+
+        private void OnFileCreated(object sender, FileSystemEventArgs e)
+        {
+            RefreshFileList();
+        }
+
+        private void OnFileChanged(object sender, FileSystemEventArgs e)
+        {
+            if (e.ChangeType == WatcherChangeTypes.Changed)
+            {
+                RefreshFileList();
+            }
+        }
+
+        private void RefreshFileList()
+        {
+            if (lstFiles.InvokeRequired)
+            {
+                lstFiles.Invoke(new Action(RefreshFileList));
+                lstFiles.BeginInvoke(new Action(RefreshFileList));
+                return;
+            }
+
+            try
+            {
+                if (!Directory.Exists(txtPath.Text))
+                {
+                    LogMessage(0, $"目录不存在: {txtPath.Text}");
+                    return;
+                }
+
+                string[] txtFiles = Directory.GetFiles(txtPath.Text, $"*.{currFileType}");
+                if (txtFiles.Length == 0)
+                {
+                    return;
+                }
+                foreach (string file in txtFiles)
+                {
+                    if (!File.Exists(file))
+                    {
+                        LogMessage(0, $"文件不存在: {file}");
+                    }
+
+                    string outFileMsg = CheckFileAccess(file);
+                    if (outFileMsg != "OK")
+                    {
+                        LogMessage(0, outFileMsg);
+                        continue;
+                    }
+
+                    if (File.ReadAllText(file).Length == 0)
+                    {
+                        continue;
+                    }
+
+                    if (equiType == "AOI")
+                    {
+                        StreamReader SR = File.OpenText(file);
+                        string restOfStream = SR.ReadToEnd();
+                        SR.Close();
+                        SR.Dispose();
+
+                        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;
+
+                        foreach (var item in lines)
+                        {
+                            if (string.IsNullOrEmpty(item)) break;
+
+                            Log itemLog = new Log() { };
+
+                            if (Array.IndexOf(lines, item) == 1) itemLog.SN = item.Split(':')[1].ToString().Trim();
+
+                            if (Array.IndexOf(lines, item) == 2) itemLog.TestTime = item.Split(':')[1].Split('.')[0].ToString().Trim();
+
+                            if (Array.IndexOf(lines, item) == 3) itemLog.Result = item.Split(':')[1].ToString().Trim();
+
+                            if (Array.IndexOf(lines, item) == 4) itemLog.Side = item.Split(':')[1].ToString().Trim();
+
+                            logArr.Add(itemLog);
+                        }
+                        if (logArr.Count == 0)
+                        {
+                            break;
+                        }
+
+                        if (InsertDb(logArr, file, fileNum))
+                        {
+                            if (ConsoleLog(restOfStream, file))
+                            {
+                                File.WriteAllText(file, string.Empty);
+                                File.Delete(file);
+                            }
+                        }
+                    }
+                    else if(equiType == "CCD")
+                    {
+                        SN = Path.GetFileName(file).Split('_')[0].ToString();
+                        if (UploadImageToFtp(file, SN))
+                        {
+                            dh.ExecuteSql($@"INSERT INTO steptestdetail( sd_id, sd_makecode, sd_sn, SD_MACHINECODE, SD_INDATE,SD_ACTVALUE)
+                                                VALUES( steptestdetail_seq.NEXTVAL, '{ma_code.Text}', '{SN}', 'CCD', sysdate,
+                                                'http://192.168.1.92:8088/ftp/mes/Picture/{SN}/{Path.GetFileName(file)}')", "insert");
+                        }
+                    }
+
+                }
+            }
+            catch (Exception ex)
+            {
+                LogMessage(0, $"Error: 解析文件列表失败: {ex.Message}");
+            }
+        }
+
+
+        private bool InsertDb(List<Log> logs, string PathName, int fileNum)
+        {
+            try
+            {
+                StringBuilder sql = new StringBuilder();
+                List<string> param = new List<string>() { };
+                foreach (var item in logs)
+                {
+                    string sqlStr = $@"select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,ma_qty - nvl(mcd_okqty, 0) remain_qty 
+                                        from make left join makecraftdetail on mcd_maid=ma_id left join product on pr_code = ma_prodcode 
+                                        where ma_code='{ma_code.Text}' and mcd_stepcode='" + User.CurrentStepCode + "'";
+                    dt = (DataTable)dh.ExecuteSql(sqlStr, "select");
+                    BaseUtil.SetFormValue(Controls, dt);
+                    //记录操作日志
+                    LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "日志解析", "日志解析过站成功", item.SN, "");
+
+                    string outMsg = "";
+                    param.Add(item.SN); 
+                    param.Add(ma_code.Text);
+                    param.Add(User.UserSourceCode);
+                    param.Add(item.Result);
+                    param.Add(item.TestTime);
+                    param.Add(item.Side);
+                    param.Add(outMsg);
+
+                    string[] paramList = param.ToArray();
+                    dh.CallProcedure("CS_INSERT_TESTDETAIL", ref paramList);
+                    LogMessage(1, $"文件: {PathName},共{fileNum}条记录SN: {item.SN}解析已过站");
+                    param.Clear();
+
+                    if (logs.IndexOf(item) == logs.Count - 1)
+                    {
+                        return true;
+                    }
+                   /* if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, item.SN, User.UserCode, false, out omakeCode, out oMsid, out oErrorMessage))
+                    {
+                        if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, item.SN, "设备日志解析", "OK", User.UserCode, false, out oErrorMessage))
+                        {
+                            string sqlStr = $@"select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,ma_qty - nvl(mcd_okqty, 0) remain_qty 
+                                        from make left join makecraftdetail on mcd_maid=ma_id left join product on pr_code = ma_prodcode 
+                                        where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'";
+                            dt = (DataTable)dh.ExecuteSql(sqlStr, "select");
+                            BaseUtil.SetFormValue(Controls, dt);
+                            //记录操作日志
+                            LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "日志解析", "日志解析成功", item.SN, "");
+
+                            string outMsg = "";
+                            param.Add(item.SN);
+                            param.Add(omakeCode);
+                            param.Add(User.UserSourceCode);
+                            param.Add(item.Result);
+                            param.Add(outMsg);
+
+                            string[] paramList = param.ToArray();
+                            dh.CallProcedure("cs_insert_testdetail", ref paramList);
+                            LogMessage($"文件: {PathName},共{fileNum}条记录SN: {item.SN}解析已过站");
+                            param.Clear();
+
+                            if (logs.IndexOf(item) == logs.Count - 1)
+                            {
+                                return true;
+                            }
+                        }
+                        else
+                        {
+                            LogMessage($"处理过站NG:{oErrorMessage}");
+                            break;
+                        }
+                    }
+                    else
+                    {
+                        LogMessage($"过站核对NG:{oErrorMessage}");
+                        break;
+                    }*/
+                }
+                return false;
+            }
+            catch (Exception ex)
+            {
+                LogMessage(0, $"Error,处理解析写入: {ex.Message}");
+                return false;
+            }
+        }
+
+        private void ChangeWoFunc(object sender, EventArgs e)
+        {
+            try
+            {
+                sql.Clear();
+                sql.Append($"SELECT dl_macode FROM deviceline WHERE dl_linecode = '{User.UserLineCode}'");
+                dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
+                if (dt.Rows.Count > 0 && !String.IsNullOrEmpty(dt.Rows[0]["dl_macode"].ToString()))
+                {
+                    ma_code.Text = dt.Rows[0]["dl_macode"].ToString().Trim();
+                    return;
+                }
+
+                LogMessage(0, $"NG,自动识别更新工单");
+            }
+            catch (Exception ex)
+            {
+                LogMessage(0, $"Error,自动切换工单: {ex.Message}");
+            }
+        }
+
+        private bool ConsoleLog(string Content, string PathName)
+        {
+            try
+            {
+                string sourceDir = Path.GetDirectoryName(PathName);
+                string newFolderName = "Logs";
+                string newFolderPath = Path.Combine(sourceDir, newFolderName);
+
+                if (!Directory.Exists(newFolderPath))
+                {
+                    Directory.CreateDirectory(newFolderPath);
+                }
+                string newFileName = "Log_" + Path.GetFileName(PathName);
+                string newFilePath = Path.Combine(newFolderPath, newFileName);
+
+                File.AppendAllText(newFilePath, Content + Environment.NewLine);
+                return true;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(this.ParentForm, ex.Message, "警告");
+                return false;
+            }
+        }
+
+        private void LogMessage(int type, string message)
+        {
+
+            if (type == 0)
+            {
+                if (lstFiles.InvokeRequired)
+                {
+                    lstFiles.Invoke(new Action<int, string>(LogMessage), new object[] { type, message });
+                    return;
+                }
+                lstFiles.Items.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
+                lstFiles.TopIndex = lstFiles.Items.Count - 1;
+            }
+            else
+            {
+                if (lstOk.InvokeRequired)
+                {
+                    lstOk.Invoke(new Action<int, string>(LogMessage), new object[] { type, message });
+                    return;
+                }
+                lstOk.Items.Add($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
+                lstOk.TopIndex = lstOk.Items.Count - 1;
+            }
+        }
+        private void lstFiles_DrawItem(object sender, DrawItemEventArgs e)
+        {
+            if (e.Index < 0) return;
+
+            e.DrawBackground();
+            string txt = lstFiles.Items[e.Index].ToString().ToUpper();
+            Brush color = Brushes.Black;
+            if (txt.Contains("NG"))
+            {
+                color = Brushes.Red;
+            }
+            else if (txt.Contains("ERROR"))
+            {
+                color = Brushes.Red;
+            }
+            else
+            {
+                color = Brushes.Green;
+            }
+            e.DrawFocusRectangle();
+            e.Graphics.DrawString(lstFiles.Items[e.Index].ToString(), e.Font, color, e.Bounds, StringFormat.GenericDefault);
+        }
+
+        public bool UploadImageToFtp(string localFilePath, string Sn)
+        {
+            //string ftpServer = "ftp://10.8.0.208:21/mes/Picture/";
+            string ftpServer = "ftp://192.168.1.92:21/mes/Picture/";
+            string username = "vsftpd";
+            string password = "vsftpd3cd79018fl";
+
+            string currentDate = DateTime.Now.ToString("yyyyMMdd");
+            string ftpFullPath = $"{ftpServer.TrimEnd('/')}/{currentDate}";
+            /*string ftpFullPath = $"{ftpServer.TrimEnd('/')}/{Sn}";*/
+            string outResult = CreateFtpDirectoryIfNotExists(ftpFullPath, username, password);
+            if (outResult.Substring(0, 2) == "NG")
+            {
+                LogMessage(0, 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(1, $"文件: {localFilePath}上传成功,状态{response.StatusDescription}");
+                    return true;
+                }
+            }
+            catch (WebException ex)
+            {
+                if (ex.Response is FtpWebResponse response)
+                {
+                    LogMessage(0, $"NG,FTP 错误码: {(int)response.StatusCode} - {response.StatusDescription}");
+                }
+                else
+                {
+                    LogMessage(0, $"NG,Web异常: {ex.Message}");
+                }
+                return false;
+            }
+            catch (Exception ex)
+            {
+                LogMessage(0, $"NG,上传失败: {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())
+                {
+                    response.Close();
+                    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;
+                }
+            }
+        }
+        public string CheckFileAccess(string filePath)
+        {
+            try
+            {
+                using (FileStream fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
+                {
+                    return "OK";
+                }
+            }
+            catch (IOException ex)
+            {
+                return "文件被占用: " + ex.Message;
+            }
+            catch (UnauthorizedAccessException ex)
+            {
+                return "权限不足,无法访问文件: " + ex.Message;
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+        }
+
+        private class Log
+        {
+            public string SN { set; get; }
+
+            public string Result { set; get; }
+
+            public string TestTime { set; get; }
+
+            public string Side { set; get; }
+        }
+    }
+}

+ 126 - 0
UAS_MES_HYSX/FunctionCode/Make/Make_ParseLog.resx

@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="openFileDialog2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>224, 17</value>
+  </metadata>
+</root>

+ 25 - 0
UAS_MES_HYSX/UAS_MES_HYSX.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.14.36202.13 d17.14
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UAS_MES_HYSX", "UAS_MES_HYSX.csproj", "{9E3D3539-7AA8-489C-BED7-DAA9C22CD7FE}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{9E3D3539-7AA8-489C-BED7-DAA9C22CD7FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9E3D3539-7AA8-489C-BED7-DAA9C22CD7FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9E3D3539-7AA8-489C-BED7-DAA9C22CD7FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9E3D3539-7AA8-489C-BED7-DAA9C22CD7FE}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {8D7ECB27-2603-40AE-B8F3-E0185CCAFD89}
+	EndGlobalSection
+EndGlobal