This commit is contained in:
wxt
2026-01-26 15:41:42 +08:00
parent 8533734111
commit 041da6e16e
6 changed files with 825 additions and 445 deletions

View File

@@ -3,6 +3,7 @@ using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -89,11 +90,18 @@ namespace 材料热传导系数
public bool IsHighMode { get; set; }
/// <summary>
///模式选择
/// </summary>
public string TemperatureMode { get; set; }
}
public class ConductivityRepository
{
public readonly string _connectionString;
public ConductivityRepository()
@@ -123,9 +131,9 @@ namespace 材料热传导系数
{
connection.Open();
var sql = @"INSERT INTO scandata
(barcode,diffpressure,exit_temperature,temperature, dwelltime,CreateTime)
(barcode,diffpressure,exit_temperature,temperature, dwelltime,CreateTime,TemperatureMode)
VALUES
(@barcode,@diffpressure,@exit_temperature,@temperature , @dwelltime ,CURRENT_TIMESTAMP)";
(@barcode,@diffpressure,@exit_temperature,@temperature , @dwelltime , CURRENT_TIMESTAMP ,@TemperatureMode)";
connection.Execute(sql, data);
}
}

View File

@@ -161,11 +161,14 @@ namespace 全自动水压检测仪
this.uiPanel2 = new Sunny.UI.UIPanel();
this.uiLabel1 = new Sunny.UI.UILabel();
this.uiLight1 = new Sunny.UI.UILight();
this.uiLabel11 = new Sunny.UI.UILabel();
this.uiLabel25 = new Sunny.UI.UILabel();
this.uiTableLayoutPanel1.SuspendLayout();
this.uiTableLayoutPanel2.SuspendLayout();
this.panel1.SuspendLayout();
this.uiPanel29.SuspendLayout();
this.uiTableLayoutPanel15.SuspendLayout();
this.uiPanel30.SuspendLayout();
this.uiPanel7.SuspendLayout();
this.uiTableLayoutPanel4.SuspendLayout();
this.uiPanel34.SuspendLayout();
@@ -315,6 +318,8 @@ namespace 全自动水压检测仪
//
// uiPanel30
//
this.uiPanel30.Controls.Add(this.uiLabel25);
this.uiPanel30.Controls.Add(this.uiLabel11);
this.uiPanel30.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel30.FillColor = System.Drawing.Color.White;
this.uiPanel30.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -325,7 +330,6 @@ namespace 全自动水压检测仪
this.uiPanel30.RectColor = System.Drawing.Color.White;
this.uiPanel30.Size = new System.Drawing.Size(154, 47);
this.uiPanel30.TabIndex = 0;
this.uiPanel30.Text = "模式切换";
this.uiPanel30.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
//
// uiSwitch1
@@ -1017,8 +1021,8 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel10.Name = "uiTableLayoutPanel10";
this.uiTableLayoutPanel10.Padding = new System.Windows.Forms.Padding(5);
this.uiTableLayoutPanel10.RowCount = 2;
this.uiTableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 15F));
this.uiTableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 85F));
this.uiTableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 13F));
this.uiTableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 87F));
this.uiTableLayoutPanel10.Size = new System.Drawing.Size(750, 210);
this.uiTableLayoutPanel10.TabIndex = 0;
this.uiTableLayoutPanel10.TagString = null;
@@ -1034,7 +1038,7 @@ namespace 全自动水压检测仪
this.uiPanel19.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel19.Name = "uiPanel19";
this.uiPanel19.RectColor = System.Drawing.Color.White;
this.uiPanel19.Size = new System.Drawing.Size(732, 20);
this.uiPanel19.Size = new System.Drawing.Size(732, 16);
this.uiPanel19.TabIndex = 1;
this.uiPanel19.Text = " 实时数据监控";
this.uiPanel19.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
@@ -1049,11 +1053,11 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel11.Controls.Add(this.uiTableLayoutPanel13, 1, 0);
this.uiTableLayoutPanel11.Controls.Add(this.uiPanel26, 0, 0);
this.uiTableLayoutPanel11.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiTableLayoutPanel11.Location = new System.Drawing.Point(8, 38);
this.uiTableLayoutPanel11.Location = new System.Drawing.Point(8, 34);
this.uiTableLayoutPanel11.Name = "uiTableLayoutPanel11";
this.uiTableLayoutPanel11.RowCount = 1;
this.uiTableLayoutPanel11.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.uiTableLayoutPanel11.Size = new System.Drawing.Size(734, 164);
this.uiTableLayoutPanel11.Size = new System.Drawing.Size(734, 168);
this.uiTableLayoutPanel11.TabIndex = 2;
this.uiTableLayoutPanel11.TagString = null;
//
@@ -1074,7 +1078,7 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel16.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.3F));
this.uiTableLayoutPanel16.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.4F));
this.uiTableLayoutPanel16.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.uiTableLayoutPanel16.Size = new System.Drawing.Size(252, 158);
this.uiTableLayoutPanel16.Size = new System.Drawing.Size(252, 162);
this.uiTableLayoutPanel16.TabIndex = 11;
this.uiTableLayoutPanel16.TagString = null;
//
@@ -1084,7 +1088,7 @@ namespace 全自动水压检测仪
this.uiPanel35.Controls.Add(this.uiLabel43);
this.uiPanel35.FillColor = System.Drawing.Color.White;
this.uiPanel35.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel35.Location = new System.Drawing.Point(4, 109);
this.uiPanel35.Location = new System.Drawing.Point(4, 111);
this.uiPanel35.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel35.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel35.Name = "uiPanel35";
@@ -1162,7 +1166,7 @@ namespace 全自动水压检测仪
this.uiPanel33.Controls.Add(this.uiLabel39);
this.uiPanel33.FillColor = System.Drawing.Color.White;
this.uiPanel33.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel33.Location = new System.Drawing.Point(4, 57);
this.uiPanel33.Location = new System.Drawing.Point(4, 58);
this.uiPanel33.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel33.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel33.Name = "uiPanel33";
@@ -1211,7 +1215,7 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel13.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.3F));
this.uiTableLayoutPanel13.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.3F));
this.uiTableLayoutPanel13.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.4F));
this.uiTableLayoutPanel13.Size = new System.Drawing.Size(250, 158);
this.uiTableLayoutPanel13.Size = new System.Drawing.Size(250, 162);
this.uiTableLayoutPanel13.TabIndex = 9;
this.uiTableLayoutPanel13.TagString = null;
//
@@ -1224,12 +1228,12 @@ namespace 全自动水压检测仪
this.uiPanel31.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel31.FillColor = System.Drawing.Color.White;
this.uiPanel31.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel31.Location = new System.Drawing.Point(4, 109);
this.uiPanel31.Location = new System.Drawing.Point(4, 111);
this.uiPanel31.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel31.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel31.Name = "uiPanel31";
this.uiPanel31.RectColor = System.Drawing.Color.White;
this.uiPanel31.Size = new System.Drawing.Size(242, 44);
this.uiPanel31.Size = new System.Drawing.Size(242, 46);
this.uiPanel31.TabIndex = 6;
this.uiPanel31.Text = null;
this.uiPanel31.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1287,12 +1291,12 @@ namespace 全自动水压检测仪
this.uiPanel23.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel23.FillColor = System.Drawing.Color.White;
this.uiPanel23.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel23.Location = new System.Drawing.Point(4, 57);
this.uiPanel23.Location = new System.Drawing.Point(4, 58);
this.uiPanel23.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel23.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel23.Name = "uiPanel23";
this.uiPanel23.RectColor = System.Drawing.Color.White;
this.uiPanel23.Size = new System.Drawing.Size(242, 42);
this.uiPanel23.Size = new System.Drawing.Size(242, 43);
this.uiPanel23.TabIndex = 5;
this.uiPanel23.Text = null;
this.uiPanel23.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1301,7 +1305,7 @@ namespace 全自动水压检测仪
//
this.uiProcessBar1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiProcessBar1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiProcessBar1.Location = new System.Drawing.Point(2, 32);
this.uiProcessBar1.Location = new System.Drawing.Point(2, 31);
this.uiProcessBar1.MinimumSize = new System.Drawing.Size(3, 3);
this.uiProcessBar1.Name = "uiProcessBar1";
this.uiProcessBar1.Size = new System.Drawing.Size(236, 10);
@@ -1313,7 +1317,7 @@ namespace 全自动水压检测仪
this.uiLabel12.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(245)))), ((int)(((byte)(245)))));
this.uiLabel12.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold);
this.uiLabel12.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiLabel12.Location = new System.Drawing.Point(148, 0);
this.uiLabel12.Location = new System.Drawing.Point(148, -1);
this.uiLabel12.Name = "uiLabel12";
this.uiLabel12.Size = new System.Drawing.Size(80, 30);
this.uiLabel12.TabIndex = 2;
@@ -1354,7 +1358,7 @@ namespace 全自动水压检测仪
this.uiPanel27.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel27.Name = "uiPanel27";
this.uiPanel27.RectColor = System.Drawing.Color.White;
this.uiPanel27.Size = new System.Drawing.Size(242, 42);
this.uiPanel27.Size = new System.Drawing.Size(242, 43);
this.uiPanel27.TabIndex = 4;
this.uiPanel27.Text = null;
this.uiPanel27.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1404,7 +1408,7 @@ namespace 全自动水压检测仪
this.uiPanel26.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel26.Name = "uiPanel26";
this.uiPanel26.RectColor = System.Drawing.Color.White;
this.uiPanel26.Size = new System.Drawing.Size(212, 154);
this.uiPanel26.Size = new System.Drawing.Size(212, 158);
this.uiPanel26.TabIndex = 6;
this.uiPanel26.Text = null;
this.uiPanel26.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1425,7 +1429,7 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.3F));
this.uiTableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.3F));
this.uiTableLayoutPanel12.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.4F));
this.uiTableLayoutPanel12.Size = new System.Drawing.Size(212, 154);
this.uiTableLayoutPanel12.Size = new System.Drawing.Size(212, 158);
this.uiTableLayoutPanel12.TabIndex = 2;
this.uiTableLayoutPanel12.TagString = null;
//
@@ -1437,12 +1441,12 @@ namespace 全自动水压检测仪
this.uiPanel24.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel24.FillColor = System.Drawing.Color.White;
this.uiPanel24.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel24.Location = new System.Drawing.Point(4, 107);
this.uiPanel24.Location = new System.Drawing.Point(4, 109);
this.uiPanel24.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel24.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel24.Name = "uiPanel24";
this.uiPanel24.RectColor = System.Drawing.Color.White;
this.uiPanel24.Size = new System.Drawing.Size(204, 42);
this.uiPanel24.Size = new System.Drawing.Size(204, 44);
this.uiPanel24.TabIndex = 6;
this.uiPanel24.Text = null;
this.uiPanel24.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1488,12 +1492,12 @@ namespace 全自动水压检测仪
this.uiPanel22.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel22.FillColor = System.Drawing.Color.White;
this.uiPanel22.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel22.Location = new System.Drawing.Point(4, 56);
this.uiPanel22.Location = new System.Drawing.Point(4, 57);
this.uiPanel22.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel22.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel22.Name = "uiPanel22";
this.uiPanel22.RectColor = System.Drawing.Color.White;
this.uiPanel22.Size = new System.Drawing.Size(204, 41);
this.uiPanel22.Size = new System.Drawing.Size(204, 42);
this.uiPanel22.TabIndex = 5;
this.uiPanel22.Text = null;
this.uiPanel22.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1544,7 +1548,7 @@ namespace 全自动水压检测仪
this.uiPanel21.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel21.Name = "uiPanel21";
this.uiPanel21.RectColor = System.Drawing.Color.White;
this.uiPanel21.Size = new System.Drawing.Size(204, 41);
this.uiPanel21.Size = new System.Drawing.Size(204, 42);
this.uiPanel21.TabIndex = 4;
this.uiPanel21.Text = null;
this.uiPanel21.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -1699,7 +1703,7 @@ namespace 全自动水压检测仪
// uiButton8
//
this.uiButton8.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton8.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton8.Location = new System.Drawing.Point(426, 126);
this.uiButton8.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton8.Name = "uiButton8";
@@ -2075,7 +2079,7 @@ namespace 全自动水压检测仪
this.uiButton14.FillPressColor = System.Drawing.Color.White;
this.uiButton14.FillSelectedColor = System.Drawing.Color.White;
this.uiButton14.Font = new System.Drawing.Font("微软雅黑", 10F);
this.uiButton14.Location = new System.Drawing.Point(501, 11);
this.uiButton14.Location = new System.Drawing.Point(438, 11);
this.uiButton14.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton14.Name = "uiButton14";
this.uiButton14.RectColor = System.Drawing.Color.White;
@@ -2126,13 +2130,13 @@ namespace 全自动水压检测仪
this.uiPanel3.Controls.Add(this.uiLabel2);
this.uiPanel3.FillColor = System.Drawing.Color.White;
this.uiPanel3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel3.Location = new System.Drawing.Point(558, 5);
this.uiPanel3.Location = new System.Drawing.Point(511, 5);
this.uiPanel3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel3.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel3.Name = "uiPanel3";
this.uiPanel3.Radius = 20;
this.uiPanel3.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.uiPanel3.Size = new System.Drawing.Size(172, 45);
this.uiPanel3.Size = new System.Drawing.Size(219, 45);
this.uiPanel3.TabIndex = 3;
this.uiPanel3.Text = null;
this.uiPanel3.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -2142,9 +2146,9 @@ namespace 全自动水压检测仪
this.uiLabel3.BackColor = System.Drawing.Color.White;
this.uiLabel3.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Bold);
this.uiLabel3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel3.Location = new System.Drawing.Point(99, 11);
this.uiLabel3.Location = new System.Drawing.Point(96, 7);
this.uiLabel3.Name = "uiLabel3";
this.uiLabel3.Size = new System.Drawing.Size(60, 23);
this.uiLabel3.Size = new System.Drawing.Size(108, 30);
this.uiLabel3.TabIndex = 1;
this.uiLabel3.Text = "0";
this.uiLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -2154,11 +2158,11 @@ namespace 全自动水压检测仪
this.uiLabel2.BackColor = System.Drawing.Color.White;
this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 11F);
this.uiLabel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel2.Location = new System.Drawing.Point(13, 11);
this.uiLabel2.Location = new System.Drawing.Point(19, 11);
this.uiLabel2.Name = "uiLabel2";
this.uiLabel2.Size = new System.Drawing.Size(112, 23);
this.uiLabel2.Size = new System.Drawing.Size(90, 23);
this.uiLabel2.TabIndex = 0;
this.uiLabel2.Text = "测试步";
this.uiLabel2.Text = "系统状态";
this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// uiPanel2
@@ -2207,6 +2211,27 @@ namespace 全自动水压检测仪
this.uiLight1.TabIndex = 1;
this.uiLight1.Text = "uiLight1";
//
// uiLabel11
//
this.uiLabel11.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel11.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel11.Location = new System.Drawing.Point(69, -1);
this.uiLabel11.Name = "uiLabel11";
this.uiLabel11.Size = new System.Drawing.Size(86, 47);
this.uiLabel11.TabIndex = 0;
this.uiLabel11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// uiLabel25
//
this.uiLabel25.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel25.ForeColor = System.Drawing.Color.Red;
this.uiLabel25.Location = new System.Drawing.Point(2, 0);
this.uiLabel25.Name = "uiLabel25";
this.uiLabel25.Size = new System.Drawing.Size(50, 47);
this.uiLabel25.TabIndex = 1;
this.uiLabel25.Text = "请切换模式";
this.uiLabel25.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// NormalTemperatureMode
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@@ -2225,6 +2250,7 @@ namespace 全自动水压检测仪
this.panel1.ResumeLayout(false);
this.uiPanel29.ResumeLayout(false);
this.uiTableLayoutPanel15.ResumeLayout(false);
this.uiPanel30.ResumeLayout(false);
this.uiPanel7.ResumeLayout(false);
this.uiTableLayoutPanel4.ResumeLayout(false);
this.uiPanel34.ResumeLayout(false);
@@ -2410,6 +2436,8 @@ namespace 全自动水压检测仪
private Sunny.UI.UIPanel uiPanel6;
private Sunny.UI.UIButton uiButton7;
private Sunny.UI.UIButton uiButton8;
private Sunny.UI.UILabel uiLabel11;
private Sunny.UI.UILabel uiLabel25;
}
}

