SetAlarmValueViewModel.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using Prism.Services.Dialogs;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using TeamAAS_VP.Core;
  10. using TeamAAS_VP.Models;
  11. namespace TeamAAS_VP.ViewModels.Home
  12. {
  13. public class SetAlarmValueViewModel : BindableBase, IDialogAware
  14. {
  15. #region 属性
  16. private int _BitAlarmValue;
  17. public int BitAlarmValue
  18. {
  19. get { return _BitAlarmValue; }
  20. set { SetProperty(ref _BitAlarmValue, value); }
  21. }
  22. private int _NozzleAlarmValue;
  23. public int NozzleAlarmValue
  24. {
  25. get { return _NozzleAlarmValue; }
  26. set { SetProperty(ref _NozzleAlarmValue, value); }
  27. }
  28. private NumberStatistics _NumStatistics = new NumberStatistics();
  29. /// <summary>
  30. /// 数量(批头、吸嘴、供料器)
  31. /// </summary>
  32. public NumberStatistics NumStatistics
  33. {
  34. get { return _NumStatistics; }
  35. set { SetProperty(ref _NumStatistics, value); }
  36. }
  37. #endregion
  38. #region 命令
  39. private DelegateCommand _ConfirmCommand;
  40. public DelegateCommand ConfirmCommand =>
  41. _ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
  42. private DelegateCommand _CancelCommand;
  43. public DelegateCommand CancelCommand =>
  44. _CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
  45. #endregion
  46. void ExecuteCancelCommand()
  47. {
  48. IDialogParameters parameters = new DialogParameters();
  49. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel, parameters));
  50. }
  51. void ExecuteConfirmCommand()
  52. {
  53. NumStatistics.NozzleAlarmValue = NozzleAlarmValue;
  54. NumStatistics.HeaderAlarmValue = BitAlarmValue;
  55. FileHelper.WriteJsonFile(NumStatistics, FilePath.NumberStatisticsPath);
  56. IDialogParameters parameters = new DialogParameters();
  57. RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
  58. }
  59. public string Title => "Set Bit/Nozzle Alarm Value";
  60. public event Action<IDialogResult> RequestClose;
  61. public bool CanCloseDialog()
  62. {
  63. return true;
  64. }
  65. public void OnDialogClosed()
  66. {
  67. }
  68. public void OnDialogOpened(IDialogParameters parameters)
  69. {
  70. try
  71. {
  72. var res = FileHelper.ReadJsonFile<NumberStatistics>(FilePath.NumberStatisticsPath);
  73. if (res != null)
  74. {
  75. BitAlarmValue = res.HeaderAlarmValue;
  76. NozzleAlarmValue = res.NozzleAlarmValue;
  77. }
  78. }
  79. catch (Exception)
  80. {
  81. }
  82. }
  83. }
  84. }