Browse Source

update 萤石对接

yhluo 1 day ago
parent
commit
36e1b5ba1f

+ 215 - 34
UAS_MES_HYSX/FunctionCode/Make/Make_ListenSocket.Designer.cs

@@ -28,78 +28,246 @@
         /// </summary>
         private void InitializeComponent()
         {
+            this.ContainerBox = new System.Windows.Forms.Panel();
             this.OperatResult = new UAS_MES_NEW.CustomControl.RichText.RichTextAutoBottom();
+            this.SettingBox = new System.Windows.Forms.Panel();
+            this.Connet = new System.Windows.Forms.Button();
             this.Start = new System.Windows.Forms.Button();
-            this.statusLab = new System.Windows.Forms.Label();
+            this.IpPort = new System.Windows.Forms.TextBox();
+            this.IpPortLab = new System.Windows.Forms.Label();
+            this.SNDetails = new UAS_MES_NEW.CustomControl.GroupBoxWithBorder.GroupBoxWithBorder();
             this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+            this.productName = new System.Windows.Forms.Label();
+            this.productCode = new System.Windows.Forms.Label();
+            this.workOrder = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.serialNumber = new System.Windows.Forms.Label();
+            this.ContainerBox.SuspendLayout();
+            this.SettingBox.SuspendLayout();
+            this.SNDetails.SuspendLayout();
             this.tableLayoutPanel1.SuspendLayout();
             this.SuspendLayout();
             // 
+            // ContainerBox
+            // 
+            this.ContainerBox.Controls.Add(this.OperatResult);
+            this.ContainerBox.Controls.Add(this.SettingBox);
+            this.ContainerBox.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.ContainerBox.Location = new System.Drawing.Point(0, 123);
+            this.ContainerBox.Name = "ContainerBox";
+            this.ContainerBox.Size = new System.Drawing.Size(1600, 777);
+            this.ContainerBox.TabIndex = 97;
+            // 
             // OperatResult
             // 
-            this.OperatResult.Dock = System.Windows.Forms.DockStyle.Top;
+            this.OperatResult.Dock = System.Windows.Forms.DockStyle.Fill;
             this.OperatResult.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.OperatResult.Location = new System.Drawing.Point(0, 0);
+            this.OperatResult.Location = new System.Drawing.Point(0, 194);
             this.OperatResult.Margin = new System.Windows.Forms.Padding(4);
             this.OperatResult.Name = "OperatResult";
-            this.OperatResult.Size = new System.Drawing.Size(1600, 735);
+            this.OperatResult.Size = new System.Drawing.Size(1600, 583);
             this.OperatResult.TabIndex = 91;
             this.OperatResult.Text = "";
             // 
+            // SettingBox
+            // 
+            this.SettingBox.Controls.Add(this.Connet);
+            this.SettingBox.Controls.Add(this.Start);
+            this.SettingBox.Controls.Add(this.IpPort);
+            this.SettingBox.Controls.Add(this.IpPortLab);
+            this.SettingBox.Dock = System.Windows.Forms.DockStyle.Top;
+            this.SettingBox.Location = new System.Drawing.Point(0, 0);
+            this.SettingBox.Name = "SettingBox";
+            this.SettingBox.Size = new System.Drawing.Size(1600, 194);
+            this.SettingBox.TabIndex = 96;
+            // 
+            // Connet
+            // 
+            this.Connet.Anchor = System.Windows.Forms.AnchorStyles.None;
+            this.Connet.Cursor = System.Windows.Forms.Cursors.Hand;
+            this.Connet.Location = new System.Drawing.Point(161, 119);
+            this.Connet.Name = "Connet";
+            this.Connet.Size = new System.Drawing.Size(144, 43);
+            this.Connet.TabIndex = 93;
+            this.Connet.Text = "开启连接";
+            this.Connet.UseVisualStyleBackColor = true;
+            this.Connet.Visible = false;
+            this.Connet.Click += new System.EventHandler(this.Connet_Click);
+            // 
             // Start
             // 
             this.Start.Anchor = System.Windows.Forms.AnchorStyles.None;
             this.Start.Cursor = System.Windows.Forms.Cursors.Hand;
-            this.Start.Location = new System.Drawing.Point(671, 75);
+            this.Start.Location = new System.Drawing.Point(394, 119);
             this.Start.Name = "Start";
-            this.Start.Size = new System.Drawing.Size(258, 57);
+            this.Start.Size = new System.Drawing.Size(144, 43);
             this.Start.TabIndex = 92;
             this.Start.Text = "开启监听";
             this.Start.UseVisualStyleBackColor = true;
             this.Start.Click += new System.EventHandler(this.Start_Click);
             // 
-            // statusLab
+            // IpPort
+            // 
+            this.IpPort.Location = new System.Drawing.Point(161, 47);
+            this.IpPort.Name = "IpPort";
+            this.IpPort.Size = new System.Drawing.Size(309, 31);
+            this.IpPort.TabIndex = 1;
             // 
-            this.statusLab.Anchor = System.Windows.Forms.AnchorStyles.None;
-            this.statusLab.AutoSize = true;
-            this.statusLab.BackColor = System.Drawing.Color.LawnGreen;
-            this.statusLab.Font = new System.Drawing.Font("微软雅黑", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.statusLab.ForeColor = System.Drawing.SystemColors.WindowText;
-            this.statusLab.Location = new System.Drawing.Point(736, 3);
-            this.statusLab.Name = "statusLab";
-            this.statusLab.Size = new System.Drawing.Size(127, 36);
-            this.statusLab.TabIndex = 93;
-            this.statusLab.Text = "运行正常";
-            this.statusLab.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+            // IpPortLab
+            // 
+            this.IpPortLab.AutoSize = true;
+            this.IpPortLab.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.IpPortLab.Location = new System.Drawing.Point(60, 47);
+            this.IpPortLab.Name = "IpPortLab";
+            this.IpPortLab.Size = new System.Drawing.Size(117, 28);
+            this.IpPortLab.TabIndex = 0;
+            this.IpPortLab.Text = "服务地址:";
+            // 
+            // SNDetails
+            // 
+            this.SNDetails.BorderColor = System.Drawing.Color.Black;
+            this.SNDetails.Controls.Add(this.tableLayoutPanel1);
+            this.SNDetails.Dock = System.Windows.Forms.DockStyle.Top;
+            this.SNDetails.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.SNDetails.Location = new System.Drawing.Point(0, 0);
+            this.SNDetails.Name = "SNDetails";
+            this.SNDetails.Size = new System.Drawing.Size(1600, 123);
+            this.SNDetails.TabIndex = 95;
+            this.SNDetails.TabStop = false;
+            this.SNDetails.Text = "产品序列信息";
+            this.SNDetails.TextColor = System.Drawing.Color.Black;
             // 
             // tableLayoutPanel1
             // 
-            this.tableLayoutPanel1.ColumnCount = 1;
-            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
-            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
-            this.tableLayoutPanel1.Controls.Add(this.Start, 0, 1);
-            this.tableLayoutPanel1.Controls.Add(this.statusLab, 0, 0);
-            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 735);
+            this.tableLayoutPanel1.ColumnCount = 8;
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.451613F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.09677F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.451613F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.09677F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.451613F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 13.19F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 6.451613F));
+            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 36.81F));
+            this.tableLayoutPanel1.Controls.Add(this.productName, 7, 0);
+            this.tableLayoutPanel1.Controls.Add(this.productCode, 5, 0);
+            this.tableLayoutPanel1.Controls.Add(this.workOrder, 3, 0);
+            this.tableLayoutPanel1.Controls.Add(this.label4, 6, 0);
+            this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
+            this.tableLayoutPanel1.Controls.Add(this.label3, 4, 0);
+            this.tableLayoutPanel1.Controls.Add(this.label2, 2, 0);
+            this.tableLayoutPanel1.Controls.Add(this.serialNumber, 1, 0);
+            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom;
+            this.tableLayoutPanel1.Location = new System.Drawing.Point(3, 37);
             this.tableLayoutPanel1.Name = "tableLayoutPanel1";
