TempAlarmWatchTableSettingViewModel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using Caliburn.Micro;
  2. using FurnaceUI.Models;
  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. namespace FurnaceUI.Views.Editors
  15. {
  16. public class TempAlarmWatchTableSettingViewModel : FurnaceUIViewModelBase
  17. {
  18. public string SelectAlarmWatchTable { get; set; } = "None";
  19. public bool IsSave { get; set; } = false;
  20. private ConfigNode levelOneNode;
  21. public ConfigNode LevelOneNode
  22. {
  23. get { return levelOneNode; }
  24. set { levelOneNode = value; this.NotifyOfPropertyChange(nameof(LevelOneNode)); }
  25. }
  26. private ConfigNode levelTwoNode;
  27. public ConfigNode LevelTwoNode
  28. {
  29. get { return levelTwoNode; }
  30. set { levelTwoNode = value; this.NotifyOfPropertyChange(nameof(LevelTwoNode)); }
  31. }
  32. private List<ConfigItem> currenItems;
  33. public List<ConfigItem> CurrenItems
  34. {
  35. get { return currenItems; }
  36. set { currenItems = value; this.NotifyOfPropertyChange(nameof(CurrenItems)); }
  37. }
  38. private string _CurrentNodeName = string.Empty;
  39. private ConfigNode _rootNode;
  40. public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  41. private bool _isAlarmNoneChecked;
  42. public bool IsAlarmNoneChecked
  43. {
  44. get => _isAlarmNoneChecked;
  45. set
  46. {
  47. _isAlarmNoneChecked = value;
  48. NotifyOfPropertyChange(nameof(IsAlarmNoneChecked));
  49. }
  50. }
  51. public Visibility isForbid;
  52. public Visibility IsForbid
  53. {
  54. get { return isForbid; }
  55. set { isForbid = value; this.NotifyOfPropertyChange(nameof(IsForbid)); }
  56. }
  57. public bool isAvailabled;
  58. public bool IsAvailabled
  59. {
  60. get { return isAvailabled; }
  61. set { isAvailabled = value; this.NotifyOfPropertyChange(nameof(IsAvailabled)); }
  62. }
  63. protected override void OnViewLoaded(object view)
  64. {
  65. base.OnViewLoaded(view);
  66. IsAlarmNoneChecked = SelectAlarmWatchTable == "None";
  67. _rootNode = SystemConfigProvider.Instance.GetConfig(true);
  68. LevelOneNode = new ConfigNode();
  69. LevelOneNode = FindNodeByName(_rootNode, "PM1.RecipeEditParameter.AlarmWatchTable.PressureAlarmWatch");
  70. LevelTwoNode = LevelOneNode.SubNodes.FirstOrDefault();
  71. IsForbid = IsAlarmNoneChecked ? Visibility.Hidden : Visibility.Visible;
  72. if (SelectAlarmWatchTable != "None")
  73. {
  74. LevelOneNode.SubNodes[int.Parse(SelectAlarmWatchTable) - 1].AlarmWatchBoolValue = true;
  75. }
  76. InitItemsCurrentValue(LevelTwoNode, true);
  77. }
  78. //public void SetAlarmWatchTable(string nameCmd)
  79. //{
  80. // int iTableIndex = 0;
  81. // if (nameCmd != "None")
  82. // {
  83. // iTableIndex = int.Parse(nameCmd);
  84. // }
  85. // var windowManager = IoC.Get<IWindowManager>();
  86. // RecipeAlarmActionViewModel recipeAlarmActionViewModel = new RecipeAlarmActionViewModel() { TableIndex = iTableIndex };
  87. // (windowManager as WindowManager)?.ShowLiftCenterScreenDialogWithTitle(recipeAlarmActionViewModel, null, "Alarm Action");
  88. // SelectAlarmWatchTable = nameCmd;
  89. //}
  90. private void InitItemsCurrentValue(ConfigNode node, bool initSubItems = true)
  91. {
  92. if (node == null) return;
  93. CurrenItems = node.Items;
  94. _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{"Table" + SelectAlarmWatchTable}";
  95. if (CurrenItems == null || CurrenItems.Count <= 0)
  96. {
  97. if (!initSubItems) return;
  98. foreach (var item in node.SubNodes)
  99. {
  100. InitItemsCurrentValue(item);
  101. }
  102. }
  103. else
  104. {
  105. GetDataOfConfigItems();
  106. }
  107. }
  108. private void GetDataOfConfigItems()
  109. {
  110. if (CurrenItems == null)
  111. return;
  112. for (int i = 0; i < CurrenItems.Count; i++)
  113. {
  114. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", CurrenItems[i].Name);
  115. CurrenItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);
  116. CurrenItems[i].Path = key;
  117. CurrenItems[i].StringValue = CurrenItems[i].CurrentValue;
  118. }
  119. }
  120. public void MenuCommand(object obj, object menuLevel)
  121. {
  122. RadioButton radioButton = obj as RadioButton;
  123. ConfigNode currentNode = null;
  124. SelectAlarmWatchTable = radioButton.Content.ToString();
  125. IsForbid = Visibility.Visible;
  126. IsAvailabled = true;
  127. //IsAlarmNoneChecked = false;
  128. if (radioButton.Content.ToString() == "None")
  129. {
  130. IsForbid = Visibility.Hidden;
  131. IsAvailabled = false;
  132. return;
  133. }
  134. switch (menuLevel.ToString())
  135. {
  136. case "LevelOne":
  137. currentNode = LevelTwoNode = LevelOneNode.SubNodes.Find((x) => x.Name == radioButton.ToolTip.ToString());
  138. break;
  139. }
  140. InitItemsCurrentValue(currentNode);
  141. }
  142. public void SetValue(object obj)
  143. {
  144. if (CurrenItems == null || currenItems.Count == 0) return;
  145. ConfigItem item = null;
  146. if (obj is Control)
  147. item = CurrenItems.Find((x) => x.Name == (obj as Control).ToolTip.ToString());
  148. else
  149. item = obj as ConfigItem;
  150. InputDialogViewModel dialog = new InputDialogViewModel();
  151. dialog.Item = item;
  152. dialog.DisplayName = "Set Value";
  153. WindowManager wm = new WindowManager();
  154. bool? bret = wm.ShowDialog(dialog);
  155. if ((bool)bret)
  156. {
  157. item.StringValue = dialog.DialogResult;
  158. string value;
  159. if (item.Type == DataType.Int)
  160. {
  161. int iValue;
  162. if (int.TryParse(item.StringValue, out iValue))
  163. {
  164. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  165. {
  166. if (iValue > item.Max || iValue < item.Min)
  167. {
  168. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString()));
  169. return;
  170. }
  171. }
  172. }
  173. else
  174. {
  175. DialogBox.ShowWarning("Please input valid data.");
  176. return;
  177. }
  178. value = item.StringValue;
  179. }
  180. value = item.StringValue;
  181. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);
  182. InvokeClient.Instance.Service.DoOperation("System.SetConfig", item.Path, value);
  183. }
  184. }
  185. private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
  186. {
  187. string strCates = strName.Split('.')[0];
  188. ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
  189. if (node == null)
  190. return parentNode;
  191. else
  192. return FindNodeByName(node, strName.Replace(strCates + ".", ""));
  193. }
  194. public void SaveCmd()
  195. {
  196. IsSave = true;
  197. ((Window)GetView()).DialogResult = true;
  198. }
  199. public void CloseCmd()
  200. {
  201. IsSave = false;
  202. ((Window)GetView()).DialogResult = false;
  203. }
  204. }
  205. }