This commit is contained in:
@@ -89,6 +89,8 @@
|
||||
uiTableLayoutPanel4 = new Sunny.UI.UITableLayoutPanel();
|
||||
uiTableLayoutPanel5 = new Sunny.UI.UITableLayoutPanel();
|
||||
uiGroupBox4 = new Sunny.UI.UIGroupBox();
|
||||
uiLabel50 = new Sunny.UI.UILabel();
|
||||
uiLabel51 = new Sunny.UI.UILabel();
|
||||
uiButton13 = new Sunny.UI.UIButton();
|
||||
uiButton10 = new Sunny.UI.UIButton();
|
||||
uiLabel46 = new Sunny.UI.UILabel();
|
||||
@@ -111,8 +113,6 @@
|
||||
uiLabel43 = new Sunny.UI.UILabel();
|
||||
uiGroupBox5 = new Sunny.UI.UIGroupBox();
|
||||
uiLabel16 = new Sunny.UI.UILabel();
|
||||
uiLabel50 = new Sunny.UI.UILabel();
|
||||
uiLabel51 = new Sunny.UI.UILabel();
|
||||
uiTableLayoutPanel1.SuspendLayout();
|
||||
uiTableLayoutPanel2.SuspendLayout();
|
||||
uiPanel3.SuspendLayout();
|
||||
@@ -752,12 +752,12 @@
|
||||
comkou.Font = new Font("宋体", 12F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
comkou.ItemHoverColor = Color.FromArgb(155, 200, 255);
|
||||
comkou.ItemSelectForeColor = Color.FromArgb(235, 243, 255);
|
||||
comkou.Location = new Point(850, 78);
|
||||
comkou.Location = new Point(872, 78);
|
||||
comkou.Margin = new Padding(4, 5, 4, 5);
|
||||
comkou.MinimumSize = new Size(63, 0);
|
||||
comkou.Name = "comkou";
|
||||
comkou.Padding = new Padding(0, 0, 30, 2);
|
||||
comkou.Size = new Size(225, 44);
|
||||
comkou.Size = new Size(203, 44);
|
||||
comkou.SymbolSize = 24;
|
||||
comkou.TabIndex = 24;
|
||||
comkou.TextAlignment = ContentAlignment.MiddleLeft;
|
||||
@@ -863,11 +863,11 @@
|
||||
uiLabel23.ForeColor = Color.FromArgb(64, 158, 255);
|
||||
uiLabel23.Location = new Point(750, 78);
|
||||
uiLabel23.Name = "uiLabel23";
|
||||
uiLabel23.Size = new Size(60, 34);
|
||||
uiLabel23.Size = new Size(73, 34);
|
||||
uiLabel23.Style = Sunny.UI.UIStyle.Custom;
|
||||
uiLabel23.StyleCustomMode = true;
|
||||
uiLabel23.TabIndex = 17;
|
||||
uiLabel23.Text = "0.0";
|
||||
uiLabel23.Text = "0.000";
|
||||
uiLabel23.TextAlign = ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// uiLabel24
|
||||
@@ -880,7 +880,7 @@
|
||||
uiLabel24.Style = Sunny.UI.UIStyle.Custom;
|
||||
uiLabel24.StyleCustomMode = true;
|
||||
uiLabel24.TabIndex = 16;
|
||||
uiLabel24.Text = "背部功率(mW):";
|
||||
uiLabel24.Text = "背部功率(W):";
|
||||
uiLabel24.TextAlign = ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// uiLabel14
|
||||
@@ -1201,6 +1201,31 @@
|
||||
uiGroupBox4.Text = "测试结果";
|
||||
uiGroupBox4.TextAlignment = ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// uiLabel50
|
||||
//
|
||||
uiLabel50.Font = new Font("微软雅黑", 12F, FontStyle.Bold, GraphicsUnit.Point, 134);
|
||||
uiLabel50.ForeColor = Color.FromArgb(64, 158, 255);
|
||||
uiLabel50.Location = new Point(161, 565);
|
||||
uiLabel50.Name = "uiLabel50";
|
||||
uiLabel50.Size = new Size(265, 31);
|
||||
uiLabel50.Style = Sunny.UI.UIStyle.Custom;
|
||||
uiLabel50.StyleCustomMode = true;
|
||||
uiLabel50.TabIndex = 28;
|
||||
uiLabel50.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// uiLabel51
|
||||
//
|
||||
uiLabel51.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
uiLabel51.ForeColor = Color.FromArgb(96, 98, 102);
|
||||
uiLabel51.Location = new Point(38, 564);
|
||||
uiLabel51.Name = "uiLabel51";
|
||||
uiLabel51.Size = new Size(136, 31);
|
||||
uiLabel51.Style = Sunny.UI.UIStyle.Custom;
|
||||
uiLabel51.StyleCustomMode = true;
|
||||
uiLabel51.TabIndex = 27;
|
||||
uiLabel51.Text = "测试时间:";
|
||||
uiLabel51.TextAlign = ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// uiButton13
|
||||
//
|
||||
uiButton13.Cursor = Cursors.Hand;
|
||||
@@ -1517,31 +1542,6 @@
|
||||
uiLabel16.TabIndex = 0;
|
||||
uiLabel16.Text = "P1:t ≥ 10 s\r\nP2:3 s ≤ t≤ 10 s\r\nP3:1 s ≤ t ≤3 s\r\nP4:t≤1 s\r\n\r\n注: P1材料需测量背面温度";
|
||||
//
|
||||
// uiLabel50
|
||||
//
|
||||
uiLabel50.Font = new Font("微软雅黑", 12F, FontStyle.Bold, GraphicsUnit.Point, 134);
|
||||
uiLabel50.ForeColor = Color.FromArgb(64, 158, 255);
|
||||
uiLabel50.Location = new Point(161, 565);
|
||||
uiLabel50.Name = "uiLabel50";
|
||||
uiLabel50.Size = new Size(265, 31);
|
||||
uiLabel50.Style = Sunny.UI.UIStyle.Custom;
|
||||
uiLabel50.StyleCustomMode = true;
|
||||
uiLabel50.TabIndex = 28;
|
||||
uiLabel50.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// uiLabel51
|
||||
//
|
||||
uiLabel51.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
uiLabel51.ForeColor = Color.FromArgb(96, 98, 102);
|
||||
uiLabel51.Location = new Point(38, 564);
|
||||
uiLabel51.Name = "uiLabel51";
|
||||
uiLabel51.Size = new Size(136, 31);
|
||||
uiLabel51.Style = Sunny.UI.UIStyle.Custom;
|
||||
uiLabel51.StyleCustomMode = true;
|
||||
uiLabel51.TabIndex = 27;
|
||||
uiLabel51.Text = "测试时间:";
|
||||
uiLabel51.TextAlign = ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// PenetrationForm
|
||||
//
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
private System.Windows.Forms.Timer _readtimer;
|
||||
private readonly object _serialLock = new object();
|
||||
private System.Windows.Forms.Timer _powerMeterTimer;
|
||||
|
||||
private readonly SemaphoreSlim _asyncLock = new SemaphoreSlim(1, 1);
|
||||
ConductivityRepository conductivityRepository;
|
||||
|
||||
public bool RunStatus = false;
|
||||
@@ -322,10 +322,13 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
}));
|
||||
|
||||
// 关键修复:只在状态从运行变为停止时插入报表
|
||||
if (_lastRunStatus && !currentRunStatus)
|
||||
if (_lastRunStatus && !currentRunStatus && !_isReported)
|
||||
{
|
||||
|
||||
// 添加延迟确保数据稳定
|
||||
await Task.Delay(500);
|
||||
// 加锁防止异步并发重复执行
|
||||
await _asyncLock.WaitAsync();
|
||||
|
||||
var model = await InsertReportAsync();
|
||||
if (model != null && !string.IsNullOrEmpty(model.Id2))
|
||||
@@ -343,6 +346,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
{
|
||||
Debug.WriteLine($"读取状态失败: {ex.Message}");
|
||||
}
|
||||
finally { _asyncLock.Release(); }
|
||||
}
|
||||
public async Task<bool[]> ReadModbusCoilAsync(ushort registerAddress, ushort readCount)
|
||||
{
|
||||
@@ -367,6 +371,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
|
||||
private async Task<PenetrationModel> InsertReportAsync()
|
||||
{
|
||||
if (_isReported) return new PenetrationModel();
|
||||
if (!_isReported)
|
||||
{
|
||||
|
||||
@@ -442,11 +447,11 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
}
|
||||
|
||||
|
||||
ushort[] petime = _modbusMaster?.ReadHoldingRegisters(1, 72, 2);
|
||||
if (petime != null && petime.Length >= 2)
|
||||
{
|
||||
penetime = c.UshortToFloat(petime[1], petime[0]);
|
||||
}
|
||||
//ushort[] petime = _modbusMaster?.ReadHoldingRegisters(1, 72, 1);
|
||||
//if (petime != null )
|
||||
//{
|
||||
penetime = float.Parse(uiLabel2.Text);
|
||||
//}
|
||||
|
||||
// 如果是P1分类,读取温度
|
||||
if (classificationIndex == 3) // P1是数组的第3个元素
|
||||
@@ -1602,6 +1607,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
this.Close();//返回主页面
|
||||
}
|
||||
|
||||
private void uiLabel23_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,35 +278,39 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
if (registers2 != null && registers2.Length >= 1)
|
||||
{
|
||||
bool currentRunStatus = registers2[0]; // 当前运行状态
|
||||
|
||||
RunStatus = currentRunStatus;
|
||||
|
||||
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
uiLabel23.Text = currentRunStatus ? "运行中" : "空闲中";
|
||||
}));
|
||||
|
||||
// 关键修复:只在状态从运行变为停止时插入报表
|
||||
if (_lastRunStatus && !currentRunStatus)
|
||||
// ========== 关键修改1:移除重复的插入逻辑,只保留一段 ==========
|
||||
// 仅在「运行→停止」且未上报过的情况下执行一次插入
|
||||
if (_lastRunStatus && !currentRunStatus && !_isReported)
|
||||
{
|
||||
// 添加延迟确保数据稳定
|
||||
await Task.Delay(500);
|
||||
|
||||
var model = await InsertReportAsync();
|
||||
if (model != null && !string.IsNullOrEmpty(model.Id))
|
||||
// 加锁防止异步并发重复执行
|
||||
await _asyncLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
conductivityRepository.InsertReportItems(model);
|
||||
_isReported = true;
|
||||
Debug.WriteLine($"报表插入成功:样品{model.sampleType}, 分类{model.result}");
|
||||
// 二次校验,防止锁等待期间状态已变更
|
||||
if (!_isReported)
|
||||
{
|
||||
var model = await InsertReportAsync();
|
||||
if (model != null && !string.IsNullOrEmpty(model.Id))
|
||||
{
|
||||
conductivityRepository.InsertReportItems(model);
|
||||
_isReported = true; // 标记已上报
|
||||
Debug.WriteLine($"报表插入成功:样品{model.sampleType}, 分类{model.result}");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_asyncLock.Release(); // 释放锁
|
||||
}
|
||||
}
|
||||
|
||||
if (_lastRunStatus && !currentRunStatus && !_isReported)
|
||||
{
|
||||
var model = await InsertReportAsync();
|
||||
conductivityRepository.InsertReportItems(model);
|
||||
_isReported = true;
|
||||
}
|
||||
|
||||
_lastRunStatus = currentRunStatus;
|
||||
@@ -341,6 +345,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
private bool _isCurrentRecordAdded = true;//重复添加标记
|
||||
private async Task<PrimaryIgnitionModel> InsertReportAsync()
|
||||
{
|
||||
if (_isReported) return new PrimaryIgnitionModel();
|
||||
if (!_isReported)
|
||||
{
|
||||
if (uiLabel10.Text != null && uiLabel10.Text.Trim() == "1")
|
||||
|
||||
@@ -27,7 +27,9 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
InitComboBoxPattern3();
|
||||
|
||||
conductivityRepository = new ConductivityRepository();
|
||||
|
||||
uiDataGridView1.AutoGenerateColumns = false;
|
||||
uiDataGridView2.AutoGenerateColumns = false;
|
||||
uiDataGridView3.AutoGenerateColumns = false;
|
||||
}
|
||||
|
||||
private void ReportForm_Load(object sender, EventArgs e)
|
||||
@@ -478,7 +480,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
|
||||
MessageBox.Show($"导出成功!文件已保存到:{filePath}", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
|
||||
|
||||
//DialogResult openResult = MessageBox.Show("是否打开导出的Excel文件?", "打开文件",
|
||||
// MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
public bool RunStatus = false;
|
||||
|
||||
ConductivityRepository conductivityRepository;
|
||||
|
||||
private readonly SemaphoreSlim _asyncLock = new SemaphoreSlim(1, 1);
|
||||
public SecondaryIgnitionForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -266,10 +266,12 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
uiLabel23.Text = currentRunStatus ? "运行中" : "空闲中";
|
||||
}));
|
||||
// 关键修复:只在状态从运行变为停止时插入报表
|
||||
if (_lastRunStatus && !currentRunStatus)
|
||||
if (_lastRunStatus && !currentRunStatus && !_isReported)
|
||||
{
|
||||
// 添加延迟确保数据稳定
|
||||
await Task.Delay(500);
|
||||
// 加锁防止异步并发重复执行
|
||||
await _asyncLock.WaitAsync();
|
||||
|
||||
var model = await InsertReportAsync();
|
||||
if (model != null && !string.IsNullOrEmpty(model.Id3))
|
||||
@@ -287,6 +289,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
{
|
||||
Debug.WriteLine($"读取状态失败: {ex.Message}");
|
||||
}
|
||||
finally { _asyncLock.Release(); }
|
||||
}
|
||||
|
||||
public async Task<bool[]> ReadModbusCoilAsync(ushort registerAddress, ushort readCount)
|
||||
@@ -301,15 +304,16 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
|
||||
|
||||
List<SecondaryIgnitionModel> reportList = new List<SecondaryIgnitionModel>();
|
||||
private string classify=null;
|
||||
private float yy=0;
|
||||
private float yh=0;
|
||||
private bool iszixi=false;
|
||||
private bool isdianhuo=false;
|
||||
private string classify = null;
|
||||
private float yy = 0;
|
||||
private float yh = 0;
|
||||
private bool iszixi = false;
|
||||
private bool isdianhuo = false;
|
||||
|
||||
private bool _isCurrentRecordAdded = false;//重复添加标记
|
||||
private async Task<SecondaryIgnitionModel> InsertReportAsync()
|
||||
{
|
||||
if (_isReported) return new SecondaryIgnitionModel();
|
||||
if (!_isReported)
|
||||
{
|
||||
if (uiComboBox2.Text != null && uiComboBox2.Text.Trim() == "样品1")
|
||||
@@ -746,7 +750,7 @@ namespace 外科辅料和患者防护罩激光抗性测试仪
|
||||
else
|
||||
{
|
||||
_isCurrentRecordAdded = false;
|
||||
return new SecondaryIgnitionModel();
|
||||
return new SecondaryIgnitionModel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user