ScheduledMaintenanceMonitorViewModel.cs 11 KB

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