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

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(); IEnumerable<SysDevice> GetDevices();
/// <summary> /// <summary>
/// 根据设备名称获取设备ID /// 根据设备名称获取设备预设工作时长
/// </summary> /// </summary>
/// <param name="DeviceName"></param> /// <param name="DeviceName"></param>
/// <returns></returns> /// <returns></returns>

View File

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

View File

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