-            this.tableLayoutPanel1.RowCount = 2;
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.45455F));
-            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 74.54546F));
-            this.tableLayoutPanel1.Size = new System.Drawing.Size(1600, 165);
-            this.tableLayoutPanel1.TabIndex = 94;
+            this.tableLayoutPanel1.RowCount = 1;
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 83F));
+            this.tableLayoutPanel1.Size = new System.Drawing.Size(1594, 83);
+            this.tableLayoutPanel1.TabIndex = 0;
+            // 
+            // productName
+            // 
+            this.productName.AutoSize = true;
+            this.productName.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.productName.Location = new System.Drawing.Point(1005, 0);
+            this.productName.Name = "productName";
+            this.productName.Size = new System.Drawing.Size(586, 83);
+            this.productName.TabIndex = 7;
+            this.productName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // productCode
+            // 
+            this.productCode.AutoSize = true;
+            this.productCode.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.productCode.Location = new System.Drawing.Point(693, 0);
+            this.productCode.Name = "productCode";
+            this.productCode.Size = new System.Drawing.Size(204, 83);
+            this.productCode.TabIndex = 6;
+            this.productCode.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // workOrder
+            // 
+            this.workOrder.AutoSize = true;
+            this.workOrder.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.workOrder.Location = new System.Drawing.Point(399, 0);
+            this.workOrder.Name = "workOrder";
+            this.workOrder.Size = new System.Drawing.Size(186, 83);
+            this.workOrder.TabIndex = 5;
+            this.workOrder.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.label4.Location = new System.Drawing.Point(903, 0);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(96, 83);
+            this.label4.TabIndex = 3;
+            this.label4.Text = "产品名称: ";
+            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.label1.Location = new System.Drawing.Point(3, 0);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(96, 83);
+            this.label1.TabIndex = 0;
+            this.label1.Text = "序列号: ";
+            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.label3.Location = new System.Drawing.Point(591, 0);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(96, 83);
+            this.label3.TabIndex = 2;
+            this.label3.Text = "产品编号: ";
+            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.label2.Location = new System.Drawing.Point(297, 0);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(96, 83);
+            this.label2.TabIndex = 1;
+            this.label2.Text = "工单: ";
+            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+            // 
+            // serialNumber
+            // 
+            this.serialNumber.AutoSize = true;
+            this.serialNumber.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.serialNumber.Location = new System.Drawing.Point(105, 0);
+            this.serialNumber.Name = "serialNumber";
+            this.serialNumber.Size = new System.Drawing.Size(186, 83);
+            this.serialNumber.TabIndex = 4;
+            this.serialNumber.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
             // 
             // Make_ListenSocket
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1600, 900);
-            this.Controls.Add(this.tableLayoutPanel1);
-            this.Controls.Add(this.OperatResult);
+            this.Controls.Add(this.ContainerBox);
+            this.Controls.Add(this.SNDetails);
             this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
             this.Margin = new System.Windows.Forms.Padding(4);
             this.Name = "Make_ListenSocket";
             this.Text = "Make_ListenSocket";
