TempAllZoneValueSetViewModel.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  10. using FurnaceUI.Models;
  11. namespace FurnaceUI.Views.Editors
  12. {
  13. public class TempAllZoneValueSetViewModel : FurnaceUIViewModelBase
  14. {
  15. public bool IsSave { get; set; } = false;
  16. public List<ConfigItem> CurrentNodeItems { get; set; } = new List<ConfigItem>();
  17. private ConfigNode _currentNode;
  18. public ConfigNode CurrentNode
  19. {
  20. get { return _currentNode; }
  21. set { _currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); }
  22. }
  23. public ConfigNode SelectedNode { get; set; }
  24. public string RecipeType { get; set; }
  25. public Visibility IsVisibilityContinue { get; set; } = Visibility.Visible;
  26. protected override void OnInitialize()
  27. {
  28. base.OnInitialize();
  29. //if (RecipeType == "Sub" || RecipeType == "Abort Sub" || RecipeType == "Abort")
  30. // IsVisibilityContinue = Visibility.Visible;
  31. GetDataOfConfigItems();
  32. }
  33. //private bool isValueButtonEnable;
  34. //public bool IsValueButtonEnable
  35. //{
  36. // get
  37. // {
  38. // isValueButtonEnable = true;
  39. // for (int i = 0; i < 5; i++)
  40. // {
  41. // if (string.IsNullOrEmpty((((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt{i + 1}") as TextBox).Text))
  42. // {
  43. // isValueButtonEnable = false;
  44. // break;
  45. // }
  46. // }
  47. // return isValueButtonEnable;
  48. // }
  49. // set { isValueButtonEnable = value; this.NotifyOfPropertyChange(nameof(IsValueButtonEnable)); }
  50. //}
  51. private bool _isValueButtonEnable;
  52. public bool IsValueButtonEnable
  53. {
  54. get => _isValueButtonEnable;
  55. set
  56. {
  57. _isValueButtonEnable = value;
  58. NotifyOfPropertyChange("IsValueButtonEnable");
  59. }
  60. }
  61. private string _TempModel;
  62. public string TempModel
  63. {
  64. get { return _TempModel; }
  65. set
  66. {
  67. _TempModel = value;
  68. NotifyOfPropertyChange("TempModel");
  69. }
  70. }
  71. public bool IsEnable => false;// CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  72. public void ValueTextChanged()
  73. {
  74. //this.NotifyOfPropertyChange(nameof(IsValueButtonEnable));
  75. }
  76. private void GetDataOfConfigItems()
  77. {
  78. ConfigNode rootNode = SystemConfigProvider.Instance.GetConfig(true);
  79. CurrentNode = FindNodeByName(rootNode, "PM1.RecipeEditParameter.TempSetting");
  80. foreach (var node in CurrentNode.SubNodes)
  81. {
  82. List<string> temperature = new List<string>();
  83. CurrentNodeItems = node.Items;
  84. foreach (var item in node.Items)
  85. {
  86. string strPath = $"PM1.RecipeEditParameter.TempSetting.{node.Name}.{item.Name}";
  87. item.CurrentValue = SystemConfigProvider.Instance.GetValueByName(strPath);
  88. item.Path = strPath;
  89. }
  90. }
  91. }
  92. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  93. {
  94. string strCates = strName.Split('.')[0];
  95. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  96. if (node == null)
  97. return parentNode;
  98. else
  99. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  100. }
  101. public void SetTempValue(object obj)
  102. {
  103. if (obj is ConfigNode)
  104. {
  105. IsValueButtonEnable = false;
  106. TempModel = "Temp";
  107. SelectedNode = obj as ConfigNode;
  108. for (int i = 0; i < SelectedNode.Items.Count; i++)
  109. {
  110. (((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt{i + 1}") as TextBox).Text = SelectedNode.Items[i].CurrentValue;
  111. }
  112. }
  113. else if (obj.ToString() == "Continue")
  114. {
  115. ConfigNode node = new ConfigNode();
  116. node.Items = new List<ConfigItem>();
  117. for (int i = 0; i < 5; i++)
  118. {
  119. node.Items.Add(new ConfigItem() { CurrentValue = obj.ToString() });
  120. }
  121. SelectedNode = node;
  122. }
  123. else
  124. {
  125. IsValueButtonEnable = true;
  126. TempModel = "Value";
  127. for (int i = 0; i < 5; i++)
  128. {
  129. (((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt{i + 1}") as TextBox).Text = "";
  130. }
  131. }
  132. }
  133. public void SaveCmd()
  134. {
  135. if (TempModel == "Value")
  136. {
  137. ConfigNode node = new ConfigNode();
  138. node.Items = new List<ConfigItem>();
  139. node.Items.Add(new ConfigItem() { CurrentValue = (((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt6") as TextBox).Text });
  140. SelectedNode = node;
  141. }
  142. IsSave = true;
  143. ((Window)GetView()).DialogResult = true;
  144. }
  145. public void CloseCmd()
  146. {
  147. IsSave = false;
  148. ((Window)GetView()).DialogResult = false;
  149. }
  150. }
  151. }