RecipePressureValveAngleSettingViewModel.cs 5.4 KB

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