+            this.ContainerBox.ResumeLayout(false);
+            this.SettingBox.ResumeLayout(false);
+            this.SettingBox.PerformLayout();
+            this.SNDetails.ResumeLayout(false);
             this.tableLayoutPanel1.ResumeLayout(false);
             this.tableLayoutPanel1.PerformLayout();
             this.ResumeLayout(false);
@@ -109,8 +277,21 @@
         #endregion
 
         private CustomControl.RichText.RichTextAutoBottom OperatResult;
-        private System.Windows.Forms.Button Start;
-        private System.Windows.Forms.Label statusLab;
+        private CustomControl.GroupBoxWithBorder.GroupBoxWithBorder SNDetails;
+        private System.Windows.Forms.Label productName;
+        private System.Windows.Forms.Label productCode;
+        private System.Windows.Forms.Label workOrder;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label serialNumber;
+        private System.Windows.Forms.Panel ContainerBox;
         private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+        private System.Windows.Forms.Button Start;
+        private System.Windows.Forms.Panel SettingBox;
+        private System.Windows.Forms.Label IpPortLab;
+        private System.Windows.Forms.TextBox IpPort;
+        private System.Windows.Forms.Button Connet;
     }
 }

+ 360 - 7
UAS_MES_HYSX/FunctionCode/Make/Make_ListenSocket.cs

