ValveInterlockViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. using MECF.Framework.Common.CommonData;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.IOCore;
  4. using OpenSEMI.ClientBase;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using FurnaceUI.Models;
  13. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  14. using MECF.Framework.UI.Client.ClientBase;
  15. using Caliburn.Micro.Core;
  16. using Caliburn.Micro;
  17. using MECF.Framework.Common.OperationCenter;
  18. namespace FurnaceUI.Views.Operations
  19. {
  20. public class ValveInterlockViewModel : FurnaceUIViewModelBase, ISupportMultipleSystem
  21. {
  22. public string ItemType { get; set; }
  23. public ObservableCollection<ValveInterLock> InterlockNodes { get; set; } = new ObservableCollection<ValveInterLock>();
  24. // public ObservableCollection<ConfigItem> InterlockNodes { get; set; } = new ObservableCollection<ConfigItem>();
  25. private ConfigNode _valveInterSelectedItem;
  26. public ConfigNode ValveInterSelectedItem
  27. {
  28. get => _valveInterSelectedItem;
  29. set
  30. {
  31. _valveInterSelectedItem = value;
  32. NotifyOfPropertyChange(nameof(ValveInterSelectedItem));
  33. }
  34. }
  35. public ValveInterlockViewModel()
  36. {
  37. }
  38. protected override void OnInitialize()
  39. {
  40. base.OnInitialize();
  41. }
  42. string strHeader = "PM1.RecipeEditParameter";
  43. private ConfigNode _rootNode;
  44. protected override void OnViewLoaded(object view)
  45. {
  46. base.OnViewLoaded(view);
  47. InitItem();
  48. }
  49. private void InitItem()
  50. {
  51. _CurrentNodeName = "";
  52. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  53. SystemConfigProvider.Instance.GetConfigTree("PM1");
  54. var stepNameNode = FindNodeByName(_rootNode, $"{strHeader}.InterLock");
  55. InterlockNodes.Clear();
  56. if (stepNameNode != null && stepNameNode.SubNodes.Count > 0)
  57. {
  58. // stepNameNode.SubNodes.ForEach(x => InterlockNodes.Add(x.Items[0]));
  59. foreach (var item in stepNameNode.SubNodes)
  60. {
  61. ValveInterLock valveInterLock = new ValveInterLock();
  62. valveInterLock.Index = item.Name;
  63. foreach (var subitem in item.Items)
  64. {
  65. switch (subitem.Name)
  66. {
  67. case "Name":
  68. valveInterLock.Name = subitem;
  69. break;
  70. case "NoneOrExist":
  71. valveInterLock.NoneOrExist = subitem;
  72. break;
  73. case "Normaly0nOrOff":
  74. valveInterLock.Normaly0nOrOff = subitem;
  75. break;
  76. case "DelayOnTime":
  77. valveInterLock.DelayOnTime = subitem;
  78. break;
  79. case "DelayOffTime":
  80. valveInterLock.DelayOffTime = subitem;
  81. break;
  82. case "ILKTime":
  83. valveInterLock.ILKTime = subitem;
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. InterlockNodes.Add(valveInterLock);
  90. }
  91. }
  92. // getValves.ToList().ForEach(x => InterlockNodes.Add(x));
  93. GetDataOfConfigItems();
  94. }
  95. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  96. {
  97. string strCates = strName.Split('.')[0];
  98. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  99. if (node == null)
  100. return parentNode;
  101. else
  102. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  103. }
  104. string _CurrentNodeName = string.Empty;
  105. private void GetDataOfConfigItems()
  106. {
  107. if (InterlockNodes == null)
  108. return;
  109. _CurrentNodeName = "PM1.RecipeEditParameter.InterLock";
  110. for (int i = 0; i < InterlockNodes.Count; i++)
  111. {
  112. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", InterlockNodes[i].Index);
  113. InterlockNodes[i].Name.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.Name");
  114. var strNoneOrExist= SystemConfigProvider.Instance.GetValueByName($"{key}.NoneOrExist");
  115. if (!string.IsNullOrEmpty(strNoneOrExist))
  116. {
  117. bool.TryParse(strNoneOrExist, out bool noneOrExist);
  118. InterlockNodes[i].NoneOrExist.BoolValue = noneOrExist;
  119. }
  120. var strNormaly0nOrOff = SystemConfigProvider.Instance.GetValueByName($"{key}.Normaly0nOrOff");
  121. if (!string.IsNullOrEmpty(strNormaly0nOrOff))
  122. {
  123. bool.TryParse(strNormaly0nOrOff, out bool normaly0nOrOff);
  124. InterlockNodes[i].Normaly0nOrOff.BoolValue = normaly0nOrOff;
  125. }
  126. InterlockNodes[i].DelayOnTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.DelayOnTime");
  127. InterlockNodes[i].DelayOffTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.DelayOffTime");
  128. InterlockNodes[i].ILKTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.ILKTime");
  129. }
  130. }
  131. public void SelectItem()
  132. {
  133. }
  134. private bool CheckValues()
  135. {
  136. bool rtn = true;
  137. foreach (var item in InterlockNodes)
  138. {
  139. if (item.Name!=null && !string.IsNullOrEmpty(item.Name.CurrentValue))
  140. {
  141. if ((item.NoneOrExist != null && item.NoneOrExist.BoolValue) && (item.Normaly0nOrOff != null && item.Normaly0nOrOff.BoolValue))
  142. {
  143. float _delayOnTime = 0;
  144. float _delayILKTime = 0;
  145. if (item.DelayOnTime != null)
  146. {
  147. var timeParas = item.DelayOnTime.CurrentValue.Split(':');
  148. if (timeParas.Length > 1)
  149. {
  150. float.TryParse(timeParas[0], out float min);
  151. float.TryParse(timeParas[1], out float sec);
  152. _delayOnTime = min * 60 * 1000 + sec * 1000;
  153. }
  154. }
  155. if (item.ILKTime != null )
  156. {
  157. var timeParas = item.ILKTime.CurrentValue.Split(':');
  158. if (timeParas.Length > 1)
  159. {
  160. float.TryParse(timeParas[0], out float min);
  161. float.TryParse(timeParas[1], out float sec);
  162. _delayILKTime = min * 60 * 1000 + sec * 1000;
  163. }
  164. }
  165. if (_delayILKTime != 0 && _delayOnTime > _delayILKTime)
  166. {
  167. DialogBox.ShowWarning($"Index:{item.Index},Name:{item.Name.CurrentValue} setup error,DelayOnTime: {item.DelayOnTime.CurrentValue} is greater than ILKTime: {item.ILKTime.CurrentValue}");
  168. rtn = false;
  169. return rtn;
  170. }
  171. }
  172. }
  173. }
  174. return rtn;
  175. }
  176. public void SaveCmd()
  177. {
  178. if (InterlockNodes == null) return;
  179. if (!CheckValues()) return;
  180. foreach (var item in InterlockNodes)
  181. {
  182. if (item.Name!=null && !item.Name.TextSaved)
  183. {
  184. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.Name.Path}.{item.Name.Name}", item.Name.CurrentValue);
  185. item.Name.TextSaved = true;
  186. }
  187. if (item.NoneOrExist != null && !item.NoneOrExist.TextSaved)
  188. {
  189. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.NoneOrExist.Path}.{item.NoneOrExist.Name}", item.NoneOrExist.BoolValue.ToString());
  190. item.NoneOrExist.TextSaved = true;
  191. }
  192. if (item.Normaly0nOrOff != null && !item.Normaly0nOrOff.TextSaved)
  193. {
  194. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.Normaly0nOrOff.Path}.{item.Normaly0nOrOff.Name}", item.Normaly0nOrOff.BoolValue.ToString());
  195. item.Normaly0nOrOff.TextSaved = true;
  196. }
  197. if (item.DelayOnTime != null && !item.DelayOnTime.TextSaved)
  198. {
  199. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.DelayOnTime.Path}.{item.DelayOnTime.Name}", item.DelayOnTime.CurrentValue);
  200. item.Name.TextSaved = true;
  201. }
  202. if (item.DelayOffTime != null && !item.DelayOffTime.TextSaved)
  203. {
  204. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.DelayOffTime.Path}.{item.DelayOffTime.Name}", item.DelayOffTime.CurrentValue);
  205. item.Name.TextSaved = true;
  206. }
  207. if (item.ILKTime != null && !item.ILKTime.TextSaved)
  208. {
  209. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.ILKTime.Path}.{item.ILKTime.Name}", item.ILKTime.CurrentValue);
  210. item.Name.TextSaved = true;
  211. }
  212. }
  213. }
  214. public void CancelCmd()
  215. {
  216. // ((Window)GetView()).DialogResult = false;
  217. }
  218. public void Normaly0nOrOffClick(ConfigItem value)
  219. {
  220. value.BoolValue = !value.BoolValue;
  221. value.TextSaved = false;
  222. }
  223. public void NoneOrExistClick(ConfigItem value)
  224. {
  225. value.BoolValue = !value.BoolValue;
  226. value.TextSaved = false;
  227. }
  228. public void SaveTimeValue(ConfigItem value)
  229. {
  230. var windowManager = IoC.Get<IWindowManager>();
  231. ValveInterlockTimeViewModel recipeStepTimeViewModel = new ValveInterlockTimeViewModel("DelayTime");
  232. recipeStepTimeViewModel.SelectValueTime = value.CurrentValue;
  233. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Step Time Set");
  234. if (recipeStepTimeViewModel.IsSave)
  235. {
  236. value.CurrentValue = recipeStepTimeViewModel.SelectValueTime;
  237. value.TextSaved = false;
  238. }
  239. }
  240. public void SetNameValue(ConfigItem value, ValveInterLock valveInterLock)
  241. {
  242. value.TextSaved = false;
  243. valveInterLock.UpdataIsEndble();
  244. }
  245. }
  246. public class ValveInterLock : PropertyChangedBase
  247. {
  248. public string Index { get; set; }
  249. public ConfigItem Name { get; set; }
  250. public void UpdataIsEndble()
  251. {
  252. NotifyOfPropertyChange(nameof(IsEndble));
  253. }
  254. public bool IsEndble
  255. {
  256. get
  257. {
  258. if (Name == null) return false;
  259. if (string.IsNullOrEmpty(Name.CurrentValue.Trim()))
  260. {
  261. return false;
  262. }
  263. return true;
  264. }
  265. }
  266. public ConfigItem NoneOrExist { get; set; }
  267. public ConfigItem Normaly0nOrOff { get; set; }
  268. public ConfigItem DelayOnTime { get; set; }
  269. public ConfigItem DelayOffTime { get; set; }
  270. public ConfigItem ILKTime { get; set; }
  271. }
  272. }