OeeDialogPageViewModel.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using HandyControl.Tools.Extension;
  2. using LogoForceTestApp.Core.Mvvm;
  3. using Prism.Commands;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel.DataAnnotations;
  10. using Validar;
  11. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  12. {
  13. [InjectValidation]
  14. internal class OeeDialogPageViewModel : BindableBase, IDialogAware
  15. {
  16. public DelegateCommand CloseCmd { get; set; }
  17. public string Message { get; set; }
  18. public DateTime ExceptionTime{ get; set; }
  19. public string Result { get; set; }
  20. public Action CloseAction { get ; set ; }
  21. public string Title { get; }
  22. public string OP_Id { get; set; }
  23. [Required]
  24. public string ExceptionContent { get; set; }
  25. [Required]
  26. public string ExceptionCode { get; set; }
  27. [Required]
  28. public string ExceptionReason { get; set; }
  29. [Range(minimum:1,maximum:int.MaxValue)]
  30. public int Duration { get; set; } = 2;
  31. public List<string> ExeceptionLists { get; set; }
  32. public OeeDialogPageViewModel()
  33. {
  34. Title = "设备异常处理";
  35. ExceptionTime = DateTime.Now;
  36. CloseCmd = new DelegateCommand(Close);
  37. ExeceptionLists = new List<string>
  38. {
  39. "1500002-其他",
  40. "6014009-急停",
  41. "30540000-维修保养"
  42. };
  43. }
  44. public bool Check()
  45. {
  46. return !string.IsNullOrWhiteSpace(OP_Id)&&
  47. !string.IsNullOrWhiteSpace(ExceptionCode)&&
  48. !string.IsNullOrWhiteSpace(ExceptionContent)&&
  49. !string.IsNullOrWhiteSpace(ExceptionReason)&&
  50. Duration>0;
  51. }
  52. public event Action<IDialogResult> RequestClose;
  53. private void Close()
  54. {
  55. var dialog = new DialogResult();
  56. dialog.Parameters.Add("OP_Id", OP_Id);
  57. dialog.Parameters.Add("ExceptionCode", ExceptionCode);
  58. dialog.Parameters.Add("ExceptionContent", ExceptionContent);
  59. dialog.Parameters.Add("Duration", Duration);
  60. dialog.Parameters.Add("ExceptionTime", ExceptionTime.ToString("yyyy-mm-dd HH:mm:ss"));
  61. dialog.Parameters.Add("Mode", "手动调试模式");
  62. dialog.Parameters.Add("Reason", ExceptionReason);
  63. RequestClose?.Invoke(dialog);
  64. }
  65. public bool CanCloseDialog()
  66. {
  67. return Check();
  68. }
  69. public void OnDialogClosed()
  70. {
  71. }
  72. public void OnDialogOpened(IDialogParameters parameters)
  73. {
  74. OP_Id = parameters.GetValue<string>("OP_Id");
  75. ExceptionCode = parameters.GetValue<string>("ExceptionCode");
  76. }
  77. }
  78. class DialogResult : IDialogResult
  79. {
  80. public DialogResult()
  81. {
  82. Parameters=new DialogParameters();
  83. Result = ButtonResult.OK;
  84. }
  85. public IDialogParameters Parameters { get; }
  86. public ButtonResult Result { get; }
  87. }
  88. }