This commit is contained in:
wxt
2026-01-19 17:50:49 +08:00
parent 8b115ff3af
commit c9a13cd558
6 changed files with 284 additions and 75 deletions

View File

@@ -36,7 +36,7 @@ namespace 全自动水压检测仪.Data
public void CheckRisingEdge()
{
if (!Value && _previousValue)
if (!Value &&_previousValue)
{
OnRisingEdge?.Invoke();
}

View File

@@ -166,6 +166,10 @@ namespace 全自动水压检测仪
this.uiPanel2 = new Sunny.UI.UIPanel();
this.uiLabel1 = new Sunny.UI.UILabel();
this.uiLight1 = new Sunny.UI.UILight();
this.uiPanel32 = new Sunny.UI.UIPanel();
this.uiLight3 = new Sunny.UI.UILight();
this.uiPanel34 = new Sunny.UI.UIPanel();
this.uiButton6 = new Sunny.UI.UIButton();
this.uiTableLayoutPanel1.SuspendLayout();
this.uiTableLayoutPanel2.SuspendLayout();
this.panel1.SuspendLayout();
@@ -219,6 +223,8 @@ namespace 全自动水压检测仪
this.uiPanel4.SuspendLayout();
this.uiPanel3.SuspendLayout();
this.uiPanel2.SuspendLayout();
this.uiPanel32.SuspendLayout();
this.uiPanel34.SuspendLayout();
this.SuspendLayout();
//
// uiTableLayoutPanel1
@@ -372,15 +378,17 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel4.BackColor = System.Drawing.Color.White;
this.uiTableLayoutPanel4.ColumnCount = 1;
this.uiTableLayoutPanel4.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.uiTableLayoutPanel4.Controls.Add(this.uiPanel34, 0, 3);
this.uiTableLayoutPanel4.Controls.Add(this.uiPanel16, 0, 2);
this.uiTableLayoutPanel4.Controls.Add(this.uiPanel15, 0, 1);
this.uiTableLayoutPanel4.Controls.Add(this.uiPanel8, 0, 0);
this.uiTableLayoutPanel4.Location = new System.Drawing.Point(3, 3);
this.uiTableLayoutPanel4.Name = "uiTableLayoutPanel4";
this.uiTableLayoutPanel4.RowCount = 3;
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 21.58019F));
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 39.20991F));
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 39.20991F));
this.uiTableLayoutPanel4.RowCount = 4;
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 15F));
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 28.3F));
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 28.3F));
this.uiTableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 28.4F));
this.uiTableLayoutPanel4.Size = new System.Drawing.Size(172, 228);
this.uiTableLayoutPanel4.TabIndex = 0;
this.uiTableLayoutPanel4.TagString = null;
@@ -391,13 +399,13 @@ namespace 全自动水压检测仪
this.uiPanel16.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel16.FillColor = System.Drawing.Color.White;
this.uiPanel16.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel16.Location = new System.Drawing.Point(4, 143);
this.uiPanel16.Location = new System.Drawing.Point(4, 103);
this.uiPanel16.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel16.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel16.Name = "uiPanel16";
this.uiPanel16.Padding = new System.Windows.Forms.Padding(5);
this.uiPanel16.RectColor = System.Drawing.Color.White;
this.uiPanel16.Size = new System.Drawing.Size(164, 80);
this.uiPanel16.Size = new System.Drawing.Size(164, 54);
this.uiPanel16.TabIndex = 4;
this.uiPanel16.Text = null;
this.uiPanel16.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -413,7 +421,7 @@ namespace 全自动水压检测仪
this.uiButton3.Location = new System.Drawing.Point(5, 5);
this.uiButton3.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton3.Name = "uiButton3";
this.uiButton3.Size = new System.Drawing.Size(154, 70);
this.uiButton3.Size = new System.Drawing.Size(154, 44);
this.uiButton3.TabIndex = 2;
this.uiButton3.Text = "停止测试";
this.uiButton3.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -425,13 +433,13 @@ namespace 全自动水压检测仪
this.uiPanel15.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel15.FillColor = System.Drawing.Color.White;
this.uiPanel15.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel15.Location = new System.Drawing.Point(4, 54);
this.uiPanel15.Location = new System.Drawing.Point(4, 39);
this.uiPanel15.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel15.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel15.Name = "uiPanel15";
this.uiPanel15.Padding = new System.Windows.Forms.Padding(5);
this.uiPanel15.RectColor = System.Drawing.Color.White;
this.uiPanel15.Size = new System.Drawing.Size(164, 79);
this.uiPanel15.Size = new System.Drawing.Size(164, 54);
this.uiPanel15.TabIndex = 3;
this.uiPanel15.Text = null;
this.uiPanel15.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -447,7 +455,7 @@ namespace 全自动水压检测仪
this.uiButton2.Location = new System.Drawing.Point(5, 5);
this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton2.Name = "uiButton2";
this.uiButton2.Size = new System.Drawing.Size(154, 69);
this.uiButton2.Size = new System.Drawing.Size(154, 44);
this.uiButton2.TabIndex = 1;
this.uiButton2.Text = "启动测试";
this.uiButton2.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
@@ -463,7 +471,7 @@ namespace 全自动水压检测仪
this.uiPanel8.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel8.Name = "uiPanel8";
this.uiPanel8.RectColor = System.Drawing.Color.White;
this.uiPanel8.Size = new System.Drawing.Size(164, 39);
this.uiPanel8.Size = new System.Drawing.Size(164, 24);
this.uiPanel8.TabIndex = 0;
this.uiPanel8.Text = "测试控制";
this.uiPanel8.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
@@ -627,15 +635,16 @@ namespace 全自动水压检测仪
this.uiTableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.uiTableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.uiTableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel32, 2, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel44, 4, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel43, 3, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel42, 2, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel41, 1, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel39, 4, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel38, 3, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel37, 2, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel36, 1, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel40, 0, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel41, 0, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel37, 1, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel36, 2, 0);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel39, 1, 1);
this.uiTableLayoutPanel7.Controls.Add(this.uiPanel42, 4, 0);
this.uiTableLayoutPanel7.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiTableLayoutPanel7.Location = new System.Drawing.Point(0, 0);
this.uiTableLayoutPanel7.Name = "uiTableLayoutPanel7";
@@ -709,10 +718,9 @@ namespace 全自动水压检测仪
// uiPanel42
//
this.uiPanel42.Controls.Add(this.uiLight10);
this.uiPanel42.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel42.Font = new System.Drawing.Font("微软雅黑", 9.5F);
this.uiPanel42.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiPanel42.Location = new System.Drawing.Point(296, 47);
this.uiPanel42.Location = new System.Drawing.Point(588, 5);
this.uiPanel42.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel42.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel42.Name = "uiPanel42";
@@ -739,16 +747,15 @@ namespace 全自动水压检测仪
// uiPanel41
//
this.uiPanel41.Controls.Add(this.uiLight9);
this.uiPanel41.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel41.Font = new System.Drawing.Font("微软雅黑", 9.5F);
this.uiPanel41.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiPanel41.Location = new System.Drawing.Point(150, 47);
this.uiPanel41.Location = new System.Drawing.Point(4, 47);
this.uiPanel41.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel41.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel41.Name = "uiPanel41";
this.uiPanel41.Size = new System.Drawing.Size(138, 32);
this.uiPanel41.TabIndex = 6;
this.uiPanel41.Text = "升温阀";
this.uiPanel41.Text = "加热状态";
this.uiPanel41.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiLight9
@@ -769,14 +776,13 @@ namespace 全自动水压检测仪
// uiPanel39
//
this.uiPanel39.Controls.Add(this.uiLight7);
this.uiPanel39.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel39.Font = new System.Drawing.Font("微软雅黑", 9.5F);
this.uiPanel39.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiPanel39.Location = new System.Drawing.Point(588, 5);
this.uiPanel39.Location = new System.Drawing.Point(150, 47);
this.uiPanel39.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel39.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel39.Name = "uiPanel39";
this.uiPanel39.Size = new System.Drawing.Size(140, 32);
this.uiPanel39.Size = new System.Drawing.Size(138, 32);
this.uiPanel39.TabIndex = 4;
this.uiPanel39.Text = "高温抽水阀";
this.uiPanel39.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
@@ -829,10 +835,9 @@ namespace 全自动水压检测仪
// uiPanel37
//
this.uiPanel37.Controls.Add(this.uiLight5);
this.uiPanel37.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel37.Font = new System.Drawing.Font("微软雅黑", 9.5F);
this.uiPanel37.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiPanel37.Location = new System.Drawing.Point(296, 5);
this.uiPanel37.Location = new System.Drawing.Point(150, 5);
this.uiPanel37.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel37.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel37.Name = "uiPanel37";
@@ -859,16 +864,15 @@ namespace 全自动水压检测仪
// uiPanel36
//
this.uiPanel36.Controls.Add(this.uiLight4);
this.uiPanel36.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel36.Font = new System.Drawing.Font("微软雅黑", 9.5F);
this.uiPanel36.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiPanel36.Location = new System.Drawing.Point(150, 5);
this.uiPanel36.Location = new System.Drawing.Point(296, 5);
this.uiPanel36.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel36.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel36.Name = "uiPanel36";
this.uiPanel36.Size = new System.Drawing.Size(138, 32);
this.uiPanel36.TabIndex = 1;
this.uiPanel36.Text = "测试高压阀";
this.uiPanel36.Text = "高压阀";
this.uiPanel36.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiLight4
@@ -2151,7 +2155,6 @@ namespace 全自动水压检测仪
this.uiButton14.TabIndex = 6;
this.uiButton14.Text = "系数页";
this.uiButton14.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton14.Click += new System.EventHandler(this.uiButton14_Click);
this.uiButton14.MouseDown += new System.Windows.Forms.MouseEventHandler(this.uiButton14_MouseDown);
this.uiButton14.MouseUp += new System.Windows.Forms.MouseEventHandler(this.uiButton14_MouseUp);
//
@@ -2272,6 +2275,69 @@ namespace 全自动水压检测仪
this.uiLight1.TabIndex = 1;
this.uiLight1.Text = "uiLight1";
//
// uiPanel32
//
this.uiPanel32.Controls.Add(this.uiLight3);
this.uiPanel32.Font = new System.Drawing.Font("微软雅黑", 9.5F);
this.uiPanel32.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60)))));
this.uiPanel32.Location = new System.Drawing.Point(296, 47);
this.uiPanel32.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel32.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel32.Name = "uiPanel32";
this.uiPanel32.Size = new System.Drawing.Size(138, 32);
this.uiPanel32.TabIndex = 10;
this.uiPanel32.Text = "高压出阀";
this.uiPanel32.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiLight3
//
this.uiLight3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(243)))), ((int)(((byte)(249)))), ((int)(((byte)(255)))));
this.uiLight3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiLight3.Location = new System.Drawing.Point(100, 3);
this.uiLight3.MinimumSize = new System.Drawing.Size(1, 1);
this.uiLight3.Name = "uiLight3";
this.uiLight3.OffColor = System.Drawing.Color.LightGray;
this.uiLight3.OnColor = System.Drawing.Color.Green;
this.uiLight3.Radius = 25;
this.uiLight3.Size = new System.Drawing.Size(25, 25);
this.uiLight3.State = Sunny.UI.UILightState.Off;
this.uiLight3.TabIndex = 1;
this.uiLight3.Text = "uiLight3";
//
// uiPanel34
//
this.uiPanel34.Controls.Add(this.uiButton6);
this.uiPanel34.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiPanel34.FillColor = System.Drawing.Color.White;
this.uiPanel34.Font = new System.Drawing.Font("宋体", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiPanel34.Location = new System.Drawing.Point(4, 167);
this.uiPanel34.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPanel34.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPanel34.Name = "uiPanel34";
this.uiPanel34.Padding = new System.Windows.Forms.Padding(5);
this.uiPanel34.RectColor = System.Drawing.Color.White;
this.uiPanel34.Size = new System.Drawing.Size(164, 56);
this.uiPanel34.TabIndex = 5;
this.uiPanel34.Text = null;
this.uiPanel34.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
//
// uiButton6
//
this.uiButton6.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton6.Dock = System.Windows.Forms.DockStyle.Fill;
this.uiButton6.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(180)))), ((int)(((byte)(0)))));
this.uiButton6.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(200)))), ((int)(((byte)(0)))));
this.uiButton6.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(160)))), ((int)(((byte)(0)))));
this.uiButton6.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Bold);
this.uiButton6.Location = new System.Drawing.Point(5, 5);
this.uiButton6.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton6.Name = "uiButton6";
this.uiButton6.Size = new System.Drawing.Size(154, 46);
this.uiButton6.TabIndex = 1;
this.uiButton6.Text = "清除报警";
this.uiButton6.TipsFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiButton6.Click += new System.EventHandler(this.uiButton6_Click);
//
// NormalTemperatureMode
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@@ -2337,6 +2403,8 @@ namespace 全自动水压检测仪
this.uiPanel4.ResumeLayout(false);
this.uiPanel3.ResumeLayout(false);
this.uiPanel2.ResumeLayout(false);
this.uiPanel32.ResumeLayout(false);
this.uiPanel34.ResumeLayout(false);
this.ResumeLayout(false);
}
@@ -2479,6 +2547,10 @@ namespace 全自动水压检测仪
private Sunny.UI.UIPanel uiPanel15;
private Sunny.UI.UIPanel uiPanel16;
private Sunny.UI.UIButton uiButton4;
private Sunny.UI.UIPanel uiPanel32;
private Sunny.UI.UILight uiLight3;
private Sunny.UI.UIPanel uiPanel34;
private Sunny.UI.UIButton uiButton6;
}
}

