SystemConfigViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Windows;
  5. using Caliburn.Micro;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.OperationCenter;
  8. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  9. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  10. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  11. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  12. using MECF.Framework.UI.Client.ClientBase;
  13. using OpenSEMI.ClientBase;
  14. using OpenSEMI.ClientBase.Command;
  15. using FurnaceUI.Views.Parameter;
  16. namespace FurnaceUI.Views.Configs
  17. {
  18. public class SystemConfigViewModel : ModuleUiViewModelBase, ISupportMultipleSystem
  19. {
  20. #region Properties
  21. public bool IsPermission { get => this.Permission == 3; }
  22. private Visibility _isShowTable = Visibility.Hidden;
  23. public Visibility IsShowTable
  24. {
  25. get => _isShowTable;
  26. set
  27. {
  28. _isShowTable = value;
  29. NotifyOfPropertyChange(nameof(IsShowTable));
  30. }
  31. }
  32. private Visibility _isShowData = Visibility.Hidden;
  33. public Visibility IsShowData
  34. {
  35. get => _isShowData;
  36. set
  37. {
  38. _isShowData = value;
  39. NotifyOfPropertyChange(nameof(IsShowData));
  40. }
  41. }
  42. private List<ConfigNode> _ConfigNodes = new List<ConfigNode>();
  43. public List<ConfigNode> ConfigNodes
  44. {
  45. get { return _ConfigNodes; }
  46. set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); }
  47. }
  48. private List<ConfigItem> _configItems = null;
  49. public List<ConfigItem> ConfigItems
  50. {
  51. get { return _configItems; }
  52. set { _configItems = value; NotifyOfPropertyChange("ConfigItems"); }
  53. }
  54. string _CurrentNodeName = string.Empty;
  55. public BaseCommand<ConfigNode> TreeViewSelectedItemChangedCmd { private set; get; }
  56. private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();
  57. private string _currentCriteria = String.Empty;
  58. public string CurrentCriteria
  59. {
  60. get { return _currentCriteria; }
  61. set
  62. {
  63. if (value == _currentCriteria)
  64. return;
  65. _currentCriteria = value;
  66. NotifyOfPropertyChange("CurrentCriteria");
  67. ApplyFilter();
  68. }
  69. }
  70. private void ApplyFilter()
  71. {
  72. foreach (var node in ConfigNodes)
  73. node.ApplyCriteria(CurrentCriteria, new Stack<ConfigNode>());
  74. }
  75. #endregion
  76. #region Functions
  77. public SystemConfigViewModel()
  78. {
  79. this.DisplayName = "System Config";
  80. TreeViewSelectedItemChangedCmd = new BaseCommand<ConfigNode>(TreeViewSelectedItemChanged);
  81. }
  82. protected override void OnInitialize()
  83. {
  84. base.OnInitialize();
  85. ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
  86. }
  87. protected override void OnActivate()
  88. {
  89. base.OnActivate();
  90. ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
  91. }
  92. private void TreeViewSelectedItemChanged(ConfigNode node)
  93. {
  94. valueList.Clear();
  95. _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
  96. ConfigItems = node.Items;
  97. if (_CurrentNodeName == "PM1.WaferCycleTime")
  98. {
  99. IsShowTable = Visibility.Visible;
  100. IsShowData = Visibility.Hidden;
  101. }
  102. else
  103. {
  104. IsShowTable = Visibility.Hidden;
  105. IsShowData = Visibility.Visible;
  106. }
  107. GetDataOfConfigItems();
  108. }
  109. private void GetDataOfConfigItems()
  110. {
  111. if (ConfigItems == null)
  112. return;
  113. for (int i = 0; i < ConfigItems.Count; i++)
  114. {
  115. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", ConfigItems[i].Name);
  116. ConfigItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(SystemName, key);
  117. if (ConfigItems[i].Type == DataType.Bool)
  118. {
  119. bool value;
  120. if (bool.TryParse(ConfigItems[i].CurrentValue, out value))
  121. {
  122. ConfigItems[i].BoolValue = value;
  123. ConfigItems[i].CurrentValue = value ? "Yes" : "No";
  124. }
  125. }
  126. else
  127. ConfigItems[i].StringValue = ConfigItems[i].CurrentValue;
  128. }
  129. }
  130. public void SetValue(ConfigItem item)
  131. {
  132. InputDialogViewModel dialog = new InputDialogViewModel();
  133. RecipeSelectDialogViewModel selectDialog = new RecipeSelectDialogViewModel();
  134. WindowManager wm = new WindowManager();
  135. bool? bret = null;
  136. if (item.Name == "Idle Recipe" || item.Name == "Abort Recipe")
  137. {
  138. selectDialog.DisplayName = "Select Recipe";
  139. var recipeProvider = new RecipeProvider();
  140. string selectRecipeType = "";
  141. if (item.Name == "Idle Recipe")
  142. selectRecipeType = "Idle";
  143. else
  144. selectRecipeType = "Abort";
  145. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}");
  146. if (processType == null)
  147. {
  148. processType = selectRecipeType;
  149. }
  150. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  151. string[] recipeProcessType = ((string)processType).Split(',');
  152. for (int i = 0; i < recipeProcessType.Length; i++)
  153. {
  154. var type = new ProcessTypeFileItem();
  155. type.ProcessType = recipeProcessType[i];
  156. var prefix = $"Furnace\\{recipeProcessType[i]}";
  157. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  158. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  159. ProcessTypeFileList.Add(type);
  160. }
  161. selectDialog.ProcessTypeFileList = ProcessTypeFileList;
  162. bret = wm.ShowDialog(selectDialog);
  163. }
  164. else
  165. {
  166. if (item.Type == DataType.String) dialog.KeyboardType = "FullKeyboard";
  167. dialog.Item = item;
  168. dialog.DisplayName = "Set Value";
  169. bret = wm.ShowDialog(dialog);
  170. }
  171. string strOldValue = item.CurrentValue;
  172. if ((bool)bret)
  173. {
  174. item.StringValue = dialog.DialogResult;
  175. //key :System.IsSimulatorMode
  176. //value: true or false 都是字符串
  177. //input check
  178. string value;
  179. if (item.Type == DataType.Bool)
  180. {
  181. if (item.StringValue.Equals("Yes", StringComparison.CurrentCultureIgnoreCase))
  182. item.BoolValue = true;
  183. else if (item.StringValue.Equals("No", StringComparison.CurrentCultureIgnoreCase))
  184. item.BoolValue = false;
  185. else
  186. {
  187. DialogBox.ShowWarning("The Value Should be Yes Or No.");
  188. return;
  189. }
  190. value = item.BoolValue.ToString().ToLower();
  191. }
  192. else
  193. {
  194. //if (item.TextSaved && item.Tag != "ReadOnlySelection")
  195. //if (item.Tag == "ReadOnlySelection")
  196. // return;
  197. if (item.Type == DataType.Int)
  198. {
  199. int iValue;
  200. if (int.TryParse(item.StringValue, out iValue))
  201. {
  202. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  203. {
  204. if (iValue > item.Max || iValue < item.Min)
  205. {
  206. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString()));
  207. return;
  208. }
  209. }
  210. }
  211. else
  212. {
  213. DialogBox.ShowWarning("Please input valid data.");
  214. return;
  215. }
  216. value = item.StringValue;
  217. }
  218. else if (item.Type == DataType.Double)
  219. {
  220. double fValue;
  221. if (double.TryParse(item.StringValue, out fValue))
  222. {
  223. if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))
  224. {
  225. if (fValue > item.Max || fValue < item.Min)
  226. {
  227. DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", item.Min.ToString(), item.Max.ToString()));
  228. return;
  229. }
  230. string[] box = fValue.ToString().Split('.');
  231. if (box.Length > 1 && box[1].Length > 3)
  232. {
  233. DialogBox.ShowWarning(string.Format("The value should be more than three decimal places"));
  234. return;
  235. }
  236. }
  237. }
  238. else
  239. {
  240. DialogBox.ShowWarning("Please input valid data.");
  241. return;
  242. }
  243. value = item.StringValue;
  244. }
  245. else
  246. {
  247. if (item.StringValue != null)
  248. value = item.StringValue;
  249. else
  250. value = selectDialog.DialogResult;
  251. }
  252. }
  253. if (_CurrentNodeName == "System.ShutDown" && item.StringValue == "ShutDown")
  254. {
  255. InvokeClient.Instance.Service.DoOperation("System.ShutDown");
  256. }
  257. //压力单位改变时候,已有设置根据改变进行值转换
  258. if (item.Name == "PressureUnit" && strOldValue != value)
  259. ChangePressureUnit(value);
  260. string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);
  261. //InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", key, value);
  262. valueList.Add(new PageValue() { Path = key, CurrentValue = value });
  263. //Reload();
  264. }
  265. }
  266. private void ChangePressureUnit(string strNewValue)
  267. {
  268. double dValue = 0;
  269. if (strNewValue.Equals("Torr"))//从Pa转换成Torr
  270. dValue = 0.0075006;
  271. else //从Torr转换成Pa
  272. dValue = 133.322;
  273. }
  274. public void Reload()
  275. {
  276. GetDataOfConfigItems();
  277. }
  278. public void SaveAll()
  279. {
  280. if (ConfigItems == null)
  281. return;
  282. ConfigItems.ForEach(item => SetValue(item));
  283. }
  284. public void SaveParameter()
  285. {
  286. foreach (var item in valueList)
  287. {
  288. InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", item.Path, item.CurrentValue);
  289. }
  290. Reload();
  291. }
  292. public void Cancel()
  293. {
  294. valueList.Clear();
  295. Reload();
  296. }
  297. public void CollapseAll()
  298. {
  299. SetExpand(ConfigNodes, false);
  300. }
  301. public void ExpandAll()
  302. {
  303. SetExpand(ConfigNodes, true);
  304. }
  305. public void ClearFilter()
  306. {
  307. CurrentCriteria = "";
  308. }
  309. public void SetExpand(List<ConfigNode> configs, bool expand)
  310. {
  311. if (configs == null)
  312. return;
  313. foreach (var configNode in configs)
  314. {
  315. configNode.IsExpanded = expand;
  316. if (configNode.SubNodes != null)
  317. SetExpand(configNode.SubNodes, expand);
  318. }
  319. }
  320. #endregion
  321. }
  322. }