TopViewModel2.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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. [Subscription("Status", "Flipper")]
  203. public string FlipperStatus
  204. {
  205. get;
  206. set;
  207. }
  208. public string FlipperBackground
  209. {
  210. get { return GetUnitStatusBackground(FlipperStatus); }
  211. }
  212. public string ServerStatusBackground
  213. {
  214. get { return GetServerStatusBackground(ServerStatus); }
  215. }
  216. public string GetServerStatusBackground(string status)
  217. {
  218. return "Transparent";
  219. // if (status != null)
  220. // status = status.Trim().ToLower();
  221. //switch (status)
  222. //{
  223. // case "unknown":
  224. // return "Yellow";
  225. // case "idle":
  226. // return "Transparent";
  227. // case "busy":
  228. // return "LawnGreen";
  229. // default:
  230. // return "Yellow";
  231. //}
  232. }
  233. public string GetUnitStatusBackground(string status)
  234. {
  235. if (status != null)
  236. status = status.Trim().ToLower();
  237. switch (status)
  238. {
  239. case "unknown":
  240. return "Yellow";
  241. case "idle":
  242. return "Transparent";
  243. case "busy":
  244. return "LawnGreen";
  245. //case "disable":
  246. // return "DarkOrange";
  247. default:
  248. return "Yellow";
  249. }
  250. }
  251. public string TopBackground
  252. {
  253. get
  254. {
  255. return ServerStatus == "Connected" ? "ForestGreen" : "Yellow";
  256. }
  257. }
  258. public string OnlineStatusBackground
  259. {
  260. get
  261. {
  262. return IsOnlineMode ? "Transparent" : "Yellow";
  263. }
  264. }
  265. public string TopViewBackground
  266. {
  267. get
  268. {
  269. return _simulatorMode ? "Goldenrod" : "Transparent";
  270. }
  271. }
  272. public string User
  273. {
  274. get
  275. {
  276. return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.AccountId;
  277. }
  278. }
  279. public string Role
  280. {
  281. get
  282. {
  283. return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.Role;
  284. }
  285. }
  286. #region Moudle Enable Flag
  287. [Subscription("LP1.IsEnable")]
  288. public bool LP1Enable { get; set; }
  289. [Subscription("LP2.IsEnable")]
  290. public bool LP2Enable { get; set; }
  291. [Subscription("Aligner1.IsEnable")]
  292. public bool Aligner1Enable { get; set; }
  293. [Subscription("Aligner2.IsEnable")]
  294. public bool Aligner2Enable { get; set; }
  295. [Subscription("Buffer.IsEnable")]
  296. public bool BufferEnable { get; set; }
  297. [Subscription("Buffer1.IsEnable")]
  298. public bool Buffer1Enable { get; set; }
  299. [Subscription("Buffer2.IsEnable")]
  300. public bool Buffer2Enable { get; set; }
  301. [Subscription("PMA.IsEnable")]
  302. public bool PMAEnable { get; set; }
  303. [Subscription("PMB.IsEnable")]
  304. public bool PMBEnable { get; set; }
  305. [Subscription("CoolingBuffer1.IsEnable")]
  306. public bool CoolingBuffer1Enable { get; set; }
  307. [Subscription("CoolingBuffer2.IsEnable")]
  308. public bool CoolingBuffer2Enable { get; set; }
  309. [Subscription("Flipper.IsEnable")]
  310. public bool FlipperEnable { get; set; }
  311. #endregion Moudle Enable Flag
  312. public ICommand SwitchOffBuzzerCommand { get; set; }
  313. public ICommand ResetCommand { get; set; }
  314. public ICommand LogoffCommand { get; set; }
  315. public bool IsEnableOnline
  316. {
  317. get { return !IsOnlineMode; }
  318. }
  319. public bool IsEnableOffline
  320. {
  321. get { return IsOnlineMode; }
  322. }
  323. private MessageControl _balloonControl;
  324. private bool _logoff;
  325. public ObservableCollection<EventItem> EventLogList { get; set; }
  326. public TopViewModel2()
  327. : base("TopViewModel2")
  328. {
  329. SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
  330. ResetCommand = new DelegateCommand<object>(DoReset);
  331. LogoffCommand = new DelegateCommand<object>(DoLogoff);
  332. SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  333. InvokePropertyChanged("SoftwareVersion");
  334. EventLogList = new ObservableCollection<EventItem>();
  335. _balloonControl = new MessageControl();
  336. EventClient.Instance.OnEvent += Instance_OnEvent;
  337. EventClient.Instance.Start();
  338. }
  339. private void Instance_OnEvent(EventItem obj)
  340. {
  341. if (_logoff)
  342. return;
  343. switch (obj.Type)
  344. {
  345. case EventType.EventUI_Notify:
  346. LogEvent(obj);
  347. break;
  348. case EventType.Dialog_Nofity:
  349. PopDialog(obj);
  350. break;
  351. case EventType.KickOut_Notify:
  352. break;
  353. case EventType.Sound_Notify:
  354. break;
  355. case EventType.UIMessage_Notify:
  356. PopUIMessage(obj);
  357. break;
  358. }
  359. }
  360. private void DoLogoff(object obj)
  361. {
  362. _logoff = true;
  363. UiApplication.Instance.Logoff();
  364. }
  365. private void DoReset(object obj)
  366. {
  367. InvokeClient.Instance.Service.DoOperation("System.Reset");
  368. EventLogList.Clear();
  369. if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset");
  370. if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset");
  371. }
  372. public void Reset()
  373. {
  374. InvokeClient.Instance.Service.DoOperation(OperationName.ResetAlarm);
  375. InvokeClient.Instance.Service.DoOperation(OperationName.ResetDevice);
  376. InvokeClient.Instance.Service.DoOperation(OperationName.ResetRouteManager);
  377. }
  378. private void OnSwitchOffBuzzer(object param)
  379. {
  380. InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer1");
  381. InvokeClient.Instance.Service.DoOperation("System.SignalTower.SwitchOffBuzzer2");
  382. }
  383. private void PopUIMessage(EventItem obj)
  384. {
  385. Application.Current.Dispatcher.Invoke(new Action(() =>
  386. {
  387. _balloonControl.SetMessage(MessageType.Info, obj.Description);
  388. ShowNotifyIcon(2000);
  389. }));
  390. }
  391. private void LogEvent(EventItem obj)
  392. {
  393. if (obj.Type != EventType.EventUI_Notify)
  394. return;
  395. Application.Current.Dispatcher.Invoke(new Action(() =>
  396. {
  397. while (EventLogList.Count > 100)
  398. {
  399. EventLogList.RemoveAt(0);
  400. }
  401. EventLogList.Add(obj);
  402. }));
  403. }
  404. private void ShowNotifyIcon(int time)
  405. {
  406. TaskbarIcon icon = new TaskbarIcon();
  407. icon.ShowCustomBalloon(_balloonControl, global::System.Windows.Controls.Primitives.PopupAnimation.Slide, time);
  408. }
  409. private void PopDialog(EventItem item)
  410. {
  411. Application.Current.Dispatcher.Invoke(new Action(() =>
  412. {
  413. switch (item.Level)
  414. {
  415. case EventLevel.Alarm:
  416. MessageBoxEx.ShowError(item.Description, item.Explaination);
  417. break;
  418. case EventLevel.Warning:
  419. MessageBoxEx.ShowWarning(item.Description, item.Explaination);
  420. break;
  421. case EventLevel.Information:
  422. MessageBoxEx.ShowInfo(item.Description, item.Explaination);
  423. break;
  424. }
  425. }));
  426. }
  427. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  428. {
  429. Application.Current.Dispatcher.Invoke(new Action(() =>
  430. {
  431. _trig.CLK = ClearEventLogEnable;
  432. if (_trig.Q)
  433. {
  434. InvokeClient.Instance.Service.DoOperation("System.Reset");
  435. EventLogList.Clear();
  436. if(LP1Enable) InvokeClient.Instance.Service.DoOperation("LP1.LPReset");
  437. if(LP2Enable) InvokeClient.Instance.Service.DoOperation("LP2.LPReset");
  438. InvokeClient.Instance.Service.DoOperation("System.ClearEventLogEnable");
  439. }
  440. }));
  441. }
  442. }
  443. }