ScheduledMaintenanceMonitorViewModel.cs 16 KB

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