diff --git a/YiDa_WinForm/Form/MainForm.cs b/YiDa_WinForm/Form/MainForm.cs index 2da1b8d..00f29ef 100644 --- a/YiDa_WinForm/Form/MainForm.cs +++ b/YiDa_WinForm/Form/MainForm.cs @@ -411,18 +411,64 @@ namespace YiDa_WinForm bool hasSelection2 = comboBox2.SelectedIndex > 0 && !string.IsNullOrEmpty(comboBox2.SelectedValue?.ToString()); + + // 1. 重置静态上传标记(每次连接都重新开始判断) + _isScrapImageUploadedOne = false; + _isRodImageUploadedOne = false; + _isScrapImageUploadedTwo = false; + _isRodImageUploadedTwo = false; + _isRodImageWorkNoticeOne = false; + _isRodImageWorkNoticeTwo = false; + _isScrapImageWorkNoticeOne = false; + _isScrapImageWorkNoticeTwo = false; + LogHelper.AppendLog("重置上传标记:连杆未上传、报废未上传"); + + string selectedContent1 = string.Empty; + string selectedContent2 = string.Empty; + + // 获取选中项的DataRowView(增加判空) + DataRowView drv1 = comboBox1.SelectedItem as DataRowView; + // 先判断drv1是否为null,再访问字段 + selectedContent1 = drv1 != null ? (drv1["part_name"]?.ToString()?.Trim() ?? string.Empty) : string.Empty; + + // 获取选中项的DataRowView(增加判空) + DataRowView drv2 = comboBox2.SelectedItem as DataRowView; + // 先判断drv2是否为null,再访问字段 + selectedContent2 = drv2 != null ? (drv2["part_name"]?.ToString()?.Trim() ?? string.Empty) : string.Empty; if (hasSelection1 && hasSelection2) { selection = "3"; + StartScrapOneAlarmTimers(); + StartScrapTwoAlarmTimers(); + if (selectedContent1.Contains("连杆2") && selectedContent2.Contains("连杆2")) + { + StartRodOneAlarmTimers(); + StartDailyRodDeviceOneFixedTimers(); + + StartRodTwoAlarmTimers(); + StartDailyRodDeviceTwoFixedTimers(); + } } else if (hasSelection1) { selection = "1"; + StartScrapOneAlarmTimers(); + if (selectedContent1.Contains("连杆2")) + { + StartRodOneAlarmTimers(); + StartDailyRodDeviceOneFixedTimers(); + } } else if (hasSelection2) { selection = "2"; + StartScrapTwoAlarmTimers(); + if (selectedContent2.Contains("连杆2")) + { + StartRodTwoAlarmTimers(); + StartDailyRodDeviceTwoFixedTimers(); + } } else { @@ -431,19 +477,6 @@ namespace YiDa_WinForm this.button2.Enabled = false; - // 1. 重置静态上传标记(每次连接都重新开始判断) - _isScrapImageUploadedOne = false; - _isRodImageUploadedOne = false; - _isScrapImageUploadedTwo = false; - _isRodImageUploadedTwo = false; - LogHelper.AppendLog("重置上传标记:连杆未上传、报废未上传"); - - // 2. 启动定时任务(复用用户保存的间隔值) - StartScrapAlarmTimers(); - StartRodAlarmTimers(); - StartDailyRodDeviceOneFixedTimers(); - StartDailyRodDeviceTwoFixedTimers(); - // 设备1选择配方 string selected1 = this.comboBox1.SelectedValue?.ToString(); if (string.IsNullOrEmpty(selected1) || selected1 == "-1") @@ -573,7 +606,7 @@ namespace YiDa_WinForm if (isImageUploadSuccess) { _buttonService.MergeAndSaveData("1", "device1"); - MqttYiDaUpload("1", "device"); + MqttYiDaUpload("1", "device1"); // 上传成功:直接标记为已上传(避免后续定时报警) _isScrapImageUploadedOne = true; } @@ -621,7 +654,7 @@ namespace YiDa_WinForm if (isImageUploadSuccess) { _buttonService.MergeAndSaveData("1", "device2"); - MqttYiDaUpload("2", "device"); + MqttYiDaUpload("2", "device2"); // 上传成功:直接标记为已上传(避免后续定时报警) _isScrapImageUploadedTwo = true; } @@ -669,7 +702,7 @@ namespace YiDa_WinForm if (isImageUploadSuccess) { _buttonService.MergeAndSaveData("2", "device1"); - MqttYiDaUpload("1", "device"); + MqttYiDaUpload("2", "device1"); // 上传成功:直接标记为已上传(避免后续定时报警) _isRodImageUploadedOne = true; DateTime now = DateTime.Now; @@ -742,7 +775,7 @@ namespace YiDa_WinForm if (isImageUploadSuccess) { _buttonService.MergeAndSaveData("2", "device1"); - MqttYiDaUpload("1", "device"); + MqttYiDaUpload("2", "device1"); // 上传成功:直接标记为已上传(避免后续定时报警) _isRodImageUploadedOne = true; DateTime now = DateTime.Now; @@ -821,7 +854,7 @@ namespace YiDa_WinForm if (isImageUploadSuccess) { _buttonService.MergeAndSaveData("2", "device2"); - MqttYiDaUpload("2", "device"); + MqttYiDaUpload("2", "device2"); // 上传成功:直接标记为已上传(避免后续定时报警) _isRodImageUploadedTwo = true; DateTime now = DateTime.Now; @@ -875,7 +908,7 @@ namespace YiDa_WinForm _lastRodIntervalTwo = interval; - // 3. 上传逻辑:仅当勾选「模具上传」时,才弹出文件选择框(分离上传和报警逻辑) + // 3. 上传逻辑 bool isImageUploadSuccess = false; OpenFileDialog openFile = new OpenFileDialog(); if (openFile.ShowDialog() == DialogResult.OK) @@ -888,7 +921,7 @@ namespace YiDa_WinForm if (isImageUploadSuccess) { _buttonService.MergeAndSaveData("2", "device2"); - MqttYiDaUpload("2", "device"); + MqttYiDaUpload("2", "device2"); // 上传成功:直接标记为已上传(避免后续定时报警) _isRodImageUploadedTwo = true; DateTime now = DateTime.Now; @@ -1054,7 +1087,7 @@ namespace YiDa_WinForm /// /// 启动报废定时任务(前30分钟上传) /// - private void StartScrapAlarmTimers() + private void StartScrapOneAlarmTimers() { // 设备1 if (_scrapAlarmTimerOne != null) @@ -1069,7 +1102,10 @@ namespace YiDa_WinForm _scrapAlarmTimerOne.Elapsed += ScrapAlarmTimerOne_Elapsed; _scrapAlarmTimerOne.Enabled = true; // 启动定时 LogHelper.AppendLog($"设备1报废上传定时已启动:若{_lastScrapIntervalOne}分钟内未上传凭证,将触发钉钉报警"); + } + private void StartScrapTwoAlarmTimers() + { // 设备2 if (_scrapAlarmTimerTwo != null) { @@ -1088,7 +1124,7 @@ namespace YiDa_WinForm /// /// 启动连杆定时任务(前30分钟上传) /// - private void StartRodAlarmTimers() + private void StartRodOneAlarmTimers() { // 设备1 if (_rodAlarmTimerOne != null) @@ -1103,7 +1139,10 @@ namespace YiDa_WinForm _rodAlarmTimerOne.Elapsed += RodAlarmTimerOne_Elapsed; _rodAlarmTimerOne.Enabled = true; // 启动定时 LogHelper.AppendLog($"设备1连杆定时已启动:若{_lastRodIntervalOne}分钟内未上传凭证,将触发钉钉报警"); + } + private void StartRodTwoAlarmTimers() + { // 设备2 if (_rodAlarmTimerTwo != null) { @@ -1346,25 +1385,6 @@ namespace YiDa_WinForm DateTime now = DateTime.Now; TimeSpan currentTime = now.TimeOfDay; - // // 1. 工作时间判断 - // if (currentTime < _morningCheckTime || currentTime > _eveningCheckTime) - // { - // LogHelper.AppendLog($"当前时间{currentTime:hh\\:mm}不在工作时间内,跳过本次连杆报警判断"); - // _rodAlarmTimerOne?.Dispose(); - // _rodAlarmTimerOne = null; - // return; - // } - - // ========== 早晚节点标记判断(已上传则跳过原有报警) ========== - if (_isMorningRodUploadedOne || _isEveningRodUploadedOne) - { - LogHelper.AppendLog("连杆图片已在早晚强制时段内上传,跳过本次原有定时报警"); - _rodAlarmTimerOne?.Dispose(); - _rodAlarmTimerOne = null; - _isRodImageUploadedOne = false; - return; - } - // 2. 使用静态标记 _isRodImageUploaded 判断是否报警 if (!_isRodImageUploadedOne) { @@ -1569,9 +1589,9 @@ namespace YiDa_WinForm private void InitDailyRodDeviceOneCheckTimes() { // 计算早上检查节点:工作开始时间 + 30分钟 - _morningCheckTimeOne = _workStartTimeOne.Add(TimeSpan.FromMinutes(30)); + _morningCheckTimeOne = _workStartTimeOne.Add(TimeSpan.FromMinutes(2)); // 计算晚上检查节点:工作结束时间 + 30分钟 - _eveningCheckTimeOne = _workEndTimeOne.Add(TimeSpan.FromMinutes(30)); + _eveningCheckTimeOne = _workEndTimeOne.Add(TimeSpan.FromMinutes(2)); // 校验:防止晚上检查节点早于早上检查节点(避免用户配置异常) if (_eveningCheckTimeOne <= _morningCheckTimeOne) @@ -2010,33 +2030,40 @@ namespace YiDa_WinForm { return string.Equals(value?.ToString(), "无错误", StringComparison.Ordinal) ? "合格" : "不合格"; } - else if ((paramName == "报废图片" || paramName == "连杆测试") && (_isScrapImageWorkNoticeOne || _isRodImageWorkNoticeOne || _isScrapImageWorkNoticeTwo || _isRodImageWorkNoticeTwo)) + else if (paramName == "报废图片" || paramName == "连杆测试") { + bool isNoticeTriggered = false; if (paramName == "报废图片") { - if (site == "1号设备") - { - _isScrapImageWorkNoticeOne = false; - } - else - { - _isScrapImageWorkNoticeTwo = false; - } + isNoticeTriggered = (site == "1号设备" && _isScrapImageWorkNoticeOne) + || (site == "2号设备" && _isScrapImageWorkNoticeTwo); } - if (paramName == "连杆测试") + else if (paramName == "连杆测试") { - if (site == "1号设备") - { - _isRodImageWorkNoticeOne = false; - } - else - { - _isRodImageWorkNoticeTwo = false; - } + isNoticeTriggered = (site == "1号设备" && _isRodImageWorkNoticeOne) + || (site == "2号设备" && _isRodImageWorkNoticeTwo); + } + if (isNoticeTriggered) + { + // 重置对应设备的标记 + if (paramName == "报废图片") + { + if (site == "1号设备") _isScrapImageWorkNoticeOne = false; + if (site == "2号设备") _isScrapImageWorkNoticeTwo = false; + } + else if (paramName == "连杆测试") + { + if (site == "1号设备") _isRodImageWorkNoticeOne = false; + if (site == "2号设备") _isRodImageWorkNoticeTwo = false; + } + return "不合格"; + } + else + { + return "合格"; } - return "不合格"; } - else if (paramName == "开模总数实时" || paramName == "托模次数" || paramName == "报废图片" || paramName == "连杆测试") + else if (paramName == "开模总数实时" || paramName == "托模次数") { return "合格"; } diff --git a/YiDa_WinForm/Service/ButtonOperationService.cs b/YiDa_WinForm/Service/ButtonOperationService.cs index 59db24e..25e46ec 100644 --- a/YiDa_WinForm/Service/ButtonOperationService.cs +++ b/YiDa_WinForm/Service/ButtonOperationService.cs @@ -150,7 +150,7 @@ namespace YiDa_WinForm.Service { try { - string strSql; + string strSql = null; if (selection != null && device == null) { if (selection.Contains("1")) @@ -169,18 +169,31 @@ namespace YiDa_WinForm.Service } else { - if (selection.Contains("1")) + if (device.Equals("device1")) { - strSql = @"SELECT * FROM yida_mqtt_message where device_code='device1' and pv_status = 1 and img_status = 1 ORDER BY create_time DESC LIMIT 1"; - } - else if (selection.Contains("2")) + if (selection.Equals("1")) + { + strSql = @"SELECT * FROM yida_mqtt_message where device_code = 'device1' and pv_status = 1 and img_status1 = 1 ORDER BY create_time DESC LIMIT 1"; + } + else + { + strSql = @"SELECT * FROM yida_mqtt_message where device_code = 'device1' and pv_status = 1 and img_status2 = 1 ORDER BY create_time DESC LIMIT 1"; + } + } + else if (device.Equals("device2")) { - strSql = @"SELECT * FROM yida_mqtt_message where device_code='device2' and pv_status = 1 and img_status = 1 ORDER BY create_time DESC LIMIT 1"; + if (selection.Equals("1")) + { + strSql = @"SELECT * FROM yida_mqtt_message where device_code = 'device2' and pv_status = 1 and img_status3 = 1 ORDER BY create_time DESC LIMIT 1"; + } + else + { + strSql = @"SELECT * FROM yida_mqtt_message where device_code = 'device2' and pv_status = 1 and img_status4 = 1 ORDER BY create_time DESC LIMIT 1"; + } } else { - strSql= - @"SELECT * FROM yida_mqtt_message where (device_code = 'device1' or device_code = 'device2') and pv_status = 1 and img_status = 1 ORDER BY create_time DESC LIMIT 1"; + strSql= @"SELECT * FROM yida_mqtt_message where (device_code = 'device1' or device_code = 'device2') and pv_status = 1 and (img_status1 = 1 or img_status2 = 1 or img_status3 = 1 or img_status4 = 1) ORDER BY create_time DESC LIMIT 1"; } } @@ -298,18 +311,37 @@ namespace YiDa_WinForm.Service string mergedData = JsonConvert.SerializeObject(dataModel); // 6. 更新数据库(调用DbHelper执行更新) - string updateSql; + string updateSql = null; if (deviceCode.Equals("device1")) { - updateSql = @"UPDATE yida_mqtt_message - SET receive_data = @mergedData, img_status = 1 + if (operationStatus == "1") + { + updateSql = @"UPDATE yida_mqtt_message + SET receive_data = @mergedData, img_status1 = 1 WHERE id = @latestId and pv_status = 1 and device_code = 'device1'"; + } + else + { + updateSql = @"UPDATE yida_mqtt_message + SET receive_data = @mergedData, img_status2 = 1 + WHERE id = @latestId and pv_status = 1 and device_code = 'device1'"; + } + } - else + if (deviceCode.Equals("device2")) { - updateSql = @"UPDATE yida_mqtt_message - SET receive_data = @mergedData, img_status = 1 + if (operationStatus == "2") + { + updateSql = @"UPDATE yida_mqtt_message + SET receive_data = @mergedData, img_status3 = 1 WHERE id = @latestId and pv_status = 1 and device_code = 'device2'"; + } + else + { + updateSql = @"UPDATE yida_mqtt_message + SET receive_data = @mergedData, img_status4 = 1 + WHERE id = @latestId and pv_status = 1 and device_code = 'device2'"; + } } var updateParameters = new[] { diff --git a/YiDa_WinForm/Service/YiDaUploadService.cs b/YiDa_WinForm/Service/YiDaUploadService.cs index 9520919..0e760d6 100644 --- a/YiDa_WinForm/Service/YiDaUploadService.cs +++ b/YiDa_WinForm/Service/YiDaUploadService.cs @@ -145,7 +145,7 @@ namespace YiDa_WinForm.Service for (int i = 0; i < yidaLists.Count; i++) { var item = yidaLists[i]; - var mqttItem = mqttLists[i]; + // var mqttItem = mqttLists[i]; var dataDict = new Dictionary { diff --git a/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe b/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe index 9d57330..2c9fa81 100644 Binary files a/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe and b/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe differ diff --git a/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe.config b/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe.config index 56fb813..68e7311 100644 --- a/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe.config +++ b/YiDa_WinForm/bin/Debug/YiDa_WinForm.exe.config @@ -35,7 +35,7 @@ - + diff --git a/YiDa_WinForm/bin/Debug/YiDa_WinForm.pdb b/YiDa_WinForm/bin/Debug/YiDa_WinForm.pdb index f78140c..698ef9f 100644 Binary files a/YiDa_WinForm/bin/Debug/YiDa_WinForm.pdb and b/YiDa_WinForm/bin/Debug/YiDa_WinForm.pdb differ