2024-08-22 08:01:33 +00:00
|
|
|
|
using InSituLaboratory.Entities;
|
|
|
|
|
|
using InSituLaboratory.IService;
|
|
|
|
|
|
using InSituLaboratory.Models;
|
|
|
|
|
|
using InSituLaboratory.Service;
|
2024-08-29 05:44:34 +00:00
|
|
|
|
using Microsoft.IdentityModel.Tokens;
|
2024-08-22 08:01:33 +00:00
|
|
|
|
using Prism.Commands;
|
|
|
|
|
|
using Prism.Services.Dialogs;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
2024-08-29 05:44:34 +00:00
|
|
|
|
using System.Windows.Forms;
|
2024-08-22 08:01:33 +00:00
|
|
|
|
|
|
|
|
|
|
namespace InSituLaboratory.ViewModels.Pages.Dialogs
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增/编辑设备配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class ModifySysDevicesViewModel : DialogViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public SysDevicesModel SysDevice { get; set; } = new SysDevicesModel();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ISysDevcieService _iSysDevcieService;
|
|
|
|
|
|
public ModifySysDevicesViewModel(ISysDevcieService sysDevcieService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_iSysDevcieService = sysDevcieService;
|
|
|
|
|
|
|
|
|
|
|
|
SaveCommand = new DelegateCommand(DoSave);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 打开弹窗
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parameters"></param>
|
|
|
|
|
|
public override void OnDialogOpened(IDialogParameters parameters)
|
|
|
|
|
|
{
|
|
|
|
|
|
var model = parameters.GetValue<SysDevicesModel>("model");
|
|
|
|
|
|
if (model == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = "新增参数配置";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = "编辑参数配置";
|
|
|
|
|
|
var sm = _iSysDevcieService.Find<SysDevice>(model.ID);
|
|
|
|
|
|
SysDevice.ID = sm.Id;
|
|
|
|
|
|
SysDevice.DeviceType = sm.DeviceType;
|
|
|
|
|
|
SysDevice.DeviceName = sm.DeviceName;
|
|
|
|
|
|
SysDevice.WorkTime = sm.WorkTime;
|
|
|
|
|
|
SysDevice.MinWorkTime = sm.MinWorkTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增/编辑保存
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void DoSave()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-08-29 05:44:34 +00:00
|
|
|
|
//非空校验
|
|
|
|
|
|
if (string.IsNullOrEmpty(SysDevice.DeviceType) || string.IsNullOrEmpty(SysDevice.DeviceName) || string.IsNullOrEmpty(SysDevice.WorkTime) || string.IsNullOrEmpty(SysDevice.MinWorkTime))
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("参数配置信息不能为空!");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 08:01:33 +00:00
|
|
|
|
//新增
|
|
|
|
|
|
if (SysDevice.ID == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_iSysDevcieService.Insert<SysDevice>(new SysDevice
|
|
|
|
|
|
{
|
|
|
|
|
|
DeviceType = SysDevice.DeviceType,
|
|
|
|
|
|
DeviceName = SysDevice.DeviceName,
|
|
|
|
|
|
WorkTime = SysDevice.WorkTime,
|
|
|
|
|
|
MinWorkTime = SysDevice.MinWorkTime,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
//编辑
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var entity = _iSysDevcieService.Find<SysDevice>(SysDevice.ID);
|
|
|
|
|
|
entity.DeviceType = SysDevice.DeviceType;
|
|
|
|
|
|
entity.DeviceName = SysDevice.DeviceName;
|
|
|
|
|
|
entity.WorkTime = SysDevice.WorkTime;
|
|
|
|
|
|
entity.MinWorkTime= SysDevice.MinWorkTime;
|
|
|
|
|
|
_iSysDevcieService.Update<SysDevice>(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
base.DoSave();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2024-08-29 05:44:34 +00:00
|
|
|
|
System.Windows.Forms.MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
2024-08-22 08:01:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|