diff --git a/全自动水压检测仪/ComeMeal-FX用户手册V1.3(1).pdf b/全自动水压检测仪/ComeMeal-FX用户手册V1.3(1).pdf new file mode 100644 index 0000000..b71e3e3 Binary files /dev/null and b/全自动水压检测仪/ComeMeal-FX用户手册V1.3(1).pdf differ diff --git a/全自动水压检测仪/NormalTemperatureMode.cs b/全自动水压检测仪/NormalTemperatureMode.cs index 25b2be8..ef42647 100644 --- a/全自动水压检测仪/NormalTemperatureMode.cs +++ b/全自动水压检测仪/NormalTemperatureMode.cs @@ -26,6 +26,7 @@ namespace 全自动水压检测仪 public partial class NormalTemperatureMode : UIForm { BoolSignal boolSignal1 = new BoolSignal(); + private BoolSignal _fallingEdgeSignal = new BoolSignal(); private Coeffiicientsetting _coeffiicientsetting; private ScanImport _scanImport; private StatusSettingsForm _statusSettingsForm; // 新增状态设置窗体 @@ -86,7 +87,7 @@ namespace 全自动水压检测仪 { HIGH_TEMP_LEVEL_MAX_ADDR, "高温液位上限报警" }, { NORMAL_TEMP_LEVEL_MAX_ADDR, "常温液位上限报警" } }; - + private bool _lastTestStatus = false; // 用于记录上一次读取到的测试状态 // 报警定时器 private System.Windows.Forms.Timer _alarmMonitorTimer; private bool _isCheckingAlarm = false; @@ -909,28 +910,74 @@ namespace 全自动水压检测仪 // 统一用SafeInvoke更新所有UI控件 SafeInvoke(() => { + //测试按键 + //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 + // { + // uiButton2.Text = "启动测试"; + // uiButton2.ForeColor = System.Drawing.Color.White; + // boolSignal1.CheckRisingEdge(); + // boolSignal1.Value = false; + // } + // } + //} //测试按键 if (modbusResults.TestStatus != null && modbusResults.TestStatus.Length > 0) { + bool currentTestStatus = modbusResults.TestStatus[0]; + + // 更新按钮文字 if (uiButton2 != null && !uiButton2.IsDisposed) { - if (modbusResults.TestStatus[0]) + if (currentTestStatus) { uiButton2.Text = "测试中"; uiButton2.ForeColor = System.Drawing.Color.Red; - boolSignal1.Value = true; - boolSignal1.CheckRisingEdge(); } else { uiButton2.Text = "启动测试"; uiButton2.ForeColor = System.Drawing.Color.White; - boolSignal1.CheckRisingEdge(); - boolSignal1.Value = false; } } - } + // 检测状态变化 + if (_lastTestStatus != currentTestStatus) + { + if (currentTestStatus) // 从 false 变为 true → 测试开始 + { + // 记录开始时间 + starttime = DateTime.Now; + // 清除图表数据 + _chartManager?.ClearData(); + // 重置标记,允许下次保存 + isAddTag = false; + // 启动压差比较定时器(如果需要在测试过程中监控) + _readTimetCompareResult?.Start(); + + Debug.WriteLine($"[测试开始] starttime = {starttime}"); + } + else // 从 true 变为 false → 测试结束 + { + // 调用保存数据的方法 + SaveTestResult(); + + Debug.WriteLine($"[测试结束] endtime = {DateTime.Now}"); + } + + _lastTestStatus = currentTestStatus; + } + } //高低温切换 if (modbusResults.ButtonStatus != null && modbusResults.ButtonStatus.Length > 0 && uiSwitch1 != null && !uiSwitch1.IsDisposed) { @@ -1089,6 +1136,65 @@ namespace 全自动水压检测仪 } + private void SaveTestResult() + { + if (isAddTag) return; // 防止重复保存 + + SafeInvoke(() => + { + uiTextBox3.Text = uiLabel14.Text; // 初始压力 + uiTextBox8.Text = uiTextBox5.Text; // 保压时间 + uiTextBox6.Text = uiLabel22.Text; // 压差 + uiTextBox7.Text = uiLabel19.Text; // 结束压力 + + // 获取联络单号和件号 + string contactNumber = uiTextBox2.Text.Trim(); + string itemNumber = uiTextBox10.Text.Trim(); + string barcode = $"{contactNumber}-{itemNumber}"; + + // 确保 starttime 有效(如果从未设置,回退为当前时间) + if (starttime == default(DateTime)) + { + starttime = DateTime.Now; + Debug.WriteLine("[Warn] starttime 未初始化,已回退为当前时间:" + starttime.ToString("o")); + } + + DateTime recordStartTime = starttime; + DateTime recordEndTime = DateTime.Now; + DateTime recordCreateTime = DateTime.Now; + + var newItem = new ConductivityTestData + { + barcode = barcode, + CreateTime = recordCreateTime, + diffpressure = uiTextBox6.Text.ToDouble(), + dwelltime = uiTextBox8.Text.ToDouble(), + temperature = uiTextBox4.Text.ToDouble(), + endpressure = uiTextBox7.Text.ToDouble(), + startpressure = uiTextBox3.Text.ToDouble(), + Type = uiLight1.State == UILightState.On ? 1 : 0, + // 新增字段 + kzh = kzh, + jh = uiTextBox10.Text, + endtime = recordEndTime, + quantity = quantity, + lldh = uiTextBox2.Text, + standarderror = standarderror, + starttime = recordStartTime, + testresult = (isValid ?? false) ? "合格" : "不合格" + }; + + CurrentReport.Add(newItem); + + _repository.InsertReportItems(newItem); + }); + + isAddTag = true; + _readTimetCompareResult?.Stop(); // 停止压差比较定时器 + } + + + private void NormalTemperatureMode_Load(object sender, EventArgs e) { // 权限检查:只有管理员才能看到"录入系统"按钮 diff --git a/全自动水压检测仪/ScanImport.cs b/全自动水压检测仪/ScanImport.cs index 2398fdd..b91ebe8 100644 --- a/全自动水压检测仪/ScanImport.cs +++ b/全自动水压检测仪/ScanImport.cs @@ -104,14 +104,16 @@ namespace 全自动水压检测仪 // 组合条码用于兼容性(可选) string barcode = $"{contactNumber}-{itemNumber}"; + // 修改这里:新增记录时,检查件号是否已存在 + // 因为是新增,所以只需要检查是否有任何记录使用了相同的件号 + bool isDuplicate = _repository.GetScanDataBylldh_jh(uiTextBox11.Text).Any(); - - bool isAny = _repository.GetScanDataBylldh_jh(uiTextBox11.Text).Any(); - if (isAny) + if (isDuplicate) { - MessageBox.Show("件号重复"); + MessageBox.Show("件号已存在,请使用不同的件号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } + try { _repository.InsertScanItems(new ScanData @@ -132,7 +134,6 @@ namespace 全自动水压检测仪 pressuresetting = pressureDifference, quantity = quantity, standarderror = standardError - }); // 重新加载数据 @@ -346,6 +347,40 @@ namespace 全自动水压检测仪 }); } } + //// 编辑按钮点击事件处理 + //private void DataGridViewCellClickHandler(object sender, DataGridViewCellEventArgs e) + //{ + // // 确保点击的是按钮列 + // if (e.RowIndex >= 0 && e.ColumnIndex >= 0 && + // uiDataGridView1.Columns[e.ColumnIndex].Name == "EditButton") + // { + // // 获取选中的行数据 + // if (uiDataGridView1.Rows[e.RowIndex].DataBoundItem is ScanData scanData) + // { + // // 保存修改到数据库 + // try + // { + // bool isAny = _repository.GetScanDataBylldh_jh(scanData.jh).Any(); + // if (isAny) + // { + // MessageBox.Show("件号重复"); + // return; + // } + + // _repository.UpdateScanItem(scanData); + + // MessageBox.Show("修改已保存!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); + + // // 刷新数据 + // LoadData(); + // } + // catch (Exception ex) + // { + // MessageBox.Show($"保存失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + // } + // } + // } + //} // 编辑按钮点击事件处理 private void DataGridViewCellClickHandler(object sender, DataGridViewCellEventArgs e) { @@ -359,10 +394,14 @@ namespace 全自动水压检测仪 // 保存修改到数据库 try { - bool isAny = _repository.GetScanDataBylldh_jh(scanData.jh).Any(); - if (isAny) + // 修改这里:检查件号重复时排除当前记录自身 + // 获取除了当前记录ID之外,是否有其他记录使用了相同的件号 + bool isDuplicate = _repository.GetScanDataBylldh_jh(scanData.jh) + .Any(x => x.Id != scanData.Id); // 排除当前记录自身 + + if (isDuplicate) { - MessageBox.Show("件号重复"); + MessageBox.Show("件号重复,请使用不同的件号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } @@ -380,7 +419,6 @@ namespace 全自动水压检测仪 } } } - private void SwitchWindow(T windowInstance, Func createFunc) where T : UIForm {