ScheduledMaintenanceMonitorViewModel.cs 15 KB

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