ValveInterlockViewModel.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 "DelayTime":
  77. valveInterLock.DelayTime = subitem;
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. InterlockNodes.Add(valveInterLock);
  84. }
  85. }
  86. // getValves.ToList().ForEach(x => InterlockNodes.Add(x));
  87. GetDataOfConfigItems();
  88. }
  89. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  90. {
  91. string strCates = strName.Split('.')[0];
  92. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  93. if (node == null)
  94. return parentNode;
  95. else
  96. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  97. }
  98. string _CurrentNodeName = string.Empty;
  99. private void GetDataOfConfigItems()
  100. {
  101. if (InterlockNodes == null)
  102. return;
  103. _CurrentNodeName = "PM1.RecipeEditParameter.InterLock";
  104. for (int i = 0; i < InterlockNodes.Count; i++)
  105. {
  106. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", InterlockNodes[i].Index);
  107. InterlockNodes[i].Name.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.Name");
  108. var strNoneOrExist= SystemConfigProvider.Instance.GetValueByName($"{key}.NoneOrExist");
  109. if (!string.IsNullOrEmpty(strNoneOrExist))
  110. {
  111. bool.TryParse(strNoneOrExist, out bool noneOrExist);
  112. InterlockNodes[i].NoneOrExist.BoolValue = noneOrExist;
  113. }
  114. var strNormaly0nOrOff = SystemConfigProvider.Instance.GetValueByName($"{key}.Normaly0nOrOff");
  115. if (!string.IsNullOrEmpty(strNormaly0nOrOff))
  116. {
  117. bool.TryParse(strNormaly0nOrOff, out bool normaly0nOrOff);
  118. InterlockNodes[i].Normaly0nOrOff.BoolValue = normaly0nOrOff;
  119. }
  120. InterlockNodes[i].DelayTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.DelayTime");
  121. }
  122. }
  123. public void SelectItem()
  124. {
  125. }
  126. public void SaveCmd()
  127. {
  128. if (InterlockNodes == null) return;
  129. foreach (var item in InterlockNodes)
  130. {
  131. if (item.Name!=null && !item.Name.TextSaved)
  132. {
  133. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.Name.Path}.{item.Name.Name}", item.Name.CurrentValue);
  134. item.Name.TextSaved = true;
  135. }
  136. if (item.NoneOrExist != null && !item.NoneOrExist.TextSaved)
  137. {
  138. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.NoneOrExist.Path}.{item.NoneOrExist.Name}", item.NoneOrExist.BoolValue.ToString());
  139. item.NoneOrExist.TextSaved = true;
  140. }
  141. if (item.Normaly0nOrOff != null && !item.Normaly0nOrOff.TextSaved)
  142. {
  143. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.Normaly0nOrOff.Path}.{item.Normaly0nOrOff.Name}", item.Normaly0nOrOff.BoolValue.ToString());
  144. item.Normaly0nOrOff.TextSaved = true;
  145. }
  146. if (item.DelayTime != null && !item.DelayTime.TextSaved)
  147. {
  148. InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.DelayTime.Path}.{item.DelayTime.Name}", item.DelayTime.CurrentValue);
  149. item.Name.TextSaved = true;
  150. }
  151. }
  152. }
  153. public void CancelCmd()
  154. {
  155. // ((Window)GetView()).DialogResult = false;
  156. }
  157. public void Normaly0nOrOffClick(ConfigItem value)
  158. {
  159. value.BoolValue = !value.BoolValue;
  160. value.TextSaved = false;
  161. }
  162. public void NoneOrExistClick(ConfigItem value)
  163. {
  164. value.BoolValue = !value.BoolValue;
  165. value.TextSaved = false;
  166. }
  167. public void SaveTimeValue(ConfigItem value)
  168. {
  169. var windowManager = IoC.Get<IWindowManager>();
  170. ValveInterlockTimeViewModel recipeStepTimeViewModel = new ValveInterlockTimeViewModel("DelayTime");
  171. recipeStepTimeViewModel.SelectValueTime = value.CurrentValue;
  172. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Step Time Set");
  173. if (recipeStepTimeViewModel.IsSave)
  174. {
  175. value.CurrentValue = recipeStepTimeViewModel.SelectValueTime;
  176. value.TextSaved = false;
  177. }
  178. }
  179. public void SetNameValue(ConfigItem value, ValveInterLock valveInterLock)
  180. {
  181. value.TextSaved = false;
  182. valveInterLock.UpdataIsEndble();
  183. }
  184. }
  185. public class ValveInterLock : PropertyChangedBase
  186. {
  187. public string Index { get; set; }
  188. public ConfigItem Name { get; set; }
  189. public void UpdataIsEndble()
  190. {
  191. NotifyOfPropertyChange(nameof(IsEndble));
  192. }
  193. public bool IsEndble
  194. {
  195. get
  196. {
  197. if (Name == null) return false;
  198. if (string.IsNullOrEmpty(Name.CurrentValue.Trim()))
  199. {
  200. return false;
  201. }
  202. return true;
  203. }
  204. }
  205. public ConfigItem NoneOrExist { get; set; }
  206. public ConfigItem Normaly0nOrOff { get; set; }
  207. public ConfigItem DelayTime { get; set; }
  208. }
  209. }