UIViewModelBase.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Forms.VisualStyles;
  5. using System.Windows.Input;
  6. using Aitex.Core.RT.Event;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.UI.MVVM;
  9. using Aitex.Core.Utilities;
  10. using Aitex.Sorter.Common;
  11. using Aitex.Sorter.UI.Config;
  12. using Aitex.Sorter.UI.Views;
  13. using MECF.Framework.Common.DataCenter;
  14. using MECF.Framework.Common.OperationCenter;
  15. using MECF.Framework.UI.Core.Accounts;
  16. namespace Aitex.Sorter.UI.ViewModel
  17. {
  18. public class UIViewModelBase : SubscriptionViewModelBase
  19. {
  20. protected const string SystemDeviceModule = "Device.System";
  21. protected const string SystemStateModule = "System";
  22. [IgnorePropertyChange]
  23. protected SCValue SCLocal
  24. {
  25. get;
  26. set;
  27. }
  28. [IgnorePropertyChange]
  29. private List<Tuple<string, string, string, bool>> _allDataItems = new List<Tuple<string, string, string, bool>>();
  30. public UIViewModelBase(string vmName)
  31. : base(vmName)
  32. {
  33. SCLocal = new SCValue();
  34. PollDataFunction = (IEnumerable<string> keys) =>
  35. {
  36. return QueryDataClient.Instance.Service.PollData(keys);
  37. };
  38. InvokeFunction = (string[] param) =>
  39. {
  40. PerformInvokeFunction(param);
  41. };
  42. DeviceFunction = (string deviceName, string operationName) =>
  43. {
  44. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), deviceName, operationName);
  45. };
  46. DeviceControlFunction = (object[] args) =>
  47. {
  48. if (args.Length == 2)
  49. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), args[0], args[1]);
  50. else if (args.Length == 3)
  51. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), args[0], args[1], args[2]);
  52. else if (args.Length == 4)
  53. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation.ToString(), args[0], args[1], args[2], args[3]);
  54. };
  55. _allDataItems = SystemConfigManager.Instance.GetMonitorDataList();
  56. }
  57. public virtual bool PerformInvokeFunctionCheck(string[] param)
  58. {
  59. if (param != null && (param[0] == "SetAutoMode" || param[0] == "SetManualMode"))
  60. {
  61. if (param.Length == 1)
  62. { return true; }
  63. if (param.Length == 2 && param[1].ToLower() == "True".ToLower())
  64. {
  65. PasswordMsgBox passwordMsgBox = new PasswordMsgBox();
  66. if (passwordMsgBox.ShowDialog() != true)
  67. {
  68. return false;
  69. }
  70. }
  71. }
  72. return true;
  73. }
  74. public override bool PerformInvokeFunction(string[] param)
  75. {
  76. if (PerformInvokeFunctionCheck(param))
  77. {
  78. if (param.Length == 1)
  79. {
  80. if(param[0] == "GonaAbort")
  81. {
  82. GonaSorterLogin mainLogin = new GonaSorterLogin();
  83. if (mainLogin.ShowDialog() == true)
  84. {
  85. bool account = AccountClient.Instance.Service.GetAccountInfo(mainLogin.textBoxUserName.Text).ActSuccess;
  86. if (account)
  87. InvokeClient.Instance.Service.DoOperation("Abort");
  88. else
  89. MessageBox.Show("Do not Support Click Abort");
  90. }
  91. }
  92. else
  93. InvokeClient.Instance.Service.DoOperation(param[0]);
  94. }
  95. else if (param.Length == 2)
  96. InvokeClient.Instance.Service.DoOperation(param[0], param[1]);
  97. else if (param.Length == 3)
  98. InvokeClient.Instance.Service.DoOperation(param[0], param[1], param[2]);
  99. }
  100. return true;
  101. }
  102. public virtual void UpdateAllConfig()
  103. {
  104. // SCLocal.Update(QueryDataClient.Instance.Service.PollConfig(SCLocal.GetKeys()));
  105. }
  106. public Dictionary<string, Tuple<string, string, bool>> GetDataElements(string culture)
  107. {
  108. Dictionary<string, Tuple<string, string, bool>> result = new Dictionary<string, Tuple<string, string, bool>>();
  109. Dictionary<string, Tuple<string, string, string, bool>> all = GetDataElements();
  110. foreach (var tuple in all)
  111. {
  112. result.Add(tuple.Key, Tuple.Create(tuple.Value.Item1, culture == CultureSupported.Chinese ? tuple.Value.Item3 : tuple.Value.Item2, tuple.Value.Item4));
  113. }
  114. return result;
  115. }
  116. public Dictionary<string, Tuple<string, string, string, bool>> GetDataElements()
  117. {
  118. UpdateAllConfig();
  119. Dictionary<string, Tuple<string, string, string, bool>> dicItems = new Dictionary<string, Tuple<string, string, string, bool>>();
  120. foreach (var dataItem in _allDataItems)
  121. {
  122. dicItems[dataItem.Item1] = dataItem;
  123. }
  124. return dicItems;
  125. }
  126. void UpdateGasItem(bool enable, string display, string id, string key, Dictionary<string, Tuple<string, string, string, bool>> dicItems)
  127. {
  128. if (enable && dicItems.ContainsKey(key))
  129. {
  130. dicItems[key] = Tuple.Create(key,
  131. dicItems[key].Item2.Replace(id, display),
  132. dicItems[key].Item3.Replace(id, display),
  133. dicItems[key].Item4);
  134. }
  135. else
  136. {
  137. dicItems.Remove(key);
  138. }
  139. }
  140. }
  141. }