View File

@@ -276,7 +276,7 @@ namespace 全自动水压检测仪
}
}
bool isAddTag = false;
// 辅助方法:安全读取寄存器
private ushort[] SafelyReadRegisters(byte slaveAddress, ushort startAddress, ushort numberOfPoints)
{
@@ -415,6 +415,7 @@ namespace 全自动水压检测仪
{
uiButton2.Text = "启动测试";
uiButton2.ForeColor = System.Drawing.Color.White;
boolSignal1.CheckRisingEdge();
boolSignal1.Value = false;
}
//高低温切换
@@ -448,18 +449,8 @@ namespace 全自动水压检测仪
uiLight2.State = UILightState.Off;
}
//进气阀指示
//bool[] valve1 = _modbusMaster?.ReadCoils(1, 10014, 1);
//if (valve1 != null && valve1.Length > 0 && valve1[0])
//{
// uiLight3.State = UILightState.On;
//}
//else
//{
// uiLight3.State = UILightState.Off;
//}
//测试高压阀指示
//高压阀指示
bool[] valve2 = _modbusMaster?.ReadCoils(1, 10008, 1);
if (valve2 != null && valve2.Length > 0 && valve2[0])
{
@@ -469,6 +460,17 @@ namespace 全自动水压检测仪
{
uiLight4.State = UILightState.Off;
}
//高压出阀
bool[] valve13 = _modbusMaster?.ReadCoils(1, 10001, 1);
if (valve13 != null && valve13.Length > 0 && valve13[0])
{
uiLight3.State = UILightState.On;
}
else
{
uiLight3.State = UILightState.Off;
}
//常温抽水阀指示
bool[] valve3 = _modbusMaster?.ReadCoils(1, 10006, 1);
if (valve3 != null && valve3.Length > 0 && valve3[0])
@@ -503,7 +505,7 @@ namespace 全自动水压检测仪
{
uiLight7.State = UILightState.Off;
}
//真空泵指示
//空气抽气阀指示
bool[] valve6 = _modbusMaster?.ReadCoils(1, 10007, 1);
if (valve6 != null && valve6.Length > 0 && valve6[0])
{
@@ -513,7 +515,7 @@ namespace 全自动水压检测仪
{
uiLight8.State = UILightState.Off;
}
//升温指示
//加热状态指示
bool[] valve7 = _modbusMaster?.ReadCoils(1, 10004, 1);
if (valve7 != null && valve7.Length > 0 && valve7[0])
{
@@ -590,10 +592,10 @@ namespace 全自动水压检测仪
//切换数页
private void uiButton14_Click(object sender, EventArgs e)
{
SwitchWindow(ref _coeffiicientsetting, () => new Coeffiicientsetting());
}
//private void uiButton14_Click(object sender, EventArgs e)
//{
// SwitchWindow(ref _coeffiicientsetting, () => new Coeffiicientsetting());
//}
private void NormalTemperatureMode_Load(object sender, EventArgs e)
{
@@ -628,12 +630,15 @@ namespace 全自动水压检测仪
void BoolSignal1_OnRisingEdge()
{
if (isAddTag) return;
uiTextBox3.Text = uiLabel14.Text;//初始压力
uiTextBox8.Text = uiTextBox5.Text;//保压时间
uiTextBox6.Text = uiLabel22.Text;//压差
uiTextBox7.Text = uiLabel19.Text;//结束压力
CurrentReport.Add(new ConductivityTestData
{
barcode = uiTextBox2.Text,
@@ -662,6 +667,8 @@ namespace 全自动水压检测仪
uiTextBox2.Text = string.Empty;
isAddTag = true;
}
private bool TryReconnect()
{
@@ -818,6 +825,7 @@ namespace 全自动水压检测仪
private void uiButton2_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 10080);
isAddTag = false;
}
//停止测试
@@ -849,6 +857,12 @@ namespace 全自动水压检测仪
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 10004);
}
//清除报警
private void uiButton6_Click(object sender, EventArgs e)
{
ma?.BtnClickFunctionForNew(Function.ButtonType., 10025);
}
#endregion
}
}

View File

@@ -1,4 +1,6 @@
using Modbus.Device;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Sunny.UI;
using System;
using System.Collections.Generic;
@@ -118,7 +120,7 @@ namespace 全自动水压检测仪
{
Name = "Id",
HeaderText = "编号",
Width = 80,
Width = 70,
DataPropertyName = "Id", // 绑定到ConductivityTestData的Id属性
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
@@ -128,7 +130,7 @@ namespace 全自动水压检测仪
{
Name = "barcode",
HeaderText = "条码",
Width = 200,
Width = 280,
DataPropertyName = "Barcode", // 注意属性名大小写
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = { Alignment = DataGridViewContentAlignment.MiddleCenter }
@@ -138,7 +140,7 @@ namespace 全自动水压检测仪
{
Name = "CreateTime",
HeaderText = "时间日期",
Width = 180,
Width = 170,
DataPropertyName = "CreateTime",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
@@ -150,8 +152,8 @@ namespace 全自动水压检测仪
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "startpressure",
HeaderText = "初始压力",
Width = 120,
HeaderText = "初始压力(PSI)",
Width = 95,
DataPropertyName = "StartPressure",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
@@ -162,22 +164,24 @@ namespace 全自动水压检测仪
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "dwelltime",
HeaderText = "保压时间",
Width = 120,
DataPropertyName = "DwellTime",
Name = "endpressure",
HeaderText = "结束压力(PSI)",
Width = 95,
DataPropertyName = "EndPressure",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
Alignment = DataGridViewContentAlignment.MiddleCenter,
Format = "F1" // 保留1位小数
Format = "F2"
}
});
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "diffpressure",
HeaderText = "压差",
Width = 130,
HeaderText = "压差(PSI)",
Width = 75,
DataPropertyName = "DiffPressure",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
@@ -188,14 +192,14 @@ namespace 全自动水压检测仪
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
Name = "endpressure",
HeaderText = "结束压力",
Width = 130,
DataPropertyName = "EndPressure",
Name = "dwelltime",
HeaderText = "保压时间(h)",
Width = 80,
DataPropertyName = "DwellTime",
SortMode = DataGridViewColumnSortMode.NotSortable,
DefaultCellStyle = {
Alignment = DataGridViewContentAlignment.MiddleCenter,
Format = "F2"
Format = "F1" // 保留1位小数
}
});
@@ -426,20 +430,29 @@ namespace 全自动水压检测仪
using (StreamWriter writer = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
{
// 写入表头
writer.WriteLine("编号,条码,时间日期,初始压力,保压时间,压差,结束压力,温度模式");
writer.WriteLine("编号,条码,时间日期,初始压力(PSI),结束压力(PSI),压差(PSI),保压时间(h),温度模式");
// 写入数据
foreach (var data in CurrentReport)
{
string tempMode = GetTemperatureModeDisplay(data.Type);
//writer.WriteLine($"{data.Id}," +
// $"{data.barcode}," +
// $"{data.CreateTime:yyyy-MM-dd HH:mm:ss}," +
// $"{data.startpressure:F2}," +
// $"{data.dwelltime:F1}," +
// $"{data.diffpressure:F2}," +
// $"{data.endpressure:F2}," +
// $"{tempMode}");
writer.WriteLine($"{data.Id}," +
$"{data.barcode}," +
$"{data.CreateTime:yyyy-MM-dd HH:mm:ss}," +
$"{data.startpressure:F2}," +
$"{data.dwelltime:F1}," +
$"{data.diffpressure:F2}," +
$"{data.endpressure:F2}," +
$"{data.diffpressure:F2}," +
$"{data.dwelltime:F1}," +
$"{tempMode}");
}
}
@@ -485,12 +498,116 @@ namespace 全自动水压检测仪
/// </summary>
private void ExportToExcel(string filePath)
{
string csvPath = Path.ChangeExtension(filePath, ".csv");
ExportToCsv(csvPath);
//string csvPath = Path.ChangeExtension(filePath, ".csv");
//ExportToCsv(csvPath);
MessageBox.Show($"由于未安装Excel库已导出为CSV文件\n{csvPath}\n\n" +
"您可以将CSV文件导入Excel使用。", "导出提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
//MessageBox.Show($"由于未安装Excel库已导出为CSV文件\n{csvPath}\n\n" +
// "您可以将CSV文件导入Excel使用。", "导出提示",
// MessageBoxButtons.OK, MessageBoxIcon.Information);
//ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // 非商业用途
using (var package = new ExcelPackage())
{
var worksheet = package.Workbook.Worksheets.Add("测试数据报表");
// 设置默认样式
worksheet.Cells.Style.Font.Name = "微软雅黑";
worksheet.Cells.Style.Font.Size = 11;
int currentRow = 1;
// 主标题
worksheet.Cells[currentRow, 1, currentRow, 8].Merge = true;
var titleCell = worksheet.Cells[currentRow, 1];
titleCell.Value = "测试数据报表";
titleCell.Style.Font.Size = 16;
titleCell.Style.Font.Bold = true;
titleCell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
titleCell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
currentRow++;
// 副标题
worksheet.Cells[currentRow, 1, currentRow, 8].Merge = true;
var subTitleCell = worksheet.Cells[currentRow, 1];
subTitleCell.Value = $"生成时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss} | 记录数量:{CurrentReport.Count}条";
subTitleCell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
subTitleCell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
currentRow += 2;
// 表头
string[] headers = { "编号", "条码", "时间日期", "初始压力(PSI)", "结束压力(PSI)", "压差(PSI)", "保压时间(h)", "温度模式" };
for (int i = 0; i < headers.Length; i++)
{
var cell = worksheet.Cells[currentRow, i + 1];
cell.Value = headers[i];
cell.Style.Font.Bold = true;
cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
cell.Style.Fill.BackgroundColor.SetColor(Color.LightSkyBlue);
cell.Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.Black);
// 设置列宽
worksheet.Column(i + 1).Width = 15;
}
// 设置表头行高
worksheet.Row(currentRow).Height = 35;
currentRow++;
// 数据行
foreach (var data in CurrentReport)
{
string tempMode = GetTemperatureModeDisplay(data.Type);
worksheet.Cells[currentRow, 1].Value = data.Id;
worksheet.Cells[currentRow, 2].Value = data.barcode;
worksheet.Cells[currentRow, 3].Value = data.CreateTime;
worksheet.Cells[currentRow, 4].Value = data.startpressure;
worksheet.Cells[currentRow, 5].Value = data.endpressure;
worksheet.Cells[currentRow, 6].Value = data.diffpressure;
worksheet.Cells[currentRow, 7].Value = data.dwelltime;
worksheet.Cells[currentRow, 8].Value = tempMode;
// 设置数据行样式
for (int col = 1; col <= 8; col++)
{
var cell = worksheet.Cells[currentRow, col];
cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
cell.Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.LightGray);
// 隔行变色
if (currentRow % 2 == 0)
{
cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
cell.Style.Fill.BackgroundColor.SetColor(Color.AliceBlue);
}
}
// 设置格式
worksheet.Cells[currentRow, 3].Style.Numberformat.Format = "yyyy-mm-dd hh:mm:ss";
worksheet.Cells[currentRow, 4].Style.Numberformat.Format = "0.00";
worksheet.Cells[currentRow, 5].Style.Numberformat.Format = "0.00";
worksheet.Cells[currentRow, 6].Style.Numberformat.Format = "0.00";
worksheet.Cells[currentRow, 7].Style.Numberformat.Format = "0.0";
// 设置行高
worksheet.Row(currentRow).Height = 25;
currentRow++;
}
// 自动调整列宽
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
// 保存
package.SaveAs(new FileInfo(filePath));
}
}
/// <summary>

