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