using Aitex.Core.Util; using Aitex.Core.Utilities; using Caliburn.Micro; using Caliburn.Micro.Core; using ExcelLibrary.BinaryFileFormat; using FurnaceUI.Models; using FurnaceUI.Views.Scheduled; using MECF.Framework.Common.CommonData.EnumData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Utilities; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using MECF.Framework.UI.Client.CenterViews.Editors.Sequence; using OpenSEMI.ClientBase; using SciChart.Core.Extensions; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Linq; using System.Windows.Documents; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; namespace FurnaceUI.Views.Editors { public class ScheduledMaintenanceMonitorViewModel : FurnaceUIViewModelBase { #region 构造函数 /// /// 构造函数 /// /// public ScheduledMaintenanceMonitorViewModel(ScheduleMaintenanceDataItem dataItem) { EditModel = CloneUtil.CloneObject(dataItem) as ScheduleMaintenanceDataItem; EnumLoop.ForEach((item) => { MaintenanceProcessingList.Add(item.ToString()); }); } private bool _jobAutoStartCommandVisibility = false; public bool JobAutoStartCommandVisibility { get => _jobAutoStartCommandVisibility; set { _jobAutoStartCommandVisibility = value; NotifyOfPropertyChange("JobAutoStartCommandVisibility"); } } private string _selectStepIdName = string.Empty; public string SelectStepIdName { get => _selectStepIdName; set { _selectStepIdName = value; NotifyOfPropertyChange("SelectStepIdName"); } } private List _maintenanceProcessingList = new List(); public List MaintenanceProcessingList { get => _maintenanceProcessingList; set { _maintenanceProcessingList = value; NotifyOfPropertyChange("MaintenanceProcessingList"); } } #endregion #region 属性 EditModel /// /// EditModel /// public ScheduleMaintenanceDataItem EditModel { get; set; } #endregion public bool IsEnable { get { return _isEnable; } set { _isEnable = value; NotifyOfPropertyChange("IsEnable"); } } private bool _isEnable; #region 方法 CurrentValueChange /// /// CurrentValueChange /// public void CurrentValueChange() { IsEnable = !IsEnable; } #endregion protected override void InvokeAfterUpdateProperty(Dictionary data) { if (EditModel != null && !string.IsNullOrEmpty(EditModel.MaintenanceProcessing) && EditModel.MaintenanceProcessing == MaintenanceProcessingCommandEnum.JobAutoStart.ToString()) { JobAutoStartCommandVisibility = true; } else { EditModel.AssociationProcessRecipeName = ""; JobAutoStartCommandVisibility = false; } } protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); var isReator = EditModel.DataItemType == DataItemEnum.Reactor; if (isReator && (EditModel.ReactorsType == ReactorsEnum.StepRunTime || EditModel.ReactorsType == ReactorsEnum.StepRunFreq) && !string.IsNullOrEmpty(EditModel.AdditionInformationDisplay)) { SelectStepIdName = $":{(string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepName.{EditModel.AdditionInformationDisplay}")}"; } if (isReator && EditModel.ReactorsType == ReactorsEnum.StepThickness) { CompareConfigurations(); } } public void SelectStepIDMethod() { var windowManager = IoC.Get(); RecipeStepNameViewModel recipeStepNameViewModel = new RecipeStepNameViewModel() { CheckNumber = true, SelectedStepName = EditModel.AdditionInformationDisplay }; if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step ID")) { var strs = recipeStepNameViewModel.SelectedStepName.Split(':'); EditModel.AdditionInformationDisplay = strs.FirstOrDefault(); if (strs.Length > 1) { SelectStepIdName =$":{strs.LastOrDefault()}"; } } } private void CompareConfigurations() { var groupValue = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{EditModel.AdditionInformationDisplay}"); if (!string.IsNullOrEmpty(EditModel.AdditionInformationDisplaySupplement)) { if (string.IsNullOrEmpty(groupValue)) { DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!"); } else { var oldDatas = EditModel.AdditionInformationDisplaySupplement.Split(',').ToList(); var newDatas = groupValue.Split(',').ToList(); // 判断 oldDatas 中有但 newDatas 中没有的元素 var differenceOldToNew = oldDatas.Except(newDatas).ToList(); // 判断 newDatas 中有但 oldDatas 中没有的元素 var differenceNewToOld = newDatas.Except(oldDatas).ToList(); // 检查是否存在差集 bool hasDifference = differenceOldToNew.Any() || differenceNewToOld.Any(); if (hasDifference) { DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!"); } } } else { if (!string.IsNullOrEmpty(groupValue)) { DialogBox.ShowWarning($"The selected {EditModel.AdditionInformationDisplay} does not match the Config {EditModel.AdditionInformationDisplay}. Please confirm!"); } } } public void SelectStepGroupMethod() { var windowManager = IoC.Get(); StepGroupSelectViewModel recipeStepNameViewModel = new StepGroupSelectViewModel() { SelectedGroupName = EditModel.AdditionInformationDisplay }; if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Select Step Group")) { EditModel.AdditionInformationDisplay = recipeStepNameViewModel.SelectedGroupName; var gropuDataStr = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.RecipeEditParameter.StepGroup.{recipeStepNameViewModel.SelectedGroupName}"); if (!string.IsNullOrEmpty(gropuDataStr)) { var datas = QueryDataClient.Instance.Service.PollConfig(gropuDataStr.Split(',').ToList().Select(a => $"PM1.RecipeEditParameter.StepName.{a}")); var recipeNames = datas.Select(a => $"{a.Key.Split('.').LastOrDefault()}"); EditModel.AdditionInformationDisplaySupplement = string.Join(",", recipeNames); } else { EditModel.AdditionInformationDisplaySupplement = ""; } } } public void SelectProcessRecipe(string value) { RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel(); dialog.DisplayName = "Select Recipe"; var recipeProvider = new RecipeProvider(); var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.SupportedProcessType"); if (processType == null) { processType = "Process"; } var ProcessTypeFileList = new ObservableCollection(); string[] recipeProcessType = ((string)processType).Split(','); var type = new ProcessTypeFileItem(); type.ProcessType = recipeProcessType[0]; var prefix = $"Furnace\\{recipeProcessType[0]}"; var recipes = recipeProvider.GetXmlRecipeList(prefix); type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files; ProcessTypeFileList.Add(type); dialog.ProcessTypeFileList = ProcessTypeFileList; WindowManager wm = new WindowManager(); bool? bret = wm.ShowDialog(dialog); if ((bool)bret) { if (value == "AssociationProcessRecipeName") { EditModel.AssociationProcessRecipeName = dialog.DialogResult; } if (value == "AdditionInformationDisplay") { EditModel.AdditionInformationDisplay = dialog.DialogResult; } } } #region 方法 ClearCurrentValue /// /// ClearCurrentValue /// public void ClearCurrentValue() { if (EditModel != null) { EditModel.CurrentValue = 0; } } #endregion #region 方法 SetSave public void SetSave() { this.TryClose(true); } #endregion #region 方法 SetCancel public void SetCancel() { TryClose(); } #endregion } }