View File

@@ -2,6 +2,7 @@
<packages>
<package id="BouncyCastle.Cryptography" version="2.6.2" targetFramework="net472" />
<package id="Dapper" version="2.1.66" targetFramework="net472" />
<package id="EPPlus" version="4.5.3.3" targetFramework="net472" />
<package id="Google.Protobuf" version="3.32.0" targetFramework="net472" />
<package id="K4os.Compression.LZ4" version="1.3.8" targetFramework="net472" />
<package id="K4os.Compression.LZ4.Streams" version="1.3.8" targetFramework="net472" />

View File

@@ -39,6 +39,9 @@
<Reference Include="Dapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapper.2.1.66\lib\net461\Dapper.dll</HintPath>
</Reference>
<Reference Include="EPPlus, Version=4.5.3.3, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
<HintPath>..\packages\EPPlus.4.5.3.3\lib\net40\EPPlus.dll</HintPath>
</Reference>
<Reference Include="Google.Protobuf, Version=3.32.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
<HintPath>..\packages\Google.Protobuf.3.32.0\lib\net45\Google.Protobuf.dll</HintPath>
</Reference>
@@ -65,6 +68,7 @@
<Reference Include="NModbus4">
<HintPath>..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="SunnyUI">
<HintPath>..\packages\SunnyUI.3.8.9\lib\net472\SunnyUI.dll</HintPath>
@@ -95,6 +99,7 @@
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>