107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
|
|
using InSituLaboratory.Entities;
|
|||
|
|
using InSituLaboratory.IService;
|
|||
|
|
using InSituLaboratory.Models;
|
|||
|
|
using InSituLaboratory.Service;
|
|||
|
|
using Microsoft.VisualBasic.ApplicationServices;
|
|||
|
|
using Prism.Regions;
|
|||
|
|
using Prism.Services.Dialogs;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows;
|
|||
|
|
|
|||
|
|
namespace InSituLaboratory.ViewModels.Pages
|
|||
|
|
{
|
|||
|
|
public class SysDeviceViewModel : ViewModelBase
|
|||
|
|
{
|
|||
|
|
ISysDevcieService _isysDevcieService;
|
|||
|
|
IDialogService _dialogService;
|
|||
|
|
|
|||
|
|
public SysDeviceViewModel(IRegionManager regionManager, ISysDevcieService sysDevcieService, IDialogService dialogService) : base(regionManager)
|
|||
|
|
{
|
|||
|
|
this.PageTitle = "传感器参数配置";
|
|||
|
|
|
|||
|
|
_isysDevcieService = sysDevcieService;
|
|||
|
|
_dialogService = dialogService;
|
|||
|
|
|
|||
|
|
this.Refresh();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
public ObservableCollection<SysDevicesModel> Devices { get; set; } = new ObservableCollection<SysDevicesModel>();
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 刷新
|
|||
|
|
/// </summary>
|
|||
|
|
public override void Refresh()
|
|||
|
|
{
|
|||
|
|
Devices.Clear();
|
|||
|
|
var devices = _isysDevcieService.GetDevices(SearchKey).ToList();
|
|||
|
|
|
|||
|
|
int index = 1;
|
|||
|
|
foreach (var device in devices)
|
|||
|
|
{
|
|||
|
|
SysDevicesModel sysDevicesModel = new SysDevicesModel
|
|||
|
|
{
|
|||
|
|
Index = index++,
|
|||
|
|
ID = device.Id,
|
|||
|
|
DeviceType = device.DeviceType,
|
|||
|
|
DeviceName = device.DeviceName,
|
|||
|
|
WorkTime = device.WorkTime,
|
|||
|
|
MinWorkTime = device.MinWorkTime
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
Devices.Add(sysDevicesModel);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 新增/编辑
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="model"></param>
|
|||
|
|
public override void DoModify(object model)
|
|||
|
|
{
|
|||
|
|
DialogParameters ps = new DialogParameters();
|
|||
|
|
ps.Add("model", model);
|
|||
|
|
_dialogService.ShowDialog("ModifySysDevicesView", ps, result =>
|
|||
|
|
{
|
|||
|
|
// 判断子窗口的返回状态,如果OK,刷新当前页面,否则不管
|
|||
|
|
if (result.Result == ButtonResult.OK)
|
|||
|
|
{
|
|||
|
|
this.Refresh();
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 删除
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="model"></param>
|
|||
|
|
public override void DoDelete(object model)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (MessageBox.Show("是否确定删除此项?", "提示", MessageBoxButton.YesNo) ==
|
|||
|
|
MessageBoxResult.Yes)
|
|||
|
|
{
|
|||
|
|
// 物理删除
|
|||
|
|
_isysDevcieService.Delete<SysDevice>((model as SysDevicesModel).ID);
|
|||
|
|
|
|||
|
|
MessageBox.Show("删除完成!", "提示");
|
|||
|
|
|
|||
|
|
Devices.Remove(model as SysDevicesModel);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show(ex.Message, "提示");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|