校验移至保存按钮,需增加编辑保存逻辑

This commit is contained in:
MoYue 2024-04-12 17:47:43 +08:00
parent 0d6f0c1f1b
commit 3efb369221
3 changed files with 298 additions and 182 deletions

View File

@ -16,7 +16,7 @@ namespace InSituLaboratory.IService
IEnumerable<SysDevice> GetDevices();
/// <summary>
/// 根据设备名称获取设备ID
/// 根据设备名称获取设备预设工作时长
/// </summary>
/// <param name="DeviceName"></param>
/// <returns></returns>

View File

@ -20,6 +20,12 @@ namespace InSituLaboratory.Service
return this.Set<SysDevice>();
}
/// <summary>
/// 根据设备名称查询预设工作时长
/// </summary>
/// <param name="DeviceName"></param>
/// <returns></returns>
public string GetDeviceByDeviceName(string DeviceName)
{
var workTime = "";

View File

@ -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
@ -52,11 +54,12 @@ namespace InSituLaboratory.ViewModels.Pages.Dialogs
/// </summary>
public string kind { get; set; }
private string _sequenceGroup;
/// <summary>
/// 配置
/// </summary>
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<string> { "当前配置存在循环时长:" + SysSequentialdata.DurationTime +"s"});
}
else
{
ErrorList.Remove("DurationTime");
}
this.RaiseErrorsChanged("DurationTime");
//SysSequentialdata = _sequentialService.GetSequentialSequenceGroup(SequenceGroup, kind);
//if (SysSequentialdata != null)
//{
// ErrorList.Add("DurationTime", new List<string> { "当前配置存在循环时长:" + SysSequentialdata.DurationTime + "s" });
//}
//else
//{
// ErrorList.Remove("DurationTime");
//}
//this.RaiseErrorsChanged("DurationTime");
}
}
private string? _sensorID;
/// <summary>
/// 传感器设备
/// </summary>
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<string> { "质谱仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "二氧化碳同位素分析仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(WorkTime) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "二氧化碳同位素分析仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "甲烷同位素分析仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(WorkTime) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "甲烷同位素分析仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "气相色谱仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(WorkTime) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "气相色谱仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "基因测序仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(WorkTime) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "基因测序仪已超出最大工作时长" });
}
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<SysSequentialDetails>(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<string> { "质谱仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
// }
// else if (_sensorID == "二氧化碳同位素分析仪")
// {
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(WorkTime) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "二氧化碳同位素分析仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
// }
// else if (_sensorID == "甲烷同位素分析仪")
// {
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(WorkTime) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "甲烷同位素分析仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
// }
// else if (_sensorID == "气相色谱仪")
// {
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(WorkTime) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "气相色谱仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
// }
// else if (_sensorID == "基因测序仪")
// {
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(WorkTime) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "基因测序仪已超出最大工作时长" });
// }
// 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<string> { "工作时长不能为空" });
}
else if (_sensorID == "质谱仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(value) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "质谱仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "二氧化碳同位素分析仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(value) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "二氧化碳同位素分析仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "甲烷同位素分析仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(value) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "甲烷同位素分析仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "气相色谱仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(value) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "气相色谱仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else if (_sensorID == "基因测序仪")
{
workInt = Convert.ToInt64(workTime) * 60 * 60;
if (Convert.ToInt64(value) > workInt)
{
ErrorList.Add("WorkTime", new List<string> { "基因测序仪已超出最大工作时长" });
}
else
{
ErrorList.Remove("WorkTime");
}
}
else
{
ErrorList.Remove("WorkTime");
}
this.RaiseErrorsChanged("WorkTime");
//this.ErrorList.Clear();
//if (string.IsNullOrEmpty(value))
//{
// ErrorList.Add("WorkTime", new List<string> { "工作时长不能为空" });
//}
//else if (_sensorID == "质谱仪")
//{
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(value) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "质谱仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
//}
//else if (_sensorID == "二氧化碳同位素分析仪")
//{
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(value) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "二氧化碳同位素分析仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
//}
//else if (_sensorID == "甲烷同位素分析仪")
//{
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(value) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "甲烷同位素分析仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
//}
//else if (_sensorID == "气相色谱仪")
//{
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(value) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "气相色谱仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
//}
//else if (_sensorID == "基因测序仪")
//{
// workInt = Convert.ToInt64(workTime) * 60 * 60;
// if (Convert.ToInt64(value) > workInt)
// {
// ErrorList.Add("WorkTime", new List<string> { "基因测序仪已超出最大工作时长" });
// }
// else
// {
// ErrorList.Remove("WorkTime");
// }
//}
//else
//{
// ErrorList.Remove("WorkTime");
//}
//this.RaiseErrorsChanged("WorkTime");
}
}
private string _durationTime;
/// <summary>
/// 循环时长
/// </summary>
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<string> { "当前配置已存在循环时长:" + 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<string> { "当前配置已存在循环时长:" + 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<SysSequentialDetails>(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<SysSequentialDetails>(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, "提示");
}
}