@@ -3,9 +3,14 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.IO;
 using System.Linq;
+using System.Net;
+using System.Net.Sockets;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
+using System.Web.Services.Description;
 using System.Windows.Forms;
 
 namespace UAS_MES_NEW.Make
@@ -17,6 +22,84 @@ namespace UAS_MES_NEW.Make
             InitializeComponent();
         }
 
+        SocketHandle client;
+
+        private void Connet_Click(object sender, EventArgs e)
+        {
+            if (Connet.Text == "开启连接")
+            {
+                Connet.Text = "关闭连接";
+            }
+            else if (Connet.Text == "关闭连接")
+            {
+                Connet.Text = "开启连接";
+            }
+        }
+
+        private async void Start_Click(object sender, EventArgs e)
+        {
+            if (string.IsNullOrEmpty(IpPort.Text))
+            {
+                ShowMsg(0, "请填写Socket服务地址");
+                return;
+            }
+
+            string ip = IpPort.Text.Split(':')[0];
+            int port = int.Parse(IpPort.Text.Split(':')[1]);
+            client = new SocketHandle(ip, port);
+
+            client.OnFileReceived += OnFileReceived;
+            client.OnMessageReceived += OnMessageReceived;
+            client.OnConnectionStatusChanged += OnConnectionStatusChanged;
+
+            if (Start.Text == "开启监听")
+            {
+                Start.Text = "关闭监听";
+                IpPort.Enabled = true;
+                client.Close();
+            }
+            else if (Start.Text == "关闭监听")
+            {
+                Start.Text = "开启监听";
+                IpPort.Enabled = false;
+
+                string msg = await client.ConnectAsync();
+                if (msg.StartsWith("NG"))
+                {
+                    ShowMsg(0, msg);
+                }
+                ShowMsg(1, msg);
+
+                string savePath = @"C:\Users\MI\Desktop\testEquiment\ReceivedFiles\received_file.txt";
+                msg = await client.ReceiveFileAsync(savePath);
+                if (msg.StartsWith("NG"))
+                {
+                    ShowMsg(0, msg);
+                }
+                ShowMsg(1, msg);
+            }
+        }
+        private async void OnFileReceived(string fileName, string savePath)
+        {
+            Console.WriteLine("文件接收完成: " + fileName + " 保存到: " + savePath);
+
+            string localFilePath = @"C:\Users\MI\Desktop\testEquiment\ReceivedFiles\send_file.txt";
+            string msg = await client.SendFileAsync(localFilePath);
+            if (msg.StartsWith("NG"))
+            {
+                ShowMsg(0, msg);
+            }
+            ShowMsg(1, "文件发送成功");
+        }
+        private void OnMessageReceived(string message)
+        {
+            Console.WriteLine("收到服务器消息: " + message);
+        }
+        private void OnConnectionStatusChanged(string status)
+        {
+            Console.WriteLine("连接状态: " + status);
+        }
+
         private void ShowMsg(int type, string msg)
         {
             msg = msg.Replace("\r", "").Replace("\n", "");
@@ -25,24 +108,294 @@ namespace UAS_MES_NEW.Make
             if (type == 0)
             {
                 OperatResult.AppendText(showMsg, Color.Red);
-                statusLab.Text = "状况异常";
             }
             else if (type == 1)
             {
                 OperatResult.AppendText(showMsg, Color.Green);
-                statusLab.Text = "运行正常";
             }
         }
 
