AddOrEditDeviceKindViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using AutoMapper;
  2. using BizService;
  3. using Model.Dto;
  4. using Prism.Commands;
  5. using Prism.Events;
  6. using Prism.Mvvm;
  7. using Prism.Services.Dialogs;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. namespace PLCTool.ViewModels.BasicConfigViewModel
  15. {
  16. public class AddOrEditDeviceKindViewModel : BindableBase, IDialogAware
  17. {
  18. private readonly IEventAggregator _aggregator;
  19. private readonly IBasicDeviceKindService _iBasicDeviceKindService;
  20. private readonly IMapper _mapper;
  21. private long id = 0;
  22. public AddOrEditDeviceKindViewModel(IEventAggregator aggregator, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper)
  23. {
  24. _aggregator = aggregator;
  25. _iBasicDeviceKindService = iBasicDeviceKindService;
  26. _mapper = mapper;
  27. CloseCommand = new DelegateCommand(Close);
  28. SureCommand = new DelegateCommand<string>(Sure);
  29. CancelCommand = new DelegateCommand(Close);
  30. }
  31. #region idialog接口实现
  32. public string Title { set; get; } = "新增设备类型";
  33. public event Action<IDialogResult> RequestClose;
  34. public bool CanCloseDialog()
  35. {
  36. return true;
  37. }
  38. public void OnDialogClosed()
  39. {
  40. }
  41. public void OnDialogOpened(IDialogParameters parameters)
  42. {
  43. var getMsg = parameters.GetValues<BasDeviceKindDto>("Key");
  44. ///值不为空,表示修改
  45. if (getMsg != null)
  46. {
  47. foreach (var item in getMsg)
  48. {
  49. if (item != null)
  50. {
  51. Title = "修改设备类型";
  52. DeviceKindName = item.DeviceKindName;
  53. DeviceKindNo = item.DeviceKindNo;
  54. Remark = item.Remark;
  55. }
  56. }
  57. }
  58. }
  59. #endregion
  60. #region 私有方法
  61. private void Close()
  62. {
  63. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
  64. }
  65. /// <summary>
  66. /// 确认
  67. /// </summary>
  68. /// <param name="obj"></param>
  69. private void Sure(string obj)
  70. {
  71. if (string.IsNullOrEmpty(DeviceKindName))
  72. {
  73. MessageBox.Show("请填写设备类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  74. return;
  75. }
  76. if (string.IsNullOrEmpty(DeviceKindNo))
  77. {
  78. MessageBox.Show("请填写设备类型编号!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  79. return;
  80. }
  81. BasDeviceKindDto basDeviceKind = new BasDeviceKindDto();
  82. basDeviceKind.DeviceKindName = DeviceKindName;
  83. basDeviceKind.DeviceKindNo = DeviceKindNo;
  84. basDeviceKind.Remark = Remark;
  85. DialogParameters parm = new DialogParameters();
  86. parm.Add("ReturnValue", basDeviceKind);
  87. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parm));
  88. }
  89. /// <summary>
  90. /// 重置
  91. /// </summary>
  92. /// <param name="obj"></param>
  93. private void ResetMethod(string obj)
  94. {
  95. }
  96. #endregion
  97. #region 命令绑定
  98. public DelegateCommand CloseCommand { set; get; }
  99. public DelegateCommand<string> SureCommand { set; get; }
  100. public DelegateCommand CancelCommand { set; get; }
  101. public DelegateCommand TxtLostFocusCommand { set; get; }
  102. public DelegateCommand TxtPLCValueLostFocusCommand { set; get; }
  103. #endregion
  104. #region 变量绑定
  105. private string deviceKindName;
  106. public string DeviceKindName
  107. {
  108. get { return deviceKindName; }
  109. set { deviceKindName = value; RaisePropertyChanged(); }
  110. }
  111. private string deviceKindNo;
  112. public string DeviceKindNo
  113. {
  114. get { return deviceKindNo; }
  115. set { deviceKindNo = value; RaisePropertyChanged(); }
  116. }
  117. private string remark;
  118. public string Remark
  119. {
  120. get { return remark; }
  121. set { remark = value; RaisePropertyChanged(); }
  122. }
  123. #endregion
  124. }
  125. }