TerminalMessageViewModel.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using Aitex.Core.Common;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.UI.Dialog;
  12. using Aitex.Core.UI.MVVM;
  13. using Aitex.Core.UI.View.Common;
  14. using Aitex.Core.Util;
  15. using Aitex.Core.Utilities;
  16. using Aitex.Sorter.Common;
  17. using MECF.Framework.Common.DataCenter;
  18. using MECF.Framework.Common.OperationCenter;
  19. using MessageBox = Xceed.Wpf.Toolkit.MessageBox;
  20. using PageSCValue = MECF.Framework.UI.Core.View.Common.PageSCValue;
  21. namespace Aitex.Sorter.UI.ViewModel
  22. {
  23. class TerminalMessageViewModel : UIViewModelBase
  24. {
  25. #region subscrib
  26. [Subscription(ParamName.IsSpoolingEnable, ChamberSetString.System)]
  27. public bool IsSpoolingEnable
  28. {
  29. get;
  30. set;
  31. }
  32. [Subscription(ParamName.SpoolingState, ChamberSetString.System)]
  33. public string SpoolingState
  34. {
  35. get;
  36. set;
  37. }
  38. [Subscription(ParamName.SpoolingActual, ChamberSetString.System)]
  39. public string SpoolingActual
  40. {
  41. get;
  42. set;
  43. }
  44. [Subscription(ParamName.SpoolingTotal, ChamberSetString.System)]
  45. public string SpoolingTotal
  46. {
  47. get;
  48. set;
  49. }
  50. [Subscription(ParamName.SpoolingFullTime, ChamberSetString.System)]
  51. public string SpoolingFullTime
  52. {
  53. get;
  54. set;
  55. }
  56. [Subscription(ParamName.SpoolingStartTime, ChamberSetString.System)]
  57. public string SpoolingStartTime
  58. {
  59. get;
  60. set;
  61. }
  62. [Subscription(ParamName.ControlStatus, ChamberSetString.System)]
  63. public string HostControlStatus
  64. {
  65. get;
  66. set;
  67. }
  68. [Subscription(ParamName.CommunicationStatus, ChamberSetString.System)]
  69. public string HostCommunicationStatus
  70. {
  71. get;
  72. set;
  73. }
  74. #endregion
  75. #region logic
  76. public FACommunicationState FACommunicationState
  77. {
  78. get { return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
  79. :(FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus); }
  80. }
  81. public FAControlState FAControlState
  82. {
  83. get { return string.IsNullOrEmpty(HostControlStatus) ? FAControlState.Unknown
  84. :(FAControlState)Enum.Parse(typeof(FAControlState), HostControlStatus); }
  85. }
  86. //Disabled,
  87. //Enabled,
  88. //EnabledNotCommunicating,
  89. //EnabledCommunicating,
  90. //WaitCRA,
  91. //WaitDelay,
  92. //WaitCRFromHost,
  93. public bool IsEnableEnableButton
  94. {
  95. get { return FACommunicationState == FACommunicationState.Disabled; }
  96. }
  97. public bool IsEnableDisableButton
  98. {
  99. get { return FACommunicationState != FACommunicationState.Disabled; }
  100. }
  101. //Unknown,
  102. //EquipmentOffline,
  103. //AttemptOnline,
  104. //HostOffline,
  105. //OnlineLocal,
  106. //OnlineRemote,
  107. public bool IsEnableOnlineButton
  108. {
  109. get { return FAControlState == FAControlState.Unknown || FAControlState == FAControlState.EquipmentOffline; }
  110. }
  111. public bool IsEnableOfflineButton
  112. {
  113. get { return FAControlState == FAControlState.Unknown || FAControlState != FAControlState.EquipmentOffline; }
  114. }
  115. public bool IsEnableLocalButton
  116. {
  117. get { return FAControlState == FAControlState.OnlineRemote; }
  118. }
  119. public bool IsEnableRemoteButton
  120. {
  121. get { return FAControlState == FAControlState.OnlineLocal; }
  122. }
  123. public bool IsEnableSpoolingEnableButton
  124. {
  125. get
  126. {
  127. return !IsSpoolingEnable;//SpoolingState == FASpoolingState.Inactive.ToString();
  128. }
  129. }
  130. public bool IsEnableSpoolingDisableButton
  131. {
  132. get
  133. {
  134. return IsSpoolingEnable;// SpoolingState == FASpoolingState.Active.ToString();
  135. }
  136. }
  137. #endregion
  138. [IgnorePropertyChange]
  139. public PageSCFA ConfigFeedback
  140. {
  141. get;
  142. set;
  143. }
  144. [IgnorePropertyChange]
  145. public PageSCFA ConfigSetPoint
  146. {
  147. get;
  148. set;
  149. }
  150. [IgnorePropertyChange]
  151. public ICommand SetConfigCommand
  152. {
  153. get;
  154. private set;
  155. }
  156. [IgnorePropertyChange]
  157. public ICommand SetConfig2Command
  158. {
  159. get;
  160. private set;
  161. }
  162. [IgnorePropertyChange]
  163. public ICommand InitializeCommand
  164. {
  165. get;
  166. private set;
  167. }
  168. public TerminalMessageViewModel():base(nameof(TerminalMessageViewModel))
  169. {
  170. ConfigFeedback = new PageSCFA();
  171. ConfigSetPoint = new PageSCFA();
  172. SetConfigCommand = new DelegateCommand<object>(SetConfig);
  173. SetConfig2Command = new DelegateCommand<object>(SetConfig2);
  174. InitializeCommand = new DelegateCommand<object>(InitializeFa);
  175. }
  176. private void InitializeFa(object obj)
  177. {
  178. if (MessageBox.Show("Are you sure you want to re-initialize FA connection?",
  179. "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  180. {
  181. InvokeClient.Instance.Service.DoOperation("Fa.Initialize");
  182. }
  183. }
  184. void SetConfig(object param)
  185. {
  186. object[] sc = (object[])param;
  187. InvokeClient.Instance.Service.DoOperation("System.SetConfig", sc[0].ToString(), sc[1].ToString());
  188. UpdateConfig();
  189. }
  190. void SetConfig2(object param)
  191. {
  192. string id = (string)param;
  193. string key = id.Replace("Fa.", "Fa_");
  194. PropertyInfo[] property = typeof(PageSCFA).GetProperties();
  195. foreach (PropertyInfo prop in property)
  196. {
  197. if (prop.Name == key)
  198. {
  199. InvokeClient.Instance.Service.DoOperation("System.SetConfig", id, prop.GetValue(ConfigSetPoint, null).ToString());
  200. break;
  201. }
  202. }
  203. UpdateConfig();
  204. }
  205. public void UpdateConfig()
  206. {
  207. ConfigFeedback.Update(QueryDataClient.Instance.Service.PollConfig(ConfigFeedback.GetKeys()));
  208. ConfigSetPoint.Update(QueryDataClient.Instance.Service.PollConfig(ConfigSetPoint.GetKeys()));
  209. InvokeAllPropertyChanged();
  210. }
  211. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  212. {
  213. }
  214. }
  215. }