-        private void Start_Click(object sender, EventArgs e)
+        public class SocketHandle
         {
-            if(Start.Text == "开启监听")
+            private Socket clientSocket;
+            private string serverIP;
+            private int serverPort;
+            private bool isConnected = false;
+
+            // 事件定义
+            public event Action<string, string> OnFileReceived;
+            public event Action<string> OnMessageReceived;
+            public event Action<string> OnConnectionStatusChanged;
+
+            public SocketHandle(string ip, int port)
             {
-                Start.Text = "关闭监听";
+                serverIP = ip;
+                serverPort = port;
+                clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             }
-            else if (Start.Text == "关闭监听")
+
+            public async Task<string> ConnectAsync()
             {
-                Start.Text = "开启监听";
+                try
+                {
+                    IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
+                    await Task.Factory.FromAsync(
+                        clientSocket.BeginConnect,
+                        clientSocket.EndConnect,
+                        endPoint,
+                        null);
+                    isConnected = true;
+                    if (OnConnectionStatusChanged != null)
+                    {
+                        OnConnectionStatusChanged("连接成功");
+                    }
+                    StartListeningAsync();
+
+                    return "OK,连接成功";
+                }
+                catch (Exception ex)
+                {
+                    return $"NG,连接失败: {ex.Message}";
+                }
+            }
+
+            private async void StartListeningAsync()
+            {
+                while (isConnected)
+                {
+                    try
+                    {
+                        byte[] lengthBytes = new byte[4];
+                        int receivedLength = await ReceiveDataAsync(lengthBytes, 0, lengthBytes.Length);
+
+                        if (receivedLength == 0) // 连接已断开
+                        {
+                            isConnected = false;
+                            if (OnConnectionStatusChanged != null)
+                            {
+                                OnConnectionStatusChanged("连接已断开");
+                            }
+                            break;
+                        }
+
+                        int messageLength = BitConverter.ToInt32(lengthBytes, 0);
+
+                        // 接收消息内容
+                        byte[] messageBytes = new byte[messageLength];
+                        await ReceiveDataAsync(messageBytes, 0, messageLength);
+                        string message = Encoding.UTF8.GetString(messageBytes);
+
+                        // 根据消息类型触发不同事件
+                        ProcessMessage(message);
+                    }
+                    catch (Exception ex)
+                    {
+                        isConnected = false;
+                        break;
+                    }
+                }
+            }
+            private void ProcessMessage(string message)
+            {
+                if (message.StartsWith("[FILE_TRANSFER]"))
+                {
+                    if (OnMessageReceived != null)
+                    {
+                        OnMessageReceived("服务器准备发送文件: " + message.Substring(15));
+                    }
+                }
+                else
+                {
+                    if (OnMessageReceived != null)
+                    {
+                        OnMessageReceived(message);
+                    }
+                }
+            }
+
+            public async Task<string> SendFileAsync(string filePath)
+            {
+                if (!isConnected)
+                {
+                    return "未连接到服务器";
+                }
+
+                if (!File.Exists(filePath))
+                {
+                    return "NG,文件不存在: " + filePath;
+                }
+
+                try
+                {
+                    FileInfo fileInfo = new FileInfo(filePath);
+                    string fileName = fileInfo.Name;
+                    long fileSize = fileInfo.Length;
+
+                    // 发送文件头信息 (文件名长度 + 文件名 + 文件大小)
+                    byte[] fileNameBytes = Encoding.UTF8.GetBytes(fileName);
+                    byte[] fileNameLengthBytes = BitConverter.GetBytes(fileNameBytes.Length);
+                    byte[] fileSizeBytes = BitConverter.GetBytes(fileSize);
+
+                    // 组合发送数据
+                    byte[] header = new byte[fileNameLengthBytes.Length + fileNameBytes.Length + fileSizeBytes.Length];
+                    Array.Copy(fileNameLengthBytes, 0, header, 0, fileNameLengthBytes.Length);
+                    Array.Copy(fileNameBytes, 0, header, fileNameLengthBytes.Length, fileNameBytes.Length);
+                    Array.Copy(fileSizeBytes, 0, header, fileNameLengthBytes.Length + fileNameBytes.Length, fileSizeBytes.Length);
+
+                    await SendDataAsync(header);
+
+                    // 发送文件内容
+                    using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
+                    {
+                        byte[] buffer = new byte[4096];
+                        int bytesRead;
+                        while ((bytesRead = await fileStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
+                        {
+                            await SendDataAsync(buffer, 0, bytesRead);
+                        }
+                    }
+
+                    return "OK,发送文件成功";
+                }
+                catch (Exception ex)
+                {
+                    return "NG,发送文件失败: " + ex.Message;
+                }
+            }
+
+            public async Task<string> ReceiveFileAsync(string savePath)
+            {
+                if (!isConnected)
+                {
+                    return "未连接到服务器";
+                }
+
+                try
+                {
+                    // 接收文件头信息
+                    byte[] fileNameLengthBytes = new byte[4];
+                    await ReceiveDataAsync(fileNameLengthBytes, 0, fileNameLengthBytes.Length);
+                    int fileNameLength = BitConverter.ToInt32(fileNameLengthBytes, 0);
+
+                    byte[] fileNameBytes = new byte[fileNameLength];
+                    await ReceiveDataAsync(fileNameBytes, 0, fileNameLength);
+                    string fileName = Encoding.UTF8.GetString(fileNameBytes);
+
+                    //byte[] fileSizeBytes = new byte[8];
+                    byte[] fileSizeBytes = new byte[4];
+                    await ReceiveDataAsync(fileSizeBytes, 0, fileSizeBytes.Length);
+                    long fileSize = BitConverter.ToInt64(fileSizeBytes, 0);
+
+                    // 确保保存目录存在
+                    string directory = Path.GetDirectoryName(savePath);
+                    if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
+                    {
+                        Directory.CreateDirectory(directory);
+                    }
+
+                    // 接收文件内容
+                    using (FileStream fileStream = new FileStream(savePath, FileMode.Create, FileAccess.Write))
+                    {
+                        byte[] buffer = new byte[4096];
+                        long totalReceived = 0;
+
+                        while (totalReceived < fileSize)
+                        {
+                            int toRead = (int)Math.Min(buffer.Length, fileSize - totalReceived);
+                            int received = await ReceiveDataAsync(buffer, 0, toRead);
+                            if (received <= 0)
+                            {
+                                break;
+                            }
+                            await fileStream.WriteAsync(buffer, 0, received);
+                            totalReceived += received;
+                        }
+                    }
+
+                    if (OnFileReceived != null)
+                    {
+                        OnFileReceived(fileName, savePath);
+                    }
+                    return "OK,接收文件成功";
+                }
+                catch (Exception ex)
+                {
+                    return "NG,接收文件失败: " + ex.Message;
+                }
+            }
+
+            public async Task<string> SendMessageAsync(string message)
+            {
+                if (!isConnected)
+                {
+                    return "未连接到服务器";
+                }
+                try
+                {
+                    byte[] messageBytes = Encoding.UTF8.GetBytes(message);
+                    byte[] lengthBytes = BitConverter.GetBytes(messageBytes.Length);
+
+                    await SendDataAsync(lengthBytes);
+                    await SendDataAsync(messageBytes);
+                    return "OK,发送消息成功";
+                }
+                catch (Exception ex)
+                {
+                    return "NG,发送消息失败: " + ex.Message;
+                }
+            }
+
+            public async Task<string> ReceiveMessageAsync()
+            {
+                try
+                {
+                    // 先接收消息长度
+                    byte[] lengthBytes = new byte[4];
+                    await ReceiveDataAsync(lengthBytes, 0, lengthBytes.Length);
+                    int messageLength = BitConverter.ToInt32(lengthBytes, 0);
+
+                    // 接收消息内容
+                    byte[] messageBytes = new byte[messageLength];
+                    await ReceiveDataAsync(messageBytes, 0, messageLength);
+
+                    return "OK," + Encoding.UTF8.GetString(messageBytes);
+                }
+                catch (Exception ex)
+                {
+                    Console.WriteLine("接收消息失败: " + ex.Message);
+                    return null;
+                }
+            }
+
+            private async Task SendDataAsync(byte[] data)
+            {
+                await SendDataAsync(data, 0, data.Length);
+            }
+
+            private async Task SendDataAsync(byte[] data, int offset, int size)
+            {
+                await Task.Factory.FromAsync((callback, state) => 
+                    clientSocket.BeginSend(data, offset, size, SocketFlags.None, callback, state),
+                    clientSocket.EndSend,
+                    null);
+            }
+
+            private async Task<int> ReceiveDataAsync(byte[] data, int offset, int size)
+            {
+                return await Task.Factory.FromAsync((callback, state) => 
+                    clientSocket.BeginReceive(data, offset, size, SocketFlags.None, callback, state),
+                    clientSocket.EndReceive,
+                    null);
+            }
+
+            public void Close()
+            {
+                isConnected = false;
+                if (clientSocket != null && clientSocket.Connected)
+                {
+                    clientSocket.Shutdown(SocketShutdown.Both);
+                    clientSocket.Close();
+                }
             }
         }
     }

+ 14 - 4
UAS_MES_HYSX/FunctionCode/Make/Make_SMTStencil.cs

@@ -101,10 +101,6 @@ namespace UAS_MES_NEW.Make
 
         private void Receive_Click(object sender, EventArgs e)
         {
-            if (ma_code.Text == "")
-            {
-                MessageBox.Show("工单号不能为空");
-            }
             DataTable dt;
 
             int WaringCount = int.Parse(dh.GetConfig("WaringCount", "Stencil").ToString());
@@ -143,6 +139,11 @@ namespace UAS_MES_NEW.Make
             }
             if (st_kind == "钢网")
             {
+                if (ma_code.Text == "")
+                {
+                    MessageBox.Show("工单号不能为空");
+                    return;
+                }
                 //限制钢网使用的产品
                 dt = (DataTable)dh.ExecuteSql("select 1 from STENILCANUSEPRO where sp_stcode='" + SU_DEVCODE.Text + "' and sp_prodcode='" + ma_prodcode.Text + "'", "select");
                 if (dt.Rows.Count == 0)
@@ -155,6 +156,10 @@ namespace UAS_MES_NEW.Make
                         return;
                     }
                 }
