RecipePressureAlarmWatchTableSettingViewModel.cs 9.3 KB

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