TopViewModel.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. using System;
  2. using System.CodeDom;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Media;
  10. using Aitex.Core.Account;
  11. using Aitex.Core.Common.DeviceData;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.UI.MVVM;
  14. using System.Windows.Input;
  15. using Aitex.Core.Util;
  16. using Aitex.Sorter.Common;
  17. using Aitex.Sorter.UI;
  18. using Aitex.Sorter.UI.Config;
  19. using Aitex.Sorter.UI.ViewModel;
  20. using MECF.Framework.Common.OperationCenter;
  21. using MECF.Framework.UI.Core.Accounts;
  22. namespace Sorter.UI.ViewModel
  23. {
  24. public class TopViewModel : UIViewModelBase
  25. {
  26. public string SoftwareVersion
  27. {
  28. get;
  29. set;
  30. }
  31. [Subscription(ParamName.ControlStatus, SystemStateModule)]
  32. public string HostControlStatus
  33. {
  34. get;
  35. set;
  36. }
  37. public string HostControlStatusBackground
  38. {
  39. get
  40. {
  41. switch (HostControlStatus)
  42. {
  43. case "Unknown":
  44. return "Yellow";
  45. case "EquipmentOffline":
  46. case "AttemptOnline":
  47. case "HostOffline":
  48. return "Transparent";
  49. case "OnlineLocal":
  50. case "OnlineRemote":
  51. return "LawnGreen";
  52. default:
  53. return "Yellow";
  54. }
  55. }
  56. }
  57. [Subscription(ParamName.CommunicationStatus, SystemStateModule)]
  58. public string HostCommunicationStatus
  59. {
  60. get;
  61. set;
  62. }
  63. /// Disabled = 0,
  64. /// Enabled = 1,
  65. /// EnabledNotCommunicating = 2,
  66. /// EnabledCommunicating = 3,
  67. /// WaitCRA = 4,
  68. /// WaitDelay = 5,
  69. /// WaitCRFromHost = 6,
  70. public string HostCommunicationStatusBackground
  71. {
  72. get
  73. {
  74. switch (HostControlStatus)
  75. {
  76. case "Disabled":
  77. return "Yellow";
  78. case "Enabled":
  79. case "EnabledNotCommunicating":
  80. case "WaitCRA":
  81. case "WaitDelay":
  82. case "WaitCRFromHost":
  83. return "Transparent";
  84. case "EnabledCommunicating":
  85. return "LawnGreen";
  86. default:
  87. return "Yellow";
  88. }
  89. }
  90. }
  91. [Subscription(ParamName.RTStatus, SystemStateModule)]
  92. public int RoutManagerState
  93. {
  94. get;
  95. set;
  96. }
  97. public string SystemStatus
  98. {
  99. get { return ((RtState)RoutManagerState).ToString(); }
  100. }
  101. public string SystemStatusBackground
  102. {
  103. get
  104. {
  105. switch (RoutManagerState)
  106. {
  107. case (int)RtState.Init:
  108. return "Yellow";
  109. case (int)RtState.Initializing:
  110. case (int)RtState.ManualTransfer:
  111. case (int)RtState.Transfer:
  112. case (int)RtState.Cycle:
  113. case (int)RtState.PrepareCycle:
  114. case (int)RtState.PostCycle:
  115. case (int)RtState.Reset:
  116. case (int)RtState.Processing:
  117. case (int)RtState.PostProcess:
  118. case (int)RtState.PauseProcess:
  119. case (int)RtState.SetSpeed:
  120. return "LawnGreen";
  121. case (int)RtState.Error:
  122. case (int)RtState.Maintenance:
  123. return "Red";
  124. case (int)RtState.Idle:
  125. return "Transparent";
  126. default:
  127. return "Goldenrod";
  128. }
  129. }
  130. }
  131. [Subscription(ParamName.LoadportState, DeviceName.LoadportA)]
  132. public string LoadPort1Status
  133. {
  134. get;
  135. set;
  136. }
  137. public string LoadPort1StatusBackground
  138. {
  139. get { return GetUnitStatusBackground(LoadPort1Status); }
  140. }
  141. [Subscription(ParamName.LoadportState, DeviceName.LoadportB)]
  142. public string LoadPort2Status
  143. {
  144. get;
  145. set;
  146. }
  147. public string LoadPort2StatusBackground
  148. {
  149. get { return GetUnitStatusBackground(LoadPort2Status); }
  150. }
  151. [Subscription(ParamName.AlignerState, DeviceName.Aligner)]
  152. public string AlignerStatus
  153. {
  154. get;
  155. set;
  156. }
  157. public string AlignerStatusBackground
  158. {
  159. get { return GetUnitStatusBackground(AlignerStatus); }
  160. }
  161. [Subscription(ParamName.RobotState, DeviceName.Robot)]
  162. public string RobotStatus
  163. {
  164. get;
  165. set;
  166. }
  167. public string RobotStatusBackground
  168. {
  169. get { return GetUnitStatusBackground(RobotStatus); }
  170. }
  171. [Subscription(DeviceName.SignalTower, SystemDeviceModule)]
  172. public AITSignalTowerData SignalTower
  173. {
  174. get;
  175. set;
  176. }
  177. [Subscription(ParamName.IsAutoMode, SystemStateModule)]
  178. public bool IsAutoMode { get; set; }
  179. private bool _simulatorMode = false;
  180. public bool IsManualButtonEnabled
  181. {
  182. get
  183. {
  184. return IsAutoMode;
  185. }
  186. }
  187. public bool IsAutoButtonEnabled
  188. {
  189. get
  190. {
  191. return !IsAutoMode;
  192. }
  193. }
  194. public string GetUnitStatusBackground(string status)
  195. {
  196. if (status!=null)
  197. status = status.Trim().ToLower();
  198. switch (status)
  199. {
  200. case "unknown":
  201. return "Yellow";
  202. case "idle":
  203. return "Transparent";
  204. case "busy":
  205. return "LawnGreen";
  206. default:
  207. return "Yellow";
  208. }
  209. }
  210. public string TopViewBackground
  211. {
  212. get
  213. {
  214. return _simulatorMode ? "Goldenrod" : "Transparent";
  215. }
  216. }
  217. public string User
  218. {
  219. get
  220. {
  221. return AccountClient.Instance.CurrentUser== null ? "" : AccountClient.Instance.CurrentUser.AccountId;
  222. }
  223. }
  224. public string Role
  225. {
  226. get
  227. {
  228. return AccountClient.Instance.CurrentUser == null ? "" : AccountClient.Instance.CurrentUser.Role;
  229. }
  230. }
  231. //public int _language;
  232. //public string LanguageButtonDisplay
  233. //{
  234. // get
  235. // {
  236. // //显示的文字,和实际的语言相反,用于切换
  237. // return _language == 1 ? "中文" : "EN";
  238. // }
  239. //}
  240. //public bool EnableEnButton
  241. //{
  242. // get
  243. // {
  244. // return _language != 1;
  245. // }
  246. //}
  247. //public bool EnableCnButton
  248. //{
  249. // get
  250. // {
  251. // return _language != 2;
  252. // }
  253. //}
  254. public string LogoSource
  255. {
  256. get
  257. {
  258. string file = SystemConfigManager.Instance.GetTopviewLogoFile();
  259. if (string.IsNullOrEmpty(file))
  260. file = "LogoEmpty.png";
  261. return "/Core;component/Resources/Main/" + file;
  262. }
  263. }
  264. public ICommand SwitchOffBuzzerCommand
  265. {
  266. get;
  267. private set;
  268. }
  269. public ICommand SwitchLanguageCommand
  270. {
  271. get;
  272. private set;
  273. }
  274. public bool IsManualMode
  275. {
  276. get
  277. {
  278. return !IsAutoMode;
  279. }
  280. }
  281. public FACommunicationState FACommunicationState
  282. {
  283. get
  284. {
  285. return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
  286. : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
  287. }
  288. }
  289. public bool IsFAEnableButtonEnabled
  290. {
  291. get { return FACommunicationState == FACommunicationState.Disabled; }
  292. }
  293. public bool IsFADisableButtonEnabled
  294. {
  295. get { return FACommunicationState != FACommunicationState.Disabled; }
  296. }
  297. public TopViewModel()
  298. : base("TopViewModel")
  299. {
  300. SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
  301. SwitchLanguageCommand = new DelegateCommand<object>(OnSwitchOffLanguage);
  302. SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  303. InvokePropertyChanged("SoftwareVersion");
  304. }
  305. public void Reset()
  306. {
  307. InvokeClient.Instance.Service.DoOperation(OperationName.Reset);
  308. }
  309. void OnSwitchOffBuzzer(object param)
  310. {
  311. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), new object[] { DeviceName.SignalTower.ToString(), AITSignalTowerOperation.SwitchOffBuzzer.ToString() });
  312. }
  313. void OnSwitchOffLanguage(object param)
  314. {
  315. //int language = param.ToString().ToLower() == "en" ? 1 : 2;
  316. //InvokeClient.Instance.Service.DoOperation(OperationName.SetConfig.ToString(), SCName.System_Language, language);
  317. }
  318. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  319. {
  320. Application.Current.Dispatcher.Invoke(new Action(() =>
  321. {
  322. //int language = (int)QueryDataClient.Instance.Service.GetConfig(SCName.System_Language);
  323. //if (language != _language)
  324. //{
  325. // _language = language;
  326. // SorterUiSystem.Instance.SetCulture(_language == 2 ? "zh-CN" : "en-US");
  327. //}
  328. //_simulatorMode = (bool) QueryDataClient.Instance.Service.GetConfig(SCName.System_IsSimulatorMode);
  329. }));
  330. }
  331. public override bool PerformInvokeFunctionCheck(string[] param)
  332. {
  333. if (param != null && (param[0]== "SetAutoMode" || param[0] == "SetManualMode"))
  334. {
  335. if (param.Length == 1)
  336. { return true; }
  337. if (param.Length == 2 && param[1].ToLower() == "True".ToLower())
  338. {
  339. PasswordMsgBox passwordMsgBox = new PasswordMsgBox();
  340. if (passwordMsgBox.DialogResult != true)
  341. {
  342. return false;
  343. }
  344. }
  345. }
  346. return true;
  347. }
  348. }
  349. }