+            }
+            else if (st_kind == "刮刀")
+            {
+
             }
             dt = (DataTable)dh.ExecuteSql("select em_name from employee where em_code='" + em_code.Text + "'", "select");
             if (dt.Rows.Count > 0)
@@ -248,6 +253,11 @@ namespace UAS_MES_NEW.Make
                         em_code1.Text = "";
                         SU_RETURNIFCLEAN.Checked = false;
                         Return.Enabled = false;
+                        ST_ENSIONA.Text = "";
+                        ST_ENSIONB.Text = "";
+                        ST_ENSIONC.Text = "";
+                        ST_ENSIOND.Text = "";
+                        ST_ENSIONE.Text = "";
                         Confirm.PerformClick();
                     }
                     else

+ 2 - 2
UAS_Tools_HY/PublicMethods/ConnectDB.cs

@@ -8,8 +8,8 @@ namespace UAS_Tools_HY.PublicMethods
 {
     internal class ConnectDB
     {
-        private static readonly string ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11687))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=N_MES_HY;Password=select!#%*(;";
-
+        //private static readonly string ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11687))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=N_MES_HY;Password=select!#%*(;";
+        private static readonly string ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.18.6.220)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=N_MES_HY;Password=select!#%*(;";
         public static bool TestConnection()
         {
             try