93 lines
2.8 KiB
C#
93 lines
2.8 KiB
C#
|
|
using InSituLaboratory.Entities;
|
|||
|
|
using InSituLaboratory.IService;
|
|||
|
|
using InSituLaboratory.Models;
|
|||
|
|
using InSituLaboratory.Service;
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
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
|
|||
|
|
{
|
|||
|
|
//新增
|
|||
|
|
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)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show(ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|