AlarmViewModel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.UI.View.Common;
  8. using Aitex.Core.Utilities;
  9. using MECF.Framework.Common.Alarms;
  10. using MECF.Framework.UI.Client.ClientBase;
  11. using System.Linq;
  12. using MECF.Framework.Common.OperationCenter;
  13. using Aitex.Core.Util;
  14. using MECF.Framework.UI.Client.CenterViews.Alarms;
  15. namespace FurnaceUI.Views.Alarms
  16. {
  17. public class AlarmViewModel : UiViewModelBase
  18. {
  19. [Subscription("System.AlarmTableID")]
  20. public string CurrentAlarmTable { get; set; }
  21. [IgnorePropertyChange]
  22. public List<AlarmItem> AlarmEvents { get; set; }
  23. public int SelectedIndex { get; set; } = -1;
  24. private AlarmProvider _alarmProvider = new AlarmProvider();
  25. public Dictionary<string, Dictionary<string, EventItem>> AllGroupAlarmDic = new Dictionary<string, Dictionary<string, EventItem>>();
  26. //public List<AlarmDefine> AlarmParameterList { get; set; } = new List<AlarmDefine>();
  27. public bool IsPermission { get => this.Permission == 3; }
  28. private string _txtAnalysisText;
  29. private long _currentEventID;
  30. private int _currentEventCount;
  31. private string _currentEventName;
  32. private bool _clearAllIsEnabled;
  33. public bool ClearAllIsEnabled
  34. {
  35. get => _clearAllIsEnabled;
  36. set
  37. {
  38. _clearAllIsEnabled = value;
  39. NotifyOfPropertyChange("ClearAllIsEnabled");
  40. }
  41. }
  42. public string TxtAnalysisText
  43. {
  44. get
  45. {
  46. return _txtAnalysisText;
  47. }
  48. set
  49. {
  50. _txtAnalysisText = value;
  51. NotifyOfPropertyChange("TxtAnalysisText");
  52. }
  53. }
  54. private bool _clearIsEnabled;
  55. public bool ClearIsEnabled
  56. {
  57. get => _clearIsEnabled;
  58. set
  59. {
  60. _clearIsEnabled = value;
  61. NotifyOfPropertyChange("ClearIsEnabled");
  62. }
  63. }
  64. private bool _abortIsEnabled;
  65. public bool AbortIsEnabled
  66. {
  67. get => _abortIsEnabled;
  68. set
  69. {
  70. _abortIsEnabled = value;
  71. NotifyOfPropertyChange("AbortIsEnabled");
  72. }
  73. }
  74. private bool _retryIsEnabled;
  75. public bool RetryIsEnabled
  76. {
  77. get => _retryIsEnabled;
  78. set
  79. {
  80. _retryIsEnabled = value;
  81. NotifyOfPropertyChange("RetryIsEnabled");
  82. }
  83. }
  84. private bool _continueIsEnabled;
  85. public bool ContinueIsEnabled
  86. {
  87. get => _continueIsEnabled;
  88. set
  89. {
  90. _continueIsEnabled = value;
  91. NotifyOfPropertyChange("ContinueIsEnabled");
  92. }
  93. }
  94. private bool _aGVRetryIsEnabled;
  95. public bool AGVRetryIsEnabled
  96. {
  97. get => _aGVRetryIsEnabled;
  98. set
  99. {
  100. _aGVRetryIsEnabled = value;
  101. NotifyOfPropertyChange("AGVRetryIsEnabled");
  102. }
  103. }
  104. private string _targetModule;
  105. public string TargetModule
  106. {
  107. get
  108. {
  109. return _targetModule;
  110. }
  111. set
  112. {
  113. _targetModule = value;
  114. NotifyOfPropertyChange("TargetModule");
  115. }
  116. }
  117. public void SetActionIsEnabled(string action)
  118. {
  119. if (action == null || action == "")
  120. {
  121. ClearIsEnabled = false;
  122. AbortIsEnabled = false;
  123. RetryIsEnabled = false;
  124. ContinueIsEnabled = false;
  125. AGVRetryIsEnabled = false;
  126. }
  127. else
  128. {
  129. string[] actions = action.Split('|');
  130. ClearIsEnabled = Array.IndexOf(actions, "Clear") != -1 ? true : false;
  131. AbortIsEnabled = Array.IndexOf(actions, "Abort") != -1 ? true : false;
  132. RetryIsEnabled = Array.IndexOf(actions, "Retry") != -1 ? true : false;
  133. ContinueIsEnabled = Array.IndexOf(actions, "Continue") != -1 ? true : false;
  134. AGVRetryIsEnabled = Array.IndexOf(actions, "AGV RETRY") != -1 ? true : false;
  135. }
  136. }
  137. public void DGOnSelectionChanged()
  138. {
  139. //var e = (SelectionChangedEventArgs)obj;
  140. if (SelectedIndex > -1)
  141. {
  142. AlarmItem item = AlarmEvents[SelectedIndex];
  143. //var item = e.AddedItems[0] as AlarmItem;
  144. //var findAlarm = AllGroupAlarmDic[CurrentAlarmTable].Values.Where(x => x.EventEnum == item.EventEnum).FirstOrDefault();
  145. if (item != null)
  146. {
  147. SetActionIsEnabled(item.Action.ToString());
  148. TxtAnalysisText = string.Format("Event Type:{0}\r\n\r\nEvent ID:{1}\r\n\r\nTime:{2}\r\n\r\nDescription:{3}\r\n\r\nCause:{4}\r\n\r\nRecovery:{5}",
  149. item.Type,
  150. item.EventId,
  151. item.OccuringTime,
  152. item.Description,
  153. item.Explaination,
  154. item.Solution
  155. );
  156. }
  157. else
  158. {
  159. SetActionIsEnabled("");
  160. TxtAnalysisText = string.Format("Event Type:{0}\r\n\r\nEvent ID:{1}\r\n\r\nTime:{2}\r\n\r\nDescription:{3}",
  161. item.Type,
  162. item.EventId,
  163. item.OccuringTime,
  164. item.Description
  165. );
  166. }
  167. TargetModule = item.Source;
  168. _currentEventID = item.EventId;
  169. _currentEventCount = item.Count;
  170. _currentEventName = item.EventEnum;
  171. }
  172. }
  173. public AlarmViewModel()
  174. {
  175. Subscribe("System.LiveAlarmEvent");
  176. }
  177. protected override void OnViewLoaded(object view)
  178. {
  179. //var alarmDict = _alarmProvider.GetXmlAlarmList();
  180. //AllGroupAlarmDic = alarmDict;
  181. //foreach (var item in AllGroupAlarmList.Keys)
  182. //{
  183. // foreach (var subitem in AllGroupAlarmList[item].Keys)
  184. // {
  185. // AlarmParameterList.Add(AllGroupAlarmList[item][subitem]);
  186. // }
  187. //}
  188. base.OnViewLoaded(view);
  189. }
  190. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  191. {
  192. if (data.ContainsKey("System.LiveAlarmEvent"))
  193. UpdateAlarmEvent((List<EventItem>)data["System.LiveAlarmEvent"]);
  194. }
  195. public void UpdateAlarmEvent(List<EventItem> evItems)
  196. {
  197. var alarmEvents = new List<AlarmItem>();
  198. foreach (EventItem item in evItems.OrderByDescending(p=>p.OccuringTime))
  199. {
  200. var it = new AlarmItem()
  201. {
  202. Type = item.Level == EventLevel.Alarm ? "Alarm" : (item.Level == EventLevel.Information ? "Info" : "Warning"),
  203. OccuringTime = item.OccuringTime.ToString("yyyy/MM/dd HH:mm:ss"),
  204. Description = item.Description,
  205. EventEnum = item.EventEnum,
  206. EventId = item.Id,
  207. Explaination = item.Explaination,
  208. Solution = item.Solution,
  209. Source = item.Source,
  210. Count = item.Count,
  211. Action = item.Action,
  212. };
  213. switch (item.Level)
  214. {
  215. case EventLevel.Alarm: it.TextColor = Brushes.Red; break;
  216. case EventLevel.Warning: it.TextColor = Brushes.Yellow; break;
  217. default: it.TextColor = Brushes.White; break;
  218. }
  219. alarmEvents.Add(it);
  220. }
  221. if (AlarmEvents == null || (alarmEvents.Count != AlarmEvents.Count))
  222. {
  223. AlarmEvents = alarmEvents;
  224. }
  225. else
  226. {
  227. bool isEqual = true;
  228. if (alarmEvents.Count == AlarmEvents.Count)
  229. {
  230. for (int i = 0; i < alarmEvents.Count; i++)
  231. {
  232. if (!alarmEvents[i].IsEqualTo(AlarmEvents[i]))
  233. {
  234. isEqual = false;
  235. break;
  236. }
  237. }
  238. }
  239. if (!isEqual)
  240. AlarmEvents = alarmEvents;
  241. }
  242. if (AlarmEvents.Count > 0)
  243. ClearAllIsEnabled = true;
  244. else
  245. ClearAllIsEnabled = false;
  246. NotifyOfPropertyChange("AlarmEvents");
  247. }
  248. public void AlarmAction(string target, string action)
  249. {
  250. InvokeClient.Instance.Service.DoOperation($"{target}.AlarmAction", action, _currentEventName);
  251. TxtAnalysisText = "";
  252. SetActionIsEnabled("");
  253. }
  254. }
  255. }