View File

@@ -60,6 +60,71 @@ namespace 全自动水压检测仪
CurrentReport = new List<ConductivityTestData>();
}
private void SafeInvoke(Action action)
{
if (action == null) return;
// 检查窗体是否已释放/句柄是否创建
if (this.IsDisposed || !this.IsHandleCreated)
{
Debug.WriteLine("窗体已释放或句柄未创建跳过UI操作");
return;
}
try
{
// 如果已经在UI线程直接执行否则Invoke
if (this.InvokeRequired)
{
this.Invoke(action);
}
else
{
action();
}
}
catch (ObjectDisposedException ex)
{
Debug.WriteLine($"UI操作时控件已释放: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Debug.WriteLine($"UI操作异常: {ex.Message}");
}
}
// 重载支持BeginInvoke异步UI更新
private void SafeBeginInvoke(Action action)
{
if (action == null) return;
if (this.IsDisposed || !this.IsHandleCreated)
{
Debug.WriteLine("窗体已释放或句柄未创建跳过异步UI操作");
return;
}
try
{
if (this.InvokeRequired)
{
this.BeginInvoke(action);
}
else
{
action();
}
}
catch (ObjectDisposedException ex)
{
Debug.WriteLine($"异步UI操作时控件已释放: {ex.Message}");
}
catch (InvalidOperationException ex)
{
Debug.WriteLine($"异步UI操作异常: {ex.Message}");
}
}
private System.Windows.Forms.Timer InitTimer()
{
var timer = new System.Windows.Forms.Timer()
@@ -101,12 +166,15 @@ namespace 全自动水压检测仪
return timer;
}
private async System.Threading.Tasks.Task ReadLeakTestParametersAsync()
private async Task ReadLeakTestParametersAsync()
{
// 检查连接状态
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
{
SafeInvoke(() =>
{
MessageBox.Show("TCP未连接或ModbusMaster未初始化", "提示");
});
return;
}
@@ -136,7 +204,6 @@ namespace 全自动水压检测仪
Real9 = SafelyReadRegisters(1, 3030, 2),// 高温实时液位
Real10 = SafelyReadRegisters(1, 3480, 2),// 箱体温度
Real11 = SafelyReadRegisters(1, 3180, 2),// 出口温度
CurrentTime = DateTime.Now
};
}
@@ -158,14 +225,8 @@ namespace 全自动水压检测仪
throw new InvalidOperationException("数据转换工具未初始化");
}
// 检查控件是否存在
if (this.IsDisposed || !this.IsHandleCreated)
{
return;
}
// 使用 BeginInvoke 确保在 UI 线程执行
this.BeginInvoke(new Action(() =>
// 使用安全的异步UI更新方法
SafeBeginInvoke(() =>
{
try
{
@@ -193,12 +254,12 @@ namespace 全自动水压检测仪
if (percentage > 100) percentage = 100;
// 更新进度条
if (uiProcessBar1 != null && !uiProcessBar1.IsDisposed)
uiProcessBar1.Value = (int)percentage;
uiLabel12.Text = value1.ToString("F2");
}
// 初始压力
if (uiLabel14 != null && !uiLabel14.IsDisposed &&
modbusData.Real3 != null && modbusData.Real3.Length >= 2)
@@ -223,30 +284,6 @@ namespace 全自动水压检测仪
uiLabel22.Text = value4.ToString("F2");
}
// 计时s
//if (uiLabel25 != null && !uiLabel25.IsDisposed &&
// modbusData.Real6 != null && modbusData.Real6.Length >= 1)
//{
// int value5 = modbusData.Real6[0];
// uiLabel25.Text = value5.ToString();
//}
//// 计时min
//if (uiLabel9 != null && !uiLabel9.IsDisposed &&
// modbusData.Real7 != null && modbusData.Real7.Length >= 1)
//{
// int value6 = modbusData.Real7[0];
// uiLabel9.Text = value6.ToString();
//}
//// 计时h
//if (uiLabel31 != null && !uiLabel31.IsDisposed &&
// modbusData.Real8 != null && modbusData.Real8.Length >= 1)
//{
// int value7 = modbusData.Real8[0];
// uiLabel31.Text = value7.ToString();
//}
// 合并显示时间格式hh:mm:ss
if (uiLabel9 != null && !uiLabel9.IsDisposed)
{
@@ -260,9 +297,6 @@ namespace 全自动水压检测仪
uiLabel9.Text = timeString;
}
// 高温实时液位
if (uiLabel7 != null && !uiLabel7.IsDisposed &&
modbusData.Real9 != null && modbusData.Real9.Length >= 2)
@@ -275,7 +309,9 @@ namespace 全自动水压检测仪
if (percentage > 100) percentage = 100;
// 更新进度条
if (uiProcessBar2 != null && !uiProcessBar2.IsDisposed)
uiProcessBar2.Value = (int)percentage;
uiLabel7.Text = value8.ToString("F2");
}
@@ -299,7 +335,7 @@ namespace 全自动水压检测仪
{
Debug.WriteLine($"UI更新异常: {uiEx.Message}");
}
}));
});
}
catch (Exception ex)
{
@@ -310,11 +346,14 @@ namespace 全自动水压检测仪
}
catch { }
SafeInvoke(() =>
{
MessageBox.Show($"读取调试参数失败:{ex.Message}", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
}
}
}
bool isAddTag = false;
// 辅助方法:安全读取寄存器
private ushort[] SafelyReadRegisters(byte slaveAddress, ushort startAddress, ushort numberOfPoints)
@@ -333,8 +372,26 @@ namespace 全自动水压检测仪
return new ushort[numberOfPoints]; // 返回默认值数组
}
private string GetStatusText(int statusValue)
{
switch (statusValue)
{
case 0:
return "空闲中";
case 1:
return "水循环中";
case 2:
return "加压中";
case 3:
return "保压测试中";
case 4:
return "空闲中"; // 根据您的要求4也显示"空闲中"
default:
return $"未知状态({statusValue})";
}
}
private async System.Threading.Tasks.Task ReadLeakTestParametersAsyncTwo()
private async Task ReadLeakTestParametersAsyncTwo()
{
//是否连接
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null) return;
@@ -342,11 +399,20 @@ namespace 全自动水压检测仪
//测试步骤
try
{
ushort[] testslip = _modbusMaster?.ReadHoldingRegisters(1, 2080, 2);
ushort[] testslip = await Task.Run(() =>
_modbusMaster?.ReadHoldingRegisters(1, 2080, 2)
);
if (testslip == null || testslip.Length == 0) return;
int testvalue = testslip[0];
uiLabel3.Text = testvalue.ToString();
string statusText = GetStatusText(testvalue);
// 使用安全的UI更新方法
SafeInvoke(() =>
{
if (uiLabel3 != null && !uiLabel3.IsDisposed)
uiLabel3.Text = statusText;
});
}
catch (Exception ex)
@@ -364,10 +430,11 @@ namespace 全自动水压检测仪
float pressureValue = c.UshortToFloat(registers[1], registers[0]);
this.Invoke(new Action(() =>
SafeInvoke(() =>
{
if (uiTextBox1 != null && !uiTextBox1.IsDisposed)
uiTextBox1.Text = pressureValue.ToString("F2");
}));
});
}
catch (Exception ex)
@@ -384,10 +451,12 @@ namespace 全自动水压检测仪
if (registers == null || registers.Length == 0) return;
float registerValue = c.UshortToFloat(registers[1], registers[0]);
this.Invoke(new Action(() =>
SafeInvoke(() =>
{
if (uiTextBox4 != null && !uiTextBox4.IsDisposed)
uiTextBox4.Text = registerValue.ToString("F2");
}));
});
}
catch (Exception ex)
@@ -404,11 +473,12 @@ namespace 全自动水压检测仪
if (registers == null || registers.Length == 0) return;
int pressureValue = registers[0];
this.Invoke(new Action(() =>
{
uiTextBox5.Text = pressureValue.ToString();
}));
SafeInvoke(() =>
{
if (uiTextBox5 != null && !uiTextBox5.IsDisposed)
uiTextBox5.Text = pressureValue.ToString();
});
}
catch (Exception ex)
@@ -425,10 +495,12 @@ namespace 全自动水压检测仪
if (registers == null || registers.Length == 0) return;
float temperatureValue = c.UshortToFloat(registers[1], registers[0]);
this.Invoke(new Action(() =>
SafeInvoke(() =>
{
if (uiTextBox9 != null && !uiTextBox9.IsDisposed)
uiTextBox9.Text = temperatureValue.ToString("F2");
}));
});
}
catch (Exception ex)
@@ -436,19 +508,55 @@ namespace 全自动水压检测仪
Debug.WriteLine($"[错误] 读取出口温度设置(地址412)失败: {ex.Message}");
}
try
{
// 所有Modbus读取操作移到后台线程
var modbusResults = await Task.Run(() =>
{
try
{
return new
{
TestStatus = _modbusMaster?.ReadCoils(1, 10081, 1),
ButtonStatus = _modbusMaster?.ReadCoils(1, 10030, 1),
LowStatus = _modbusMaster?.ReadCoils(1, 10031, 1),
HighStatus = _modbusMaster?.ReadCoils(1, 10032, 1),
Valve2 = _modbusMaster?.ReadCoils(1, 10008, 1),
Valve13 = _modbusMaster?.ReadCoils(1, 10001, 1),
Valve3 = _modbusMaster?.ReadCoils(1, 10006, 1),
Valve4 = _modbusMaster?.ReadCoils(1, 10013, 1),
Valve5 = _modbusMaster?.ReadCoils(1, 10005, 1),
Valve6 = _modbusMaster?.ReadCoils(1, 10007, 1),
Valve7 = _modbusMaster?.ReadCoils(1, 10004, 1),
Valve8 = _modbusMaster?.ReadCoils(1, 10010, 1),
Valve9 = _modbusMaster?.ReadCoils(1, 10012, 1),
Valve10 = _modbusMaster?.ReadCoils(1, 10009, 1),
Valve12 = _modbusMaster?.ReadCoils(1, 10004, 1)
};
}
catch (Exception ex)
{
Debug.WriteLine($"Modbus读取阀门状态失败: {ex.Message}");
return null;
}
});
if (modbusResults == null) return;
// 统一用SafeInvoke更新所有UI控件
SafeInvoke(() =>
{
//测试按键
bool[] testStatus = _modbusMaster?.ReadCoils(1, 10081, 1);
if (testStatus != null && testStatus.Length > 0 && testStatus[0])
if (modbusResults.TestStatus != null && modbusResults.TestStatus.Length > 0)
{
if (uiButton2 != null && !uiButton2.IsDisposed)
{
if (modbusResults.TestStatus[0])
{
uiButton2.Text = "测试中";
uiButton2.ForeColor = System.Drawing.Color.Red;
boolSignal1.Value = true;
boolSignal1.CheckRisingEdge();
}
else
{
@@ -457,151 +565,121 @@ namespace 全自动水压检测仪
boolSignal1.CheckRisingEdge();
boolSignal1.Value = false;
}
//高低温切换
bool[] buttonStatus = _modbusMaster?.ReadCoils(1, 10030, 1);
if (buttonStatus != null && buttonStatus.Length > 0 && buttonStatus[0])
{
uiSwitch1.Active = true;
}
else
{
uiSwitch1.Active = false;
}
//低温指示
bool[] lowStatus = _modbusMaster?.ReadCoils(1, 10031, 1);
if (lowStatus != null && lowStatus.Length > 0 && lowStatus[0])
{
uiLight1.State = UILightState.On;
}
else
{
uiLight1.State = UILightState.Off;
}
//高温指示
bool[] highStatus = _modbusMaster?.ReadCoils(1, 10032, 1);
if (highStatus != null && highStatus.Length > 0 && highStatus[0])
{
uiLight2.State = UILightState.On;
}
else
{
uiLight2.State = UILightState.Off;
}
//高低温切换
if (modbusResults.ButtonStatus != null && modbusResults.ButtonStatus.Length > 0 && uiSwitch1 != null && !uiSwitch1.IsDisposed)
{
uiSwitch1.Active = modbusResults.ButtonStatus[0];
}
//低温指示
if (modbusResults.LowStatus != null && modbusResults.LowStatus.Length > 0 && uiLight1 != null && !uiLight1.IsDisposed)
{
uiLight1.State = modbusResults.LowStatus[0] ? UILightState.On : UILightState.Off;
}
//高温指示
if (modbusResults.HighStatus != null && modbusResults.HighStatus.Length > 0 && uiLight2 != null && !uiLight2.IsDisposed)
{
uiLight2.State = modbusResults.HighStatus[0] ? UILightState.On : UILightState.Off;
}
//高压进阀指示
bool[] valve2 = _modbusMaster?.ReadCoils(1, 10008, 1);
if (valve2 != null && valve2.Length > 0 && valve2[0])
if (modbusResults.Valve2 != null && modbusResults.Valve2.Length > 0 && uiLight4 != null && !uiLight4.IsDisposed)
{
uiLight4.State = UILightState.On;
}
else
{
uiLight4.State = UILightState.Off;
uiLight4.State = modbusResults.Valve2[0] ? UILightState.On : UILightState.Off;
}
//高压出阀
bool[] valve13 = _modbusMaster?.ReadCoils(1, 10001, 1);
if (valve13 != null && valve13.Length > 0 && valve13[0])
if (modbusResults.Valve13 != null && modbusResults.Valve13.Length > 0 && uiLight3 != null && !uiLight3.IsDisposed)
{
uiLight3.State = UILightState.On;
}
else
{
uiLight3.State = UILightState.Off;
uiLight3.State = modbusResults.Valve13[0] ? UILightState.On : UILightState.Off;
}
//常温抽水阀指示
bool[] valve3 = _modbusMaster?.ReadCoils(1, 10006, 1);
if (valve3 != null && valve3.Length > 0 && valve3[0])
if (modbusResults.Valve3 != null && modbusResults.Valve3.Length > 0 && uiLight5 != null && !uiLight5.IsDisposed)
{
uiLight5.State = UILightState.On;
}
else
{
uiLight5.State = UILightState.Off;
uiLight5.State = modbusResults.Valve3[0] ? UILightState.On : UILightState.Off;
}
//常温水箱加水指示
bool[] valve4 = _modbusMaster?.ReadCoils(1, 10013, 1);
if (valve4 != null && valve4.Length > 0 && valve4[0])
if (modbusResults.Valve4 != null && modbusResults.Valve4.Length > 0)
{
if (uiLight6 != null && !uiLight6.IsDisposed)
uiLight6.State = modbusResults.Valve4[0] ? UILightState.On : UILightState.Off;
if (uiButton13 != null && !uiButton13.IsDisposed)
{
if (modbusResults.Valve4[0])
{
uiLight6.State = UILightState.On;
uiButton13.ForeColor = Color.Red;
uiButton13.Text = "常温加水中";
}
else
{
uiLight6.State = UILightState.Off;
uiButton13.ForeColor = Color.White;
uiButton13.Text = "常温加水";
}
}
}
//高温抽水阀指示
bool[] valve5 = _modbusMaster?.ReadCoils(1, 10005, 1);
if (valve5 != null && valve5.Length > 0 && valve5[0])
if (modbusResults.Valve5 != null && modbusResults.Valve5.Length > 0 && uiLight7 != null && !uiLight7.IsDisposed)
{
uiLight7.State = UILightState.On;
}
else
{
uiLight7.State = UILightState.Off;
uiLight7.State = modbusResults.Valve5[0] ? UILightState.On : UILightState.Off;
}
//空气抽气阀指示
bool[] valve6 = _modbusMaster?.ReadCoils(1, 10007, 1);
if (valve6 != null && valve6.Length > 0 && valve6[0])
if (modbusResults.Valve6 != null && modbusResults.Valve6.Length > 0 && uiLight8 != null && !uiLight8.IsDisposed)
{
uiLight8.State = UILightState.On;
}
else
{
uiLight8.State = UILightState.Off;
uiLight8.State = modbusResults.Valve6[0] ? UILightState.On : UILightState.Off;
}
//加热状态指示
bool[] valve7 = _modbusMaster?.ReadCoils(1, 10004, 1);
if (valve7 != null && valve7.Length > 0 && valve7[0])
if (modbusResults.Valve7 != null && modbusResults.Valve7.Length > 0 && uiLight9 != null && !uiLight9.IsDisposed)
{
uiLight9.State = UILightState.On;
}
else
{
uiLight9.State = UILightState.Off;
uiLight9.State = modbusResults.Valve7[0] ? UILightState.On : UILightState.Off;
}
//常温回水阀指示
bool[] valve8 = _modbusMaster?.ReadCoils(1, 10010, 1);
if (valve8 != null && valve8.Length > 0 && valve8[0])
if (modbusResults.Valve8 != null && modbusResults.Valve8.Length > 0 && uiLight10 != null && !uiLight10.IsDisposed)
{
uiLight10.State = UILightState.On;
}
else
{
uiLight10.State = UILightState.Off;
uiLight10.State = modbusResults.Valve8[0] ? UILightState.On : UILightState.Off;
}
//高温水箱加水指示
bool[] valve9 = _modbusMaster?.ReadCoils(1, 10012, 1);
if (valve9 != null && valve9.Length > 0 && valve9[0])
if (modbusResults.Valve9 != null && modbusResults.Valve9.Length > 0)
{
if (uiLight11 != null && !uiLight11.IsDisposed)
uiLight11.State = modbusResults.Valve9[0] ? UILightState.On : UILightState.Off;
if (uiButton5 != null && !uiButton5.IsDisposed)
{
if (modbusResults.Valve9[0])
{
uiLight11.State = UILightState.On;
uiButton5.ForeColor = Color.Red;
uiButton5.Text = "高温加水中";
}
else
{
uiLight11.State = UILightState.Off;
uiButton5.ForeColor = Color.White;
uiButton5.Text = "高温加水";
}
//高温回水阀指示
bool[] valve10 = _modbusMaster?.ReadCoils(1, 10009, 1);
if (valve10 != null && valve10.Length > 0 && valve10[0])
{
uiLight12.State = UILightState.On;
}
else
}
//高温回水阀指示
if (modbusResults.Valve10 != null && modbusResults.Valve10.Length > 0 && uiLight12 != null && !uiLight12.IsDisposed)
{
uiLight12.State = UILightState.Off;
uiLight12.State = modbusResults.Valve10[0] ? UILightState.On : UILightState.Off;
}
//水箱加热指示
bool[] valve12 = _modbusMaster?.ReadCoils(1, 10004, 1);
if (valve12 != null && valve12.Length > 0 && valve12[0])
if (modbusResults.Valve12 != null && modbusResults.Valve12.Length > 0 && uiButton4 != null && !uiButton4.IsDisposed)
{
if (modbusResults.Valve12[0])
{
uiButton4.ForeColor = Color.Red;
uiButton4.Text = "加热中";
@@ -612,6 +690,15 @@ namespace 全自动水压检测仪
uiButton4.Text = "水箱加热";
}
}
// 更新温度模式
if (!string.IsNullOrEmpty(_currentTemperatureMode) && uiLabel11 != null && !uiLabel11.IsDisposed)
{
uiLabel11.Text = _currentTemperatureMode;
}
});
}
catch (Exception ex)
{
Debug.WriteLine($"[错误] 读取阀门状态失败: {ex.Message}");
@@ -619,12 +706,6 @@ namespace 全自动水压检测仪
}
//切换数页
//private void uiButton14_Click(object sender, EventArgs e)
//{
// SwitchWindow(ref _coeffiicientsetting, () => new Coeffiicientsetting());
//}
private void NormalTemperatureMode_Load(object sender, EventArgs e)
{
string plcIp = "192.168.1.10";
@@ -660,13 +741,14 @@ namespace 全自动水压检测仪
{
if (isAddTag) return;
// 使用SafeInvoke确保UI读取操作在UI线程执行
SafeInvoke(() =>
{
uiTextBox3.Text = uiLabel14.Text;//初始压力
uiTextBox8.Text = uiTextBox5.Text;//保压时间
uiTextBox6.Text = uiLabel22.Text;//压差
uiTextBox7.Text = uiLabel19.Text;//结束压力
CurrentReport.Add(new ConductivityTestData
{
barcode = uiTextBox2.Text,
@@ -679,8 +761,6 @@ namespace 全自动水压检测仪
Type = uiLight1.State == UILightState.On ? 1 : 0
});
_repository.InsertReportItems(new ConductivityTestData
{
barcode = uiTextBox2.Text,
@@ -693,8 +773,8 @@ namespace 全自动水压检测仪
Type = uiLight1.State == UILightState.On ? 1 : 0
});
uiTextBox2.Text = string.Empty;
});
isAddTag = true;
}
@@ -717,48 +797,103 @@ namespace 全自动水压检测仪
}
return false;
}
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : UIForm
//private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : UIForm
//{
// _isSwitchingWindow = true;
// _readTimer?.Stop();
// _readTimerTwo?.Stop(); // 停止第二个定时器
// // 2. 检查资源是否可用(添加重连机制)
// if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
// {
// //尝试重新连接
// bool reconnectSuccess = TryReconnect();
// if (!reconnectSuccess)
// {
// MessageBox.Show("TCP连接已断开请重新连接", "提示");
// return;
// }
// }
// // 3. 复用窗口实例:不存在则创建,存在则激活
// if (windowInstance == null || windowInstance.IsDisposed)
// {
// windowInstance = createFunc();
// windowInstance.FormClosed += (s, e) =>
// {
// this.Invoke(new Action(() =>
// {
// _isSwitchingWindow = false;
// _readTimer?.Start();
// _readTimerTwo?.Start(); // 恢复第二个定时器
// this.Show();
// this.Activate();
// }));
// };
// }
// else
// {
// windowInstance.Activate();
// return;
// }
// this.Hide();
// windowInstance.Show();
//}
private void SwitchWindow<T>(T windowInstance, Func<T> createFunc) where T : UIForm
{
_isSwitchingWindow = true;
_readTimer?.Stop();
_readTimerTwo?.Stop(); // 停止第二个定时器
_readTimerTwo?.Stop();
// 2. 检查资源是否可用(添加重连机制)
// 检查资源是否可用
if (_tcpClient == null || !_tcpClient.Connected || _modbusMaster == null)
{
//尝试重新连接
bool reconnectSuccess = TryReconnect();
if (!reconnectSuccess)
{
SafeInvoke(() =>
{
MessageBox.Show("TCP连接已断开请重新连接", "提示");
});
return;
}
}
// 3. 复用窗口实例:不存在则创建,存在则激活
if (windowInstance == null || windowInstance.IsDisposed)
// 需要将 windowInstance 声明为局部变量
T localInstance = windowInstance;
// 复用窗口实例
if (localInstance == null || localInstance.IsDisposed)
{
windowInstance = createFunc();
windowInstance.FormClosed += (s, e) =>
localInstance = createFunc();
localInstance.FormClosed += (s, e) =>
{
this.Invoke(new Action(() =>
SafeInvoke(() =>
{
_isSwitchingWindow = false;
_readTimer?.Start();
_readTimerTwo?.Start(); // 恢复第二个定时器
_readTimerTwo?.Start();
this.Show();
this.Activate();
}));
});
};
}
else
{
windowInstance.Activate();
SafeInvoke(() => localInstance.Activate());
return;
}
SafeInvoke(() =>
{
this.Hide();
windowInstance.Show();
localInstance.Show();
});
// 如果需要更新外部引用,可以返回实例
// return localInstance;
}
private void NormalTemperatureMode_FormClosing(object sender, FormClosingEventArgs e)
@@ -784,14 +919,20 @@ namespace 全自动水压检测仪
//压力设置
private void uiTextBox1_Click(object sender, EventArgs e)
{
SafeInvoke(() =>
{
ma?.WriteToPLCForNew(uiTextBox1.Text.Trim(), 2400, Function.DataType.);
});
}
//测试保压时间设置
private void uiTextBox5_Click(object sender, EventArgs e)
{
SafeInvoke(() =>
{
ma?.WriteToPLCForNew(uiTextBox5.Text.Trim(), 2404, Function.DataType.);
});
}
#region
@@ -830,19 +971,22 @@ namespace 全自动水压检测仪
private void EnterFunction()
{
// 长按后进入的功能
SwitchWindow(ref _coeffiicientsetting, () => new Coeffiicientsetting());
SwitchWindow(_coeffiicientsetting, () => new Coeffiicientsetting());
}
//切换报告界面
private void uiButton1_Click(object sender, EventArgs e)
{
SwitchWindow(ref _report, () => new Report(CurrentReport));
SwitchWindow(_report, () => new Report(CurrentReport));
}
//箱体温度设置
private void uiTextBox4_Click(object sender, EventArgs e)
{
SafeInvoke(() =>
{
ma?.WriteToPLCForNew(uiTextBox4.Text.Trim(), 2402, Function.DataType.);
});
}
//启动测试
@@ -866,8 +1010,11 @@ namespace 全自动水压检测仪
//出口温度设置
private void uiTextBox9_Click(object sender, EventArgs e)
{
SafeInvoke(() =>
{
ma?.WriteToPLCForNew(uiTextBox9.Text.Trim(), 2412, Function.DataType.);
});
}
//高温加水
@@ -902,19 +1049,31 @@ namespace 全自动水压检测仪
//返回录入系统
private void uiButton7_Click(object sender, EventArgs e)
{
SwitchWindow(ref _scanImport, () => new ScanImport());
SwitchWindow(_scanImport, () => new ScanImport());
}
private string _currentTemperatureMode = ""; // 保存当前温度模式
private string _currentBarcode = ""; // 保存当前条码
private void uiButton8_Click(object sender, EventArgs e)
{
try
{
// 1. 获取条码输入
string barcode = uiTextBox2.Text.Trim();
// 1. 获取条码输入确保在UI线程读取
string barcode = "";
SafeInvoke(() =>
{
barcode = uiTextBox2.Text.Trim();
});
if (string.IsNullOrEmpty(barcode))
{
SafeInvoke(() =>
{
MessageBox.Show("请输入条码!");
});
return;
}
@@ -922,19 +1081,34 @@ namespace 全自动水压检测仪
ScanData scanData = GetScanDataByBarcode(barcode);
if (scanData == null)
{
SafeInvoke(() =>
{
MessageBox.Show($"未找到条码为 {barcode} 的记录!");
});
return;
}
// 3. 连接到PLC并写入数据
WriteScanDataToPLC(scanData);
// 4. 保存当前条码和温度模式
_currentBarcode = barcode;
_currentTemperatureMode = scanData.TemperatureMode.ToString();
// 5. 更新显示
SafeInvoke(() =>
{
uiLabel11.Text = _currentTemperatureMode;
});
}
catch (Exception ex)
{
SafeInvoke(() =>
{
MessageBox.Show($"操作失败:{ex.Message}");
});
}
}
@@ -986,6 +1160,8 @@ namespace 全自动水压检测仪
float exitTemperature = data.exit_temperature;
ushort[] exitTempRegisters = ConvertFloatToRegisters(exitTemperature);
_modbusMaster.WriteMultipleRegisters(1, 2412, exitTempRegisters);
}
// 将浮点数转换为寄存器数组2个寄存器

