using Aitex.Core.Util; using Caliburn.Micro; using Caliburn.Micro.Core; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using MECF.Framework.UI.Client.CenterViews.Editors.Sequence; using MECF.Framework.UI.Client.ClientBase; using OpenSEMI.ClientBase; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using System.Windows; using FurnaceUI.Models; using FurnaceUI.Views.Recipes; using ProcessTypeFileItems = MECF.Framework.UI.Client.CenterViews.Editors.Recipe.ProcessTypeFileItem; using System.Text.RegularExpressions; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using FurnaceUI.Views.Editors; namespace FurnaceUI.Views.Recipes { public class RecipeJobEditViewModel : FurnaceUIViewModelBase { public RecipeJobEditViewModel(string strPrefixPath, string strRecipeName,string permission="") { CurrentRecipe.PrefixPath = strPrefixPath; CurrentRecipe.Name = strRecipeName; CurrentRecipe.RecipePermission = permission; } private readonly RecipeProvider _recipeProvider = new RecipeProvider(); public string SelectRecipeType { get; set; } public RecipeDataJob CurrentRecipe { get; set; } = new RecipeDataJob(); private string _coolTime; private WindowManager windowManager; public string CoolTime { get => _coolTime; set { _coolTime = value; NotifyOfPropertyChange(nameof(CoolTime)); } } public bool IsEnable => CGlobal.RecipeJobEditViewEnable;//是否是View模式 protected override void OnInitialize() { base.OnInitialize(); LoadData(); } private void LoadData() { CurrentRecipe.Clear(); var recipeContent = _recipeProvider.LoadRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name); if (string.IsNullOrEmpty(recipeContent)) { System.Windows.MessageBox.Show($"{CurrentRecipe.PrefixPath}\\{CurrentRecipe.Name} is empty, please confirm the file is valid."); return; } CurrentRecipe.RecipeChamberType = "OriginChamber"; CurrentRecipe.InitData(CurrentRecipe.PrefixPath, CurrentRecipe.Name, recipeContent, "PM1"); if (SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.CoolTime.{CurrentRecipe.CoolTime}").Length > 0) CoolTime = CurrentRecipe.CoolTime + ":" + SystemConfigProvider.Instance.GetValueByName($"PM1.RecipeEditParameter.CoolTime.{CurrentRecipe.CoolTime}"); else CoolTime = "Value:" + CurrentRecipe.CoolTime; } public void SelectProcessRecipe() { RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel(); dialog.DisplayName = "Select Process 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(','); for (int i = 0; i < recipeProcessType.Length; i++) { var type = new ProcessTypeFileItems(); type.ProcessType = recipeProcessType[i]; var prefix = $"Furnace\\{recipeProcessType[i]}"; 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) { //var array = dialog.DialogResult.Split(new char[] { '\\' }); //CurrentRecipe.ProcessRecipe = array[array.Length - 1]; CurrentRecipe.ProcessRecipe = dialog.DialogResult; } } public void SelectLayoutRecipe() { RecipeSelectDialogViewModel dialog = new RecipeSelectDialogViewModel(); dialog.DisplayName = "Select Layout Recipe"; var recipeProvider = new RecipeProvider(); //var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedLayoutType"); if (SelectRecipeType == null) { SelectRecipeType = "Layout"; } var ProcessTypeFileList = new ObservableCollection(); string[] recipeProcessType = ((string)SelectRecipeType).Split(','); for (int i = 0; i < recipeProcessType.Length; i++) { var type = new ProcessTypeFileItems(); type.ProcessType = recipeProcessType[i]; var prefix = $"Furnace\\{recipeProcessType[i]}"; 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) { //var array = dialog.DialogResult.Split(new char[] { '\\' }); //CurrentRecipe.LayoutRecipe = array[array.Length - 1]; CurrentRecipe.LayoutRecipe = dialog.DialogResult; } } public void CoolTimeEdit() { var windowManager = IoC.Get(); RecipeStepTimeViewModel recipeStepTimeViewModel = new RecipeStepTimeViewModel("CoolTime"); recipeStepTimeViewModel.SelectTime = CurrentRecipe.CoolTime; (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Cooling Time Set"); if (recipeStepTimeViewModel.IsSave) { if (recipeStepTimeViewModel.SelectTime == "Value") { CoolTime = recipeStepTimeViewModel.SelectTime + ":" + recipeStepTimeViewModel.SelectValueTime; CurrentRecipe.CoolTime = recipeStepTimeViewModel.SelectValueTime; } else { CoolTime = recipeStepTimeViewModel.SelectTime + ":" + recipeStepTimeViewModel.RecipeStepTime[recipeStepTimeViewModel.SelectTime]; CurrentRecipe.CoolTime = recipeStepTimeViewModel.SelectTime; } } } public void SaveCmd() { RecipePermissionSelectViewModel dialog = new RecipePermissionSelectViewModel("Save recipe and permission", CurrentRecipe.RecipePermission); WindowManager wm = new WindowManager(); bool? dialogReturn = wm.ShowDialog(dialog); if (!dialogReturn.HasValue || !dialogReturn.Value) return; if (string.IsNullOrEmpty(CurrentRecipe.ProcessRecipe)) { DialogBox.ShowWarning("Process recipe is empty"); return; } if (string.IsNullOrEmpty(CurrentRecipe.LayoutRecipe)) { DialogBox.ShowWarning("Layout recipe is empty"); return; } if (string.IsNullOrEmpty(CurrentRecipe.CoolTime)) { DialogBox.ShowWarning("Cool time is empty"); return; } //if (!CheckTimeFormat()) //{ // DialogBox.ShowWarning("Cool time format is error"); // return; //} CurrentRecipe.LastReviseBy = BaseApp.Instance.UserContext.LoginName; CurrentRecipe.LastRevisionTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); this.CurrentRecipe.RecipeLevel = this.LevelDisplay; this.CurrentRecipe.RecipePermission = dialog.RecipePermission; _recipeProvider.SaveRecipe(CurrentRecipe.PrefixPath, CurrentRecipe.Name, CurrentRecipe.GetXmlString()); ((Window)GetView()).DialogResult = true; } private bool CheckTimeFormat() { bool bResult, bTimeH = true, bTimeM = true, bTimeS = true; string pattern = "^[0-9]*$"; Regex rex = new Regex(pattern); //if (!rex.IsMatch(CurrentRecipe.CoolTimeH)) //{ // bTimeH = false; //} //if (!rex.IsMatch(CurrentRecipe.CoolTimeM)) //{ // bTimeM = false; //} //if (!rex.IsMatch(CurrentRecipe.CoolTimeS)) //{ // bTimeS = false; //} bResult = bTimeH && bTimeM && bTimeS; return bResult; } public void ClosedCmd() { if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, " You confirm that you want to unsave the recipe and exit the interface?") == DialogButton.No) return; ((Window)GetView()).DialogResult = false; } } }