ScheduledMaintenanceMonitorViewModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. if (IsExist(strs.FirstOrDefault()))
  164. {
  165. DialogBox.ShowWarning($"Step: {strs.FirstOrDefault()} repeated selection!");
  166. return;
  167. }
  168. EditModel.AdditionInformationDisplay = strs.FirstOrDefault();
  169. if (strs.Length > 1)
  170. {
  171. SelectStepIdName = $":{strs.LastOrDefault()}";
  172. }
  173. }
  174. }
  175. private bool IsExist(string stepId)
  176. {
  177. string sql = $"SELECT addition_information_display FROM \"schedule_maintenance\" WHERE path='{EditModel.DataItemType}.{EditModel.ReactorsType}' AND addition_information_display='{stepId}'";
  178. DataTable dt = QueryDataClient.Instance.Service.QueryData(sql);
  179. if (dt != null && dt.Rows != null)
  180. {
  181. return dt.Rows.Count >= 1;
  182. }
  183. return false;
  184. }
  185. private void CompareConfigurations()
  186. {
  187. var groupValue = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{EditModel.AdditionInformationDisplay}");
  188. if (!string.IsNullOrEmpty(EditModel.AdditionInformationDisplaySupplement))
  189. {
  190. if (string.IsNullOrEmpty(groupValue))
  191. {
  192. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  193. }
  194. else
  195. {
  196. var oldDatas = EditModel.AdditionInformationDisplaySupplement.Split(',').ToList();
  197. var newDatas = groupValue.Split(',').ToList();
  198. // 判断 oldDatas 中有但 newDatas 中没有的元素
  199. var differenceOldToNew = oldDatas.Except(newDatas).ToList();
  200. // 判断 newDatas 中有但 oldDatas 中没有的元素
  201. var differenceNewToOld = newDatas.Except(oldDatas).ToList();
  202. // 检查是否存在差集
  203. bool hasDifference = differenceOldToNew.Any() || differenceNewToOld.Any();
  204. if (hasDifference)
  205. {
  206. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  207. }
  208. }
  209. }
  210. else
  211. {
  212. if (!string.IsNullOrEmpty(groupValue))
  213. {
  214. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  215. }
  216. }
  217. }
  218. public void SelectStepGroupMethod()
  219. {
  220. var windowManager = IoC.Get<IWindowManager>();
  221. StepGroupSelectViewModel recipeStepNameViewModel = new StepGroupSelectViewModel() { SelectedGroupName = EditModel.AdditionInformationDisplay };
  222. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step Group"))
  223. {
  224. EditModel.AdditionInformationDisplay = recipeStepNameViewModel.SelectedGroupName;
  225. var gropuDataStr = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{recipeStepNameViewModel.SelectedGroupName}");
  226. if (!string.IsNullOrEmpty(gropuDataStr))
  227. {
  228. var datas = QueryDataClient.Instance.Service.PollConfig(gropuDataStr.Split(',').ToList().Select(a => $"PM1.RecipeEditParameter.StepName.{a}"));
  229. var recipeNames = datas.Select(a => $"{a.Key.Split('.').LastOrDefault()}");
  230. EditModel.AdditionInformationDisplaySupplement = string.Join(",", recipeNames);
  231. }
  232. else
  233. {
  234. EditModel.AdditionInformationDisplaySupplement = "";
  235. }
  236. }
  237. }
  238. public void SelectProcessRecipe(string value)
  239. {
  240. RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel();
  241. dialog.DisplayName = "Select Recipe";
  242. var recipeProvider = new RecipeProvider();
  243. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.SupportedProcessType");
  244. if (processType == null)
  245. {
  246. processType = "Process";
  247. }
  248. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  249. string[] recipeProcessType = ((string)processType).Split(',');
  250. var type = new ProcessTypeFileItem();
  251. type.ProcessType = recipeProcessType[0];
  252. var prefix = $"Furnace\\{recipeProcessType[0]}";
  253. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  254. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  255. ProcessTypeFileList.Add(type);
  256. dialog.ProcessTypeFileList = ProcessTypeFileList;
  257. WindowManager wm = new WindowManager();
  258. bool? bret = wm.ShowDialog(dialog);
  259. if ((bool)bret)
  260. {
  261. if (value == "AssociationProcessRecipeName")
  262. {
  263. EditModel.AssociationProcessRecipeName = dialog.DialogResult;
  264. }
  265. if (value == "AdditionInformationDisplay")
  266. {
  267. EditModel.AdditionInformationDisplay = dialog.DialogResult;
  268. }
  269. }
  270. }
  271. #region 方法 ClearCurrentValue
  272. /// <summary>
  273. /// ClearCurrentValue
  274. /// </summary>
  275. public void ClearCurrentValue()
  276. {
  277. if (EditModel != null)
  278. {
  279. EditModel.CurrentValue = 0;
  280. }
  281. }
  282. #endregion
  283. #region 方法 SetSave
  284. public void SetSave()
  285. {
  286. this.TryClose(true);
  287. }
  288. #endregion
  289. #region 方法 SetCancel
  290. public void SetCancel()
  291. {
  292. TryClose();
  293. }
  294. #endregion
  295. }
  296. }