RecipePressureSensorSettingViewModel.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using Caliburn.Micro;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.OperationCenter;
  4. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  5. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  6. using OpenSEMI.ClientBase;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using FurnaceUI.Models;
  15. namespace FurnaceUI.Views.Editors
  16. {
  17. public class RecipePressureSensorSettingViewModel : FurnaceUIViewModelBase
  18. {
  19. private string _selectPressureSonsorValue = "0";
  20. public string SelectPressureSonsorValue
  21. {
  22. get
  23. {
  24. return _selectPressureSonsorValue;
  25. }
  26. set
  27. {
  28. _selectPressureSonsorValue = value;
  29. NotifyOfPropertyChange("SelectPressureSonsorValue");
  30. }
  31. }
  32. public double PressureScale
  33. {
  34. get;
  35. set;
  36. }
  37. //public Dictionary<string, string> RecipePressureValveAngleList = new Dictionary<string, string>();
  38. public bool IsSave { get; set; } = false;
  39. public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  40. private string _CurrentNodeName = string.Empty;
  41. private ConfigNode levelOneNode;
  42. public ConfigNode LevelOneNode
  43. {
  44. get { return levelOneNode; }
  45. set { levelOneNode = value; this.NotifyOfPropertyChange(nameof(LevelOneNode)); }
  46. }
  47. private List<ConfigItem> currenItems;
  48. public List<ConfigItem> CurrenItems
  49. {
  50. get { return currenItems; }
  51. set { currenItems = value; this.NotifyOfPropertyChange(nameof(CurrenItems)); }
  52. }
  53. private ConfigNode _rootNode;
  54. private bool _isPressureSetpoint;
  55. public bool IsPressureSetpoint
  56. {
  57. get { return _isPressureSetpoint; }
  58. set { _isPressureSetpoint = value; NotifyOfPropertyChange(nameof(IsPressureSetpoint)); }
  59. }
  60. protected override void OnViewLoaded(object view)
  61. {
  62. base.OnViewLoaded(view);
  63. IsPressureSetpoint = true;
  64. this.SystemName = "System";
  65. string strHeader = "PM1.RecipeEditParameter";
  66. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  67. LevelOneNode = FindNodeByName(_rootNode, $"{strHeader}.APCSetting.Pressure");
  68. InitItemsCurrentValue(LevelOneNode, false);
  69. PressureScale = (double)QueryDataClient.Instance.Service.GetConfig("PM1.APC.PressureScale");
  70. //foreach (var item in RecipePressureValveAngleList.Keys)
  71. //{
  72. // object Txt = ((RecipePressureSensorSettingView)(((Window)GetView()).Content)).FindName("Txt" + item);
  73. // if (Txt is TextBlock)
  74. // {
  75. // ((TextBlock)Txt).Text = RecipePressureValveAngleList[item];
  76. // }
  77. //}
  78. }
  79. private void InitItemsCurrentValue(ConfigNode node, bool initSubItems = true)
  80. {
  81. if (node == null) return;
  82. CurrenItems = node.Items;
  83. _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
  84. if (CurrenItems == null || CurrenItems.Count <= 0)
  85. {
  86. if (!initSubItems) return;
  87. foreach (var item in node.SubNodes)
  88. {
  89. InitItemsCurrentValue(item);
  90. }
  91. }
  92. else
  93. {
  94. GetDataOfConfigItems();
  95. }
  96. }
  97. private void GetDataOfConfigItems()
  98. {
  99. if (CurrenItems == null)
  100. return;
  101. for (int i = 0; i < CurrenItems.Count; i++)
  102. {
  103. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", CurrenItems[i].Name);
  104. CurrenItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);
  105. CurrenItems[i].Path = key;
  106. }
  107. //var temp = GenerateAToZ();
  108. //var index = 0.1;
  109. //foreach (var item in temp)
  110. //{
  111. // RecipePressureSensorList[item] = index.ToString();// SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.StepTime.{item}");
  112. // index += 0.1;
  113. //}
  114. }
  115. public void SetValue(string nameCmd, string valueCmd)
  116. {
  117. if (nameCmd == "Value")
  118. {
  119. IsPressureSetpoint = true;
  120. }
  121. else
  122. {
  123. SelectPressureSonsorValue = nameCmd + ":" + valueCmd;
  124. IsPressureSetpoint = false;
  125. }
  126. }
  127. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  128. {
  129. string strCates = strName.Split('.')[0];
  130. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  131. if (node == null)
  132. return parentNode;
  133. else
  134. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  135. }
  136. public void SaveCmd()
  137. {
  138. IsSave = true;
  139. ((Window)GetView()).DialogResult = true;
  140. }
  141. public void CloseCmd()
  142. {
  143. IsSave = false;
  144. ((Window)GetView()).DialogResult = false;
  145. }
  146. IEnumerable<string> GenerateAToZ()
  147. {
  148. for (char c = 'A'; c <= 'Z'; c++)
  149. yield return new string(c, 1);
  150. }
  151. }
  152. }