FAViewModelII.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 PageSCFAII : PageSCValue
  25. {
  26. public string FA_HsmsConnectionMode { get; set; }
  27. public string FA_HsmsLocalIP { get; set; }
  28. public int FA_HsmsLocalPort { get; set; }
  29. public string FA_HsmsRemoteIP { get; set; }
  30. public int FA_HsmsRemotePort { get; set; }
  31. public int FA_HsmsT3timeout { get; set; }
  32. public int FA_HsmsT5timeout { get; set; }
  33. public int FA_HsmsT6timeout { get; set; }
  34. public int FA_HsmsT7timeout { get; set; }
  35. public int FA_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 FA_DeviceID { get; set; }
  42. public PageSCFAII()
  43. {
  44. UpdateKeys(typeof(PageSCFAII).GetProperties());
  45. }
  46. }
  47. class FAViewModelII : 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 PageSCFAII ConfigFeedback
  170. {
  171. get;
  172. set;
  173. }
  174. [IgnorePropertyChange]
  175. public PageSCFAII 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 SetConfigExCommand
  188. {
  189. get;
  190. private set;
  191. }
  192. [IgnorePropertyChange]
  193. public ICommand SetConfig2Command
  194. {
  195. get;
  196. private set;
  197. }
  198. [IgnorePropertyChange]
  199. public ICommand InitializeCommand
  200. {
  201. get;
  202. private set;
  203. }
  204. [IgnorePropertyChange]
  205. public ICommand SetHSMSCommand
  206. {
  207. get;
  208. private set;
  209. }
  210. [IgnorePropertyChange]
  211. public ICommand SetHSMSCommandEx
  212. {
  213. get;
  214. private set;
  215. }
  216. public FAViewModelII() : base(nameof(FAViewModel))
  217. {
  218. ConfigFeedback = new PageSCFAII();
  219. ConfigSetPoint = new PageSCFAII();
  220. SetConfigCommand = new DelegateCommand<object>(SetConfig);
  221. SetConfigExCommand = new DelegateCommand<DependencyObject>(SetConfigEx);
  222. SetConfig2Command = new DelegateCommand<object>(SetConfig2);
  223. InitializeCommand = new DelegateCommand<object>(InitializeFa);
  224. SetHSMSCommand = new DelegateCommand<object>(SetHSMS);
  225. SetHSMSCommandEx = new DelegateCommand<DependencyObject>(SetHSMSEx);
  226. UpdateSetHSMS();
  227. }
  228. string[] keysisInt = new string[] { "HsmsLocalPort", "HsmsRemotePort", "HsmsT3timeout"
  229. ,"HsmsT5timeout","HsmsT6timeout","HsmsT7timeout","HsmsT8timeout" };
  230. private void UpdateSetHSMS()
  231. {
  232. var liststr = ConfigFeedback.GetKeys();
  233. Dictionary<string, object> keyValuePairs = new Dictionary<string, object>();
  234. foreach (var item in liststr)
  235. {
  236. object value = QueryDataClient.Instance.Service.GetData(item);
  237. if (value != null)
  238. {
  239. if (keysisInt.Contains(item))
  240. { keyValuePairs.Add(item, int.Parse(value.ToString())); }
  241. else
  242. { keyValuePairs.Add(item, value); }
  243. }
  244. }
  245. ConfigFeedback.Update(keyValuePairs);
  246. ConfigSetPoint.Update(keyValuePairs);
  247. InvokeAllPropertyChanged();
  248. }
  249. private void SetHSMS(object sender)
  250. {
  251. object[] sc = (object[])sender;
  252. InvokeClient.Instance.Service.DoOperation("FACommand", sc);
  253. UpdateSetHSMS();
  254. }
  255. private void SetHSMSEx(DependencyObject sender)
  256. {
  257. // object[] sc = (object[])obj;
  258. var command = CommandHelper.GetCommandItem(sender);
  259. var lstParameter = new List<object>(command.Parameters);
  260. lstParameter.Insert(0, command.CommandName);
  261. // lstParameter.Insert(1, command.Parameters);
  262. InvokeClient.Instance.Service.DoOperation("FACommand", lstParameter.ToArray());
  263. UpdateSetHSMS();
  264. }
  265. private void InitializeFa(object obj)
  266. {
  267. if (MessageBox.Show("Are you sure you want to re-initialize FA connection?",
  268. "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  269. {
  270. InvokeClient.Instance.Service.DoOperation("Fa.Initialize");
  271. }
  272. }
  273. void SetConfig(object param)
  274. {
  275. object[] sc = (object[])param;
  276. if (!PerformInvokeFunctionCheck(new string[] { "Config", "Set" })) return;
  277. InvokeClient.Instance.Service.DoOperation("System.SetConfig", sc[0].ToString(), sc[1].ToString());
  278. UpdateConfig();
  279. }
  280. void SetConfigEx(DependencyObject sender)
  281. {
  282. var command = CommandHelper.GetCommandItem(sender);
  283. var lstParameter = new List<object>(command.Parameters);
  284. //lstParameter.Insert(0, command.CommandName);
  285. InvokeClient.Instance.Service.DoOperation("System.SetConfig", command.CommandName, (string)lstParameter[0]);
  286. UpdateConfig();
  287. }
  288. void SetConfig2(object param)
  289. {
  290. string id = (string)param;
  291. string key = id.Replace("FA.", "FA_");
  292. PropertyInfo[] property = typeof(PageSCFA).GetProperties();
  293. foreach (PropertyInfo prop in property)
  294. {
  295. if (prop.Name == key)
  296. {
  297. InvokeClient.Instance.Service.DoOperation("System.SetConfig", id, prop.GetValue(ConfigSetPoint, null).ToString());
  298. break;
  299. }
  300. }
  301. UpdateConfig();
  302. }
  303. public void UpdateConfig()
  304. {
  305. ConfigFeedback.Update(QueryDataClient.Instance.Service.PollConfig(ConfigFeedback.GetKeys()));
  306. ConfigSetPoint.Update(QueryDataClient.Instance.Service.PollConfig(ConfigSetPoint.GetKeys()));
  307. InvokeAllPropertyChanged();
  308. }
  309. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  310. {
  311. }
  312. }
  313. }