View File

@@ -28,11 +28,11 @@
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle21 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle22 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle23 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle24 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle25 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle10 = new System.Windows.Forms.DataGridViewCellStyle();
this.save = new Sunny.UI.UIButton();
this.uiDataGridView1 = new Sunny.UI.UIDataGridView();
this.uiTextBox2 = new Sunny.UI.UITextBox();
@@ -45,15 +45,17 @@
this.uiButton1 = new Sunny.UI.UIButton();
this.uiLabel1 = new Sunny.UI.UILabel();
this.uiTextBox1 = new Sunny.UI.UITextBox();
this.uiCheckBox1 = new Sunny.UI.UICheckBox();
this.uiCheckBox2 = new Sunny.UI.UICheckBox();
this.uiButton2 = new Sunny.UI.UIButton();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column7 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column8 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column6 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.uiTextBox3 = new Sunny.UI.UITextBox();
this.uiLabel2 = new Sunny.UI.UILabel();
((System.ComponentModel.ISupportInitialize)(this.uiDataGridView1)).BeginInit();
this.SuspendLayout();
//
@@ -61,10 +63,10 @@
//
this.save.Cursor = System.Windows.Forms.Cursors.Hand;
this.save.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.save.Location = new System.Drawing.Point(870, 43);
this.save.Location = new System.Drawing.Point(270, 623);
this.save.MinimumSize = new System.Drawing.Size(1, 1);
this.save.Name = "save";
this.save.Size = new System.Drawing.Size(100, 35);
this.save.Size = new System.Drawing.Size(130, 50);
this.save.TabIndex = 0;
this.save.Text = "保存";
this.save.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -72,18 +74,18 @@
//
// uiDataGridView1
//
dataGridViewCellStyle21.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiDataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle21;
dataGridViewCellStyle6.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiDataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle6;
this.uiDataGridView1.BackgroundColor = System.Drawing.Color.White;
this.uiDataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle22.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle22.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle22.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle22.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle22.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle22.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle22.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.uiDataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle22;
dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle7.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle7.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle7.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.uiDataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle7;
this.uiDataGridView1.ColumnHeadersHeight = 32;
this.uiDataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.uiDataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
@@ -93,35 +95,36 @@
this.Column4,
this.Column7,
this.Column5,
this.Column8,
this.Column6});
dataGridViewCellStyle23.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle23.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle23.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle23.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
dataGridViewCellStyle23.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle23.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle23.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.uiDataGridView1.DefaultCellStyle = dataGridViewCellStyle23;
dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle8.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle8.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.uiDataGridView1.DefaultCellStyle = dataGridViewCellStyle8;
this.uiDataGridView1.EnableHeadersVisualStyles = false;
this.uiDataGridView1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiDataGridView1.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
this.uiDataGridView1.Location = new System.Drawing.Point(12, 137);
this.uiDataGridView1.Name = "uiDataGridView1";
dataGridViewCellStyle24.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle24.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
dataGridViewCellStyle24.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle24.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
dataGridViewCellStyle24.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle24.SelectionForeColor = System.Drawing.Color.White;
dataGridViewCellStyle24.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.uiDataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle24;
dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle9.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
dataGridViewCellStyle9.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle9.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
dataGridViewCellStyle9.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle9.SelectionForeColor = System.Drawing.Color.White;
dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.uiDataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle9;
this.uiDataGridView1.RowHeadersWidth = 51;
dataGridViewCellStyle25.BackColor = System.Drawing.Color.White;
dataGridViewCellStyle25.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiDataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle25;
dataGridViewCellStyle10.BackColor = System.Drawing.Color.White;
dataGridViewCellStyle10.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiDataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle10;
this.uiDataGridView1.RowTemplate.Height = 27;
this.uiDataGridView1.SelectedIndex = -1;
this.uiDataGridView1.Size = new System.Drawing.Size(958, 537);
this.uiDataGridView1.Size = new System.Drawing.Size(958, 452);
this.uiDataGridView1.StripeOddColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiDataGridView1.TabIndex = 1;
//
@@ -146,9 +149,9 @@
//
this.uiLabel48.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel48.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel48.Location = new System.Drawing.Point(517, 38);
this.uiLabel48.Location = new System.Drawing.Point(604, 47);
this.uiLabel48.Name = "uiLabel48";
this.uiLabel48.Size = new System.Drawing.Size(170, 30);
this.uiLabel48.Size = new System.Drawing.Size(124, 30);
this.uiLabel48.TabIndex = 29;
this.uiLabel48.Text = "出口温度设置(℃):";
this.uiLabel48.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -157,7 +160,7 @@
//
this.uiTextBox9.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox9.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox9.Location = new System.Drawing.Point(708, 42);
this.uiTextBox9.Location = new System.Drawing.Point(735, 49);
this.uiTextBox9.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox9.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox9.Name = "uiTextBox9";
@@ -174,7 +177,7 @@
//
this.uiTextBox5.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox5.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox5.Location = new System.Drawing.Point(419, 79);
this.uiTextBox5.Location = new System.Drawing.Point(476, 89);
this.uiTextBox5.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox5.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox5.Name = "uiTextBox5";
@@ -191,7 +194,7 @@
//
this.uiLabel41.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel41.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel41.Location = new System.Drawing.Point(300, 77);
this.uiLabel41.Location = new System.Drawing.Point(357, 87);
this.uiLabel41.Name = "uiLabel41";
this.uiLabel41.Size = new System.Drawing.Size(110, 30);
this.uiLabel41.TabIndex = 17;
@@ -202,7 +205,7 @@
//
this.uiLabel4.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel4.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel4.Location = new System.Drawing.Point(300, 41);
this.uiLabel4.Location = new System.Drawing.Point(357, 51);
this.uiLabel4.Name = "uiLabel4";
this.uiLabel4.Size = new System.Drawing.Size(119, 30);
this.uiLabel4.TabIndex = 18;
@@ -213,7 +216,7 @@
//
this.uiTextBox4.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox4.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox4.Location = new System.Drawing.Point(419, 43);
this.uiTextBox4.Location = new System.Drawing.Point(476, 53);
this.uiTextBox4.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox4.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox4.Name = "uiTextBox4";
@@ -230,10 +233,10 @@
//
this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton1.Location = new System.Drawing.Point(870, 84);
this.uiButton1.Location = new System.Drawing.Point(548, 623);
this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton1.Name = "uiButton1";
this.uiButton1.Size = new System.Drawing.Size(100, 35);
this.uiButton1.Size = new System.Drawing.Size(130, 50);
this.uiButton1.TabIndex = 31;
this.uiButton1.Text = "测试";
this.uiButton1.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -243,7 +246,7 @@
//
this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel1.Location = new System.Drawing.Point(517, 84);
this.uiLabel1.Location = new System.Drawing.Point(604, 91);
this.uiLabel1.Name = "uiLabel1";
this.uiLabel1.Size = new System.Drawing.Size(83, 30);
this.uiLabel1.TabIndex = 34;
@@ -254,7 +257,7 @@
//
this.uiTextBox1.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox1.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox1.Location = new System.Drawing.Point(708, 84);
this.uiTextBox1.Location = new System.Drawing.Point(735, 91);
this.uiTextBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox1.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox1.Name = "uiTextBox1";
@@ -267,6 +270,43 @@
this.uiTextBox1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
this.uiTextBox1.Watermark = "";
//
// uiCheckBox1
//
this.uiCheckBox1.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiCheckBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiCheckBox1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiCheckBox1.Location = new System.Drawing.Point(18, 91);
this.uiCheckBox1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiCheckBox1.Name = "uiCheckBox1";
this.uiCheckBox1.Size = new System.Drawing.Size(140, 29);
this.uiCheckBox1.TabIndex = 36;
this.uiCheckBox1.Text = "常温模式";
//
// uiCheckBox2
//
this.uiCheckBox2.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiCheckBox2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiCheckBox2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiCheckBox2.Location = new System.Drawing.Point(162, 90);
this.uiCheckBox2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiCheckBox2.Name = "uiCheckBox2";
this.uiCheckBox2.Size = new System.Drawing.Size(133, 29);
this.uiCheckBox2.TabIndex = 37;
this.uiCheckBox2.Text = "高温模式";
//
// uiButton2
//
this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton2.Location = new System.Drawing.Point(409, 623);
this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton2.Name = "uiButton2";
this.uiButton2.Size = new System.Drawing.Size(130, 50);
this.uiButton2.TabIndex = 38;
this.uiButton2.Text = "清除";
this.uiButton2.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
//
// Column1
//
this.Column1.DataPropertyName = "Id";
@@ -286,77 +326,60 @@
// Column3
//
this.Column3.DataPropertyName = "diffpressure";
this.Column3.HeaderText = "压力";
this.Column3.HeaderText = "压力(PSI)";
this.Column3.MinimumWidth = 6;
this.Column3.Name = "Column3";
this.Column3.Width = 70;
this.Column3.ReadOnly = true;
this.Column3.Width = 150;
//
// Column4
//
this.Column4.DataPropertyName = "temperature";
this.Column4.HeaderText = "出口温度";
this.Column4.HeaderText = "出口温度(℃)";
this.Column4.MinimumWidth = 6;
this.Column4.Name = "Column4";
this.Column4.Width = 150;
this.Column4.Width = 180;
//
// Column7
//
this.Column7.DataPropertyName = "temperature";
this.Column7.HeaderText = "温度";
this.Column7.HeaderText = "温度(℃)";
this.Column7.MinimumWidth = 6;
this.Column7.Name = "Column7";
this.Column7.Width = 125;
this.Column7.Width = 120;
//
// Column5
//
this.Column5.DataPropertyName = "dwelltime";
this.Column5.HeaderText = "保压时间";
this.Column5.HeaderText = "保压时间(h)";
this.Column5.MinimumWidth = 6;
this.Column5.Name = "Column5";
this.Column5.Width = 125;
//
// Column8
//
this.Column8.DataPropertyName = "TemperatureMode";
this.Column8.HeaderText = "温度模式";
this.Column8.MinimumWidth = 8;
this.Column8.Name = "Column8";
this.Column8.ReadOnly = true;
this.Column8.Width = 150;
//
// Column6
//
this.Column6.DataPropertyName = "CreateTime";
this.Column6.HeaderText = "录入时间";
this.Column6.MinimumWidth = 6;
this.Column6.Name = "Column6";
this.Column6.Width = 125;
//
// uiTextBox3
//
this.uiTextBox3.Cursor = System.Windows.Forms.Cursors.IBeam;
this.uiTextBox3.Font = new System.Drawing.Font("微软雅黑", 10.5F);
this.uiTextBox3.Location = new System.Drawing.Point(118, 81);
this.uiTextBox3.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiTextBox3.MinimumSize = new System.Drawing.Size(1, 16);
this.uiTextBox3.Name = "uiTextBox3";
this.uiTextBox3.Padding = new System.Windows.Forms.Padding(5);
this.uiTextBox3.Radius = 3;
this.uiTextBox3.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.uiTextBox3.ShowText = false;
this.uiTextBox3.Size = new System.Drawing.Size(91, 28);
this.uiTextBox3.TabIndex = 36;
this.uiTextBox3.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
this.uiTextBox3.Watermark = "";
//
// uiLabel2
//
this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLabel2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.uiLabel2.Location = new System.Drawing.Point(49, 79);
this.uiLabel2.Name = "uiLabel2";
this.uiLabel2.Size = new System.Drawing.Size(110, 30);
this.uiLabel2.TabIndex = 37;
this.uiLabel2.Text = "序号:";
this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.Column6.Width = 180;
//
// ScanImport
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(982, 693);
this.Controls.Add(this.uiTextBox3);
this.Controls.Add(this.uiLabel2);
this.Controls.Add(this.uiButton2);
this.Controls.Add(this.uiCheckBox2);
this.Controls.Add(this.uiCheckBox1);
this.Controls.Add(this.uiLabel1);
this.Controls.Add(this.uiTextBox1);
this.Controls.Add(this.uiButton1);
@@ -392,14 +415,16 @@
private Sunny.UI.UIButton uiButton1;
private Sunny.UI.UILabel uiLabel1;
private Sunny.UI.UITextBox uiTextBox1;
private Sunny.UI.UICheckBox uiCheckBox1;
private Sunny.UI.UICheckBox uiCheckBox2;
private Sunny.UI.UIButton uiButton2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.DataGridViewTextBoxColumn Column7;
private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
private System.Windows.Forms.DataGridViewTextBoxColumn Column8;
private System.Windows.Forms.DataGridViewTextBoxColumn Column6;
private Sunny.UI.UITextBox uiTextBox3;
private Sunny.UI.UILabel uiLabel2;
}
}

