RecipeGASSettingMFCAlarmViewModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using Caliburn.Micro.Core;
  2. using MECF.Framework.Common.RecipeCenter;
  3. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  4. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  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 System.Windows.Controls;
  13. using FurnaceUI.Models;
  14. namespace FurnaceUI.Views.Editors
  15. {
  16. public class RecipeGASSettingMFCAlarmViewModel : FurnaceUIViewModelBase
  17. {
  18. ConfigNode currentNode = SystemConfigProvider.Instance.GetConfig(true);
  19. public ConfigNode CurrentNode
  20. {
  21. get { return currentNode; }
  22. set { currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); }
  23. }
  24. private List<ConfigItem> currenItems;
  25. public List<ConfigItem> CurrenItems
  26. {
  27. get { return currenItems; }
  28. set { currenItems = value; this.NotifyOfPropertyChange(nameof(CurrenItems)); }
  29. }
  30. public string CurrentValue { get; set; }
  31. public RecipeGASSettingMFCAlarmViewModel(string strCurrentValue)
  32. {
  33. CurrentValue = strCurrentValue;
  34. }
  35. private Visibility visibilityShow;
  36. public Visibility VisibilityShow
  37. {
  38. get => visibilityShow;
  39. set
  40. {
  41. visibilityShow = value;
  42. NotifyOfPropertyChange(nameof(VisibilityShow));
  43. }
  44. }
  45. protected override void OnInitialize()
  46. {
  47. base.OnInitialize();
  48. CurrentNode = FindNodeByName(CurrentNode, "PM1.RecipeEditParameter.AlarmWatchTable.FlowAlarmWatch");
  49. currentNode.SubNodes.Insert(0, new ConfigNode() { Name = "None", IsSelected = false }); ;//增加选项0
  50. GetDataOfConfigItems(CurrentNode);
  51. if (CurrentValue == "None")
  52. {
  53. CurrenItems = CurrentNode.SubNodes[0].Items;
  54. CurrentNode.SubNodes[0].IsSelected = true;
  55. VisibilityShow = Visibility.Hidden;
  56. }
  57. else
  58. {
  59. CurrenItems = CurrentNode.SubNodes[int.Parse(CurrentValue)].Items;
  60. CurrentNode.SubNodes[int.Parse(CurrentValue)].IsSelected = true;
  61. VisibilityShow = Visibility.Visible;
  62. }
  63. }
  64. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  65. {
  66. string strCates = strName.Split('.')[0];
  67. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  68. if (node == null)
  69. {
  70. return parentNode;
  71. }
  72. else
  73. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  74. }
  75. private void GetDataOfConfigItems(ConfigNode node)
  76. {
  77. if (node.Items == null && node.SubNodes == null) return;
  78. if(node.Items.Count<=0)
  79. {
  80. foreach (var item in node.SubNodes)
  81. {
  82. GetDataOfConfigItems(item);
  83. }
  84. }
  85. else
  86. {
  87. foreach (var item in node.Items)
  88. {
  89. string key = String.Format("{0}.{1}.{2}", node.Path,node.Name, item.Name);
  90. item.CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);
  91. item.Path = key;
  92. if (item.Type == DataType.Bool)
  93. {
  94. bool value;
  95. if (bool.TryParse(item.CurrentValue, out value))
  96. {
  97. item.BoolValue = value;
  98. item.CurrentValue = value ? "Yes" : "No";
  99. }
  100. }
  101. else
  102. item.StringValue = item.CurrentValue;
  103. }
  104. }
  105. }
  106. public void MenuCommand(object obj, object menuLevel)
  107. {
  108. RadioButton radioButton = obj as RadioButton;
  109. CurrentValue = radioButton.Content.ToString();
  110. if (CurrentValue == "None")
  111. {
  112. CurrenItems = CurrentNode.SubNodes[0].Items;
  113. VisibilityShow = Visibility.Hidden;
  114. }
  115. else
  116. {
  117. CurrenItems = CurrentNode.SubNodes[int.Parse(CurrentValue)].Items;
  118. VisibilityShow = Visibility.Visible;
  119. }
  120. }
  121. public void Close()
  122. {
  123. ((Window)GetView()).DialogResult = false;
  124. }
  125. public void Save()
  126. {
  127. ((Window)GetView()).DialogResult = true;
  128. }
  129. }
  130. }