ScheduledMaintenanceMonitorViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. using Aitex.Core.Util;
  2. using Aitex.Core.Utilities;
  3. using Caliburn.Micro;
  4. using Caliburn.Micro.Core;
  5. using ExcelLibrary.BinaryFileFormat;
  6. using FurnaceUI.Models;
  7. using FurnaceUI.Views.Scheduled;
  8. using MECF.Framework.Common.CommonData.EnumData;
  9. using MECF.Framework.Common.DataCenter;
  10. using MECF.Framework.Common.OperationCenter;
  11. using MECF.Framework.Common.Utilities;
  12. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  13. using MECF.Framework.UI.Client.CenterViews.Dialogs;
  14. using MECF.Framework.UI.Client.CenterViews.Editors;
  15. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  16. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  17. using OpenSEMI.ClientBase;
  18. using SciChart.Core.Extensions;
  19. using System.Collections.Generic;
  20. using System.Collections.ObjectModel;
  21. using System.Data;
  22. using System.Linq;
  23. using System.Windows.Controls;
  24. using System.Windows.Documents;
  25. using System.Windows.Input;
  26. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
  27. namespace FurnaceUI.Views.Editors
  28. {
  29. public class ScheduledMaintenanceMonitorViewModel : FurnaceUIViewModelBase
  30. {
  31. #region 构造函数
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. /// <param name="dataItem"></param>
  36. public ScheduledMaintenanceMonitorViewModel(ScheduleMaintenanceDataItem dataItem)
  37. {
  38. EditModel = CloneUtil.CloneObject(dataItem) as ScheduleMaintenanceDataItem;
  39. EnumLoop<MaintenanceProcessingCommandEnum>.ForEach((item) =>
  40. {
  41. MaintenanceProcessingList.Add(item.ToString());
  42. });
  43. }
  44. private bool _jobAutoStartCommandVisibility = false;
  45. public bool JobAutoStartCommandVisibility
  46. {
  47. get => _jobAutoStartCommandVisibility;
  48. set
  49. {
  50. _jobAutoStartCommandVisibility = value;
  51. NotifyOfPropertyChange("JobAutoStartCommandVisibility");
  52. }
  53. }
  54. private string _selectStepIdName = string.Empty;
  55. public string SelectStepIdName
  56. {
  57. get => _selectStepIdName;
  58. set
  59. {
  60. _selectStepIdName = value;
  61. NotifyOfPropertyChange("SelectStepIdName");
  62. }
  63. }
  64. private List<string> _maintenanceProcessingList = new List<string>();
  65. public List<string> MaintenanceProcessingList
  66. {
  67. get => _maintenanceProcessingList;
  68. set
  69. {
  70. _maintenanceProcessingList = value;
  71. NotifyOfPropertyChange("MaintenanceProcessingList");
  72. }
  73. }
  74. #endregion
  75. #region 属性 EditModel
  76. /// <summary>
  77. /// EditModel
  78. /// </summary>
  79. public ScheduleMaintenanceDataItem EditModel { get; set; }
  80. #endregion
  81. public bool IsEnable
  82. {
  83. get { return _isEnable; }
  84. set
  85. {
  86. _isEnable = value;
  87. NotifyOfPropertyChange("IsEnable");
  88. }
  89. }
  90. private bool _isEnable;
  91. #region 方法 CurrentValueChange
  92. /// <summary>
  93. /// CurrentValueChange
  94. /// </summary>
  95. public void SetCurrentValue(object obj, MouseButtonEventArgs e)
  96. {
  97. e.Handled = true;
  98. NumberKeyboard fullKeyboard = new NumberKeyboard("", "0");
  99. if ((bool)fullKeyboard.ShowDialog())
  100. {
  101. var data = fullKeyboard.ValueString;
  102. if (EditModel.Path == "Reactor.StepRunTime")
  103. {
  104. var dataStrs = data.Split('.').ToList();
  105. if (dataStrs.Count > 1)
  106. {
  107. EditModel.CurrentValue = float.Parse(dataStrs.FirstOrDefault()) * 3600 + float.Parse(dataStrs.LastOrDefault()) * 60;
  108. }
  109. else
  110. {
  111. EditModel.CurrentValue = float.Parse(dataStrs.FirstOrDefault()) * 3600;
  112. }
  113. }
  114. else
  115. {
  116. EditModel.CurrentValue = float.Parse(data);
  117. }
  118. }
  119. //if ((bool)fullKeyboard.ShowDialog())
  120. //{
  121. // //InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", path, fullKeyboard.ValueString);
  122. // //currentValue = fullKeyboard.ValueString;
  123. // //EditModel.CurrentValue = fullKeyboard.ValueString;
  124. //}
  125. }
  126. public void CurrentValueChange()
  127. {
  128. IsEnable = !IsEnable;
  129. }
  130. #endregion
  131. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  132. {
  133. if (EditModel != null && !string.IsNullOrEmpty(EditModel.MaintenanceProcessing) && EditModel.MaintenanceProcessing == MaintenanceProcessingCommandEnum.JobAutoStart.ToString())
  134. {
  135. JobAutoStartCommandVisibility = true;
  136. }
  137. else
  138. {
  139. EditModel.AssociationProcessRecipeName = "";
  140. JobAutoStartCommandVisibility = false;
  141. }
  142. }
  143. protected override void OnViewLoaded(object view)
  144. {
  145. base.OnViewLoaded(view);
  146. var isReator = EditModel.DataItemType == DataItemEnum.Reactor;
  147. if (isReator && (EditModel.ReactorsType == ReactorsEnum.StepRunTime || EditModel.ReactorsType == ReactorsEnum.StepRunFreq) && !string.IsNullOrEmpty(EditModel.AdditionInformationDisplay))
  148. {
  149. SelectStepIdName = $":{(string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepName.{EditModel.AdditionInformationDisplay}")}";
  150. }
  151. if (isReator && EditModel.ReactorsType == ReactorsEnum.StepThickness)
  152. {
  153. CompareConfigurations();
  154. }
  155. }
  156. public void SelectStepIDMethod()
  157. {
  158. var windowManager = IoC.Get<IWindowManager>();
  159. RecipeStepNameViewModel recipeStepNameViewModel = new RecipeStepNameViewModel() { CheckNumber = true, SelectedStepName = EditModel.AdditionInformationDisplay };
  160. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step ID"))
  161. {
  162. var strs = recipeStepNameViewModel.SelectedStepName.Split(':');
  163. EditModel.AdditionInformationDisplay = strs.FirstOrDefault();
  164. if (strs.Length > 1)
  165. {
  166. SelectStepIdName = $":{strs.LastOrDefault()}";
  167. }
  168. }
  169. }
  170. private void CompareConfigurations()
  171. {
  172. var groupValue = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{EditModel.AdditionInformationDisplay}");
  173. if (!string.IsNullOrEmpty(EditModel.AdditionInformationDisplaySupplement))
  174. {
  175. if (string.IsNullOrEmpty(groupValue))
  176. {
  177. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  178. }
  179. else
  180. {
  181. var oldDatas = EditModel.AdditionInformationDisplaySupplement.Split(',').ToList();
  182. var newDatas = groupValue.Split(',').ToList();
  183. // 判断 oldDatas 中有但 newDatas 中没有的元素
  184. var differenceOldToNew = oldDatas.Except(newDatas).ToList();
  185. // 判断 newDatas 中有但 oldDatas 中没有的元素
  186. var differenceNewToOld = newDatas.Except(oldDatas).ToList();
  187. // 检查是否存在差集
  188. bool hasDifference = differenceOldToNew.Any() || differenceNewToOld.Any();
  189. if (hasDifference)
  190. {
  191. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  192. }
  193. }
  194. }
  195. else
  196. {
  197. if (!string.IsNullOrEmpty(groupValue))
  198. {
  199. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  200. }
  201. }
  202. }
  203. public void SelectStepGroupMethod()
  204. {
  205. var windowManager = IoC.Get<IWindowManager>();
  206. StepGroupSelectViewModel recipeStepNameViewModel = new StepGroupSelectViewModel() { SelectedGroupName = EditModel.AdditionInformationDisplay };
  207. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step Group"))
  208. {
  209. EditModel.AdditionInformationDisplay = recipeStepNameViewModel.SelectedGroupName;
  210. var gropuDataStr = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{recipeStepNameViewModel.SelectedGroupName}");
  211. if (!string.IsNullOrEmpty(gropuDataStr))
  212. {
  213. var datas = QueryDataClient.Instance.Service.PollConfig(gropuDataStr.Split(',').ToList().Select(a => $"PM1.RecipeEditParameter.StepName.{a}"));
  214. var recipeNames = datas.Select(a => $"{a.Key.Split('.').LastOrDefault()}");
  215. EditModel.AdditionInformationDisplaySupplement = string.Join(",", recipeNames);
  216. }
  217. else
  218. {
  219. EditModel.AdditionInformationDisplaySupplement = "";
  220. }
  221. }
  222. }
  223. public void SelectProcessRecipe(string value)
  224. {
  225. RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel();
  226. dialog.DisplayName = "Select Recipe";
  227. var recipeProvider = new RecipeProvider();
  228. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.SupportedProcessType");
  229. if (processType == null)
  230. {
  231. processType = "Process";
  232. }
  233. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  234. string[] recipeProcessType = ((string)processType).Split(',');
  235. var type = new ProcessTypeFileItem();
  236. type.ProcessType = recipeProcessType[0];
  237. var prefix = $"Furnace\\{recipeProcessType[0]}";
  238. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  239. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  240. ProcessTypeFileList.Add(type);
  241. dialog.ProcessTypeFileList = ProcessTypeFileList;
  242. WindowManager wm = new WindowManager();
  243. bool? bret = wm.ShowDialog(dialog);
  244. if ((bool)bret)
  245. {
  246. if (value == "AssociationProcessRecipeName")
  247. {
  248. EditModel.AssociationProcessRecipeName = dialog.DialogResult;
  249. }
  250. if (value == "AdditionInformationDisplay")
  251. {
  252. EditModel.AdditionInformationDisplay = dialog.DialogResult;
  253. }
  254. }
  255. }
  256. #region 方法 ClearCurrentValue
  257. /// <summary>
  258. /// ClearCurrentValue
  259. /// </summary>
  260. public void ClearCurrentValue()
  261. {
  262. if (EditModel != null)
  263. {
  264. EditModel.CurrentValue = 0;
  265. }
  266. }
  267. #endregion
  268. #region 方法 SetSave
  269. public void SetSave()
  270. {
  271. this.TryClose(true);
  272. }
  273. #endregion
  274. #region 方法 SetCancel
  275. public void SetCancel()
  276. {
  277. TryClose();
  278. }
  279. #endregion
  280. }
  281. }