AlarmErrorJumpStepViewModel.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Caliburn.Micro;
  2. using MECF.Framework.Common.OperationCenter;
  3. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  4. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  5. using MECF.Framework.UI.Client.ClientBase;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Aitex.Core.RT.SCCore;
  13. using MECF.Framework.Common.DataCenter;
  14. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  15. using OpenSEMI.ClientBase;
  16. using SciChart.Core.Extensions;
  17. using System.Globalization;
  18. using System.Windows;
  19. using System.Windows.Controls;
  20. using System.Windows.Data;
  21. using System.Windows.Threading;
  22. using FurnaceUI.Models;
  23. using FurnaceUI.Views.Parameter;
  24. namespace FurnaceUI.Views.Editors
  25. {
  26. public class AlarmErrorJumpStepViewModel : FurnaceUIViewModelBase
  27. {
  28. private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();
  29. public string ResultParameterStr { get; set; }
  30. public ObservableCollection<ConfigItem> StepNames { get; set; } = new ObservableCollection<ConfigItem>();
  31. private string currentValue;
  32. private string path;
  33. private ConfigNode _rootNode;
  34. private ConfigNode _currentNode;
  35. private string _CurrentNodeName = string.Empty;
  36. string strHeader = "PM1.RecipeEditParameter";
  37. public ConfigNode CurrentNode
  38. {
  39. get { return _currentNode; }
  40. set { _currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); }
  41. }
  42. public AlarmErrorJumpStepViewModel()
  43. {
  44. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  45. InitAllParameterTree(new ParamBase() { ID = 1, ParentID = 0, Name = "StepName", ConfigName = "StepName" });
  46. var stepNameNode = FindNodeByName(_rootNode, $"PM1.RecipeEditParameter.StepName");
  47. if (stepNameNode != null && stepNameNode.Items.Count > 0)
  48. {
  49. stepNameNode.Items.ForEach(x => StepNames.Add(x));
  50. }
  51. }
  52. private void InitItemsCurrentValue(ConfigNode node, bool initSubItems = true)
  53. {
  54. if (node == null) return;
  55. _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
  56. if (node.Items == null || node.Items.Count <= 0)
  57. {
  58. if (!initSubItems) return;
  59. foreach (var item in node.SubNodes)
  60. {
  61. InitItemsCurrentValue(item);
  62. }
  63. }
  64. else
  65. {
  66. GetDataOfConfigItems(node);
  67. }
  68. }
  69. private void GetDataOfConfigItems(ConfigNode node)
  70. {
  71. if (node.Items == null)
  72. return;
  73. List<string> allItems = new List<string>();
  74. for (int i = 0; i < node.Items.Count; i++)
  75. {
  76. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", node.Items[i].Name);
  77. allItems.Add(key);
  78. }
  79. List<string> newallItems = allItems.Distinct().ToList();
  80. var DictItems = QueryDataClient.Instance.Service.PollConfig(newallItems);
  81. for (int i = 0; i < node.Items.Count; i++)
  82. {
  83. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", node.Items[i].Name);
  84. node.Items[i].CurrentValue = DictItems.ContainsKey(key) ? DictItems[key].ToString() : "";
  85. node.Items[i].Path = key;
  86. //if (CurrenItems[i].Path.Contains("PM1.RecipeEditParameter.PressureStabilizeTable"))
  87. // DefaultUnit = CurrenItems[i].Unit;
  88. if (node.Items[i].Type == DataType.Bool)
  89. {
  90. bool value;
  91. if (bool.TryParse(node.Items[i].CurrentValue, out value))
  92. {
  93. node.Items[i].BoolValue = value;
  94. node.Items[i].CurrentValue = value ? "Yes" : "No";
  95. }
  96. }
  97. else
  98. node.Items[i].StringValue = node.Items[i].CurrentValue;
  99. }
  100. }
  101. private void InitAllParameterTree(ParamBase para)
  102. {
  103. CurrentNode = new ConfigNode();
  104. CurrentNode = FindNodeByName(_rootNode, $"{strHeader}.{para.ConfigName}");
  105. InitItemsCurrentValue(CurrentNode, true);
  106. if (CurrentNode.SubNodes != null)
  107. {
  108. foreach (var item in CurrentNode.SubNodes)
  109. {
  110. InitItemsCurrentValue(item, true);
  111. }
  112. }
  113. }
  114. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  115. {
  116. string strCates = strName.Split('.')[0];
  117. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  118. if (node == null)
  119. return parentNode;
  120. else
  121. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  122. }
  123. public void SetStepNameValue(object obj)
  124. {
  125. if (StepNames == null || StepNames.Count == 0) return;
  126. ConfigItem item = obj as ConfigItem;
  127. ResultParameterStr = $"{item.Name}:{item.CurrentValue}";
  128. ((Window)GetView()).DialogResult = true;
  129. }
  130. public void CloseCommand()
  131. {
  132. ((Window)GetView()).DialogResult = false;
  133. }
  134. }
  135. }