diff --git a/InSituLaboratory.Entities/SysEmu.cs b/InSituLaboratory.Entities/SysEmu.cs new file mode 100644 index 0000000..5e52274 --- /dev/null +++ b/InSituLaboratory.Entities/SysEmu.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace InSituLaboratory.Entities +{ + /// + /// 子时序号枚举 + /// + public class SysEmu + { + [Key] + public int ID { get; set; } + + public int Number { get; set; } + } +} diff --git a/InSituLaboratory.IService/IDeviceSvice.cs b/InSituLaboratory.IService/IDeviceSvice.cs index ee58877..37e82b4 100644 --- a/InSituLaboratory.IService/IDeviceSvice.cs +++ b/InSituLaboratory.IService/IDeviceSvice.cs @@ -31,5 +31,12 @@ namespace InSituLaboratory.IService /// string GetDeviceByDeviceNameMinTime(string DeviceName); + + /// + /// 获取子时序号 + /// + /// + IEnumerable GetNum(); + } } diff --git a/InSituLaboratory.ORM/NoimptyDbContext.cs b/InSituLaboratory.ORM/NoimptyDbContext.cs index 3528109..dbe4562 100644 --- a/InSituLaboratory.ORM/NoimptyDbContext.cs +++ b/InSituLaboratory.ORM/NoimptyDbContext.cs @@ -72,6 +72,7 @@ namespace InSituLaboratory.ORM public virtual DbSet SysSequential { get; set; } public virtual DbSet SysSequentialDetails { get; set; } public virtual DbSet SysDevice { get; set; } + public virtual DbSet SysEmu { get; set; } public virtual DbSet SysSequentialTotal { get; set; } public virtual DbSet CurrentFaultyEquipment { get; set; } public virtual DbSet CurrentWorkEquipment { get; set; } diff --git a/InSituLaboratory.Service/DeviceService.cs b/InSituLaboratory.Service/DeviceService.cs index 5358d70..33df9a4 100644 --- a/InSituLaboratory.Service/DeviceService.cs +++ b/InSituLaboratory.Service/DeviceService.cs @@ -57,5 +57,11 @@ namespace InSituLaboratory.Service return workTime; } + + + public IEnumerable GetNum() + { + return this.Set(); + } } } diff --git a/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs b/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs index f3e45e3..8a517f6 100644 --- a/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs @@ -12,6 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; +using System.Windows.Markup; using System.Windows.Media.Animation; namespace InSituLaboratory.ViewModels.Pages.Dialogs @@ -26,6 +27,7 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs /// 传感器设备集合 /// public List DeviceNodes { get; set; } = new List(); + public List SysNumberList { get; set; } = new List(); public SysSequentialDetails SysSequentialdata { get; set; } @@ -46,12 +48,12 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs /// 开始时间 /// - public DateTime? startTime { get; set; } + public DateTime startTime { get; set; } /// /// 结束时间 /// - public DateTime? endTime { get; set; } + public DateTime endTime { get; set; } /// /// 序号 @@ -163,34 +165,34 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs } DeviceNodes = _deviceSvice.GetDevices().ToList(); - Intlist = new List() { 1, 2, 3, 4, 5, 6 }; + //更换子时序号数据源 + SysNumberList = _deviceSvice.GetNum().ToList(); } public override void DoSave() { try { - //非空校验 + #region 非空校验 if (string.IsNullOrEmpty(SequenceGroup)) { - System.Windows.Forms.MessageBox.Show("子时序号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("子时序号不能为空"); } else if (string.IsNullOrEmpty(SensorID)) { - System.Windows.Forms.MessageBox.Show("设备编号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("设备编号不能为空"); } else if (WorkTime == null || WorkTime == 0) { - System.Windows.Forms.MessageBox.Show("工作时长不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("工作时长不能为空"); } else if (DurationTime == null || DurationTime == 0) { - System.Windows.Forms.MessageBox.Show("循环间隔时长不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("循环间隔时长不能为空"); } + #endregion + + #region 传感器是否已存在校验 | 循环时长校验 var data = _sequentialService.GetSequentials(kind).ToList(); if (data.Count != 0) { @@ -203,14 +205,13 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs if (Device != SensorID) { //传感器是否已存在校验 - var selectFirst = _sequentialService.Query(m => m.SensorID == SensorID && m.Sequential == kind && m.IsDelete == 0).ToList(); + var selectFirst = _sequentialService.Query(m => m.Number == Number).ToList(); if (selectFirst.Count != 0) { - foreach (var item in selectFirst) - { - System.Windows.Forms.MessageBox.Show(kind + "- 子时序" + item.SequenceGroup + "中,已配置" + SensorID + "!!!" + " 请重新配置。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } + + System.Windows.Forms.MessageBox.Show(kind + "- 子时序" + selectFirst[0].SequenceGroup + "中,已配置" + SensorID + "!!!" + " 请重新配置。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } } } @@ -229,6 +230,7 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs } } + ///循环时长校验 if (data1.StartTime == startTime && data1.EndTime == endTime) { @@ -243,8 +245,10 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs } } } + #endregion + + #region 工作时长是否已超过传感器预设时间 - ///工作时长是否已超过传感器预设时间 workTime = _deviceSvice.GetDeviceByDeviceName(SensorID); minworkTime = _deviceSvice.GetDeviceByDeviceNameMinTime(SensorID); if (workTime == "无") @@ -257,74 +261,118 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs } workInt = Convert.ToInt64(workTime); //设备预设最大工作时长 minworkInt = Convert.ToInt64(minworkTime);//设备预设最小工作时长 + switch (SensorID) { case "气相色谱仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } else if (Convert.ToInt64(WorkTime) < minworkInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } break; case "质谱仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } else if (Convert.ToInt64(WorkTime) < minworkInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } break; case "二氧化碳同位素分析仪": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } else if (Convert.ToInt64(WorkTime) < minworkInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } break; case "甲烷传感器": if (Convert.ToInt64(WorkTime) > workInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + "超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } else if (Convert.ToInt64(WorkTime) < minworkInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } break; case "显微拉曼分析仪": if (Convert.ToInt64(WorkTime) < minworkInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } break; case "色质联用": if (Convert.ToInt64(WorkTime) < minworkInt) { - System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - return; + throw new Exception("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!"); } break; default: break; } + + ///计算设备工作时长是否超过总时序时长 + System.TimeSpan t1 = endTime - startTime; + float getMinute = (float)t1.TotalMinutes; + + //根据开始时间、结束时间、是否删除查询母时序表 + //若存在记录,则根据母表ID去查询子表中所有子时序的工作时长与时序总时长进行对比 + var serID = 0; + float? time = 0; + var DataList = _sequentialService.Query(m => m.StartTime == startTime && m.EndTime == endTime && m.IsDelete == 0 && m.Sequential == kind).ToList(); + if (DataList.Count() != 0) + { + foreach (var Data in DataList) + { + serID = Data.Number; + } + var data_child = _sequentialService.Query(m => m.SysSquentialID == serID && m.IsDelete == 0).ToList(); + foreach (var Data in data_child) + { + time += Data.WorkTime; + } + //编辑情况下 + if (Number != 0) + { + var child = _sequentialService.Query(m => m.Number == Number).ToList(); + if (WorkTime > child[0].WorkTime) + { + time = time - child[0].WorkTime; + var total = time + WorkTime; + if (total > getMinute) + { + throw new Exception("当前设置的传感器总工作时长" + "(" + total + "分钟" + ")" + " 已超过时序总时长!" + "(" + getMinute + "分钟" + ")"); + } + } + } + else + { + var total = time + WorkTime; + if (total > getMinute) + { + throw new Exception("当前设置的传感器总工作时长" + "(" + total + "分钟" + ")" + " 已超过时序总时长!" + "(" + getMinute + "分钟" + ")"); + } + } + } + else + { + if (WorkTime > getMinute) + { + throw new Exception("当前设置的传感器总工作时长" + "(" + WorkTime + "分钟" + ")" + " 已超过时序总时长!" + "(" + getMinute + "分钟" + ")"); + } + } + #endregion + //保存时 首次去查询 data == null 说明数据库中无数据 为第一次插入 if (data.Count() == 0) { diff --git a/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml b/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml index e46de87..b6fc704 100644 --- a/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml +++ b/InSituLaboratory/Views/Pages/Dialogs/ModifySequentialView.xaml @@ -33,7 +33,7 @@ - +