using Aitex.Core.UI.MVVM; using Aitex.Core.Utilities; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.Common.Utilities; using Prism.Mvvm; using PunkHPX8_MainPages.PMs; using PunkHPX8_Themes.UserControls; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; namespace PunkHPX8_MainPages.ViewModels { public class VpwRecipeViewModel : BindableBase { private const string ENGINEERING = "Engineering"; #region 内部变量 private Dictionary _recipeNodeDic = new Dictionary(); private ObservableCollection _recipeNodes; private UiRecipeManager _uiRecipeManager = new UiRecipeManager(); private Dictionary _propertyValidResultDic = new Dictionary(); private VpwRecipe _recipe; private bool _editEnable; private bool _createEnable; private RecipeNode _currentNode; private bool _enable = false; private bool _isEdit = false; /// /// Wafer尺寸集合 /// private List _waferSizeLst = null; /// /// Vacuum Prewet step选择索引 /// private int _selectedVacuumPrewetIndex = -1; /// /// Extend Clean step选择索引 /// private int _selectedExtendCleanIndex = -1; /// /// Vent Prewet step选择索引 /// private int _selectedVentPrewetIndex = -1; #endregion #region 属性 public ObservableCollection RecipeNodes { get { return _recipeNodes; } set { SetProperty(ref _recipeNodes, value); } } public Dictionary PropertyValidResultDic { get { return _propertyValidResultDic; } set { SetProperty(ref _propertyValidResultDic, value); } } public RecipeNode CurrentNode { get { return _currentNode; } set { SetProperty(ref _currentNode, value); } } public bool Enable { get { return _enable; } set { SetProperty(ref _enable, value); } } public bool EditEnable { get { return _editEnable; } set { SetProperty(ref _editEnable, value); } } public bool CreateEnable { get { return _createEnable; } set { SetProperty(ref _createEnable, value); } } public VpwRecipe Recipe { get { return _recipe; } set { SetProperty(ref _recipe, value); } } /// /// Wafer 尺寸集合 /// public List WaferSizeLst { get { return _waferSizeLst; } set { SetProperty(ref _waferSizeLst, value); } } /// /// Vacuum Prewet step选择索引 /// public int SelectedVacuumPrewetIndex { get { return _selectedVacuumPrewetIndex; } set { SetProperty(ref _selectedVacuumPrewetIndex, value); } } /// /// SelectedExtendCleanIndex选择索引 /// public int SelectedExtendCleanIndex { get { return _selectedExtendCleanIndex; } set { SetProperty(ref _selectedExtendCleanIndex, value); } } /// /// SelectedVentPrewetIndex选择索引 /// public int SelectedVentPrewetIndex { get { return _selectedVentPrewetIndex; } set { SetProperty(ref _selectedVentPrewetIndex, value); } } #region 指令 public ICommand OperationCommand { get; private set; } [IgnorePropertyChange] public ICommand CreateCommand { get; private set; } [IgnorePropertyChange] public ICommand EditCommand { get; private set; } [IgnorePropertyChange] public ICommand SaveRecipeCommand { get; private set; } [IgnorePropertyChange] public ICommand SaveAsRecipeCommand { get; private set; } [IgnorePropertyChange] public ICommand IsSprayBarRetractFalseCommand { get; private set; } #endregion public VpwRecipeViewModel() { OperationCommand = new DelegateCommand(SelectionChangedAction); CreateCommand = new DelegateCommand(CreateAction); EditCommand = new DelegateCommand(EditAction); SaveRecipeCommand = new DelegateCommand(SaveAction); SaveAsRecipeCommand = new DelegateCommand(SaveAsAction); IsSprayBarRetractFalseCommand = new DelegateCommand(IsSprayBarRetractFalseAction); //Wafer尺寸集合 WaferSizeLst = new List(); WaferSizeLst.Add(100); WaferSizeLst.Add(150); WaferSizeLst.Add(200); WaferSizeLst.Add(300); InitializeProprtyValidResultDictionary(); } #endregion private void InitializeProprtyValidResultDictionary() { //需要检验的参数 PropertyValidResultDic["VacuumTarget"] = false; PropertyValidResultDic["DryHoldTime"] = false; PropertyValidResultDic["DiwLoopDoSet"] = false; PropertyValidResultDic["SpinSpeed"] = false; PropertyValidResultDic["SpinTime"] = false; } public void LoadRecipeData() { RecipeNodes = _uiRecipeManager.GetRecipesByType("vpw"); _recipeNodeDic.Clear(); InitializeDictionary(RecipeNodes); } private void InitializeDictionary(ObservableCollection nodes) { if (nodes != null) { foreach (var node in nodes) { if (node.NodeType == RecipeNodeType.File) { _recipeNodeDic[node.Name] = node; } InitializeDictionary(node.Children); } } } private void SelectionChangedAction(object param) { if (_recipeNodeDic.ContainsKey(param.ToString())) { CurrentNode = _recipeNodeDic[param.ToString()]; if (CurrentNode.NodeType == RecipeNodeType.File) { if (CurrentNode.RecipeLocation == ENGINEERING) { EditEnable = true; CreateEnable = true; } else { EditEnable = false; CreateEnable = false; } } Recipe = _uiRecipeManager.LoadRecipe(CurrentNode.RecipeFullFileName); if (Recipe == null) { MessageBox.Show("Invalid Recipe", "Load Recipe", MessageBoxButton.OK, MessageBoxImage.Error); EditEnable = false; CreateEnable = false; } Enable = false; } else { if (param.ToString() == ENGINEERING) { CreateEnable = true; } else { CreateEnable = false; } CurrentNode = null; Recipe = null; EditEnable = false; Enable = false; } } private void CreateAction(object param) { RecipeNameDialog recipeNameDialog = new RecipeNameDialog(); if (recipeNameDialog.ShowDialog().Value) { if (!CheckNameExist(recipeNameDialog.RecipeName)) { Recipe = new VpwRecipe(); Recipe.CreateDate = DateTime.Now; Recipe.Ppid = recipeNameDialog.RecipeName; Recipe.Description = recipeNameDialog.RecipeDescription; Enable = true; _isEdit = false; } } } private void EditAction(object param) { Enable = true; _isEdit = false; } private void SaveAction(object param) { if (CheckValid(_isEdit)) { Recipe.SaveDate = DateTime.Now; try { _uiRecipeManager.SaveRecipe(ENGINEERING, Recipe.Ppid, "vpw", Recipe); LoadRecipeData(); MessageBox.Show("Save Recipe Success", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Information); Enable = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error); } } } /// /// 另存为 /// /// private void SaveAsAction(object param) { if (Recipe == null) { MessageBox.Show("Select a Recipe first", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Error); return; } VpwRecipe recipe = new VpwRecipe(); if (CheckValid(_isEdit)) { RecipeNameDialog recipeNameDialog = new RecipeNameDialog(); if (recipeNameDialog.ShowDialog().Value) { if (!CheckNameExist(recipeNameDialog.RecipeName)) { recipe = new VpwRecipe(); recipe = (VpwRecipe)PropertyUtil.Clone(Recipe); recipe.CreateDate = DateTime.Now; recipe.Ppid = recipeNameDialog.RecipeName; recipe.Description = recipeNameDialog.RecipeDescription; } else if (recipeNameDialog.RecipeName != null) { MessageBox.Show("Name can not be Null", "Create Recipe", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { return; } } try { _uiRecipeManager.SaveRecipe(ENGINEERING, recipe.Ppid, "vpw", recipe); LoadRecipeData(); MessageBox.Show("Save As Recipe Success", "SaveAs Recipe", MessageBoxButton.OK, MessageBoxImage.Information); Enable = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Save As Recipe", MessageBoxButton.OK, MessageBoxImage.Error); } } } private bool CheckNameExist(string name) { foreach (string item in _recipeNodeDic.Keys) { if (item == name) { MessageBox.Show($"{name} is exsit", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error); return true; } } return false; } private bool CheckValid(bool editType) { foreach (string key in _propertyValidResultDic.Keys) { bool valid = _propertyValidResultDic[key]; if (!valid) { MessageBox.Show($"{key} data invalid", "Save Recipe", MessageBoxButton.OK, MessageBoxImage.Error); return false; } } return true; } private void IsSprayBarRetractFalseAction(object param) { Recipe.IsSprayBarRetract = false; } #region Vacuum prewet按钮 /// /// 增加 /// /// private void AddBelowAction(object param) { if (Recipe != null) { VpwRinseStep currentRinseSteps = new VpwRinseStep(); Recipe.VacuumRinseStep.Insert(SelectedVacuumPrewetIndex + 1, currentRinseSteps); SelectedVacuumPrewetIndex++; } } /// /// 增加 /// /// private void AddAboveAction(object param) { if (Recipe != null) { VpwRinseStep currentRinseSteps = new VpwRinseStep(); if (SelectedVacuumPrewetIndex == -1) { Recipe.VacuumRinseStep.Add(currentRinseSteps); SelectedVacuumPrewetIndex = 0; } else { Recipe.VacuumRinseStep.Insert(SelectedVacuumPrewetIndex, currentRinseSteps); SelectedVacuumPrewetIndex--; } } } /// /// 上移 /// /// private void MoveUpAction(object param) { if (Recipe != null) { if (SelectedVacuumPrewetIndex > 0) { int currentIndex = SelectedVacuumPrewetIndex; VpwRinseStep currentRinseSteps = Recipe.VacuumRinseStep[SelectedVacuumPrewetIndex]; Recipe.VacuumRinseStep.RemoveAt(SelectedVacuumPrewetIndex); Recipe.VacuumRinseStep.Insert(currentIndex - 1, currentRinseSteps); SelectedVacuumPrewetIndex = currentIndex - 1; } } } /// /// 下移 /// /// private void MoveDownAction(object param) { if (Recipe != null) { if (SelectedVacuumPrewetIndex >= 0 && SelectedVacuumPrewetIndex < Recipe.VacuumRinseStep.Count - 1 && Recipe.VacuumRinseStep.Count > 1) { int currentIndex = SelectedVacuumPrewetIndex; VpwRinseStep currentRinseSteps = Recipe.VacuumRinseStep[SelectedVacuumPrewetIndex]; Recipe.VacuumRinseStep.RemoveAt(SelectedVacuumPrewetIndex); Recipe.VacuumRinseStep.Insert(currentIndex + 1, currentRinseSteps); SelectedVacuumPrewetIndex = currentIndex + 1; } } } /// /// 删除 /// /// private void DeleteAction(object param) { if (SelectedVacuumPrewetIndex != -1) { if (Recipe != null && Recipe.VacuumRinseStep.Count > SelectedVacuumPrewetIndex) { Recipe.VacuumRinseStep.RemoveAt(SelectedVacuumPrewetIndex); } } } #endregion #region Vent prewet按钮 /// /// 增加 /// /// private void VentPrewetAddBelowAction(object param) { if (Recipe != null) { VpwRinseStep currentRinseSteps = new VpwRinseStep(); Recipe.VentRinseStep.Insert(SelectedVentPrewetIndex + 1, currentRinseSteps); SelectedVentPrewetIndex++; } } /// /// 增加 /// /// private void VentPrewetAddAboveAction(object param) { if (Recipe != null) { VpwRinseStep currentRinseSteps = new VpwRinseStep(); if (SelectedVentPrewetIndex == -1) { Recipe.VentRinseStep.Add(currentRinseSteps); SelectedVentPrewetIndex = 0; } else { Recipe.VentRinseStep.Insert(SelectedVentPrewetIndex, currentRinseSteps); SelectedVentPrewetIndex--; } } } /// /// 上移 /// /// private void VentPrewetMoveUpAction(object param) { if (Recipe != null) { if (SelectedVentPrewetIndex > 0) { int currentIndex = SelectedVentPrewetIndex; VpwRinseStep currentRinseSteps = Recipe.VentRinseStep[SelectedVentPrewetIndex]; Recipe.VentRinseStep.RemoveAt(SelectedVentPrewetIndex); Recipe.VentRinseStep.Insert(currentIndex - 1, currentRinseSteps); SelectedVentPrewetIndex = currentIndex - 1; } } } /// /// 下移 /// /// private void VentPrewetMoveDownAction(object param) { if (Recipe != null) { if (SelectedVentPrewetIndex >= 0 && SelectedVentPrewetIndex < Recipe.VentRinseStep.Count - 1 && Recipe.VentRinseStep.Count > 1) { int currentIndex = SelectedVentPrewetIndex; VpwRinseStep currentRinseSteps = Recipe.VentRinseStep[SelectedVentPrewetIndex]; Recipe.VentRinseStep.RemoveAt(SelectedVentPrewetIndex); Recipe.VentRinseStep.Insert(currentIndex + 1, currentRinseSteps); SelectedVentPrewetIndex = currentIndex + 1; } } } /// /// 删除 /// /// private void VentPrewetDeleteAction(object param) { if (SelectedVentPrewetIndex != -1) { if (Recipe != null && Recipe.VentRinseStep.Count > SelectedVentPrewetIndex) { Recipe.VentRinseStep.RemoveAt(SelectedVentPrewetIndex); } } } #endregion #region Extend Clean按钮 /// /// 增加 /// /// private void ExtendCleanAddBelowAction(object param) { if (Recipe != null) { VpwRinseStep currentRinseSteps = new VpwRinseStep(); Recipe.ExtendCleanRinseStep.Insert(SelectedExtendCleanIndex + 1, currentRinseSteps); SelectedExtendCleanIndex++; } } /// /// 增加 /// /// private void ExtendCleanAddAboveAction(object param) { if (Recipe != null) { VpwRinseStep currentRinseSteps = new VpwRinseStep(); if (SelectedExtendCleanIndex == -1) { Recipe.ExtendCleanRinseStep.Add(currentRinseSteps); SelectedExtendCleanIndex = 0; } else { Recipe.ExtendCleanRinseStep.Insert(SelectedExtendCleanIndex, currentRinseSteps); SelectedExtendCleanIndex--; } } } /// /// 上移 /// /// private void ExtendCleanMoveUpAction(object param) { if (Recipe != null) { if (SelectedExtendCleanIndex > 0) { int currentIndex = SelectedExtendCleanIndex; VpwRinseStep currentRinseSteps = Recipe.ExtendCleanRinseStep[SelectedExtendCleanIndex]; Recipe.ExtendCleanRinseStep.RemoveAt(SelectedExtendCleanIndex); Recipe.ExtendCleanRinseStep.Insert(currentIndex - 1, currentRinseSteps); SelectedExtendCleanIndex = currentIndex - 1; } } } /// /// 下移 /// /// private void ExtendCleanMoveDownAction(object param) { if (Recipe != null) { if (SelectedExtendCleanIndex >= 0 && SelectedExtendCleanIndex < Recipe.ExtendCleanRinseStep.Count - 1 && Recipe.ExtendCleanRinseStep.Count > 1) { int currentIndex = SelectedExtendCleanIndex; VpwRinseStep currentRinseSteps = Recipe.ExtendCleanRinseStep[SelectedExtendCleanIndex]; Recipe.ExtendCleanRinseStep.RemoveAt(SelectedExtendCleanIndex); Recipe.ExtendCleanRinseStep.Insert(currentIndex + 1, currentRinseSteps); SelectedExtendCleanIndex = currentIndex + 1; } } } /// /// 删除 /// /// private void ExtendCleanDeleteAction(object param) { if (SelectedExtendCleanIndex != -1) { if (Recipe != null && Recipe.ExtendCleanRinseStep.Count > SelectedExtendCleanIndex) { Recipe.ExtendCleanRinseStep.RemoveAt(SelectedExtendCleanIndex); } } } #endregion } }