From d9a3f196783790cf8e74ab90883895f7bc45942a Mon Sep 17 00:00:00 2001 From: zhougf Date: Wed, 26 Mar 2025 10:05:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E6=9D=90=E6=96=99=E7=A0=81=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E5=9B=BA=E5=8C=96=E6=97=B6=E9=97=B4=EF=BC=8C?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WindowsFormsApp1/MES_PLC_Control.csproj | 11 + WindowsFormsApp1/MainForm.Designer.cs | 108 ++++---- WindowsFormsApp1/MainForm.cs | 76 ++++++ WindowsFormsApp1/MaterialScanForm.Designer.cs | 239 ++++++++++++++++++ WindowsFormsApp1/MaterialScanForm.cs | 226 +++++++++++++++++ WindowsFormsApp1/MaterialScanForm.resx | 120 +++++++++ WindowsFormsApp1/form/LoginForm.Designer.cs | 70 ++--- .../mod/database/t_materialcall.cs | 19 ++ .../mod/database/t_materialscan.cs | 17 ++ WindowsFormsApp1/server/ApiClient.cs | 50 +++- 10 files changed, 842 insertions(+), 94 deletions(-) create mode 100644 WindowsFormsApp1/MaterialScanForm.Designer.cs create mode 100644 WindowsFormsApp1/MaterialScanForm.cs create mode 100644 WindowsFormsApp1/MaterialScanForm.resx create mode 100644 WindowsFormsApp1/mod/database/t_materialcall.cs create mode 100644 WindowsFormsApp1/mod/database/t_materialscan.cs diff --git a/WindowsFormsApp1/MES_PLC_Control.csproj b/WindowsFormsApp1/MES_PLC_Control.csproj index 75b0099..6c15e57 100644 --- a/WindowsFormsApp1/MES_PLC_Control.csproj +++ b/WindowsFormsApp1/MES_PLC_Control.csproj @@ -231,6 +231,14 @@ MESUrl.cs + + Form + + + MaterialScanForm.cs + + + @@ -340,6 +348,9 @@ MESUrl.cs + + MaterialScanForm.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/WindowsFormsApp1/MainForm.Designer.cs b/WindowsFormsApp1/MainForm.Designer.cs index 2c22344..53d2471 100644 --- a/WindowsFormsApp1/MainForm.Designer.cs +++ b/WindowsFormsApp1/MainForm.Designer.cs @@ -1,4 +1,6 @@ -namespace WindowsFormsApp1 +using System; + +namespace WindowsFormsApp1 { partial class MainForm { @@ -49,6 +51,7 @@ this.扭力曲线配置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.压力曲线设置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.系统参数配置ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.材料扫码ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel(); this.groupBox4 = new System.Windows.Forms.GroupBox(); @@ -76,11 +79,11 @@ this.MES提示信息 = new System.Windows.Forms.Label(); this.原料包装LOT号 = new System.Windows.Forms.GroupBox(); this.tableLayoutPanel5 = new System.Windows.Forms.TableLayoutPanel(); - this.Tray盘二维码 = new System.Windows.Forms.Label(); - this.MES提示 = new System.Windows.Forms.Label(); this.LOT号显示 = new System.Windows.Forms.Label(); this.LOT号 = new System.Windows.Forms.Label(); - this.胶水上下线 = new System.Windows.Forms.Button(); + this.剩余寿命 = new System.Windows.Forms.Label(); + this.MES提示 = new System.Windows.Forms.Label(); + this.Tray盘二维码 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel(); this.开始处理 = new System.Windows.Forms.Button(); @@ -102,7 +105,7 @@ this.底部注释4 = new System.Windows.Forms.Label(); this.底部注释5 = new System.Windows.Forms.Label(); this.timer1 = new System.Windows.Forms.Timer(this.components); - this.剩余寿命 = new System.Windows.Forms.Label(); + this.胶水上下线 = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel4.SuspendLayout(); @@ -133,7 +136,8 @@ this.流程管理ToolStripMenuItem, this.mES接口配置ToolStripMenuItem, this.扫码枪配置ToolStripMenuItem, - this.系统参数配置ToolStripMenuItem}); + this.系统参数配置ToolStripMenuItem, + this.材料扫码ToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(8, 2, 0, 2); @@ -283,6 +287,13 @@ this.系统参数配置ToolStripMenuItem.Text = "系统参数配置"; this.系统参数配置ToolStripMenuItem.Click += new System.EventHandler(this.系统参数配置ToolStripMenuItem_Click); // + // 材料扫码ToolStripMenuItem + // + this.材料扫码ToolStripMenuItem.Name = "材料扫码ToolStripMenuItem"; + this.材料扫码ToolStripMenuItem.Size = new System.Drawing.Size(166, 45); + this.材料扫码ToolStripMenuItem.Text = "材料扫码"; + this.材料扫码ToolStripMenuItem.Click += new System.EventHandler(this.材料扫码ToolStripMenuItem_Click); + // // tableLayoutPanel1 // this.tableLayoutPanel1.ColumnCount = 1; @@ -662,32 +673,9 @@ this.tableLayoutPanel5.RowCount = 2; this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel5.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel5.Size = new System.Drawing.Size(1215, 258); this.tableLayoutPanel5.TabIndex = 0; // - // Tray盘二维码 - // - this.Tray盘二维码.Anchor = System.Windows.Forms.AnchorStyles.None; - this.Tray盘二维码.AutoSize = true; - this.Tray盘二维码.Font = new System.Drawing.Font("宋体", 21.85714F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.Tray盘二维码.Location = new System.Drawing.Point(339, 163); - this.Tray盘二维码.Name = "Tray盘二维码"; - this.Tray盘二维码.Size = new System.Drawing.Size(664, 59); - this.Tray盘二维码.TabIndex = 2; - this.Tray盘二维码.Text = "托盘二维码:921391293"; - // - // MES提示 - // - this.MES提示.Anchor = System.Windows.Forms.AnchorStyles.None; - this.MES提示.AutoSize = true; - this.MES提示.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.MES提示.Location = new System.Drawing.Point(26, 169); - this.MES提示.Name = "MES提示"; - this.MES提示.Size = new System.Drawing.Size(212, 48); - this.MES提示.TabIndex = 4; - this.MES提示.Text = "托盘码:"; - // // LOT号显示 // this.LOT号显示.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -710,17 +698,38 @@ this.LOT号.TabIndex = 0; this.LOT号.Text = "SN:23199191"; // - // 胶水上下线 + // 剩余寿命 // - this.胶水上下线.Dock = System.Windows.Forms.DockStyle.Fill; - this.胶水上下线.Location = new System.Drawing.Point(1081, 5); - this.胶水上下线.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.胶水上下线.Name = "胶水上下线"; - this.胶水上下线.Size = new System.Drawing.Size(130, 119); - this.胶水上下线.TabIndex = 3; - this.胶水上下线.Text = "材料\r\n上下线"; - this.胶水上下线.UseVisualStyleBackColor = true; - this.胶水上下线.Click += new System.EventHandler(this.胶水上下线_Click); + this.剩余寿命.Anchor = System.Windows.Forms.AnchorStyles.None; + this.剩余寿命.AutoSize = true; + this.剩余寿命.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.剩余寿命.Location = new System.Drawing.Point(1090, 160); + this.剩余寿命.Name = "剩余寿命"; + this.剩余寿命.Size = new System.Drawing.Size(111, 66); + this.剩余寿命.TabIndex = 5; + this.剩余寿命.Text = "剩余寿命"; + // + // MES提示 + // + this.MES提示.Anchor = System.Windows.Forms.AnchorStyles.None; + this.MES提示.AutoSize = true; + this.MES提示.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.MES提示.Location = new System.Drawing.Point(26, 169); + this.MES提示.Name = "MES提示"; + this.MES提示.Size = new System.Drawing.Size(212, 48); + this.MES提示.TabIndex = 4; + this.MES提示.Text = "托盘码:"; + // + // Tray盘二维码 + // + this.Tray盘二维码.Anchor = System.Windows.Forms.AnchorStyles.None; + this.Tray盘二维码.AutoSize = true; + this.Tray盘二维码.Font = new System.Drawing.Font("宋体", 21.85714F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Tray盘二维码.Location = new System.Drawing.Point(339, 163); + this.Tray盘二维码.Name = "Tray盘二维码"; + this.Tray盘二维码.Size = new System.Drawing.Size(664, 59); + this.Tray盘二维码.TabIndex = 2; + this.Tray盘二维码.Text = "托盘二维码:921391293"; // // groupBox1 // @@ -1028,16 +1037,16 @@ this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // - // 剩余寿命 + // 胶水上下线 // - this.剩余寿命.Anchor = System.Windows.Forms.AnchorStyles.None; - this.剩余寿命.AutoSize = true; - this.剩余寿命.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.剩余寿命.Location = new System.Drawing.Point(1090, 160); - this.剩余寿命.Name = "剩余寿命"; - this.剩余寿命.Size = new System.Drawing.Size(111, 66); - this.剩余寿命.TabIndex = 5; - this.剩余寿命.Text = "剩余寿命"; + this.胶水上下线.Dock = System.Windows.Forms.DockStyle.Fill; + this.胶水上下线.Location = new System.Drawing.Point(1081, 5); + this.胶水上下线.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.胶水上下线.Name = "胶水上下线"; + this.胶水上下线.Size = new System.Drawing.Size(130, 119); + this.胶水上下线.TabIndex = 3; + this.胶水上下线.Text = "胶水寿命"; + this.胶水上下线.UseVisualStyleBackColor = true; // // MainForm // @@ -1092,6 +1101,7 @@ private System.Windows.Forms.ToolStripMenuItem pLC地址设置ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 扫码枪配置ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 系统参数配置ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 材料扫码ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 扫码枪配置ToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem 修改密码ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem 切换用户ToolStripMenuItem; @@ -1119,7 +1129,6 @@ private System.Windows.Forms.Label LOT号显示; private System.Windows.Forms.Label LOT号; private System.Windows.Forms.Timer timer1; - private System.Windows.Forms.Button 胶水上下线; private System.Windows.Forms.Label MES提示; private System.Windows.Forms.ToolStripMenuItem 产线基础信息管理ToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem pLC报警设置ToolStripMenuItem; @@ -1157,6 +1166,7 @@ private System.Windows.Forms.Label linecode; private System.Windows.Forms.Label linename; private System.Windows.Forms.Label 剩余寿命; + private System.Windows.Forms.Button 胶水上下线; } } diff --git a/WindowsFormsApp1/MainForm.cs b/WindowsFormsApp1/MainForm.cs index 0a7916e..c1d463a 100644 --- a/WindowsFormsApp1/MainForm.cs +++ b/WindowsFormsApp1/MainForm.cs @@ -22,6 +22,7 @@ using WindowsFormsApp1.mod.database; using WindowsFormsApp1.mod.server; using WindowsFormsApp1.server; using static SQLite.SQLite3; +using static WindowsFormsApp1.server.ApiClient; namespace WindowsFormsApp1 { @@ -359,6 +360,75 @@ namespace WindowsFormsApp1 } #endregion + #region 判断物料调用次数 固化站 + if (Init.t_Line.lineremark1 == "Curing") + { + SQLiteHelper materialCallHelper = new SQLiteHelper(); + string materialId = PlcData.Read_MaterialCode1; + bool shouldCallApi = false; + + var materialCall = materialCallHelper.Query(m => m.materialid == materialId).Data.FirstOrDefault(); + if (materialCall == null) + { + // 首次进站,需要调用接口 + materialCall = new t_materialcall { materialid = materialId }; + materialCall.checkin1 = DateTime.Now; + materialCallHelper.Insert(materialCall); + shouldCallApi = true; + } + else + { + // 判断当前是第几次调用 + if (!materialCall.checkin1.HasValue) + { + materialCall.checkin1 = DateTime.Now; + shouldCallApi = true; + } + else if (!materialCall.checkout3.HasValue && nowinterface.code.Contains("Checkout")) + { + // 第三次出站,需要调用接口 + materialCall.checkout3 = DateTime.Now; + shouldCallApi = true; + } + else + { + // 更新对应的时间 + if (nowinterface.code.Contains("SN_CheckIN")) + { + if (!materialCall.checkin2.HasValue) + materialCall.checkin2 = DateTime.Now; + else if (!materialCall.checkin3.HasValue) + materialCall.checkin3 = DateTime.Now; + } + else if (nowinterface.code.Contains("SN_Checkout")) + { + if (!materialCall.checkout1.HasValue) + materialCall.checkout1 = DateTime.Now; + else if (!materialCall.checkout2.HasValue) + materialCall.checkout2 = DateTime.Now; + } + } + materialCallHelper.Update(materialCall); + } + + if (!shouldCallApi) + { + // 不需要调用接口,直接返回成功 + PlcData.Write_Status = nowinterface.code.Contains("SN_CheckIN") + ? (short)PLC_Status.SN_CheckIN + : (short)PLC_Status.SN_Checkout; + var writeresult = siemensHelp.WriteAddress(plcaddress, PlcData); + if (!writeresult.Success) + { + PLC_Form(Plc, plcstate.NG, DateTime.Now); + LogExecute.logNet.WriteError($"{Plc.plcip}写入地址处理错误:处理停止"); + continue; + } + continue; + } + } + #endregion + #region 调用后端接口 var result = apiClient.CallFunctionByName(nowinterface.code, PlcData, otherdata); if (result.IsShow) @@ -639,6 +709,12 @@ namespace WindowsFormsApp1 keyValue.ShowDialog(); } + private void 材料扫码ToolStripMenuItem_Click(object sender, EventArgs e) + { + MaterialScanForm materialScanForm = new MaterialScanForm(); + materialScanForm.Show(); + } + private void pLC通讯设置ToolStripMenuItem_Click(object sender, EventArgs e) { Plc_Manage pLC_Manage = new Plc_Manage(); diff --git a/WindowsFormsApp1/MaterialScanForm.Designer.cs b/WindowsFormsApp1/MaterialScanForm.Designer.cs new file mode 100644 index 0000000..c035a59 --- /dev/null +++ b/WindowsFormsApp1/MaterialScanForm.Designer.cs @@ -0,0 +1,239 @@ +namespace WindowsFormsApp1 +{ + partial class MaterialScanForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panelTop = new System.Windows.Forms.Panel(); + this.lblScan = new System.Windows.Forms.Label(); + this.lblPosition = new System.Windows.Forms.Label(); + this.lblDescription = new System.Windows.Forms.Label(); + this.txtScan = new System.Windows.Forms.TextBox(); + this.rbPosition1 = new System.Windows.Forms.RadioButton(); + this.rbPosition2 = new System.Windows.Forms.RadioButton(); + this.txtDescription = new System.Windows.Forms.TextBox(); + this.btnAdd = new System.Windows.Forms.Button(); + this.dgvMaterials = new System.Windows.Forms.DataGridView(); + this.colOffline = new System.Windows.Forms.DataGridViewButtonColumn(); + this.colScanCode = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.colPosition = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.colDescription = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.colTime = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.panelTop.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dgvMaterials)).BeginInit(); + this.SuspendLayout(); + // + // panelTop + // + this.panelTop.Controls.Add(this.lblScan); + this.panelTop.Controls.Add(this.lblPosition); + this.panelTop.Controls.Add(this.lblDescription); + this.panelTop.Controls.Add(this.txtScan); + this.panelTop.Controls.Add(this.rbPosition1); + this.panelTop.Controls.Add(this.rbPosition2); + this.panelTop.Controls.Add(this.txtDescription); + this.panelTop.Controls.Add(this.btnAdd); + this.panelTop.Dock = System.Windows.Forms.DockStyle.Top; + this.panelTop.Location = new System.Drawing.Point(0, 0); + this.panelTop.Margin = new System.Windows.Forms.Padding(6); + this.panelTop.Name = "panelTop"; + this.panelTop.Size = new System.Drawing.Size(2148, 300); + this.panelTop.TabIndex = 6; + // + // lblScan + // + this.lblScan.Font = new System.Drawing.Font("微软雅黑", 14F); + this.lblScan.Location = new System.Drawing.Point(24, 50); + this.lblScan.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.lblScan.Name = "lblScan"; + this.lblScan.Size = new System.Drawing.Size(200, 50); + this.lblScan.TabIndex = 0; + this.lblScan.Text = "扫描条码"; + // + // lblPosition + // + this.lblPosition.Font = new System.Drawing.Font("微软雅黑", 14F); + this.lblPosition.Location = new System.Drawing.Point(700, 50); + this.lblPosition.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.lblPosition.Name = "lblPosition"; + this.lblPosition.Size = new System.Drawing.Size(200, 50); + this.lblPosition.TabIndex = 1; + this.lblPosition.Text = "位置"; + // + // lblDescription + // + this.lblDescription.Font = new System.Drawing.Font("微软雅黑", 14F); + this.lblDescription.Location = new System.Drawing.Point(1200, 50); + this.lblDescription.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.lblDescription.Name = "lblDescription"; + this.lblDescription.Size = new System.Drawing.Size(200, 50); + this.lblDescription.TabIndex = 2; + this.lblDescription.Text = "说明"; + // + // txtScan + // + this.txtScan.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txtScan.Location = new System.Drawing.Point(24, 110); + this.txtScan.Margin = new System.Windows.Forms.Padding(6); + this.txtScan.Name = "txtScan"; + this.txtScan.Size = new System.Drawing.Size(596, 57); + this.txtScan.TabIndex = 3; + // + // rbPosition1 + // + this.rbPosition1.Checked = true; + this.rbPosition1.Font = new System.Drawing.Font("微软雅黑", 14F); + this.rbPosition1.Location = new System.Drawing.Point(700, 110); + this.rbPosition1.Margin = new System.Windows.Forms.Padding(6); + this.rbPosition1.Name = "rbPosition1"; + this.rbPosition1.Size = new System.Drawing.Size(180, 64); + this.rbPosition1.TabIndex = 4; + this.rbPosition1.TabStop = true; + this.rbPosition1.Text = "位置1"; + // + // rbPosition2 + // + this.rbPosition2.Font = new System.Drawing.Font("微软雅黑", 14F); + this.rbPosition2.Location = new System.Drawing.Point(900, 110); + this.rbPosition2.Margin = new System.Windows.Forms.Padding(6); + this.rbPosition2.Name = "rbPosition2"; + this.rbPosition2.Size = new System.Drawing.Size(180, 64); + this.rbPosition2.TabIndex = 5; + this.rbPosition2.Text = "位置2"; + // + // txtDescription + // + this.txtDescription.Font = new System.Drawing.Font("微软雅黑", 14F); + this.txtDescription.Location = new System.Drawing.Point(1200, 110); + this.txtDescription.Margin = new System.Windows.Forms.Padding(6); + this.txtDescription.Name = "txtDescription"; + this.txtDescription.Size = new System.Drawing.Size(596, 57); + this.txtDescription.TabIndex = 6; + // + // btnAdd + // + this.btnAdd.Font = new System.Drawing.Font("微软雅黑", 14F); + this.btnAdd.Location = new System.Drawing.Point(1840, 104); + this.btnAdd.Margin = new System.Windows.Forms.Padding(6); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(200, 76); + this.btnAdd.TabIndex = 7; + this.btnAdd.Text = "上线"; + // + // dgvMaterials + // + this.dgvMaterials.AllowUserToAddRows = false; + this.dgvMaterials.AllowUserToDeleteRows = false; + this.dgvMaterials.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dgvMaterials.ColumnHeadersHeight = 40; + this.dgvMaterials.Dock = System.Windows.Forms.DockStyle.Fill; + this.dgvMaterials.Font = new System.Drawing.Font("微软雅黑", 14F); + this.dgvMaterials.Location = new System.Drawing.Point(0, 300); + this.dgvMaterials.Margin = new System.Windows.Forms.Padding(6); + this.dgvMaterials.Name = "dgvMaterials"; + this.dgvMaterials.ReadOnly = true; + this.dgvMaterials.RowHeadersWidth = 82; + this.dgvMaterials.RowTemplate.Height = 35; + this.dgvMaterials.Size = new System.Drawing.Size(2148, 1134); + this.dgvMaterials.TabIndex = 5; + // + // colOffline + // + this.colOffline.HeaderText = ""; + this.colOffline.MinimumWidth = 10; + this.colOffline.Name = "colOffline"; + this.colOffline.Text = "下线"; + this.colOffline.UseColumnTextForButtonValue = true; + this.colOffline.Width = 80; + // + // colScanCode + // + this.colScanCode.HeaderText = "扫描码"; + this.colScanCode.MinimumWidth = 10; + this.colScanCode.Name = "colScanCode"; + this.colScanCode.Width = 200; + // + // colPosition + // + this.colPosition.HeaderText = "位置"; + this.colPosition.MinimumWidth = 10; + this.colPosition.Name = "colPosition"; + this.colPosition.Width = 200; + // + // colDescription + // + this.colDescription.HeaderText = "说明"; + this.colDescription.MinimumWidth = 10; + this.colDescription.Name = "colDescription"; + this.colDescription.Width = 200; + // + // colTime + // + this.colTime.HeaderText = "时间"; + this.colTime.MinimumWidth = 10; + this.colTime.Name = "colTime"; + this.colTime.ReadOnly = true; + this.colTime.Width = 200; + // + // MaterialScanForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(2148, 1434); + this.Controls.Add(this.dgvMaterials); + this.Controls.Add(this.panelTop); + this.Margin = new System.Windows.Forms.Padding(6); + this.Name = "MaterialScanForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "材料扫码管理"; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + this.panelTop.ResumeLayout(false); + this.panelTop.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dgvMaterials)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panelTop; + private System.Windows.Forms.TextBox txtScan; + private System.Windows.Forms.RadioButton rbPosition1; + private System.Windows.Forms.RadioButton rbPosition2; + private System.Windows.Forms.TextBox txtDescription; + private System.Windows.Forms.Button btnAdd; + private System.Windows.Forms.DataGridView dgvMaterials; + private System.Windows.Forms.Label lblScan; + private System.Windows.Forms.Label lblPosition; + private System.Windows.Forms.Label lblDescription; + private System.Windows.Forms.DataGridViewButtonColumn colOffline; + private System.Windows.Forms.DataGridViewTextBoxColumn colScanCode; + private System.Windows.Forms.DataGridViewTextBoxColumn colPosition; + private System.Windows.Forms.DataGridViewTextBoxColumn colDescription; + private System.Windows.Forms.DataGridViewTextBoxColumn colTime; + } +} \ No newline at end of file diff --git a/WindowsFormsApp1/MaterialScanForm.cs b/WindowsFormsApp1/MaterialScanForm.cs new file mode 100644 index 0000000..f8412d4 --- /dev/null +++ b/WindowsFormsApp1/MaterialScanForm.cs @@ -0,0 +1,226 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Xml.Linq; +using WindowsFormsApp1.db; +using WindowsFormsApp1.mod; +using WindowsFormsApp1.mod.server; +using WindowsFormsApp1.server; + +namespace WindowsFormsApp1 +{ + public partial class MaterialScanForm : Form + { + private SQLiteHelper _dbHelper; + private List materials = new List(); + private ApiClient _apiClient; + public MaterialScanForm() + { + InitializeComponent(); + //Init.ScanPort.DataReceived += SerialPort_DataReceived_CL; + _dbHelper = new SQLiteHelper(); + _apiClient = new ApiClient(); + LoadMaterials(); + SetupControls(); + } + + private void LoadMaterials() + { + var result = _dbHelper.Query(m => m.isonline); + if (result.Success) + { + materials = result.Data; + } + RefreshDataGrid(); + } + + public void SerialPort_DataReceived_CL(object sender, SerialDataReceivedEventArgs e) + { + try + { + if (!Init.ScanPort.IsOpen) + { + Init.ScanPort?.Open(); + } + // 读取串口接收到的数据 + var dataBuilder = new StringBuilder(); + while (Init.ScanPort.BytesToRead > 0) + { + System.Threading.Thread.Sleep(100); + dataBuilder.Append(Init.ScanPort.ReadExisting()); + } + var barcode = dataBuilder.ToString(); + txtScan.Text = barcode; + } + catch (Exception ex) + { + MessageBox.Show($"读取数据时出错: {ex.Message}"); + } + } + + + private void BtnAdd_Click(object sender, EventArgs e) + { + if (string.IsNullOrWhiteSpace(txtScan.Text) || txtScan.Text == "请扫描材料条码") + { + MessageBox.Show("请扫描材料条码!"); + return; + } + + string scanCode = txtScan.Text; + if (materials.Any(m => m.scancode == scanCode)) + { + MessageBox.Show("该材料已经在列表中!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + txtScan.Text = "请扫描材料条码"; + txtScan.ForeColor = Color.Gray; + txtScan.Focus(); + return; + } + + // 调用接口 + var OtherData = new otherdata(); + OtherData.JS_SN = scanCode; + OtherData.locationindex = rbPosition1.Checked ? 1 : 2; + OtherData.opindex = 1; + var mesResult = _apiClient.CallFunctionByName("Glue_CheckOut", new plcdata(), OtherData); + + var material = new t_materialscan + { + scancode = scanCode, + position = rbPosition1.Checked ? "1" : "2", + description = txtDescription.Text == "请输入说明" ? "" : txtDescription.Text, + scantime = DateTime.Now, + isonline = true + }; + + var result = _dbHelper.Insert(material); + if (result.Success) + { + materials.Add(material); + RefreshDataGrid(); + + // 清空输入 + txtScan.Text = "请扫描材料条码"; + txtScan.ForeColor = Color.Gray; + txtDescription.Text = "请输入说明"; + txtDescription.ForeColor = Color.Gray; + txtScan.Focus(); + } + else + { + MessageBox.Show("保存失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void DgvMaterials_CellClick(object sender, DataGridViewCellEventArgs e) + { + if (e.ColumnIndex == 0 && e.RowIndex >= 0) + { + if (MessageBox.Show("确认要下线该材料吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + var material = materials[e.RowIndex]; + // 调用接口 + var OtherData = new otherdata(); + OtherData.JS_SN = material.scancode; + OtherData.locationindex = int.Parse(material.position); + OtherData.opindex = 2; + var mesResult = _apiClient.CallFunctionByName("Glue_CheckOut", new plcdata(), OtherData); + + material.isonline = false; + var result = _dbHelper.Update(material); + if (result.Success) + { + materials.RemoveAt(e.RowIndex); + RefreshDataGrid(); + } + else + { + MessageBox.Show("下线失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void SetupControls() + { + // 设置文本框默认提示 + SetupTextBoxHint(txtScan, "请扫描材料条码"); + SetupTextBoxHint(txtDescription, "请输入说明"); + + // 绑定事件 + btnAdd.Click += BtnAdd_Click; + dgvMaterials.CellClick += DgvMaterials_CellClick; + + // 调整表格行高和样式 + dgvMaterials.RowTemplate.Height = 60; // 增加行高 + dgvMaterials.ColumnHeadersHeight = 60; // 相应调整表头高度 + dgvMaterials.DefaultCellStyle.Font = new Font("微软雅黑", 14F); + dgvMaterials.ColumnHeadersDefaultCellStyle.Font = new Font("微软雅黑", 14F); + dgvMaterials.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; + dgvMaterials.AllowUserToAddRows = false; + dgvMaterials.AllowUserToDeleteRows = false; + dgvMaterials.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dgvMaterials.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; + dgvMaterials.RowHeadersVisible = false; + } + + private void SetupTextBoxHint(TextBox textBox, string hint) + { + textBox.Text = hint; + textBox.ForeColor = Color.Gray; + + textBox.Enter += (s, e) => { + if (textBox.Text == hint) + { + textBox.Text = ""; + textBox.ForeColor = Color.Black; + } + }; + + textBox.Leave += (s, e) => { + if (string.IsNullOrWhiteSpace(textBox.Text)) + { + textBox.Text = hint; + textBox.ForeColor = Color.Gray; + } + }; + } + + private void RefreshDataGrid() + { + // 确保表格有列 + if (dgvMaterials.Columns.Count == 0) + { + dgvMaterials.Columns.Add(colOffline); + dgvMaterials.Columns.Add(colScanCode); + dgvMaterials.Columns.Add(colPosition); + dgvMaterials.Columns.Add(colDescription); + dgvMaterials.Columns.Add(colTime); + + // 调整列宽 + colOffline.Width = 50; + colScanCode.Width = 400; + colPosition.Width = 50; + colDescription.Width = 80; + colTime.Width = 250; + } + + dgvMaterials.Rows.Clear(); + foreach (var material in materials) + { + dgvMaterials.Rows.Add("下线", material.scancode, material.position, + material.description, material.scantime.ToString("yyyy-MM-dd HH:mm:ss")); + } + + // 确保所有行的高度都是60 + foreach (DataGridViewRow row in dgvMaterials.Rows) + { + row.Height = 60; + } + } + } +} \ No newline at end of file diff --git a/WindowsFormsApp1/MaterialScanForm.resx b/WindowsFormsApp1/MaterialScanForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WindowsFormsApp1/MaterialScanForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WindowsFormsApp1/form/LoginForm.Designer.cs b/WindowsFormsApp1/form/LoginForm.Designer.cs index dd28afe..3b49d36 100644 --- a/WindowsFormsApp1/form/LoginForm.Designer.cs +++ b/WindowsFormsApp1/form/LoginForm.Designer.cs @@ -34,18 +34,18 @@ this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.comboBox1 = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.button1.Location = new System.Drawing.Point(201, 274); - this.button1.Margin = new System.Windows.Forms.Padding(2); + this.button1.Location = new System.Drawing.Point(402, 548); + this.button1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(173, 39); + this.button1.Size = new System.Drawing.Size(346, 78); this.button1.TabIndex = 0; this.button1.Text = "登录"; this.button1.UseVisualStyleBackColor = true; @@ -54,29 +54,30 @@ // textBox1 // this.textBox1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.textBox1.Location = new System.Drawing.Point(201, 48); - this.textBox1.Margin = new System.Windows.Forms.Padding(2); + this.textBox1.Location = new System.Drawing.Point(402, 96); + this.textBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(268, 29); + this.textBox1.Size = new System.Drawing.Size(532, 51); this.textBox1.TabIndex = 1; // // textBox2 // this.textBox2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.textBox2.Location = new System.Drawing.Point(201, 120); - this.textBox2.Margin = new System.Windows.Forms.Padding(2); + this.textBox2.Location = new System.Drawing.Point(402, 240); + this.textBox2.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(268, 29); + this.textBox2.PasswordChar = '*'; + this.textBox2.Size = new System.Drawing.Size(532, 51); this.textBox2.TabIndex = 2; // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label1.Location = new System.Drawing.Point(87, 51); - this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label1.Location = new System.Drawing.Point(174, 102); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(69, 19); + this.label1.Size = new System.Drawing.Size(134, 38); this.label1.TabIndex = 3; this.label1.Text = "用户名"; // @@ -84,10 +85,10 @@ // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label2.Location = new System.Drawing.Point(103, 123); - this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label2.Location = new System.Drawing.Point(206, 246); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(49, 19); + this.label2.Size = new System.Drawing.Size(95, 38); this.label2.TabIndex = 4; this.label2.Text = "密码"; // @@ -101,41 +102,44 @@ this.groupBox1.Controls.Add(this.button1); this.groupBox1.Controls.Add(this.textBox2); this.groupBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.groupBox1.Location = new System.Drawing.Point(30, 26); + this.groupBox1.Location = new System.Drawing.Point(60, 52); + this.groupBox1.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(564, 359); + this.groupBox1.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.groupBox1.Size = new System.Drawing.Size(1128, 718); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; this.groupBox1.Text = "用户登录"; // - // comboBox1 - // - this.comboBox1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.comboBox1.FormattingEnabled = true; - this.comboBox1.Location = new System.Drawing.Point(201, 195); - this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(268, 27); - this.comboBox1.TabIndex = 5; - // // label3 // this.label3.AutoSize = true; this.label3.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label3.Location = new System.Drawing.Point(87, 198); - this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.label3.Location = new System.Drawing.Point(174, 396); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(89, 19); + this.label3.Size = new System.Drawing.Size(173, 38); this.label3.TabIndex = 6; this.label3.Text = "选择产线"; // + // comboBox1 + // + this.comboBox1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(402, 390); + this.comboBox1.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(532, 46); + this.comboBox1.TabIndex = 5; + // // LoginForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(620, 408); + this.ClientSize = new System.Drawing.Size(1240, 816); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Margin = new System.Windows.Forms.Padding(2); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "LoginForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "LoginForm"; diff --git a/WindowsFormsApp1/mod/database/t_materialcall.cs b/WindowsFormsApp1/mod/database/t_materialcall.cs new file mode 100644 index 0000000..c7ff421 --- /dev/null +++ b/WindowsFormsApp1/mod/database/t_materialcall.cs @@ -0,0 +1,19 @@ +using SQLite; +using System; + +namespace WindowsFormsApp1.mod +{ + [Table("material_call")] + public class t_materialcall + { + [PrimaryKey, AutoIncrement] + public int id { get; set; } + public string materialid { get; set; } + public DateTime? checkin1 { get; set; } + public DateTime? checkin2 { get; set; } + public DateTime? checkin3 { get; set; } + public DateTime? checkout1 { get; set; } + public DateTime? checkout2 { get; set; } + public DateTime? checkout3 { get; set; } + } +} \ No newline at end of file diff --git a/WindowsFormsApp1/mod/database/t_materialscan.cs b/WindowsFormsApp1/mod/database/t_materialscan.cs new file mode 100644 index 0000000..429adb9 --- /dev/null +++ b/WindowsFormsApp1/mod/database/t_materialscan.cs @@ -0,0 +1,17 @@ +using SQLite; +using System; + +namespace WindowsFormsApp1.mod +{ + [Table("material_scan")] + public class t_materialscan + { + [PrimaryKey, AutoIncrement] + public int id { get; set; } + public string scancode { get; set; } + public string position { get; set; } + public string description { get; set; } + public DateTime scantime { get; set; } + public bool isonline { get; set; } + } +} \ No newline at end of file diff --git a/WindowsFormsApp1/server/ApiClient.cs b/WindowsFormsApp1/server/ApiClient.cs index 4984fa8..c0f4af1 100644 --- a/WindowsFormsApp1/server/ApiClient.cs +++ b/WindowsFormsApp1/server/ApiClient.cs @@ -86,12 +86,10 @@ namespace WindowsFormsApp1.server var station = Init.t_Line.lineremark2.ToLower(); switch (station) { - case "Potting"://灌胶 - case "ThermalPaste"://点胶&CCD检测 - case "UVCoating"://三防漆涂覆 - case "Sealant"://点密封胶&CCD - break; - default: + case "potting"://灌胶 + case "thermalpaste"://点胶&CCD检测 + case "uvcoating"://三防漆涂覆 + case "sealant"://点密封胶&CCD var power = Init.t_Keyvalues.First(x => x.key == "Power"); power.value = DateTime.Now.Millisecond.ToString(); SQLiteHelper kvHelper = new db.SQLiteHelper(); @@ -327,10 +325,10 @@ namespace WindowsFormsApp1.server var locationindex = 1; switch (station) { - case "Potting"://灌胶 - case "ThermalPaste"://点胶&CCD检测 - case "UVCoating"://三防漆涂覆 - case "Sealant"://点密封胶&CCD + case "potting"://灌胶 + case "thermalpaste"://点胶&CCD检测 + case "uvcoating"://三防漆涂覆 + case "sealant"://点密封胶&CCD break; default: fixsn_1 = "CompPN"; @@ -514,7 +512,7 @@ namespace WindowsFormsApp1.server { // 根据不同的lineCode构建不同的请求 var lineCode = Init.t_Line.linecode; - var stationid = Init.t_Line.lineremark2; + var stationid = Init.t_Line.lineremark2.ToLower(); var result = PlcData.Read_Result == 1 ? "PASS" : "FAIL"; var logresult = PlcData.Read_Result == 1 ? "OK" : "NG"; @@ -550,7 +548,7 @@ namespace WindowsFormsApp1.server var compListItem = new CompListItem(); //气密 - if ("SWAT".Contains(stationid)) + if ("WAT,Leakage".Contains(stationid)) { sninfo.DC_INFO.Add(new DCInfoItem @@ -615,7 +613,33 @@ namespace WindowsFormsApp1.server //固化 时间 if ("Curing".Contains(stationid)) { + SQLiteHelper materialHelper = new db.SQLiteHelper(); + var material = materialHelper.QuerySingle(x => x.materialid == PlcData.Read_MaterialCode0); + if (material.Success) + { + // 计算加热时间 + var time = ((TimeSpan)(material.Data.checkin2 - material.Data.checkout2)).TotalMinutes; + var jrTime = Convert.ToInt32(time).ToString(); + sninfo.DC_INFO.Add(new DCInfoItem + { + Item = OutItem.固化时间, + Value = jrTime, + Result = result + }); + sninfo.DC_INFO.Add(new DCInfoItem + { + Item = OutItem.固化温度, + Value = PlcData.Read_UploadData0.ToString(), + Up = "85", + Down = "75", + Result = result + }); + } + else + { + //报错,没有这个物料 + } } //胶重 if ("Potting,ThermalPaste,Sealant".Contains(stationid)) @@ -867,6 +891,8 @@ namespace WindowsFormsApp1.server { public string Item { get; set; } public string Value { get; set; } + public string Up { get; set; } = ""; + public string Down { get; set; } = ""; public string Result { get; set; } }