diff --git a/InSituLaboratory.IService/IDeviceSvice.cs b/InSituLaboratory.IService/IDeviceSvice.cs index 5d49bcc..7546365 100644 --- a/InSituLaboratory.IService/IDeviceSvice.cs +++ b/InSituLaboratory.IService/IDeviceSvice.cs @@ -16,7 +16,7 @@ namespace InSituLaboratory.IService IEnumerable GetDevices(); /// - /// 根据设备名称获取设备ID + /// 根据设备名称获取设备预设工作时长 /// /// /// diff --git a/InSituLaboratory.Service/DeviceService.cs b/InSituLaboratory.Service/DeviceService.cs index 7366e69..b9989f1 100644 --- a/InSituLaboratory.Service/DeviceService.cs +++ b/InSituLaboratory.Service/DeviceService.cs @@ -20,6 +20,12 @@ namespace InSituLaboratory.Service return this.Set(); } + + /// + /// 根据设备名称查询预设工作时长 + /// + /// + /// public string GetDeviceByDeviceName(string DeviceName) { var workTime = ""; diff --git a/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs b/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs index 4aaf9e4..cacb446 100644 --- a/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs @@ -2,6 +2,7 @@ using InSituLaboratory.IService; using InSituLaboratory.Models; using InSituLaboratory.Service; +using Microsoft.IdentityModel.Tokens; using Microsoft.VisualBasic.ApplicationServices; using Prism.Services.Dialogs; using System; @@ -10,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Forms; using System.Windows.Media.Animation; namespace InSituLaboratory.ViewModels.Pages.Dialogs @@ -25,7 +27,7 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs /// public List DeviceNodes { get; set; } = new List(); - public SysSequentialDetails SysSequentialdata { get; set; } + public SysSequentialDetails SysSequentialdata { get; set; } public string? workTime { get; set; } @@ -52,11 +54,12 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs /// public string kind { get; set; } + + private string _sequenceGroup; + /// /// 配置 /// - private string _sequenceGroup; - public string SequenceGroup { get { return _sequenceGroup; } @@ -64,99 +67,117 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs { _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"); + //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; /// /// 传感器设备 /// - private string _sensorID; - - public string SensorID + public string? SensorID { get { return _sensorID; } set { _sensorID = value; - //通过设备信息查询设备工作时长 - workTime = _deviceSvice.GetDeviceByDeviceName(_sensorID); - this.ErrorList.Clear(); - if (_sensorID == "质谱仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(WorkTime) > workInt) - { - ErrorList.Add("WorkTime", new List { "质谱仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "二氧化碳同位素分析仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(WorkTime) > workInt) - { - ErrorList.Add("WorkTime", new List { "二氧化碳同位素分析仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "甲烷同位素分析仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(WorkTime) > workInt) - { - ErrorList.Add("WorkTime", new List { "甲烷同位素分析仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "气相色谱仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(WorkTime) > workInt) - { - ErrorList.Add("WorkTime", new List { "气相色谱仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "基因测序仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(WorkTime) > workInt) - { - ErrorList.Add("WorkTime", new List { "基因测序仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else - { - ErrorList.Remove("WorkTime"); - } - this.RaiseErrorsChanged("WorkTime"); + //if (SequenceGroup == null) + //{ + // System.Windows.Forms.MessageBox.Show("配置为空!!! 请选择配置后,必须重新选择传感器设备!!!", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); + //} + //else + //{ + // ///查询当前设备是否已存在数据库中 + // var select = _sequentialService.Query(m => m.SensorID == value && m.SequenceGroup == SequenceGroup && m.Sequential == kind && m.IsDelete == 0).ToList(); + + // if (select.Count() == 0) + // { + // //通过设备信息查询设备工作时长 + // workTime = _deviceSvice.GetDeviceByDeviceName(_sensorID); + + // this.ErrorList.Clear(); + // if (_sensorID == "质谱仪") + // { + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(WorkTime) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "质谱仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + // } + // else if (_sensorID == "二氧化碳同位素分析仪") + // { + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(WorkTime) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "二氧化碳同位素分析仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + // } + // else if (_sensorID == "甲烷同位素分析仪") + // { + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(WorkTime) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "甲烷同位素分析仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + // } + // else if (_sensorID == "气相色谱仪") + // { + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(WorkTime) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "气相色谱仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + // } + // else if (_sensorID == "基因测序仪") + // { + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(WorkTime) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "基因测序仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + // this.RaiseErrorsChanged("WorkTime"); + // } + // else + // { + // System.Windows.MessageBox.Show(kind + "中 配置" + SequenceGroup + " 已存在" + SensorID, "提示"); + // workTime = _deviceSvice.GetDeviceByDeviceName(_sensorID); + // } + //} } } @@ -172,107 +193,108 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs set { _workTime = value; - this.ErrorList.Clear(); - if (string.IsNullOrEmpty(value)) - { - ErrorList.Add("WorkTime", new List { "工作时长不能为空" }); - } - else if (_sensorID == "质谱仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(value) > workInt) - { - ErrorList.Add("WorkTime", new List { "质谱仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "二氧化碳同位素分析仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(value) > workInt) - { - ErrorList.Add("WorkTime", new List { "二氧化碳同位素分析仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "甲烷同位素分析仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(value) > workInt) - { - ErrorList.Add("WorkTime", new List { "甲烷同位素分析仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "气相色谱仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(value) > workInt) - { - ErrorList.Add("WorkTime", new List { "气相色谱仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else if (_sensorID == "基因测序仪") - { - workInt = Convert.ToInt64(workTime) * 60 * 60; - if (Convert.ToInt64(value) > workInt) - { - ErrorList.Add("WorkTime", new List { "基因测序仪已超出最大工作时长" }); - } - else - { - ErrorList.Remove("WorkTime"); - } - } - else - { - ErrorList.Remove("WorkTime"); - } - this.RaiseErrorsChanged("WorkTime"); + //this.ErrorList.Clear(); + //if (string.IsNullOrEmpty(value)) + //{ + // ErrorList.Add("WorkTime", new List { "工作时长不能为空" }); + //} + //else if (_sensorID == "质谱仪") + //{ + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(value) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "质谱仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + //} + //else if (_sensorID == "二氧化碳同位素分析仪") + //{ + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(value) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "二氧化碳同位素分析仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + //} + //else if (_sensorID == "甲烷同位素分析仪") + //{ + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(value) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "甲烷同位素分析仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + //} + //else if (_sensorID == "气相色谱仪") + //{ + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(value) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "气相色谱仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + //} + //else if (_sensorID == "基因测序仪") + //{ + // workInt = Convert.ToInt64(workTime) * 60 * 60; + // if (Convert.ToInt64(value) > workInt) + // { + // ErrorList.Add("WorkTime", new List { "基因测序仪已超出最大工作时长" }); + // } + // else + // { + // ErrorList.Remove("WorkTime"); + // } + //} + //else + //{ + // ErrorList.Remove("WorkTime"); + //} + //this.RaiseErrorsChanged("WorkTime"); } } + + private string _durationTime; + /// /// 循环时长 /// - private string _durationTime; - public string DurationTime { get { return _durationTime; } set { _durationTime = value; - ErrorList.Remove("DurationTime"); - if (SequenceGroup != null) - { - if (SysSequentialdata != null) - { - if (_durationTime != SysSequentialdata.DurationTime) - { - ErrorList.Add("DurationTime", new List { "当前配置已存在循环时长:" + SysSequentialdata.DurationTime +"s"+",无法修改" }); - } - else - { - ErrorList.Remove("DurationTime"); - } - this.RaiseErrorsChanged("DurationTime"); - } - } + //ErrorList.Remove("DurationTime"); + //if (SequenceGroup != null) + //{ + // if (SysSequentialdata != null) + // { + // if (_durationTime != SysSequentialdata.DurationTime) + // { + // ErrorList.Add("DurationTime", new List { "当前配置已存在循环时长:" + SysSequentialdata.DurationTime + "s" + ",无法修改" }); + // } + // else + // { + // ErrorList.Remove("DurationTime"); + // } + // this.RaiseErrorsChanged("DurationTime"); + // } + //} } } @@ -286,6 +308,7 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs { _sequentialService = sequentialService; _deviceSvice = deviceSvice; + } public override void OnDialogOpened(IDialogParameters parameters) @@ -306,9 +329,9 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs this.Title = "编辑时序配置"; var su = _sequentialService.Find(SequentialDetail.Number); Number = su.Number; + SequenceGroup = su.SequenceGroup; SensorID = su.SensorID; WorkTime = su.WorkTime; - SequenceGroup = su.SequenceGroup; DurationTime = su.DurationTime; } @@ -319,16 +342,101 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs { try { - if (SysSequentialdata != null) + //非空校验 + if (string.IsNullOrEmpty(SequenceGroup)) { - if (SysSequentialdata.DurationTime == DurationTime) - { - ErrorList.Remove("DurationTime"); - this.RaiseErrorsChanged("DurationTime"); - } + System.Windows.MessageBox.Show("配置不能为空", "提示"); + return; + } + else if (string.IsNullOrEmpty(SensorID)) + { + System.Windows.MessageBox.Show("传感器设备不能为空", "提示"); + return; + } + else if (string.IsNullOrEmpty(WorkTime)) + { + System.Windows.MessageBox.Show("工作时长不能为空", "提示"); + return; + } + else if (string.IsNullOrEmpty(DurationTime)) + { + System.Windows.MessageBox.Show("循环时长不能为空", "提示"); + return; } - if (this.HasErrors) return; + + if (Number != 0) + { + //编辑情况下 + + + } + //传感器是否已存在校验 + var select = _sequentialService.Query(m => m.SensorID == SensorID && m.SequenceGroup == SequenceGroup && m.Sequential == kind && m.IsDelete == 0).ToList(); + if (select.Count != 0) + { + System.Windows.MessageBox.Show(kind + "- 配置" + SequenceGroup + "中已存在" + SensorID, "提示"); + return; + } + + ///工作时长是否已超过传感器预设时间 + workTime = _deviceSvice.GetDeviceByDeviceName(SensorID); + if (workTime == "无") + { + workTime = "0"; + } + workInt = Convert.ToInt64(workTime) * 60 * 60; + switch (SensorID) + { + case "气相色谱仪": + if (Convert.ToInt64(WorkTime) > workInt) + { + System.Windows.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime +"h/ " + workInt +"s", "提示"); + return; + } + break; + case "质谱仪": + if (Convert.ToInt64(WorkTime) > workInt) + { + System.Windows.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示"); + return; + } + break; + case "二氧化碳同位素分析仪": + if (Convert.ToInt64(WorkTime) > workInt) + { + System.Windows.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示"); + return; + } + break; + case "基因测序仪": + if (Convert.ToInt64(WorkTime) > workInt) + { + System.Windows.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示"); + return; + } + break; + case "甲烷同位素分析仪": + if (Convert.ToInt64(WorkTime) > workInt) + { + System.Windows.MessageBox.Show(SensorID + "设置的工作时长超过传感器本身最大工作时长,为:" + workTime + "h/ " + workInt + "s", "提示"); + return; + } + break; + default: + break; + } + + ///循环时长校验 + var SysSequentialdata1 = _sequentialService.GetSequentialSequenceGroup(SequenceGroup, kind); + if (SysSequentialdata1 != null) + { + if (DurationTime != SysSequentialdata1.DurationTime) + { + System.Windows.MessageBox.Show(kind + "- 配置"+ SequenceGroup + " 已存在循环时长:" + SysSequentialdata1.DurationTime + "s" + ",无法修改", "提示"); + return; + } + } var data = _sequentialService.GetSequentials(kind).ToList(); //保存时 首次去查询 data == null 说明数据库中无数据 为第一次插入 @@ -371,6 +479,8 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs SysSquentialID = data1.Number, SensorID = SensorID, DurationTime = DurationTime, + WorkTime = WorkTime, + SequenceGroup = SequenceGroup, CreateTime = DateTime.Now, Sequential = kind, IsDelete = 0 @@ -419,7 +529,7 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs } catch (Exception ex) { - MessageBox.Show(ex.Message, "提示"); + System.Windows.MessageBox.Show(ex.Message, "提示"); } }