ScheduledMaintenanceMonitorViewModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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;
  20. using System.Collections.Generic;
  21. using System.Collections.ObjectModel;
  22. using System.Data;
  23. using System.Linq;
  24. using System.Text;
  25. using System.Windows.Controls;
  26. using System.Windows.Documents;
  27. using System.Windows.Input;
  28. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
  29. namespace FurnaceUI.Views.Editors
  30. {
  31. public class ScheduledMaintenanceMonitorViewModel : FurnaceUIViewModelBase
  32. {
  33. #region 构造函数
  34. /// <summary>
  35. /// 构造函数
  36. /// </summary>
  37. /// <param name="dataItem"></param>
  38. public ScheduledMaintenanceMonitorViewModel(ScheduleMaintenanceDataItem dataItem)
  39. {
  40. EditModel = CloneUtil.CloneObject(dataItem) as ScheduleMaintenanceDataItem;
  41. EnumLoop<MaintenanceProcessingCommandEnum>.ForEach((item) =>
  42. {
  43. MaintenanceProcessingList.Add(item.ToString());
  44. });
  45. }
  46. private bool _jobAutoStartCommandVisibility = false;
  47. public bool JobAutoStartCommandVisibility
  48. {
  49. get => _jobAutoStartCommandVisibility;
  50. set
  51. {
  52. _jobAutoStartCommandVisibility = value;
  53. NotifyOfPropertyChange("JobAutoStartCommandVisibility");
  54. }
  55. }
  56. private string _selectStepIdName = string.Empty;
  57. public string SelectStepIdName
  58. {
  59. get => _selectStepIdName;
  60. set
  61. {
  62. _selectStepIdName = value;
  63. NotifyOfPropertyChange("SelectStepIdName");
  64. }
  65. }
  66. private List<string> _maintenanceProcessingList = new List<string>();
  67. public List<string> MaintenanceProcessingList
  68. {
  69. get => _maintenanceProcessingList;
  70. set
  71. {
  72. _maintenanceProcessingList = value;
  73. NotifyOfPropertyChange("MaintenanceProcessingList");
  74. }
  75. }
  76. #endregion
  77. #region 属性 EditModel
  78. /// <summary>
  79. /// EditModel
  80. /// </summary>
  81. public ScheduleMaintenanceDataItem EditModel { get; set; }
  82. #endregion
  83. public bool IsEnable
  84. {
  85. get { return _isEnable; }
  86. set
  87. {
  88. _isEnable = value;
  89. NotifyOfPropertyChange("IsEnable");
  90. }
  91. }
  92. private bool _isEnable;
  93. public void TimeSelect(object cmdName, object value)
  94. {
  95. var windowManager = IoC.Get<IWindowManager>();
  96. RecipeStepTimeViewModel recipeStepTimeViewModel = new RecipeStepTimeViewModel("StepTime");
  97. bool isCurrentValue = value.ToString() == "CurrentValue";
  98. bool isStartValue = value.ToString() == "StartValue";
  99. bool isLimitValue = value.ToString() == "LimitValue";
  100. if (isCurrentValue)
  101. {
  102. recipeStepTimeViewModel.SelectValueTime = DateTimeUtil.SecondToHHmmss(EditModel.CurrentValue.ToString());
  103. }
  104. else if (isStartValue)
  105. {
  106. recipeStepTimeViewModel.SelectValueTime = DateTimeUtil.SecondToHHmmss(EditModel.StartValue.ToString());
  107. }
  108. else if (isLimitValue)
  109. {
  110. recipeStepTimeViewModel.SelectValueTime = DateTimeUtil.SecondToHHmmss(EditModel.LimitValue.ToString());
  111. }
  112. (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Standby Time Setting");
  113. if (recipeStepTimeViewModel.IsSave)
  114. {
  115. if (recipeStepTimeViewModel.SelectTime == "Value")
  116. {
  117. var allSecond = DateTimeUtil.GetSecond(recipeStepTimeViewModel.SelectValueTime);
  118. if (isCurrentValue)
  119. {
  120. EditModel.CurrentValue = allSecond;
  121. }
  122. else if (isStartValue)
  123. {
  124. EditModel.StartValue = allSecond;
  125. }
  126. else if (isLimitValue)
  127. {
  128. EditModel.LimitValue = allSecond;
  129. }
  130. }
  131. }
  132. }
  133. #region 方法 CurrentValueChange
  134. /// <summary>
  135. /// CurrentValueChange
  136. /// </summary>
  137. public void SetCurrentValue(object obj, MouseButtonEventArgs e)
  138. {
  139. e.Handled = true;
  140. NumberKeyboard fullKeyboard = new NumberKeyboard("", "0");
  141. if ((bool)fullKeyboard.ShowDialog())
  142. {
  143. var data = fullKeyboard.ValueString;
  144. if (EditModel.Path == "Reactor.StepRunTime")
  145. {
  146. var dataStrs = data.Split('.').ToList();
  147. if (dataStrs.Count > 1)
  148. {
  149. EditModel.CurrentValue = float.Parse(dataStrs.FirstOrDefault()) * 3600 + float.Parse(dataStrs.LastOrDefault()) * 60;
  150. }
  151. else
  152. {
  153. EditModel.CurrentValue = float.Parse(dataStrs.FirstOrDefault()) * 3600;
  154. }
  155. }
  156. else
  157. {
  158. EditModel.CurrentValue = float.Parse(data);
  159. }
  160. }
  161. //if ((bool)fullKeyboard.ShowDialog())
  162. //{
  163. // //InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", path, fullKeyboard.ValueString);
  164. // //currentValue = fullKeyboard.ValueString;
  165. // //EditModel.CurrentValue = fullKeyboard.ValueString;
  166. //}
  167. }
  168. public void CurrentValueChange()
  169. {
  170. IsEnable = !IsEnable;
  171. }
  172. #endregion
  173. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  174. {
  175. if (EditModel != null && !string.IsNullOrEmpty(EditModel.MaintenanceProcessing) && EditModel.MaintenanceProcessing == MaintenanceProcessingCommandEnum.JobAutoStart.ToString())
  176. {
  177. JobAutoStartCommandVisibility = true;
  178. }
  179. else
  180. {
  181. EditModel.AssociationProcessRecipeName = "";
  182. JobAutoStartCommandVisibility = false;
  183. }
  184. }
  185. protected override void OnViewLoaded(object view)
  186. {
  187. base.OnViewLoaded(view);
  188. var isReator = EditModel.DataItemType == DataItemEnum.Reactor;
  189. if (isReator && (EditModel.ReactorsType == ReactorsEnum.StepRunTime || EditModel.ReactorsType == ReactorsEnum.StepRunFreq) && !string.IsNullOrEmpty(EditModel.AdditionInformationDisplay))
  190. {
  191. SelectStepIdName = $":{(string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepName.{EditModel.AdditionInformationDisplay}")}";
  192. }
  193. if (isReator && EditModel.ReactorsType == ReactorsEnum.StepThickness)
  194. {
  195. CompareConfigurations();
  196. }
  197. }
  198. public void SelectStepIDMethod()
  199. {
  200. var windowManager = IoC.Get<IWindowManager>();
  201. RecipeStepNameViewModel recipeStepNameViewModel = new RecipeStepNameViewModel() { CheckNumber = true, SelectedStepName = EditModel.AdditionInformationDisplay };
  202. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step ID"))
  203. {
  204. var strs = recipeStepNameViewModel.SelectedStepName.Split(':');
  205. if (IsExist(strs.FirstOrDefault()))
  206. {
  207. DialogBox.ShowWarning($"Step: {strs.FirstOrDefault()} repeated selection!");
  208. return;
  209. }
  210. EditModel.AdditionInformationDisplay = strs.FirstOrDefault();
  211. if (strs.Length > 1)
  212. {
  213. SelectStepIdName = $":{strs.LastOrDefault()}";
  214. }
  215. }
  216. }
  217. private bool IsExist(string stepId)
  218. {
  219. string sql = $"SELECT addition_information_display FROM \"schedule_maintenance\" WHERE path='{EditModel.DataItemType}.{EditModel.ReactorsType}' AND addition_information_display='{stepId}'";
  220. DataTable dt = QueryDataClient.Instance.Service.QueryData(sql);
  221. if (dt != null && dt.Rows != null)
  222. {
  223. return dt.Rows.Count >= 1;
  224. }
  225. return false;
  226. }
  227. private void CompareConfigurations()
  228. {
  229. var groupValue = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{EditModel.AdditionInformationDisplay}");
  230. if (!string.IsNullOrEmpty(EditModel.AdditionInformationDisplaySupplement))
  231. {
  232. if (string.IsNullOrEmpty(groupValue))
  233. {
  234. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  235. }
  236. else
  237. {
  238. var oldDatas = EditModel.AdditionInformationDisplaySupplement.Split(',').ToList();
  239. var newDatas = groupValue.Split(',').ToList();
  240. // 判断 oldDatas 中有但 newDatas 中没有的元素
  241. var differenceOldToNew = oldDatas.Except(newDatas).ToList();
  242. // 判断 newDatas 中有但 oldDatas 中没有的元素
  243. var differenceNewToOld = newDatas.Except(oldDatas).ToList();
  244. // 检查是否存在差集
  245. bool hasDifference = differenceOldToNew.Any() || differenceNewToOld.Any();
  246. if (hasDifference)
  247. {
  248. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  249. }
  250. }
  251. }
  252. else
  253. {
  254. if (!string.IsNullOrEmpty(groupValue))
  255. {
  256. DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!");
  257. }
  258. }
  259. }
  260. public void SelectStepGroupMethod()
  261. {
  262. var windowManager = IoC.Get<IWindowManager>();
  263. StepGroupSelectViewModel recipeStepNameViewModel = new StepGroupSelectViewModel() { SelectedGroupName = EditModel.AdditionInformationDisplay };
  264. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step Group"))
  265. {
  266. EditModel.AdditionInformationDisplay = recipeStepNameViewModel.SelectedGroupName;
  267. var gropuDataStr = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{recipeStepNameViewModel.SelectedGroupName}");
  268. if (!string.IsNullOrEmpty(gropuDataStr))
  269. {
  270. var datas = QueryDataClient.Instance.Service.PollConfig(gropuDataStr.Split(',').ToList().Select(a => $"PM1.RecipeEditParameter.StepName.{a}"));
  271. var recipeNames = datas.Select(a => $"{a.Key.Split('.').LastOrDefault()}");
  272. EditModel.AdditionInformationDisplaySupplement = string.Join(",", recipeNames);
  273. }
  274. else
  275. {
  276. EditModel.AdditionInformationDisplaySupplement = "";
  277. }
  278. }
  279. }
  280. public void SelectProcessRecipe(string value)
  281. {
  282. RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel();
  283. dialog.DisplayName = "Select Recipe";
  284. var recipeProvider = new RecipeProvider();
  285. var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.SupportedProcessType");
  286. if (processType == null)
  287. {
  288. processType = "Process";
  289. }
  290. var ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
  291. string[] recipeProcessType = ((string)processType).Split(',');
  292. var type = new ProcessTypeFileItem();
  293. type.ProcessType = recipeProcessType[0];
  294. var prefix = $"Furnace\\{recipeProcessType[0]}";
  295. var recipes = recipeProvider.GetXmlRecipeList(prefix);
  296. type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files;
  297. ProcessTypeFileList.Add(type);
  298. dialog.ProcessTypeFileList = ProcessTypeFileList;
  299. WindowManager wm = new WindowManager();
  300. bool? bret = wm.ShowDialog(dialog);
  301. if ((bool)bret)
  302. {
  303. if (value == "AssociationProcessRecipeName")
  304. {
  305. EditModel.AssociationProcessRecipeName = dialog.DialogResult;
  306. }
  307. if (value == "AdditionInformationDisplay")
  308. {
  309. EditModel.AdditionInformationDisplay = dialog.DialogResult;
  310. }
  311. }
  312. }
  313. #region 方法 ClearCurrentValue
  314. /// <summary>
  315. /// ClearCurrentValue
  316. /// </summary>
  317. public void ClearCurrentValue()
  318. {
  319. if (EditModel != null)
  320. {
  321. EditModel.CurrentValue = 0;
  322. }
  323. }
  324. #endregion
  325. #region 方法 SetSave
  326. public void SetSave()
  327. {
  328. this.TryClose(true);
  329. }
  330. #endregion
  331. #region 方法 SetCancel
  332. public void SetCancel()
  333. {
  334. TryClose();
  335. }
  336. #endregion
  337. }
  338. }