AlarmErrorCommandViewModel.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using Caliburn.Micro;
  2. using Caliburn.Micro.Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using FurnaceUI.Models;
  11. using FurnaceUI.Views.Jobs;
  12. using System.Windows.Controls;
  13. using MECF.Framework.UI.Client.CenterViews.Parameter;
  14. namespace FurnaceUI.Views.Editors
  15. {
  16. public class AlarmErrorCommandViewModel : FurnaceUIViewModelBase
  17. {
  18. private string selectCommand;
  19. public string SelectCommand
  20. {
  21. get { return selectCommand; }
  22. set { selectCommand = value; this.NotifyOfPropertyChange(nameof(SelectCommand)); }
  23. }
  24. private AlarmErrorCommandView _view;
  25. public string ResultParameterStr { get; set; }
  26. private string _alarmStr;
  27. public string AlarmStr
  28. {
  29. get { return _alarmStr; }
  30. set
  31. {
  32. _alarmStr = value; this.NotifyOfPropertyChange(nameof(AlarmStr));
  33. }
  34. }
  35. private Visibility _isJumpVisibility = Visibility.Collapsed;
  36. public Visibility IsJumpVisibility
  37. {
  38. get { return _isJumpVisibility; }
  39. set { _isJumpVisibility = value; this.NotifyOfPropertyChange(nameof(IsJumpVisibility)); }
  40. }
  41. private Visibility _isAlarmVisibility = Visibility.Collapsed;
  42. public Visibility IsAlarmVisibility
  43. {
  44. get { return _isAlarmVisibility; }
  45. set { _isAlarmVisibility = value; this.NotifyOfPropertyChange(nameof(IsAlarmVisibility)); }
  46. }
  47. private Visibility _isAbortVisibility = Visibility.Collapsed;
  48. public Visibility IsAbortVisibility
  49. {
  50. get { return _isAbortVisibility; }
  51. set { _isAbortVisibility = value; this.NotifyOfPropertyChange(nameof(IsAbortVisibility)); }
  52. }
  53. private string _abortStr;
  54. public string AbortStr
  55. {
  56. get { return _abortStr; }
  57. set { _abortStr = value; this.NotifyOfPropertyChange(nameof(AbortStr)); }
  58. }
  59. private string _jumpStr;
  60. public string JumpStr
  61. {
  62. get { return _jumpStr; }
  63. set { _jumpStr = value; this.NotifyOfPropertyChange(nameof(JumpStr)); }
  64. }
  65. protected override void OnInitialize()
  66. {
  67. base.OnInitialize();
  68. InitControl();
  69. }
  70. /// <summary>
  71. /// 初始化按钮 是否被选中
  72. /// </summary>
  73. private void InitControl()
  74. {
  75. if (string.IsNullOrEmpty(selectCommand))
  76. return;
  77. _view = ((GetView() as Window).Content) as AlarmErrorCommandView;
  78. var key = selectCommand.Split(' ')[0];
  79. Dictionary<string, string> dicNames = new Dictionary<string, string>() {
  80. { "Call Alarm Recipe","CallAlarmRecipe"},
  81. { "Call Abort Recipe","CallAbortRecipe"},
  82. { "ABORT","CallAbortRecipe"},
  83. { "CALL","CallAlarmRecipe"},
  84. { "JUMP","JumpStep"},
  85. };
  86. string nameKey = dicNames.ContainsKey(key) ? dicNames[key] : selectCommand;
  87. var control = _view.FindName(nameKey);
  88. if (control is null)
  89. return;
  90. RadioButton radioButton = control as RadioButton;
  91. radioButton.IsChecked = true;
  92. if (key.Equals("CALL"))
  93. {
  94. AlarmStr = selectCommand.Replace("CALL ","");
  95. IsAlarmVisibility = Visibility.Visible;
  96. }
  97. else if (key.Equals("ABORT"))
  98. {
  99. AbortStr = selectCommand.Replace("ABORT ", "");
  100. IsAbortVisibility = Visibility.Visible;
  101. }
  102. else if (key.Equals("JUMP"))
  103. {
  104. JumpStr= selectCommand.Replace("JUMP ", "");
  105. IsJumpVisibility = Visibility.Visible;
  106. }
  107. }
  108. public void SetCommand(string commandContent)
  109. {
  110. var windowManager = IoC.Get<IWindowManager>();
  111. AlarmErrorCallRecipeViewModel errorCallRecipeViewModel = new AlarmErrorCallRecipeViewModel();
  112. if (commandContent.Equals("Call Alarm Recipe"))
  113. {
  114. errorCallRecipeViewModel.IsAlarmVisibility = Visibility.Visible;
  115. errorCallRecipeViewModel.ResultParameterStr = AlarmStr;
  116. errorCallRecipeViewModel.CallReciepType = "alarm";
  117. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(errorCallRecipeViewModel, null, "Call Alarm Recipe"))
  118. {
  119. ResultParameterStr = errorCallRecipeViewModel.ResultParameterStr;
  120. AlarmStr = ResultParameterStr;
  121. IsAlarmVisibility = Visibility.Visible;
  122. IsAbortVisibility = Visibility.Collapsed;
  123. IsJumpVisibility = Visibility.Collapsed;
  124. }
  125. else
  126. {
  127. ((Window)GetView()).DialogResult = false;
  128. }
  129. selectCommand = "CALL";
  130. }
  131. else if (commandContent.Equals("JumpStep"))
  132. {
  133. AlarmErrorJumpStepViewModel alarmErrorJumpStepView = new AlarmErrorJumpStepViewModel();
  134. alarmErrorJumpStepView.ResultParameterStr = JumpStr;
  135. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(alarmErrorJumpStepView, null, "Jump"))
  136. {
  137. ResultParameterStr = alarmErrorJumpStepView.ResultParameterStr;
  138. JumpStr = ResultParameterStr;
  139. IsJumpVisibility = Visibility.Visible;
  140. IsAbortVisibility = Visibility.Collapsed;
  141. IsAlarmVisibility = Visibility.Collapsed;
  142. }
  143. else
  144. {
  145. ((Window)GetView()).DialogResult = false;
  146. }
  147. selectCommand = "JUMP";
  148. }
  149. else if (commandContent.Equals("Call Abort Recipe"))
  150. {
  151. errorCallRecipeViewModel = new AlarmErrorCallRecipeViewModel();
  152. errorCallRecipeViewModel.IsAlarmVisibility = Visibility.Hidden;
  153. errorCallRecipeViewModel.ResultParameterStr = AbortStr;
  154. errorCallRecipeViewModel.CallReciepType = "abort";
  155. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(errorCallRecipeViewModel, null, "Call Abort Recipe"))
  156. {
  157. ResultParameterStr = errorCallRecipeViewModel.ResultParameterStr;
  158. AbortStr = ResultParameterStr;
  159. IsAbortVisibility = Visibility.Visible;
  160. IsAlarmVisibility = Visibility.Collapsed;
  161. IsJumpVisibility = Visibility.Collapsed;
  162. }
  163. else {
  164. ((Window)GetView()).DialogResult = false;
  165. }
  166. selectCommand = "ABORT";
  167. }
  168. else
  169. {
  170. ResultParameterStr = null;
  171. selectCommand = commandContent;
  172. }
  173. }
  174. public void CloseCommand()
  175. {
  176. ((Window)GetView()).DialogResult = false;
  177. }
  178. public void OKCommand()
  179. {
  180. ((Window)GetView()).DialogResult = true;
  181. }
  182. }
  183. }