20230201_145_upperpc/InSituLaboratory/ViewModels/Pages/Dialogs/ModifySequentialViewModel.cs

481 lines
21 KiB
C#
Raw Normal View History

2024-04-09 08:17:44 +00:00
using InSituLaboratory.Entities;
using InSituLaboratory.IService;
using InSituLaboratory.Models;
using InSituLaboratory.Service;
using Microsoft.IdentityModel.Tokens;
2024-04-09 08:17:44 +00:00
using Microsoft.VisualBasic.ApplicationServices;
2024-03-27 13:49:16 +00:00
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-04-09 08:17:44 +00:00
using System.Windows;
using System.Windows.Forms;
2024-04-10 09:50:54 +00:00
using System.Windows.Media.Animation;
2024-03-27 13:49:16 +00:00
namespace InSituLaboratory.ViewModels.Pages.Dialogs
{
2024-04-09 08:17:44 +00:00
/// <summary>
/// 新增或者增加时序
/// </summary>
public class ModifySequentialViewModel : DialogViewModelBase
2024-03-27 13:49:16 +00:00
{
2024-04-10 09:50:54 +00:00
#region Model
/// <summary>
/// 传感器设备集合
/// </summary>
2024-04-09 08:17:44 +00:00
public List<SysDevice> DeviceNodes { get; set; } = new List<SysDevice>();
public SysSequentialDetails SysSequentialdata { get; set; }
2024-04-11 09:49:43 +00:00
public List<Int32> Intlist { get; set; } = new List<Int32>() { 1, 2, 3, 4, 5, 6 };
2024-04-10 09:50:54 +00:00
public string? workTime { get; set; }
2024-06-28 09:51:00 +00:00
public string? minworkTime { get; set; }
2024-04-10 09:50:54 +00:00
public long? workInt { get; set; }
2024-06-28 09:51:00 +00:00
public long? minworkInt { get; set; }
/// <summary>
/// 记录编辑时第一次带入的设备名称
/// </summary>
public string Device { get; set; }
2024-04-10 09:50:54 +00:00
/// <summary>
/// 开始时间
/// </summary>
2024-04-09 08:17:44 +00:00
public DateTime? startTime { get; set; }
2024-04-10 09:50:54 +00:00
/// <summary>
/// 结束时间
/// </summary>
2024-04-09 08:17:44 +00:00
public DateTime? endTime { get; set; }
2024-04-12 05:30:03 +00:00
/// <summary>
/// 序号
/// </summary>
public int Number { get; set; }
/// <summary>
/// 时序类别
/// </summary>
public string kind { get; set; }
private string _sequenceGroup;
2024-04-10 09:50:54 +00:00
/// <summary>
/// 配置
/// </summary>
2024-04-11 09:49:43 +00:00
public string SequenceGroup
{
get { return _sequenceGroup; }
set
{
_sequenceGroup = value;
}
}
private string? _sensorID;
2024-04-10 09:50:54 +00:00
/// <summary>
/// 传感器设备
/// </summary>
public string? SensorID
2024-04-10 09:50:54 +00:00
{
2024-04-11 09:49:43 +00:00
get { return _sensorID; }
set
{
2024-04-10 09:50:54 +00:00
_sensorID = value;
}
}
2024-04-09 08:17:44 +00:00
2024-06-28 09:51:00 +00:00
private float? _workTime;
2024-04-10 09:50:54 +00:00
/// <summary>
/// 工作时长
/// </summary>
2024-06-28 09:51:00 +00:00
public float? WorkTime
2024-04-10 09:50:54 +00:00
{
get { return _workTime; }
2024-04-11 09:49:43 +00:00
set
2024-04-10 09:50:54 +00:00
{
_workTime = value;
}
}
2024-06-28 09:51:00 +00:00
private float? _durationTime;
2024-04-12 05:30:03 +00:00
/// <summary>
/// 循环时长
/// </summary>
2024-06-28 09:51:00 +00:00
public float? DurationTime
2024-04-12 05:30:03 +00:00
{
get { return _durationTime; }
set
{
_durationTime = value;
}
}
2024-06-19 02:19:37 +00:00
private string totalKind;
2024-04-10 09:50:54 +00:00
#endregion
2024-04-09 08:17:44 +00:00
ISysSequentialService _sequentialService;
IDeviceSvice _deviceSvice;
public ModifySequentialViewModel(ISysSequentialService sequentialService, IDeviceSvice deviceSvice)
2024-03-27 13:49:16 +00:00
{
2024-04-09 08:17:44 +00:00
_sequentialService = sequentialService;
_deviceSvice = deviceSvice;
2024-03-27 13:49:16 +00:00
}
public override void OnDialogOpened(IDialogParameters parameters)
{
2024-04-09 08:17:44 +00:00
var SequentialDetail = parameters.GetValue<SysSequentialDetails>("model");
startTime = parameters.GetValue<DateTime>("sequentialStartTime");
endTime = parameters.GetValue<DateTime>("sequentialEndTime");
kind = parameters.GetValue<string>("kind");
2024-04-11 09:49:43 +00:00
2024-04-09 08:17:44 +00:00
2024-06-19 02:19:37 +00:00
2024-04-09 08:17:44 +00:00
if (SequentialDetail == null)
{
this.Title = "新增时序配置";
}
else
{
this.Title = "编辑时序配置";
var su = _sequentialService.Find<SysSequentialDetails>(SequentialDetail.Number);
Number = su.Number;
SequenceGroup = su.SequenceGroup;
2024-04-09 08:17:44 +00:00
SensorID = su.SensorID;
2024-04-11 09:49:43 +00:00
WorkTime = su.WorkTime;
2024-04-09 08:17:44 +00:00
DurationTime = su.DurationTime;
Device = SensorID;
2024-04-09 08:17:44 +00:00
}
DeviceNodes = _deviceSvice.GetDevices().ToList();
2024-03-27 13:49:16 +00:00
}
public override void DoSave()
{
2024-04-09 08:17:44 +00:00
try
{
//非空校验
if (string.IsNullOrEmpty(SequenceGroup))
{
2024-07-01 10:12:44 +00:00
System.Windows.Forms.MessageBox.Show("子时序号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else if (string.IsNullOrEmpty(SensorID))
{
2024-07-01 10:12:44 +00:00
System.Windows.Forms.MessageBox.Show("设备编号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
2024-06-28 09:51:00 +00:00
else if (WorkTime == null || WorkTime == 0)
{
System.Windows.Forms.MessageBox.Show("工作时长不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
2024-06-28 09:51:00 +00:00
else if (DurationTime == null || DurationTime == 0)
{
2024-07-01 10:12:44 +00:00
System.Windows.Forms.MessageBox.Show("循环间隔时长不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
var data = _sequentialService.GetSequentials(kind).ToList();
if (data.Count != 0)
{
var data1 = _sequentialService.GetSequentials(kind).First();
if (data1.StartTime == startTime && data1.EndTime == endTime)
{
//编辑情况下
if (Number != 0)
{
if (Device != SensorID)
{
//传感器是否已存在校验
var selectFirst = _sequentialService.Query<SysSequentialDetails>(m => m.SensorID == SensorID && m.Sequential == kind && m.IsDelete == 0).ToList();
if (selectFirst.Count != 0)
{
foreach (var item in selectFirst)
{
2024-07-01 10:12:44 +00:00
System.Windows.Forms.MessageBox.Show(kind + "- 子时序" + item.SequenceGroup + "中,已配置" + SensorID + "" + " 请重新配置。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
}
}
else
{
//传感器是否已存在校验
var select = _sequentialService.Query<SysSequentialDetails>(m => m.SensorID == SensorID && m.Sequential == kind && m.IsDelete == 0).ToList();
if (select.Count != 0)
{
foreach (var item in select)
{
2024-07-01 10:12:44 +00:00
System.Windows.Forms.MessageBox.Show(kind + "- 子时序" + item.SequenceGroup + "中,已配置" + SensorID + "" + " 请重新配置。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
}
}
///循环时长校验
if (data1.StartTime == startTime && data1.EndTime == endTime)
{
var SysSequentialdata1 = _sequentialService.GetSequentialSequenceGroup(SequenceGroup, kind, data1.Number);
if (SysSequentialdata1 != null)
{
if (DurationTime != SysSequentialdata1.DurationTime)
{
2024-07-01 10:12:44 +00:00
System.Windows.Forms.MessageBox.Show(kind + "- 子时序" + SequenceGroup + " 已存在循环时长:" + SysSequentialdata1.DurationTime + "分钟" + ",无法修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
}
}
}
///工作时长是否已超过传感器预设时间
workTime = _deviceSvice.GetDeviceByDeviceName(SensorID);
2024-06-28 09:51:00 +00:00
minworkTime = _deviceSvice.GetDeviceByDeviceNameMinTime(SensorID);
if (workTime == "无")
2024-04-11 09:49:43 +00:00
{
workTime = "0";
}
2024-06-28 09:51:00 +00:00
if (minworkTime == "无")
{
minworkTime = "0";
}
workInt = Convert.ToInt64(workTime); //设备预设最大工作时长
minworkInt = Convert.ToInt64(minworkTime);//设备预设最小工作时长
switch (SensorID)
{
case "气相色谱仪":
if (Convert.ToInt64(WorkTime) > workInt)
{
2024-06-28 09:51:00 +00:00
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else if (Convert.ToInt64(WorkTime) < minworkInt)
{
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
break;
case "质谱仪":
if (Convert.ToInt64(WorkTime) > workInt)
{
2024-06-28 09:51:00 +00:00
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else if (Convert.ToInt64(WorkTime) < minworkInt)
{
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
break;
case "二氧化碳同位素分析仪":
if (Convert.ToInt64(WorkTime) > workInt)
{
2024-06-28 09:51:00 +00:00
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",已超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else if (Convert.ToInt64(WorkTime) < minworkInt)
{
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
break;
2024-06-28 09:51:00 +00:00
case "甲烷传感器":
if (Convert.ToInt64(WorkTime) > workInt)
{
2024-06-28 09:51:00 +00:00
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + "超过设备最大工作时长:" + workTime + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else if (Convert.ToInt64(WorkTime) < minworkInt)
{
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
break;
case "显微拉曼分析仪":
if (Convert.ToInt64(WorkTime) < minworkInt)
{
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
break;
case "色质联用":
if (Convert.ToInt64(WorkTime) < minworkInt)
{
System.Windows.Forms.MessageBox.Show("您填写的" + SensorID + "设置的工作时长:" + WorkTime + "分钟" + ",未能达到设备最小工作时长:" + minworkInt + "分钟" + "\n 请修改您填写的设备工作时长后重试!!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
break;
default:
break;
}
2024-04-09 08:17:44 +00:00
//保存时 首次去查询 data == null 说明数据库中无数据 为第一次插入
if (data.Count() == 0)
{
_sequentialService.Insert(new SysSequential
{
StartTime = startTime,
EndTime = endTime,
CreateTime = DateTime.Now,
Sequential = kind,
Status = "已生成未下发",
2024-04-09 08:17:44 +00:00
IsDelete = 0
});
var Squential = _sequentialService.Query<SysSequential>(m => m.Sequential == kind).OrderByDescending(n => n.CreateTime).First();
_sequentialService.Insert(new SysSequentialDetails
{
SysSquentialID = Squential.Number,
SensorID = SensorID,
DurationTime = DurationTime,
2024-04-11 09:49:43 +00:00
WorkTime = WorkTime,
SequenceGroup = SequenceGroup,
2024-04-09 08:17:44 +00:00
CreateTime = DateTime.Now,
Sequential = kind,
IsDelete = 0
});
//向时序总表中插入相应的数据
_sequentialService.Insert(new SysSequentialTotal
{
Sequential = kind,
StartTime = startTime,
EndTime = endTime,
SensorID = SensorID,
DurationTime = DurationTime,
WorkTime = WorkTime,
SequenceGroup = SequenceGroup,
CreateTime = DateTime.Now,
Status = "已生成未下发",
IsDelete = 0
});
2024-04-09 08:17:44 +00:00
}
else
{
//判断查询的当前时序开始和结束时间与打开的窗口传值是否有变化
//无变化说明是在当前时序下新增传感器运行时间配置
var data1 = _sequentialService.GetSequentials(kind).First();
if (data1.StartTime == startTime && data1.EndTime == endTime)
{
//新增传感器配置
if (Number == 0)
{
_sequentialService.Insert(new SysSequentialDetails
{
SysSquentialID = data1.Number,
SensorID = SensorID,
DurationTime = DurationTime,
WorkTime = WorkTime,
SequenceGroup = SequenceGroup,
2024-04-09 08:17:44 +00:00
CreateTime = DateTime.Now,
Sequential = kind,
IsDelete = 0
});
//向时序总表中插入相应的数据
_sequentialService.Insert(new SysSequentialTotal
{
Sequential = kind,
StartTime = startTime,
EndTime = endTime,
SensorID = SensorID,
DurationTime = DurationTime,
WorkTime = WorkTime,
SequenceGroup = SequenceGroup,
CreateTime = DateTime.Now,
Status = "已生成未下发",
IsDelete = 0
});
2024-04-09 08:17:44 +00:00
}
else
{
//修改传感器配置
var ssd = _sequentialService.Find<SysSequentialDetails>(Number);
ssd.SensorID = SensorID;
ssd.DurationTime = DurationTime;
2024-04-11 09:49:43 +00:00
ssd.WorkTime = WorkTime;
ssd.SequenceGroup = SequenceGroup;
2024-04-09 08:17:44 +00:00
_sequentialService.Update(ssd);
//修改时序总表中的相应的数据
var ssm = _sequentialService.Find<SysSequentialTotal>(Number);
ssm.SensorID = SensorID;
ssm.DurationTime = DurationTime;
ssm.WorkTime = WorkTime;
ssm.SequenceGroup = SequenceGroup;
_sequentialService.Update(ssd);
2024-04-09 08:17:44 +00:00
}
}
else
{
//新的时序
_sequentialService.Insert(new SysSequential
{
StartTime = startTime,
EndTime = endTime,
CreateTime = DateTime.Now,
Sequential = kind,
Status = "已生成未下发",
2024-04-09 08:17:44 +00:00
IsDelete = 0
});
var Squential = _sequentialService.Query<SysSequential>(m => m.Sequential == kind).OrderByDescending(n => n.CreateTime).First();
_sequentialService.Insert(new SysSequentialDetails
{
SysSquentialID = Squential.Number,
SensorID = SensorID,
DurationTime = DurationTime,
2024-04-11 09:49:43 +00:00
WorkTime = WorkTime,
SequenceGroup = SequenceGroup,
2024-04-09 08:17:44 +00:00
CreateTime = DateTime.Now,
Sequential = kind,
IsDelete = 0
});
//向时序总表中插入相应的数据
_sequentialService.Insert(new SysSequentialTotal
{
Sequential = kind,
StartTime = startTime,
EndTime = endTime,
SensorID = SensorID,
DurationTime = DurationTime,
WorkTime = WorkTime,
SequenceGroup = SequenceGroup,
CreateTime = DateTime.Now,
Status = "已生成未下发",
IsDelete = 0
});
2024-04-09 08:17:44 +00:00
}
}
2024-04-11 09:49:43 +00:00
2024-04-09 08:17:44 +00:00
base.DoSave();
2024-03-27 13:49:16 +00:00
2024-04-09 08:17:44 +00:00
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
2024-04-09 08:17:44 +00:00
}
2024-03-27 13:49:16 +00:00
}
}
}