PlcPointOffserParamsViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using Prism.Services.Dialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Windows;
  9. using TeamAAS_VP.Interfaces;
  10. using TeamAAS_VP.Models;
  11. using TeamAAS_VP.Models.PLC;
  12. using TeamAAS_VP.Resources.Languages;
  13. using TeamAAS_VP.Views.Setting;
  14. namespace TeamAAS_VP.ViewModels.Product
  15. {
  16. public class PlcPointOffserParamsViewModel : BindableBase, IDialogAware
  17. {
  18. #region 属性
  19. private ObservableCollection<PlcPoint> _Points = new ObservableCollection<PlcPoint>();
  20. /// <summary>
  21. /// 点位集合
  22. /// </summary>
  23. public ObservableCollection<PlcPoint> Points
  24. {
  25. get { return _Points; }
  26. set { SetProperty(ref _Points, value); }
  27. }
  28. #endregion
  29. #region 命令
  30. private DelegateCommand _ConfirmCommand;
  31. public DelegateCommand ConfirmCommand =>
  32. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand, CanExecuteConfirmCommand));
  33. private DelegateCommand _CancelCommand;
  34. public DelegateCommand CancelCommand =>
  35. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  36. private DelegateCommand _ClearAllOffsetCommand;
  37. public DelegateCommand ClearAllOffsetCommand =>
  38. _ClearAllOffsetCommand ?? (_ClearAllOffsetCommand = new DelegateCommand(ExecuteClearAllOffsetCommand));
  39. #endregion
  40. public PlcPointOffserParamsViewModel()
  41. {
  42. }
  43. /// <summary>
  44. /// 确认按钮
  45. /// </summary>
  46. /// <returns></returns>
  47. bool CanExecuteConfirmCommand()
  48. {
  49. return true;
  50. }
  51. void ExecuteConfirmCommand()
  52. {
  53. IDialogParameters parameters = new DialogParameters();
  54. parameters.Add("Points", Points.ToArray());
  55. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  56. }
  57. /// <summary>
  58. /// 取消按钮
  59. /// </summary>
  60. void ExecuteCancelCommand()
  61. {
  62. IDialogParameters parameters = new DialogParameters();
  63. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  64. }
  65. /// <summary>
  66. /// 清除所有补偿值
  67. /// </summary>
  68. void ExecuteClearAllOffsetCommand()
  69. {
  70. foreach (var point in Points)
  71. {
  72. point.X_Offset = 0;
  73. point.Y_Offset = 0;
  74. point.Z_Start_Offset = 0;
  75. point.Z_Stop_Offset = 0;
  76. point.U_Offset = 0;
  77. point.R_Offset = 0;
  78. }
  79. }
  80. private string _Title;
  81. public string Title
  82. {
  83. get { return _Title; }
  84. set { SetProperty(ref _Title, value); }
  85. }
  86. public event Action<IDialogResult> RequestClose;
  87. public bool CanCloseDialog()
  88. {
  89. return true;
  90. }
  91. public void OnDialogClosed()
  92. {
  93. }
  94. public void OnDialogOpened(IDialogParameters parameters)
  95. {
  96. Title = parameters.GetValue<string>("Title");
  97. var pts = parameters.GetValue<PlcPoint[]>("Points");
  98. if (pts != null)
  99. {
  100. Points = new ObservableCollection<PlcPoint>(pts);
  101. }
  102. }
  103. }
  104. }