TopViewModel2.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.UI.Control;
  4. using Aitex.Core.UI.Dialog;
  5. using Aitex.Core.UI.MVVM;
  6. using Aitex.Core.Util;
  7. using Aitex.Core.WCF;
  8. using Aitex.Sorter.Common;
  9. using Aitex.Sorter.UI.ViewModel;
  10. using Hardcodet.Wpf.TaskbarNotification;
  11. using MECF.Framework.Common.OperationCenter;
  12. using MECF.Framework.UI.Core.Accounts;
  13. using MECF.Framework.UI.Core.Applications;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Collections.ObjectModel;
  17. using System.Windows;
  18. using System.Windows.Input;
  19. namespace Sorter.UI.ViewModel
  20. {
  21. public class TopViewModel2 : UIViewModelBase
  22. {
  23. public string SoftwareVersion
  24. {
  25. get;
  26. set;
  27. }
  28. [Subscription(ParamName.RTStatus, SystemStateModule)]
  29. public int RoutManagerState
  30. {
  31. get;
  32. set;
  33. }
  34. public string SystemStatus
  35. {
  36. get { return ((RtState)RoutManagerState).ToString(); }
  37. }
  38. public string SystemStatusBackground
  39. {
  40. get
  41. {
  42. switch (RoutManagerState)
  43. {
  44. case (int)RtState.Init:
  45. return "Yellow";
  46. case (int)RtState.Initializing:
  47. case (int)RtState.ManualTransfer:
  48. case (int)RtState.Transfer:
  49. case (int)RtState.Cycle:
  50. case (int)RtState.PrepareCycle:
  51. case (int)RtState.PostCycle:
  52. case (int)RtState.Reset:
  53. case (int)RtState.Processing:
  54. case (int)RtState.PostProcess:
  55. case (int)RtState.PauseProcess:
  56. case (int)RtState.SetSpeed:
  57. return "LawnGreen";
  58. case (int)RtState.Error:
  59. case (int)RtState.Maintenance:
  60. return "Red";
  61. case (int)RtState.Idle:
  62. return "Transparent";
  63. default:
  64. return "Goldenrod";
  65. }
  66. }
  67. }
  68. [Subscription("Status", "LP1")]
  69. public string LoadPort1Status
  70. {
  71. get;
  72. set;
  73. }
  74. public string LoadPort1StatusBackground
  75. {
  76. get { return GetUnitStatusBackground(LoadPort1Status); }
  77. }
  78. [Subscription("Status", "LP2")]
  79. public string LoadPort2Status
  80. {
  81. get;
  82. set;
  83. }
  84. public string LoadPort2StatusBackground
  85. {
  86. get { return GetUnitStatusBackground(LoadPort2Status); }
  87. }
  88. [Subscription("LoadportState", "LP3")]
  89. public string LoadPort3Status
  90. {
  91. get;
  92. set;
  93. }
  94. public string LoadPort3StatusBackground
  95. {
  96. get { return GetUnitStatusBackground(LoadPort3Status); }
  97. }
  98. [Subscription("LoadportState", "LP4")]
  99. public string LoadPort4Status
  100. {
  101. get;
  102. set;
  103. }
  104. public string LoadPort4StatusBackground
  105. {
  106. get { return GetUnitStatusBackground(LoadPort4Status); }
  107. }
  108. [Subscription("Robot.State")]
  109. public string RobotStatus
  110. {
  111. get;
  112. set;
  113. }
  114. public string RobotStatusBackground
  115. {
  116. get { return GetUnitStatusBackground(RobotStatus); }
  117. }
  118. [Subscription("System.SignalTower.DeviceData")]
  119. public AITSignalTowerData SignalTower
  120. {
  121. get;
  122. set;
  123. }
  124. [Subscription("System.IsOnlineMode")]
  125. public bool IsOnlineMode { get; set; }
  126. public string OnlineStatus
  127. {
  128. get { return IsOnlineMode ? "Online" : "Offline"; }
  129. }
  130. private bool _simulatorMode = false;
  131. [Subscription("System.ServerStatus")]
  132. public string ServerStatus
  133. {
  134. get; set;
  135. }
  136. public R_TRIG _trig = new R_TRIG();
  137. public bool _clearEventLogEnable;
  138. [Subscription("System.ClearEventLogEnable")]
  139. public bool ClearEventLogEnable
  140. {
  141. get;
  142. set;
  143. //get
  144. // {
  145. // return _clearEventLogEnable;
  146. //}
  147. //set
  148. //{
  149. // _clearEventLogEnable = value;
  150. // if (value)
  151. // {
  152. // _trig.CLK = value;
  153. // if (_trig.Q)
  154. // EventLogList.Clear();
  155. // }
  156. // else
  157. // {
  158. // _trig.RST = true;
  159. // }
  160. //}
  161. }
  162. [Subscription("CoolingBuffer1.CoolingBuffer1.Status")]
  163. public string CoolingBuffer1Status
  164. {
  165. get; set;
  166. }
  167. public string _CoolingBuffer1Status => CoolingBuffer1Status == "Disable" ? "" : CoolingBuffer1Status;
  168. public string CoolingBuffer1Background
  169. {
  170. get { return GetUnitStatusBackground(CoolingBuffer1Status); }
  171. }
  172. [Subscription("CoolingBuffer2.CoolingBuffer2.Status")]
  173. public string CoolingBuffer2Status
  174. {
  175. get; set;
  176. }
  177. public string _CoolingBuffer2Status => CoolingBuffer2Status == "Disable" ? "" : CoolingBuffer2Status;
  178. public string CoolingBuffer2Background
  179. {
  180. get { return GetUnitStatusBackground(CoolingBuffer2Status); }
  181. }
  182. [Subscription("Aligner1.Aligner1.Status")]
  183. public string Aligner1Status
  184. {
  185. get; set;
  186. }
  187. public string _Aligner1Status => Aligner1Status == "Disable" ? "" : Aligner1Status;
  188. public string Aligner1Background
  189. {
  190. get { return GetUnitStatusBackground(Aligner1Status); }
  191. }
  192. [Subscription("Aligner2.Aligner2.Status")]
  193. public string Aligner2Status
  194. {
  195. get; set;
  196. }
  197. public string _Aligner2Status => Aligner2Status == "Disable" ? "" : Aligner2Status;
  198. public string Aligner2Background
  199. {
  200. get { return GetUnitStatusBackground(Aligner2Status); }
  201. }
  202. public string ServerStatusBackground
  203. {
  204. get { return GetServerStatusBackground(ServerStatus); }
  205. }
  206. public string GetServerStatusBackground(string status)
  207. {
  208. return "Transparent";
  209. // if (status != null)
  210. // status = status.Trim().ToLower();
  211. //switch (status)
  212. //{
  213. // case "unknown":
  214. // return "Yellow";
  215. // case "idle":
  216. // return "Transparent";
  217. // case "busy":
  218. // return "LawnGreen";
  219. // default:
  220. // return "Yellow";
  221. //}
  222. }
  223. public string GetUnitStatusBackground(string status)
  224. {
  225. if (status != null)
  226. status = status.Trim().ToLower();
  227. switch (status)
  228. {
  229. case "unknown":
  230. return "Yellow";
  231. case "idle":
  232. return "Transparent";
  233. case "busy":
  234. return "LawnGreen";
  235. //case "disable":
  236. // return "DarkOrange";
  237. default:
  238. return "Yellow";
  239. }
  240. }
  241. public string TopBackground
  242. {
  243. get
  244. {
  245. return ServerStatus == "Connected" ? "ForestGreen" : "Yellow";
  246. }
  247. }
  248. public string OnlineStatusBackground
  249. {
  250. get
  251. {
  252. return IsOnlineMode ? "Transparent" : "Yellow";
  253. }
  254. }
  255. public string TopViewBackground
  256. {
  257. get
  258. {
  259. return _simulatorMode ? "Goldenrod" : "Transparent";
  260. }
  261. }
  262. public string User
  263. {
  264. get
  265. {
  266. return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.AccountId;
  267. }
  268. }
  269. public string Role
  270. {
  271. get
  272. {
  273. return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.Role;
  274. }
  275. }
  276. #region Moudle Enable Flag
  277. [Subscription("LP1.IsEnable")]
  278. public bool LP1Enable { get; set; }
  279. [Subscription("LP2.IsEnable")]
  280. public bool LP2Enable { get; set; }
  281. [Subscription("Aligner1.IsEnable")]
  282. public bool Aligner1Enable { get; set; }
  283. [Subscription("Aligner2.IsEnable")]
  284. public bool Aligner2Enable { get; set; }
  285. [Subscription("Buffer.IsEnable")]
  286. public bool BufferEnable { get; set; }
  287. [Subscription("Buffer1.IsEnable")]
  288. public bool Buffer1Enable { get; set; }
  289. [Subscription("Buffer2.IsEnable")]
  290. public bool Buffer2Enable { get; set; }
  291. [Subscription("PMA.IsEnable")]
  292. public bool PMAEnable { get; set; }
  293. [Subscription("PMB.IsEnable")]
  294. public bool PMBEnable { get; set; }
  295. [Subscription("CoolingBuffer1.IsEnable")]
  296. public bool CoolingBuffer1Enable { get; set; }
  297. [Subscription("CoolingBuffer2.IsEnable")]
  298. public bool CoolingBuffer2Enable { get; set; }
  299. #endregion Moudle Enable Flag
  300. public ICommand SwitchOffBuzzerCommand { get; set; }
  301. public ICommand ResetCommand { get; set; }
  302. public ICommand LogoffCommand { get; set; }
  303. public bool IsEnableOnline
  304. {
  305. get { return !IsOnlineMode; }
  306. }
  307. public bool IsEnableOffline
  308. {
  309. get { return IsOnlineMode; }
  310. }
  311. private MessageControl _balloonControl;
  312. private bool _logoff;
  313. public ObservableCollection<EventItem> EventLogList { get; set; }
  314. public TopViewModel2()
  315. : base("TopViewModel2")
  316. {
  317. SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
  318. ResetCommand = new DelegateCommand<object>(DoReset);
  319. LogoffCommand = new DelegateCommand<object>(DoLogoff);
  320. SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  321. InvokePropertyChanged("SoftwareVersion");
  322. EventLogList = new ObservableCollection<EventItem>();
  323. _balloonControl = new MessageControl();
  324. EventClient.Instance.OnEvent += Instance_OnEvent;
  325. EventClient.Instance.Start();
  326. }
  327. private void Instance_OnEvent(EventItem obj)
  328. {
  329. if (_logoff)
  330. return;
  331. switch (obj.Type)
  332. {
  333. case EventType.EventUI_Notify:
  334. LogEvent(obj);
  335. break;
  336. case EventType.Dialog_Nofity:
  337. PopDialog(obj);
  338. break;
  339. case EventType.KickOut_Notify:
  340. break;
  341. case EventType.Sound_Notify:
  342. break;
  343. case EventType.UIMessage_Notify:
  344. PopUIMessage(obj);
  345. break;
  346. }
  347. }
  348. private void DoLogoff(object obj)
  349. {
  350. _logoff = true;
  351. UiApplication.Instance.Logoff();
  352. }
  353. private void DoReset(object obj)
  354. {
  355. InvokeClient.Instance.Service.DoOperation("System.Reset");
  356. EventLogList.Clear();
  357. if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset");
  358. if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset");
  359. }
  360. public void Reset()
  361. {
  362. InvokeClient.Instance.Service.DoOperation(OperationName.ResetAlarm);
  363. InvokeClient.Instance.Service.DoOperation(OperationName.ResetDevice);
  364. InvokeClient.Instance.Service.DoOperation(OperationName.ResetRouteManager);
  365. }
  366. private void OnSwitchOffBuzzer(object param)
  367. {
  368. InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer1");
  369. InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer2");
  370. }
  371. private void PopUIMessage(EventItem obj)
  372. {
  373. Application.Current.Dispatcher.Invoke(new Action(() =>
  374. {
  375. _balloonControl.SetMessage(MessageType.Info, obj.Description);
  376. ShowNotifyIcon(2000);
  377. }));
  378. }
  379. private void LogEvent(EventItem obj)
  380. {
  381. if (obj.Type != EventType.EventUI_Notify)
  382. return;
  383. Application.Current.Dispatcher.Invoke(new Action(() =>
  384. {
  385. while (EventLogList.Count > 100)
  386. {
  387. EventLogList.RemoveAt(0);
  388. }
  389. EventLogList.Add(obj);
  390. }));
  391. }
  392. private void ShowNotifyIcon(int time)
  393. {
  394. TaskbarIcon icon = new TaskbarIcon();
  395. icon.ShowCustomBalloon(_balloonControl, global::System.Windows.Controls.Primitives.PopupAnimation.Slide, time);
  396. }
  397. private void PopDialog(EventItem item)
  398. {
  399. Application.Current.Dispatcher.Invoke(new Action(() =>
  400. {
  401. switch (item.Level)
  402. {
  403. case EventLevel.Alarm:
  404. MessageBoxEx.ShowError(item.Description, item.Explaination);
  405. break;
  406. case EventLevel.Warning:
  407. MessageBoxEx.ShowWarning(item.Description, item.Explaination);
  408. break;
  409. case EventLevel.Information:
  410. MessageBoxEx.ShowInfo(item.Description, item.Explaination);
  411. break;
  412. }
  413. }));
  414. }
  415. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  416. {
  417. Application.Current.Dispatcher.Invoke(new Action(() =>
  418. {
  419. _trig.CLK = ClearEventLogEnable;
  420. if (_trig.Q)
  421. {
  422. InvokeClient.Instance.Service.DoOperation("System.Reset");
  423. EventLogList.Clear();
  424. if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset");
  425. if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset");
  426. InvokeClient.Instance.Service.DoOperation("System.ClearEventLogEnable");
  427. }
  428. }));
  429. }
  430. }
  431. }