From 5663aeff05592a7c8bccd57c3163b3723130cb8c Mon Sep 17 00:00:00 2001 From: MoYue Date: Mon, 24 Jun 2024 15:05:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E5=BA=8F=E4=B8=8B=E5=8F=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8A=9F=E8=80=97=E8=AE=A1=E7=AE=97=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dialogs/ModifySequentialViewModel.cs | 28 +- .../Pages/SequentialDistributionViewModel.cs | 315 +++++++++++------- .../Pages/Dialogs/ModifySequentialView.xaml | 4 +- .../Pages/SequentialDistributionView.xaml | 20 +- 4 files changed, 213 insertions(+), 154 deletions(-) diff --git a/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs b/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs index 0e02b57..36a7b86 100644 --- a/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs @@ -71,17 +71,6 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs set { _sequenceGroup = value; - - //SysSequentialdata = _sequentialService.GetSequentialSequenceGroup(SequenceGroup, kind); - //if (SysSequentialdata != null) - //{ - // ErrorList.Add("DurationTime", new List { "当前配置存在循环时长:" + SysSequentialdata.DurationTime + "s" }); - //} - //else - //{ - // ErrorList.Remove("DurationTime"); - //} - //this.RaiseErrorsChanged("DurationTime"); } } private string? _sensorID; @@ -256,41 +245,34 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs { workTime = "0"; } - workInt = Convert.ToInt64(workTime) * 60 * 60; + workInt = Convert.ToInt64(workTime); switch (SensorID) { case "气相色谱仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长:" + WorkTime + "h"+ ",已超过设备最大工作时长:" + workTime + "h" +"\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } break; case "质谱仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长:" + WorkTime + "h"+ ",已超过设备最大工作时长:" + workTime + "h" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } break; case "二氧化碳同位素分析仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; - } - break; - case "基因测序仪": - if (Convert.ToInt64(WorkTime) > workInt) - { - System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长:" + WorkTime + "h"+ ",已超过设备最大工作时长:" + workTime + "h" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } break; case "甲烷同位素分析仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + System.Windows.Forms.MessageBox.Show(SensorID + "设置的工作时长:" + WorkTime + "h" + ",已超过设备最大工作时长:" + workTime + "h" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } break; diff --git a/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs b/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs index 920a26e..ab5393f 100644 --- a/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs @@ -116,21 +116,63 @@ namespace InSituLaboratory.ViewModels.Pages /// public override void DoModifyS1(object model) { - var status = ""; - var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); - if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) + try { - System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else - { - if (datalist1.Count() != 0) + var status = ""; + var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); + if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) { - foreach (var item in datalist1) + throw new Exception("时序1: 开始时间和结束时间不能为空!"); + } + else + { + if (datalist1.Count() != 0) { - status = item.Status; + foreach (var item in datalist1) + { + status = item.Status; + } + if (status == "已生成未下发") + { + DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1; + DateTime dateTime = DateTime.Now; + + if (expirationDate < dateTime) + { + throw new Exception("时序1: 开始时间不得早于当前时间!"); + } + else if (expirationDate1 < dateTime) + { + throw new Exception("时序1: 结束时间不得早于当前时间!"); + } + else if (expirationDate >= expirationDate1) + { + throw new Exception("时序1: 结束时间不得早于开始时间!"); + } + else + { + DialogParameters ps = new DialogParameters(); + ps.Add("model", model); + ps.Add("sequentialStartTime", sequentStatusModel.SequentialStartTime1); + ps.Add("sequentialEndTime", sequentStatusModel.SequentialEndTime1); + ps.Add("kind", "时序1"); + _dialogService.ShowDialog("ModifySequentialView", ps, result => + { + // 判断子窗口的返回状态,如果OK,刷新当前页面,否则不管 + if (result.Result == ButtonResult.OK) + { + this.RefreshS1(); + } + }); + } + } + else + { + throw new Exception("当前时序已下发!!! \n 若要设置新的时序,您可以修改时序的开始时间和结束时间即可!"); + } } - if (status == "已生成未下发") + else { DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1; DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1; @@ -138,15 +180,15 @@ namespace InSituLaboratory.ViewModels.Pages if (expirationDate < dateTime) { - System.Windows.Forms.MessageBox.Show("时序1: 开始时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + throw new Exception("时序1: 开始时间不得早于当前时间!"); } else if (expirationDate1 < dateTime) { - System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + throw new Exception("时序1: 结束时间不得早于当前时间!"); } else if (expirationDate >= expirationDate1) { - System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于开始时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + throw new Exception("时序1: 结束时间不得早于开始时间!"); } else { @@ -164,49 +206,15 @@ namespace InSituLaboratory.ViewModels.Pages } }); } - } - else - { - System.Windows.Forms.MessageBox.Show(" 当前时序已下发!!! \n 若要设置新的时序,您可以修改时序的开始时间和结束时间即可!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - else - { - DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1; - DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1; - DateTime dateTime = DateTime.Now; - if (expirationDate < dateTime) - { - System.Windows.Forms.MessageBox.Show("时序1: 开始时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } - else if (expirationDate1 < dateTime) - { - System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else if (expirationDate >= expirationDate1) - { - System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于开始时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else - { - DialogParameters ps = new DialogParameters(); - ps.Add("model", model); - ps.Add("sequentialStartTime", sequentStatusModel.SequentialStartTime1); - ps.Add("sequentialEndTime", sequentStatusModel.SequentialEndTime1); - ps.Add("kind", "时序1"); - _dialogService.ShowDialog("ModifySequentialView", ps, result => - { - // 判断子窗口的返回状态,如果OK,刷新当前页面,否则不管 - if (result.Result == ButtonResult.OK) - { - this.RefreshS1(); - } - }); - } - } } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } /// @@ -268,76 +276,79 @@ namespace InSituLaboratory.ViewModels.Pages /// public override void SendS1() { - var status = ""; - var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); + try + { + var status = ""; + var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); - if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) - { - System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else if (datalist1.Count() == 0) - { - System.Windows.Forms.MessageBox.Show("时序1中未有设备,无法下发!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else - { - if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) { - DateTime startTime = (DateTime)sequentStatusModel.SequentialStartTime1; - DateTime endTime = (DateTime)sequentStatusModel.SequentialEndTime1; - foreach (var item in datalist1) - { - status = item.Status; - } - if (status == "已生成未下发") - { - System.Windows.Forms.DialogResult s1 = System.Windows.Forms.MessageBox.Show("是否修改并等待当前工作设备工作完最短周期后生效新时序? \n若选择否,则修改且关闭该时序所有设备!!!", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); - - //修改并等待当前工作设备工作完最短周期后生效新时序 - if (s1 == System.Windows.Forms.DialogResult.Yes) - { - //计算设备功耗是否超总功耗及设备运行时长是否超时 - - - - List byteaq = encode(startTime, endTime, 0x01, "时序1"); - List buffer = Escape(byteaq.ToArray()); - string list = tools.byteToHexStr(buffer.ToArray()); - byte[] bytea = tools.ConvertHexStringToBytes(list); - RelayViewModel.clientModel.SendData(bytea); - - //更新时序母表及时序总表状态字段 - UpdateData(startTime, endTime, "时序1", "已下发"); - System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - //修改且关闭该时序所有设备 - else if (s1 == System.Windows.Forms.DialogResult.No) - { - //计算设备功耗是否超总功耗及设备运行时长是否超时 - - - List byteaq = encode((DateTime)sequentStatusModel.SequentialStartTime1, (DateTime)sequentStatusModel.SequentialEndTime1, 0x02, "时序1"); - List buffer = Escape(byteaq.ToArray()); - string list = tools.byteToHexStr(buffer.ToArray()); - byte[] bytea = tools.ConvertHexStringToBytes(list); - RelayViewModel.clientModel.SendData(bytea); - - //更新时序母表及时序总表状态字段 - UpdateData(startTime, endTime, "时序1", "已下发"); - System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - } - else - { - System.Windows.Forms.MessageBox.Show("当前时序已下发!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - this.RefreshS1(); + throw new Exception("时序1: 开始时间和结束时间不能为空!"); + } + else if (datalist1.Count() == 0) + { + throw new Exception("时序1中未有设备,无法下发!!!"); } else { - System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + DateTime startTime = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime endTime = (DateTime)sequentStatusModel.SequentialEndTime1; + foreach (var item in datalist1) + { + status = item.Status; + } + if (status == "已生成未下发") + { + System.Windows.Forms.DialogResult s1 = System.Windows.Forms.MessageBox.Show("是否修改并等待当前工作设备工作完最短周期后生效新时序? \n若选择否,则修改且关闭该时序所有设备!!!", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + //修改并等待当前工作设备工作完最短周期后生效新时序 + if (s1 == System.Windows.Forms.DialogResult.Yes) + { + //计算设备功耗是否超总功耗及设备运行时长是否超时 + List byteaq = encode(startTime, endTime, 0x01, "时序1"); + List buffer = Escape(byteaq.ToArray()); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + RelayViewModel.clientModel.SendData(bytea); + + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已下发"); + System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + //修改且关闭该时序所有设备 + else if (s1 == System.Windows.Forms.DialogResult.No) + { + //计算设备功耗是否超总功耗及设备运行时长是否超时 + List byteaq = encode((DateTime)sequentStatusModel.SequentialStartTime1, (DateTime)sequentStatusModel.SequentialEndTime1, 0x02, "时序1"); + List buffer = Escape(byteaq.ToArray()); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + RelayViewModel.clientModel.SendData(bytea); + + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已下发"); + System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + else + { + throw new Exception("当前时序已下发!!!"); + } + this.RefreshS1(); + } + else + { + throw new Exception("请先连接服务端!"); + } } } + catch (Exception ex) + { + System.Windows.Forms.MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } /// @@ -1321,6 +1332,15 @@ namespace InSituLaboratory.ViewModels.Pages ulong endmin; ulong endsec; + //初始化电能板1 负载功耗=0 + float EnergyBoard1 = 0; + //初始化电能板2 负载功耗=0 + float EnergyBoard2 = 0; + //初始化电能板3 负载功耗=0 + float EnergyBoard3 = 0; + //初始化电能板4 负载功耗=0 + float EnergyBoard4 = 0; + //定义消息体数组 List byteaq = new List(); @@ -1391,7 +1411,12 @@ namespace InSituLaboratory.ViewModels.Pages //先遍历 datalist 确定 SequenceGroup的种类和数量 for (int i = 0; i < datalist.Length; i++) { - if (i != 0 && datalist.Length >= 1) + //只有一个子时序且子时序中只有一台设备 + if (datalist.Length == 1) + { + b.Add(1); + } + else if (i != 0 && datalist.Length > 1) { if (datalist[i].SequenceGroup != datalist[i - 1].SequenceGroup) { @@ -1404,6 +1429,7 @@ namespace InSituLaboratory.ViewModels.Pages m = 0; } } + } //b = new List() { 4, 3, 4, 6 }; //3 3 2 1 @@ -1428,76 +1454,127 @@ namespace InSituLaboratory.ViewModels.Pages { case "工控机": byteaq.Add(0x00); + EnergyBoard3 += 12; + break; case "色质联用": byteaq.Add(0x01); + EnergyBoard2 += 150; + break; case "备用串口1": byteaq.Add(0x02); + EnergyBoard1 += 100; + break; case "备用串口2": byteaq.Add(0x03); + EnergyBoard1 += 100; + break; case "光通讯机": byteaq.Add(0x04); + EnergyBoard1 += 30; + break; case "ADCP": byteaq.Add(0x05); + EnergyBoard1 += 24; + break; case "CTD": byteaq.Add(0x06); + EnergyBoard1 += 0.2F; + break; case "气相色谱仪": byteaq.Add(0x07); + EnergyBoard3 += 120; + break; case "甲烷传感器": byteaq.Add(0x08); + EnergyBoard2 += 80; + break; case "二氧化碳同位素分析仪": byteaq.Add(0x09); + EnergyBoard3 += 48; + break; case "备用网口设备": byteaq.Add(0x0a); break; case "ICL": byteaq.Add(0x0b); + EnergyBoard2 += 8; + break; case "显微拉曼分析仪": byteaq.Add(0x0c); + EnergyBoard4 += 150; + break; case "质谱仪": byteaq.Add(0x0d); + EnergyBoard4 += 150; + break; case "声学定位": byteaq.Add(0x0e); + EnergyBoard4 += 10; + break; case "摄像1": byteaq.Add(0x0f); + EnergyBoard2 += 3; + break; case "摄像2": byteaq.Add(0x10); + EnergyBoard3 += 3; + + break; case "电交换机2": byteaq.Add(0x11); + EnergyBoard4 += 8.4F; break; default: break; } //定义接收工作时长 - int w = Convert.ToInt32(datalist[i == 0 ? j : n + j].WorkTime); + int w = Convert.ToInt32(datalist[i == 0 ? j : n + j].WorkTime) * 60 * 60; byteaq.Add((byte)(w & 0xFF)); byteaq.Add((byte)((w & 0xFF00) >> 8)); byteaq.Add((byte)((w & 0xFF0000) >> 16)); byteaq.Add((byte)((w >> 24) & 0xFF)); //接收循环间隔时长 - d = Convert.ToInt32(datalist[i == 0 ? j : n + j].DurationTime); + d = Convert.ToInt32(datalist[i == 0 ? j : n + j].DurationTime) * 60 * 60; } byteaq.Add((byte)(d & 0xFF)); byteaq.Add((byte)((d & 0xFF00) >> 8)); byteaq.Add((byte)((d & 0xFF0000) >> 16)); byteaq.Add((byte)((d >> 24) & 0xFF)); + + if (EnergyBoard1 > 250) + { + throw new Exception("当前所下发的时序中电能板1总功耗:" + EnergyBoard1 + "W" + " ,已超过电能板1额定功率250W \n 时序无法下发,请修改设备后重试!!!"); + } + if (EnergyBoard2 > 250) + { + throw new Exception("当前所下发的时序中电能板2总功耗:" + EnergyBoard2 + "W" + " ,已超过电能板2额定功率250W \n 时序无法下发,请修改设备后重试!!!"); + } + if (EnergyBoard3 > 250) + { + throw new Exception("当前所下发的时序中电能板3总功耗:" + EnergyBoard3 + "W" + " ,已超过电能板3额定功率250W \n 时序无法下发,请修改设备后重试!!!"); + } + if (EnergyBoard4 > 250) + { + throw new Exception("当前所下发的时序中电能板4总功耗:" + EnergyBoard4 + "W" + " ,已超过电能板4额定功率250W \n 时序无法下发,请修改设备后重试!!!"); + } } return byteaq; } diff --git a/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml b/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml index 4dbc1b7..cd8a2ee 100644 --- a/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml +++ b/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml @@ -30,8 +30,8 @@ - - + + diff --git a/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml b/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml index 238eaad..20dabee 100644 --- a/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml +++ b/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml @@ -185,8 +185,8 @@ - - + + @@ -306,8 +306,8 @@ - - + + @@ -426,8 +426,8 @@ - - + + @@ -546,8 +546,8 @@ - - + + @@ -666,8 +666,8 @@ - - + +