123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- 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 AddOrEditDeviceKindViewModel : BindableBase, IDialogAware
- {
- private readonly IEventAggregator _aggregator;
- private readonly IBasicDeviceKindService _iBasicDeviceKindService;
- private readonly IMapper _mapper;
-
- private long id = 0;
- public AddOrEditDeviceKindViewModel(IEventAggregator aggregator, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper)
- {
- _aggregator = aggregator;
- _iBasicDeviceKindService = iBasicDeviceKindService;
- _mapper = mapper;
- CloseCommand = new DelegateCommand(Close);
- SureCommand = new DelegateCommand<string>(Sure);
- CancelCommand = new DelegateCommand(Close);
- }
- #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<BasDeviceKindDto>("Key");
- ///值不为空,表示修改
- if (getMsg != null)
- {
- foreach (var item in getMsg)
- {
- if (item != null)
- {
- Title = "修改设备类型";
- DeviceKindName = item.DeviceKindName;
- DeviceKindNo = item.DeviceKindNo;
-
- 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(DeviceKindName))
- {
- MessageBox.Show("请填写设备类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
- if (string.IsNullOrEmpty(DeviceKindNo))
- {
- MessageBox.Show("请填写设备类型编号!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
-
- BasDeviceKindDto basDeviceKind = new BasDeviceKindDto();
- basDeviceKind.DeviceKindName = DeviceKindName;
- basDeviceKind.DeviceKindNo = DeviceKindNo;
- basDeviceKind.Remark = Remark;
- DialogParameters parm = new DialogParameters();
- parm.Add("ReturnValue", basDeviceKind);
- 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 deviceKindName;
- public string DeviceKindName
- {
- get { return deviceKindName; }
- set { deviceKindName = value; RaisePropertyChanged(); }
- }
- private string deviceKindNo;
- public string DeviceKindNo
- {
- get { return deviceKindNo; }
- set { deviceKindNo = value; RaisePropertyChanged(); }
- }
-
- private string remark;
- public string Remark
- {
- get { return remark; }
- set { remark = value; RaisePropertyChanged(); }
- }
- #endregion
- }
- }
|