FFUConfigViewModel.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Shell;
  12. using Aitex.Core.Common.DeviceData;
  13. using Aitex.Core.RT.IOCore;
  14. using Aitex.Core.RT.Log;
  15. using Aitex.Core.UI.DeviceControl;
  16. using Aitex.Core.Util;
  17. using Caliburn.Micro.Core;
  18. using FurnaceUI.Models;
  19. using FurnaceUI.Views.Recipes;
  20. using MECF.Framework.Common.CommonData.DeviceData;
  21. using MECF.Framework.Common.DataCenter;
  22. using MECF.Framework.Common.Device;
  23. using MECF.Framework.Common.OperationCenter;
  24. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  25. using OpenSEMI.ClientBase;
  26. namespace FurnaceUI.Views.Maintenances
  27. {
  28. public class FFUConfigViewModel : FurnaceUIViewModelBase
  29. {
  30. public bool SetField<T>(ref T field, T value, string propertyName)
  31. {
  32. if (EqualityComparer<T>.Default.Equals(field, value)) return false;
  33. field = value;
  34. NotifyOfPropertyChange(propertyName);
  35. return true;
  36. }
  37. [Subscription("System.FFUKeyDict")]
  38. public List<string> FFUKeyDict { get; set; }
  39. public bool IsPermission { get => this.Permission == 3; }
  40. private ObservableCollection<FFUData> _ffuDatas = new ObservableCollection<FFUData>();
  41. public ObservableCollection<FFUData> FFUDataList
  42. {
  43. get => _ffuDatas;
  44. set
  45. {
  46. _ffuDatas = value;
  47. NotifyOfPropertyChange(nameof(FFUDataList));
  48. }
  49. }
  50. private bool _powerOffVisibility = false;
  51. public bool PowerOffVisibility
  52. {
  53. get => _powerOffVisibility;
  54. set => SetField(ref _powerOffVisibility, value, nameof(PowerOffVisibility));
  55. }
  56. private bool _powerOnVisibility = true;
  57. public bool PowerOnVisibility
  58. {
  59. get => _powerOnVisibility;
  60. set => SetField(ref _powerOnVisibility, value, nameof(PowerOnVisibility));
  61. }
  62. protected override void OnActivate()
  63. {
  64. base.OnActivate();
  65. FFUKeyDict = QueryDataClient.Instance.Service.GetData("System.FFUKeyDict") as List<string>;
  66. FFUDataList.Clear();
  67. foreach (var item in FFUKeyDict)
  68. {
  69. var deviceName = item.Split('.').ToList()[1];
  70. var ffuConfigData = QueryDataClient.Instance.Service.GetConfig($"FFU.{deviceName}.SetSpeed");
  71. FFUDataList.Add(new FFUData()
  72. {
  73. RTName = deviceName,
  74. Value = ffuConfigData.ToString(),
  75. });
  76. }
  77. }
  78. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  79. {
  80. base.InvokeAfterUpdateProperty(data);
  81. if (FFUDataList != null && FFUDataList.Count > 0)
  82. {
  83. var allFfuName = FFUDataList.Select(a => $"PM1.{a.RTName}.DeviceData").ToList();
  84. var allRtData = QueryDataClient.Instance.Service.PollData(allFfuName);
  85. foreach (var item in FFUDataList)
  86. {
  87. var rtItem = allRtData.FirstOrDefault(a => a.Key == $"PM1.{item.RTName}.DeviceData");
  88. if (rtItem.Value == null)
  89. continue;
  90. item.DisplayName = ((AITFFUData)rtItem.Value).DisplayName;
  91. item.ActualValue = ((AITFFUData)rtItem.Value).Feedback;
  92. item.IsSwitch = ((AITFFUData)rtItem.Value).IsSwitchOn;
  93. }
  94. }
  95. }
  96. public void AllFFUPower(string value)
  97. {
  98. var setValue = bool.Parse(value);
  99. if (setValue)
  100. {
  101. PowerOnVisibility = false;
  102. PowerOffVisibility = true;
  103. }
  104. else
  105. {
  106. PowerOnVisibility = true;
  107. PowerOffVisibility = false;
  108. }
  109. InvokeClient.Instance.Service.DoOperation($"PM1.SetAllFFUPower", setValue);
  110. }
  111. public void SetValueTextChanged(string type, object sender, object item)
  112. {
  113. try
  114. {
  115. }
  116. catch (Exception ex)
  117. {
  118. LOG.Write(ex);
  119. }
  120. }
  121. public void Save()
  122. {
  123. if (!DialogBox.Confirm("Are you sure Determine the speed parameters for FFU"))
  124. return;
  125. foreach (var item in FFUDataList)
  126. {
  127. InvokeClient.Instance.Service.DoOperation($"PM1.{item.RTName}.SetCurrectSpeed", item.Value);
  128. }
  129. (GetView() as Window).Close();
  130. }
  131. public void Cancle()
  132. {
  133. (GetView() as Window).Close();
  134. }
  135. public void AllSetClick(object sender)
  136. {
  137. string stSetValue = ShowNumberKeyboard(sender as Button, "", 1);
  138. var values = QueryDataClient.Instance.Service.PollData(FFUKeyDict).Values.Select(a => (a as AITFFUData)).ToList();
  139. foreach (var item in FFUDataList)
  140. {
  141. var rtData = values.FirstOrDefault(a => a.RTName == item.RTName);
  142. if (rtData == null)
  143. continue;
  144. item.Value = stSetValue;
  145. }
  146. }
  147. private string ShowNumberKeyboard(Control control, string defaultValue, int keepDecimals = -1)
  148. {
  149. NumberKeyboard numberKeyboard = new NumberKeyboard("", defaultValue);
  150. numberKeyboard.KeepDecimals = keepDecimals;
  151. var point = control.PointFromScreen(new Point(0, 0));
  152. double wx = SystemParameters.WorkArea.Width;
  153. double hy = SystemParameters.WorkArea.Height;
  154. if (-point.Y + control.ActualHeight + 5 + numberKeyboard.Height < hy)
  155. {
  156. numberKeyboard.Top = -point.Y + control.ActualHeight + 5;
  157. }
  158. else
  159. {
  160. numberKeyboard.Top = -point.Y - numberKeyboard.Height - 5;
  161. }
  162. if (-point.X + numberKeyboard.Width < wx)
  163. {
  164. numberKeyboard.Left = -point.X;
  165. }
  166. else
  167. {
  168. numberKeyboard.Left = -point.X - (numberKeyboard.Width - control.ActualWidth);
  169. }
  170. if ((bool)numberKeyboard.ShowDialog())
  171. return numberKeyboard.ValueString;
  172. else
  173. return "Cancel";
  174. }
  175. }
  176. public class FFUData : PropertyChangedBase
  177. {
  178. private int _no;
  179. public int No
  180. {
  181. get => _no;
  182. set
  183. {
  184. _no = value;
  185. NotifyOfPropertyChange(nameof(No));
  186. }
  187. }
  188. private string _rtName;
  189. public string RTName
  190. {
  191. get => _rtName;
  192. set
  193. {
  194. _rtName = value;
  195. NotifyOfPropertyChange(nameof(RTName));
  196. }
  197. }
  198. private string _displayName;
  199. public string DisplayName
  200. {
  201. get => _displayName;
  202. set
  203. {
  204. _displayName = value;
  205. NotifyOfPropertyChange(nameof(DisplayName));
  206. }
  207. }
  208. private double _lastSetValue;
  209. public double LastSetValue
  210. {
  211. get => _lastSetValue;
  212. set
  213. {
  214. _lastSetValue = value;
  215. NotifyOfPropertyChange(nameof(LastSetValue));
  216. }
  217. }
  218. private double _actualValue;
  219. public double ActualValue
  220. {
  221. get => _actualValue;
  222. set
  223. {
  224. _actualValue = value;
  225. NotifyOfPropertyChange(nameof(ActualValue));
  226. }
  227. }
  228. private string _value;
  229. public string Value
  230. {
  231. get => _value;
  232. set
  233. {
  234. _value = value;
  235. NotifyOfPropertyChange(nameof(Value));
  236. }
  237. }
  238. private bool _isSwitch;
  239. public bool IsSwitch
  240. {
  241. get => _isSwitch;
  242. set
  243. {
  244. _isSwitch = value;
  245. NotifyOfPropertyChange(nameof(IsSwitch));
  246. }
  247. }
  248. private string _maxValue;
  249. public string MaxValue
  250. {
  251. get => _maxValue; set
  252. {
  253. _maxValue = value;
  254. NotifyOfPropertyChange(nameof(MaxValue));
  255. }
  256. }
  257. private string _minValue;
  258. public string MinValue
  259. {
  260. get => _minValue; set
  261. {
  262. _minValue = value;
  263. NotifyOfPropertyChange(nameof(MinValue));
  264. }
  265. }
  266. private bool _isSetChanged = true;
  267. public bool IsSetChanged
  268. {
  269. get => _isSetChanged;
  270. set
  271. {
  272. _isSetChanged = value;
  273. NotifyOfPropertyChange(nameof(IsSetChanged));
  274. }
  275. }
  276. }
  277. }