123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using AutoMapper;
- using BizService;
- using Model.Dto;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PLCTool.ViewModels.BasicConfigViewModel
- {
-
- public class AddOrEditDeviceViewModel : BindableBase, IDialogAware
- {
- private readonly IEventAggregator _aggregator;
- private readonly IBasicDeviceService _iBasicDeviceService;
- private readonly IBasicDeviceKindService _iBasicDeviceKindService;
- private readonly IBasicProjectService _iBasicProjectService;
- private readonly IMapper _mapper;
- private long id = 0;
- public AddOrEditDeviceViewModel(IEventAggregator aggregator, IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService,IBasicProjectService iBasicProjectService, IMapper mapper)
- {
- _aggregator = aggregator;
- _iBasicDeviceService = iBasicDeviceService;
- _iBasicDeviceKindService = iBasicDeviceKindService;
- _iBasicProjectService= iBasicProjectService;
- _mapper = mapper;
- CloseCommand = new DelegateCommand(Close);
- SureCommand = new DelegateCommand<string>(Sure);
- CancelCommand = new DelegateCommand(Close);
- DeviceKindNameList= _iBasicDeviceKindService.FindAllDeviceKind();
- ProjectNameList = _iBasicProjectService.FindAllProject();
- }
- #region idialog接口实现
- public string Title { set; get; } = "新增设备";
- public event Action<IDialogResult> RequestClose;
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- var getMsg = parameters.GetValues<BasDeviceDto>("Key");
- ///值不为空,表示修改
- if (getMsg != null)
- {
- foreach (var item in getMsg)
- {
- if (item != null)
- {
- Title = "修改设备";
- DeviceName = item.DeviceName;
- DeviceNo = item.DeviceNo;
- ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name;
- DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
- Remark = item.Remark;
- }
- }
- }
- }
- #endregion
- #region 私有方法
- private void Close()
- {
- RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
- }
- /// <summary>
- /// 确认
- /// </summary>
- /// <param name="obj"></param>
- private void Sure(string obj)
- {
- if (string.IsNullOrEmpty(DeviceName))
- {
- MessageBox.Show("请填写设备名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
- if (string.IsNullOrEmpty(DeviceNo))
- {
- MessageBox.Show("请填写设备编号!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
- if (string.IsNullOrEmpty(ProjectName))
- {
- MessageBox.Show("请选择项目名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
- if (string.IsNullOrEmpty(DeviceKindName))
- {
- MessageBox.Show("请填写设备类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
- BasDeviceDto basDevice = new BasDeviceDto();
- basDevice.DeviceName = DeviceName;
- basDevice.DeviceNo = DeviceNo;
- basDevice.ProjectId= (long)(_iBasicProjectService.FindByProjectName(ProjectName)?.project_id);
- basDevice.DeviceKindId= (long)(_iBasicDeviceKindService.FindByDeviceKindName(DeviceKindName)?.devicekind_id);
- basDevice.Remark = Remark;
- DialogParameters parm = new DialogParameters();
- parm.Add("ReturnValue", basDevice);
- RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parm));
- }
- /// <summary>
- /// 重置
- /// </summary>
- /// <param name="obj"></param>
- private void ResetMethod(string obj)
- {
- }
- #endregion
- #region 命令绑定
- public DelegateCommand CloseCommand { set; get; }
- public DelegateCommand<string> SureCommand { set; get; }
- public DelegateCommand CancelCommand { set; get; }
- public DelegateCommand TxtLostFocusCommand { set; get; }
- public DelegateCommand TxtPLCValueLostFocusCommand { set; get; }
- #endregion
- #region 变量绑定
- private string deviceName;
- public string DeviceName
- {
- get { return deviceName; }
- set { deviceName = value; RaisePropertyChanged(); }
- }
- private string deviceNo;
- public string DeviceNo
- {
- get { return deviceNo; }
- set { deviceNo = value; RaisePropertyChanged(); }
- }
- private string projectName;
- public string ProjectName
- {
- get { return projectName; }
- set { projectName = value; RaisePropertyChanged(); }
- }
- private string deviceKindName;
- public string DeviceKindName
- {
- get { return deviceKindName; }
- set { deviceKindName = value; RaisePropertyChanged(); }
- }
- private List<string> projectNameList;
- public List<string> ProjectNameList
- {
- get { return projectNameList; }
- set { projectNameList = value; RaisePropertyChanged(); }
- }
- private List<string> deviceKindNameList;
- public List<string> DeviceKindNameList
- {
- get { return deviceKindNameList; }
- set { deviceKindNameList = value; RaisePropertyChanged(); }
- }
- private string remark;
- public string Remark
- {
- get { return remark; }
- set { remark = value; RaisePropertyChanged(); }
- }
- #endregion
- }
- }
|