FAViewModel.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 Aitex.Sorter.UI.Controls.Common;
  18. using MECF.Framework.Common.DataCenter;
  19. using MECF.Framework.Common.OperationCenter;
  20. using MessageBox = Xceed.Wpf.Toolkit.MessageBox;
  21. using PageSCValue = MECF.Framework.UI.Core.View.Common.PageSCValue;
  22. namespace Aitex.Sorter.UI.ViewModel
  23. {
  24. public class PageSCFA : PageSCValue
  25. {
  26. public string HsmsConnectionMode { get; set; }
  27. public string HsmsLocalIP { get; set; }
  28. public int HsmsLocalPort { get; set; }
  29. public string HsmsRemoteIP { get; set; }
  30. public int HsmsRemotePort { get; set; }
  31. public int HsmsT3timeout { get; set; }
  32. public int HsmsT5timeout { get; set; }
  33. public int HsmsT6timeout { get; set; }
  34. public int HsmsT7timeout { get; set; }
  35. public int HsmsT8timeout { get; set; }
  36. public bool FA_EnableSpooling { get; set; }
  37. public int FA_FaLinkTestInterval { get; set; }
  38. public string FA_FaDefaultCommunicationState { get; set; }
  39. public string FA_FaDefaultControlState { get; set; }
  40. public string FA_FaDefaultControlSubState { get; set; }
  41. public string SecsDeviceID { get; set; }
  42. public PageSCFA()
  43. {
  44. UpdateKeys(typeof(PageSCFA).GetProperties());
  45. }
  46. }
  47. class FAViewModel : UIViewModelBase
  48. {
  49. #region subscrib
  50. [Subscription(ParamName.IsSpoolingEnable, ChamberSetString.System)]
  51. public bool IsSpoolingEnable
  52. {
  53. get;
  54. set;
  55. }
  56. [Subscription(ParamName.SpoolingState, ChamberSetString.System)]
  57. public string SpoolingState
  58. {
  59. get;
  60. set;
  61. }
  62. [Subscription(ParamName.SpoolingActual, ChamberSetString.System)]
  63. public string SpoolingActual
  64. {
  65. get;
  66. set;
  67. }
  68. [Subscription(ParamName.SpoolingTotal, ChamberSetString.System)]
  69. public string SpoolingTotal
  70. {
  71. get;
  72. set;
  73. }
  74. [Subscription(ParamName.SpoolingFullTime, ChamberSetString.System)]
  75. public string SpoolingFullTime
  76. {
  77. get;
  78. set;
  79. }
  80. [Subscription(ParamName.SpoolingStartTime, ChamberSetString.System)]
  81. public string SpoolingStartTime
  82. {
  83. get;
  84. set;
  85. }
  86. [Subscription(ParamName.ControlStatus, ChamberSetString.System)]
  87. public string HostControlStatus
  88. {
  89. get;
  90. set;
  91. }
  92. [Subscription(ParamName.CommunicationStatus, ChamberSetString.System)]
  93. public string HostCommunicationStatus
  94. {
  95. get;
  96. set;
  97. }
  98. #endregion
  99. #region logic
  100. public FACommunicationState FACommunicationState
  101. {
  102. get
  103. {
  104. return string.IsNullOrEmpty(HostCommunicationStatus) ? FACommunicationState.Disabled
  105. : (FACommunicationState)Enum.Parse(typeof(FACommunicationState), HostCommunicationStatus);
  106. }
  107. }
  108. public FAControlState FAControlState
  109. {
  110. get
  111. {
  112. return string.IsNullOrEmpty(HostControlStatus) ? FAControlState.Unknown
  113. : (FAControlState)Enum.Parse(typeof(FAControlState), HostControlStatus);
  114. }
  115. }
  116. //Disabled,
  117. //Enabled,
  118. //EnabledNotCommunicating,
  119. //EnabledCommunicating,
  120. //WaitCRA,
  121. //WaitDelay,
  122. //WaitCRFromHost,
  123. public bool IsEnableEnableButton
  124. {
  125. get { return FACommunicationState == FACommunicationState.Disabled; }
  126. }
  127. public bool IsEnableDisableButton
  128. {
  129. get { return FACommunicationState != FACommunicationState.Disabled; }
  130. }
  131. //Unknown,
  132. //EquipmentOffline,
  133. //AttemptOnline,
  134. //HostOffline,
  135. //OnlineLocal,
  136. //OnlineRemote,
  137. public bool IsEnableOnlineButton
  138. {
  139. get { return FAControlState == FAControlState.Unknown || FAControlState == FAControlState.EquipmentOffline; }
  140. }
  141. public bool IsEnableOfflineButton
  142. {
  143. get { return FAControlState == FAControlState.Unknown || FAControlState != FAControlState.EquipmentOffline; }
  144. }
  145. public bool IsEnableLocalButton
  146. {
  147. get { return FAControlState == FAControlState.OnlineRemote; }
  148. }
  149. public bool IsEnableRemoteButton
  150. {
  151. get { return FAControlState == FAControlState.OnlineLocal; }
  152. }
  153. public bool IsEnableSpoolingEnableButton
  154. {
  155. get
  156. {
  157. return !IsSpoolingEnable;//SpoolingState == FASpoolingState.Inactive.ToString();
  158. }
  159. }
  160. public bool IsEnableSpoolingDisableButton
  161. {
  162. get
  163. {
  164. return IsSpoolingEnable;// SpoolingState == FASpoolingState.Active.ToString();
  165. }
  166. }
  167. #endregion
  168. [IgnorePropertyChange]
  169. public PageSCFA ConfigFeedback
  170. {
  171. get;
  172. set;
  173. }
  174. [IgnorePropertyChange]
  175. public PageSCFA ConfigSetPoint
  176. {
  177. get;
  178. set;
  179. }
  180. [IgnorePropertyChange]
  181. public ICommand SetConfigCommand
  182. {
  183. get;
  184. private set;
  185. }
  186. [IgnorePropertyChange]
  187. public ICommand SetConfig2Command
  188. {
  189. get;
  190. private set;
  191. }
  192. [IgnorePropertyChange]
  193. public ICommand InitializeCommand
  194. {
  195. get;
  196. private set;
  197. }
  198. [IgnorePropertyChange]
  199. public ICommand SetHSMSCommand
  200. {
  201. get;
  202. private set;
  203. }
  204. [IgnorePropertyChange]
  205. public ICommand SetHSMSCommandEx
  206. {
  207. get;
  208. private set;
  209. }
  210. public FAViewModel() : base(nameof(FAViewModel))
  211. {
  212. ConfigFeedback = new PageSCFA();
  213. ConfigSetPoint = new PageSCFA();
  214. SetConfigCommand = new DelegateCommand<object>(SetConfig);
  215. SetConfig2Command = new DelegateCommand<object>(SetConfig2);
  216. InitializeCommand = new DelegateCommand<object>(InitializeFa);
  217. SetHSMSCommand = new DelegateCommand<object>(SetHSMS);
  218. SetHSMSCommandEx = new DelegateCommand<DependencyObject>(SetHSMSEx);
  219. UpdateSetHSMS();
  220. }
  221. string[] keysisInt = new string[] { "HsmsLocalPort", "HsmsRemotePort", "HsmsT3timeout"
  222. ,"HsmsT5timeout","HsmsT6timeout","HsmsT7timeout","HsmsT8timeout" };
  223. private void UpdateSetHSMS()
  224. {
  225. var liststr = ConfigFeedback.GetKeys();
  226. Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
  227. foreach (var item in liststr)
  228. {
  229. object value = QueryDataClient.Instance.Service.GetData("System." + item);
  230. if (value != null)
  231. {
  232. if (keysisInt.Contains(item))
  233. { keyValuePairs.Add(item, int.Parse(value.ToString())); }
  234. else
  235. { keyValuePairs.Add(item, value); }
  236. }
  237. }
  238. ConfigFeedback.Update(keyValuePairs);
  239. ConfigSetPoint.Update(keyValuePairs);
  240. InvokeAllPropertyChanged();
  241. }
  242. private void SetHSMS(object sender)
  243. {
  244. object[] sc = (object[])sender;
  245. InvokeClient.Instance.Service.DoOperation("FACommand", sc);
  246. UpdateSetHSMS();
  247. }
  248. private void SetHSMSEx(DependencyObject sender)
  249. {
  250. // object[] sc = (object[])obj;
  251. var command = CommandHelper.GetCommandItem(sender);
  252. var lstParameter = new List<object>(command.Parameters);
  253. lstParameter.Insert(0, command.CommandName);
  254. // lstParameter.Insert(1, command.Parameters);
  255. InvokeClient.Instance.Service.DoOperation("FACommand", lstParameter.ToArray());
  256. UpdateSetHSMS();
  257. }
  258. private void InitializeFa(object obj)
  259. {
  260. if (MessageBox.Show("Are you sure you want to re-initialize FA connection?",
  261. "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  262. {
  263. InvokeClient.Instance.Service.DoOperation("Fa.Initialize");
  264. }
  265. }
  266. void SetConfig(object param)
  267. {
  268. object[] sc = (object[])param;
  269. InvokeClient.Instance.Service.DoOperation("System.SetConfig", sc[0].ToString(), sc[1].ToString());
  270. UpdateConfig();
  271. }
  272. void SetConfig2(object param)
  273. {
  274. string id = (string)param;
  275. string key = id.Replace("FA.", "FA_");
  276. PropertyInfo[] property = typeof(PageSCFA).GetProperties();
  277. foreach (PropertyInfo prop in property)
  278. {
  279. if (prop.Name == key)
  280. {
  281. InvokeClient.Instance.Service.DoOperation("System.SetConfig", id, prop.GetValue(ConfigSetPoint, null).ToString());
  282. break;
  283. }
  284. }
  285. UpdateConfig();
  286. }
  287. public void UpdateConfig()
  288. {
  289. ConfigFeedback.Update(QueryDataClient.Instance.Service.PollConfig(ConfigFeedback.GetKeys()));
  290. ConfigSetPoint.Update(QueryDataClient.Instance.Service.PollConfig(ConfigSetPoint.GetKeys()));
  291. InvokeAllPropertyChanged();
  292. }
  293. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  294. {
  295. }
  296. }
  297. }