TopViewModel.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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.Triton160.Common;
  17. using Aitex.Triton160.UI;
  18. using Aitex.Triton160.UI.Config;
  19. using Aitex.Triton160.UI.ViewModel;
  20. using Aitex.Triton160.UI.Views;
  21. namespace Triton160.UI.ViewModel
  22. {
  23. class TopViewModel : UIViewModelBase
  24. {
  25. public string SoftwareVersion
  26. {
  27. get;
  28. set;
  29. }
  30. [Subscription(TritonDevice.EmoSystem, SystemDeviceModule)]
  31. public AITEmoData EmoState
  32. {
  33. get;
  34. set;
  35. }
  36. [Subscription(StateData.PMState, SystemStateModule)]
  37. public int PMState
  38. {
  39. get;
  40. set;
  41. }
  42. [Subscription(TritonDevice.SignalTower, SystemDeviceModule)]
  43. public AITSignalTowerData SignalTower
  44. {
  45. get;
  46. set;
  47. }
  48. public string SystemStatus
  49. {
  50. get
  51. {
  52. PMState status = (PMState)PMState;
  53. return status.ToString();
  54. }
  55. }
  56. private bool _simulatorMode = false;
  57. public string TopViewBackground
  58. {
  59. get
  60. {
  61. return _simulatorMode ? "Goldenrod" : "Transparent";
  62. }
  63. }
  64. public SolidColorBrush MainContactorColor
  65. {
  66. get
  67. {
  68. return EmoState != null && EmoState.MainContactorSignal ? Brushes.Lime : Brushes.Gray;
  69. }
  70. }
  71. public SolidColorBrush EmoStopColor
  72. {
  73. get
  74. {
  75. return EmoState != null && EmoState.StopButtonSignal ? Brushes.Lime : Brushes.Gray;
  76. }
  77. }
  78. public string User
  79. {
  80. get
  81. {
  82. return Globals.Session["CurrentUser"] == null ? "" : (Globals.Session["CurrentUser"] as Account).AccountId;
  83. }
  84. }
  85. public string Role
  86. {
  87. get
  88. {
  89. return Globals.Session["CurrentUser"] == null ? "" : (Globals.Session["CurrentUser"] as Account).Role;
  90. }
  91. }
  92. public int _language;
  93. //public string LanguageButtonDisplay
  94. //{
  95. // get
  96. // {
  97. // //显示的文字,和实际的语言相反,用于切换
  98. // return _language == 1 ? "中文" : "EN";
  99. // }
  100. //}
  101. public bool EnableEnButton
  102. {
  103. get
  104. {
  105. return _language != 1;
  106. }
  107. }
  108. public bool EnableCnButton
  109. {
  110. get
  111. {
  112. return _language != 2;
  113. }
  114. }
  115. public string LogoSource
  116. {
  117. get
  118. {
  119. string file = SystemConfigManager.Instance.GetTopviewLogoFile();
  120. if (string.IsNullOrEmpty(file))
  121. file = "LogoEmpty.png";
  122. return "/Core;component/Resources/Main/" + file;
  123. }
  124. }
  125. public ICommand SwitchOffBuzzerCommand
  126. {
  127. get;
  128. private set;
  129. }
  130. public ICommand SwitchLanguageCommand
  131. {
  132. get;
  133. private set;
  134. }
  135. public FACommunicationState FACommunicationState
  136. {
  137. get
  138. {
  139. return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
  140. : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
  141. }
  142. }
  143. public FAControlState FAControlState
  144. {
  145. get
  146. {
  147. return string.IsNullOrEmpty(HostControlStatus) ? FAControlState.Unknown
  148. : (FAControlState)Enum.Parse(typeof(FAControlState), HostControlStatus);
  149. }
  150. }
  151. //Disabled,
  152. //Enabled,
  153. //EnabledNotCommunicating,
  154. //EnabledCommunicating,
  155. //WaitCRA,
  156. //WaitDelay,
  157. //WaitCRFromHost,
  158. public bool IsEnableEnableButton
  159. {
  160. get { return FACommunicationState == FACommunicationState.Disabled; }
  161. }
  162. [Subscription("System.ControlStatus")]
  163. public string HostControlStatus
  164. {
  165. get;
  166. set;
  167. }
  168. [Subscription("System.CommunicationStatus")]
  169. public string HostCommunicationStatus
  170. {
  171. get;
  172. set;
  173. }
  174. public string HostControlStatusBackground
  175. {
  176. get
  177. {
  178. if (FACommunicationState == FACommunicationState.Disabled)
  179. return "Transparent";
  180. if (FACommunicationState != FACommunicationState.EnabledCommunicating)
  181. return "Transparent";
  182. switch (FAControlState)
  183. {
  184. case FAControlState.OnlineLocal:
  185. case FAControlState.OnlineRemote:
  186. return "Green";
  187. case FAControlState.HostOffline:
  188. //case FAControlState.AttemptOnline:
  189. case FAControlState.EquipmentOffline:
  190. case FAControlState.Unknown:
  191. return "Transparent";
  192. }
  193. return "Orange";
  194. }
  195. }
  196. public string HostStatusBackground
  197. {
  198. get
  199. {
  200. switch (FACommunicationState)
  201. {
  202. case FACommunicationState.EnabledCommunicating:
  203. return "Green";
  204. case FACommunicationState.Disabled:
  205. return "Transparent";
  206. }
  207. return "Orange";
  208. }
  209. }
  210. private bool _isFaEnable;
  211. public Visibility VisibleHostStatus
  212. {
  213. get { return _isFaEnable ? Visibility.Visible : Visibility.Hidden; }
  214. }
  215. public string SystemStatusBackground
  216. {
  217. get { return GetUnitStatusBackground(SystemStatus); }
  218. }
  219. public string GetUnitStatusBackground(string status)
  220. {
  221. if (status != null)
  222. status = status.Trim().ToLower();
  223. switch (status)
  224. {
  225. case "error":
  226. return "red";
  227. case "idle":
  228. return "Transparent";
  229. case "init":
  230. return "Orange";
  231. default:
  232. return "Green";
  233. }
  234. }
  235. public TopViewModel()
  236. : base("TopViewModel")
  237. {
  238. SwitchOffBuzzerCommand = new DelegateCommand<object>(OnSwitchOffBuzzer);
  239. SwitchLanguageCommand = new DelegateCommand<object>(OnSwitchOffLanguage);
  240. SoftwareVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
  241. InvokePropertyChanged("SoftwareVersion");
  242. }
  243. public void Reset()
  244. {
  245. Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.Reset.ToString());
  246. }
  247. void OnSwitchOffBuzzer(object param)
  248. {
  249. Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.DeviceOperation.ToString(), new object[] { TritonDevice.SignalTower.ToString(), AITSignalTowerOperation.SwitchOffBuzzer.ToString() });
  250. Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.BuzzerOFF.ToString());
  251. }
  252. void OnSwitchOffLanguage(object param)
  253. {
  254. int language = param.ToString().ToLower() == "en" ? 1 : 2;
  255. Triton160UiSystem.Instance.WCF.Invoker.DoOperation(TritonOperation.SetConfig.ToString(), SCName.System_Language, language);
  256. }
  257. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  258. {
  259. Application.Current.Dispatcher.Invoke(new Action(() =>
  260. {
  261. int language = (int)Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_Language);
  262. if (language != _language)
  263. {
  264. _language = language;
  265. Triton160UiSystem.Instance.SetCulture(_language == 2 ? "zh-CN" : "en-US");
  266. }
  267. _simulatorMode = (bool) Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_IsSimulatorMode);
  268. _isFaEnable = (bool)Triton160UiSystem.Instance.WCF.Query.GetConfig(SCName.System_EnableFa);
  269. }));
  270. }
  271. }
  272. }