View File

@@ -24,65 +24,205 @@ namespace 全自动水压检测仪
uiDataGridView1.AutoGenerateColumns = false;
}
private void SafeInvoke(Action action)
{
if (action == null) return;
// 检查窗体是否已释放/句柄是否创建
if (this.IsDisposed || !this.IsHandleCreated)
{
System.Diagnostics.Debug.WriteLine("ScanImport窗体已释放或句柄未创建跳过UI操作");
return;
}
try
{
// 如果已经在UI线程直接执行否则Invoke
if (this.InvokeRequired)
{
this.Invoke(action);
}
else
{
action();
}
}
catch (ObjectDisposedException ex)
{
System.Diagnostics.Debug.WriteLine($"ScanImport UI操作时控件已释放: {ex.Message}");
}
catch (InvalidOperationException ex)
{
System.Diagnostics.Debug.WriteLine($"ScanImport UI操作异常: {ex.Message}");
}
}
private void save_Click(object sender, EventArgs e)
{
float diffpressure = 0,exit_temperature = 0, dwelltime = 0, temperature = 0;
float.TryParse(uiTextBox4.Text, out diffpressure);
float.TryParse(uiTextBox9.Text, out exit_temperature);
float.TryParse(uiTextBox5.Text, out dwelltime);
float.TryParse(uiTextBox1.Text, out temperature);
SafeInvoke(() =>
{
float diffpressure = 0, exit_temperature = 0, dwelltime = 0, temperature = 0;
float.TryParse(uiTextBox4?.Text ?? "", out diffpressure);
float.TryParse(uiTextBox9?.Text ?? "", out exit_temperature);
float.TryParse(uiTextBox5?.Text ?? "", out dwelltime);
float.TryParse(uiTextBox1?.Text ?? "", out temperature);
string temperatureMode = "";
if (uiCheckBox1?.Checked == true)
{
temperatureMode = "常温模式";
}
else if (uiCheckBox2?.Checked == true)
{
temperatureMode = "高温模式";
}
try
{
_repository.InsertScanItems(new ScanData
{
barcode = uiTextBox2.Text,
barcode = uiTextBox2?.Text ?? "",
diffpressure = diffpressure,
exit_temperature = exit_temperature,
dwelltime = dwelltime,
IsHighMode = temperature > 0,
temperature = temperature
temperature = temperature,
TemperatureMode = temperatureMode
});
// 重新加载数据
LoadData();
// 可选:清空输入框
ClearInputFields();
}
catch (Exception ex)
{
MessageBox.Show($"保存失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
});
}
private void ClearInputFields()
{
if (uiTextBox1 != null) uiTextBox1.Text = "";
if (uiTextBox2 != null) uiTextBox2.Text = "";
if (uiTextBox4 != null) uiTextBox4.Text = "";
if (uiTextBox5 != null) uiTextBox5.Text = "";
if (uiTextBox9 != null) uiTextBox9.Text = "";
if (uiCheckBox1 != null) uiCheckBox1.Checked = false;
if (uiCheckBox2 != null) uiCheckBox2.Checked = false;
}
private void ScanImport_Load(object sender, EventArgs e)
{
SafeInvoke(() =>
{
LoadData();
});
}
private void LoadData()
{
try
{
// 将数据查询操作移到后台线程避免UI卡顿
System.Threading.Tasks.Task.Run(() =>
{
var data = _repository.GetScanData();
uiDataGridView1.DataSource = data;
// 安全更新DataGridView
SafeInvoke(() =>
{
// 避免重复绑定导致的异常
if (uiDataGridView1 != null && !uiDataGridView1.IsDisposed)
{
// 先解绑再重新绑定
uiDataGridView1.DataSource = null;
uiDataGridView1.DataSource = data;
uiDataGridView1.Refresh();
}
});
});
}
catch (Exception ex)
{
SafeInvoke(() =>
{
MessageBox.Show($"加载数据失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
}
private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : UIForm
//private void SwitchWindow<T>(ref T windowInstance, Func<T> createFunc) where T : UIForm
//{
// if (windowInstance == null || windowInstance.IsDisposed)
// {
// windowInstance = createFunc();
// windowInstance.FormClosed += (s, e) =>
// {
// this.Invoke(new Action(() =>
// {
// this.Show();
// this.Activate();
// }));
// };
// }
// else
// {
// windowInstance.Activate();
// return;
// }
// this.Hide();
// windowInstance.Show();
//}
private void SwitchWindow<T>(T windowInstance, Func<T> createFunc) where T : UIForm
{
if (windowInstance == null || windowInstance.IsDisposed)
// 需要将 windowInstance 声明为局部变量
T localInstance = windowInstance;
// 复用窗口实例
if (localInstance == null || localInstance.IsDisposed)
{
windowInstance = createFunc();
windowInstance.FormClosed += (s, e) =>
localInstance = createFunc();
localInstance.FormClosed += (s, e) =>
{
this.Invoke(new Action(() =>
SafeInvoke(() =>
{
this.Show();
this.Activate();
}));
});
};
}
else
{
windowInstance.Activate();
SafeInvoke(() => localInstance.Activate());
return;
}
this.Hide();
windowInstance.Show();
}
SafeInvoke(() =>
{
this.Hide();
localInstance.Show();
});
// 如果需要更新外部引用,可以返回实例
// return localInstance;
}
private void uiButton1_Click(object sender, EventArgs e)
{
SwitchWindow(ref _normalTemperatureMode, () => new NormalTemperatureMode());
SwitchWindow(_normalTemperatureMode, () => new NormalTemperatureMode());
}
//清除
private void uiButton2_Click(object sender, EventArgs e)
{
}
}
}

View File

@@ -135,6 +135,9 @@
<metadata name="Column5.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column8.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column6.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>