using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.Log; using Aitex.Core.UI.Dialog; using Aitex.Core.UI.MVVM; using Aitex.Core.Utilities; using Caliburn.Micro.Core; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.RecipeCenter; using CyberX8_Core; using CyberX8_MainPages.PMs; using CyberX8_Themes.UserControls; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace CyberX8_MainPages.ViewModels { public class DepRecipeViewModel : BindableBase { #region 常量 private const string ENGINEERING = "Engineering"; private const string DEP = "dep"; #endregion #region 内部变量 /// /// Recipe节点字典 /// private Dictionary _recipeNodeDic = new Dictionary(); /// /// 属性检验结果字典 /// private Dictionary _propertyValidResultDic = new Dictionary(); /// /// Recipe节点集合 /// private ObservableCollection _recipeNodes; /// /// uiRecipeManager /// private UiRecipeManager _uiRecipeManager = new UiRecipeManager(); /// /// recipe /// private DepRecipe _recipe; /// /// 编辑可用性 /// private bool _editEnable; /// /// 创建可用性 /// private bool _createEnable; /// /// 当前节点 /// private RecipeNode _currentNode; /// /// 是否可用 /// private bool _enable = false; /// /// 是否为编辑(true-Edit,false-add) /// private bool _isEdit = false; /// /// 化学液集合 /// private List _chemistryLst = new List(); /// /// 显示MultiZone列 /// private bool _multiZoneShow = false; /// /// 显示SingleZone列 /// private bool _singleZoneShow = false; /// /// 选择AnodeType /// private string _selectAnodeType; /// /// Ramp DataGrid选择索引 /// private int _selectedRampIndex = -1; /// /// Pulse DataGrid选择索引 /// private int _selectedPulseIndex = -1; /// /// Pulse类型集合 /// private List _pulseTypeList = new List(); #endregion #region 属性 public ObservableCollection RecipeNodes { get { return _recipeNodes; } set { SetProperty(ref _recipeNodes, value); } } /// /// Recipe /// public DepRecipe Recipe { get { return _recipe; } set { SetProperty(ref _recipe, value); } } /// /// 创建可用性 /// public bool CreateEnable { get { return _createEnable; } set { SetProperty(ref _createEnable, value);} } /// /// 编辑可用性 /// public bool EditEnable { get { return _editEnable; } set { SetProperty(ref _editEnable, value);} } /// /// 当前节点 /// public RecipeNode CurrentNode { get { return _currentNode; } set { SetProperty(ref _currentNode, value);} } /// /// 可用性 /// public bool Enable { get { return _enable; } set { SetProperty(ref _enable, value); } } /// /// 属性数据检验结果 /// public Dictionary PropertyValidResultDic { get { return _propertyValidResultDic; } set { SetProperty(ref _propertyValidResultDic, value); } } /// /// 化学液集合 /// public List ChemistryLst { get { return _chemistryLst; } set { SetProperty(ref _chemistryLst, value); } } /// /// MultiZone 显示 /// public bool MultiZoneShow { get { return _multiZoneShow; } set { SetProperty(ref _multiZoneShow, value); SingleZoneShow = !value; } } /// /// SingleZone显示列 /// public bool SingleZoneShow { get { return _singleZoneShow; } set { SetProperty(ref _singleZoneShow, value);} } /// /// 选择Anode Type /// public string SelectedAnodeType { get { return _selectAnodeType; } set { SetProperty(ref _selectAnodeType, value); UpdateDataGridShow(); } } /// /// DataGrid 索引 /// public int SelectedRampIndex { get { return _selectedRampIndex; } set { SetProperty(ref _selectedRampIndex, value);} } /// /// Pulse Datagrid选择索引 /// public int SelectedPulseIndex { get { return _selectedPulseIndex; } set { SetProperty(ref _selectedPulseIndex, value); } } public List PulseTypeList { get { return _pulseTypeList; } set { SetProperty(ref _pulseTypeList, value); } } #endregion #region 指令 [IgnorePropertyChange] 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 AddBelowCommand { get;private set; } [IgnorePropertyChange] public ICommand AddAboveCommand { get; private set; } [IgnorePropertyChange] public ICommand MoveUpCommand { get; private set; } [IgnorePropertyChange] public ICommand MoveDownCommand { get; private set; } [IgnorePropertyChange] public ICommand DeleteCommand { get;private set; } [IgnorePropertyChange] public ICommand AddBelowPulseCommand { get; private set; } [IgnorePropertyChange] public ICommand AddAbovePulseCommand { get; private set; } [IgnorePropertyChange] public ICommand MoveUpPulseCommand { get; private set; } [IgnorePropertyChange] public ICommand MoveDownPulseCommand { get; private set; } [IgnorePropertyChange] public ICommand DeletePulseCommand { get; private set; } #endregion /// /// 构造函数 /// public DepRecipeViewModel() { OperationCommand = new DelegateCommand(SelectionChangedAction); CreateCommand = new DelegateCommand(CreateAction); EditCommand = new DelegateCommand(EditAction); SaveRecipeCommand = new DelegateCommand(SaveAction); AddBelowCommand = new DelegateCommand(AddBelowAction); AddAboveCommand = new DelegateCommand(AddAboveAction); MoveUpCommand=new DelegateCommand(MoveUpAction); MoveDownCommand=new DelegateCommand(MoveDownAction); DeleteCommand=new DelegateCommand(DeleteAction); AddBelowPulseCommand = new DelegateCommand(AddBelowPulseAction); AddAbovePulseCommand = new DelegateCommand(AddAbovePulseAction); MoveUpPulseCommand=new DelegateCommand(MoveUpPulseAction); MoveDownPulseCommand = new DelegateCommand(MoveDownPulseAction); DeletePulseCommand =new DelegateCommand(DeletePulseAction); string chemistryContent = QueryDataClient.Instance.Service.GetConfig($"System.ChemistryList").ToString(); if (!string.IsNullOrEmpty(chemistryContent)) { ChemistryLst = chemistryContent.Split(',').ToList(); } PulseTypeList.Add("Plus"); PulseTypeList.Add("Minus"); PulseTypeList.Add("Off"); InitializeProprtyValidResultDictionary(); } /// /// 初始化属性数据检验结果字典 /// private void InitializeProprtyValidResultDictionary() { PropertyValidResultDic["CurrentWarningLevel"] = false; PropertyValidResultDic["FaultPercent"] = false; PropertyValidResultDic["VolatageLimitMin"] = false; PropertyValidResultDic["VolatageLimitMax"] = false; PropertyValidResultDic["VoltageWarningLevel"] = false; PropertyValidResultDic["PlatingDelaySeconds"] = false; } /// /// 加载数据 /// public void LoadRecipeData() { RecipeNodes = _uiRecipeManager.GetRecipesByType(DEP); _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; } } #region Action /// /// 创建 /// /// private void CreateAction(object param) { RecipeNameDialog recipeNameDialog = new RecipeNameDialog(); if (recipeNameDialog.ShowDialog().Value) { Recipe = new DepRecipe(); Recipe.CreateDate = DateTime.Now; Recipe.Ppid = recipeNameDialog.RecipeName; Recipe.Description=recipeNameDialog.RecipeDescription; Recipe.CurrentRampProfileSteps = new ObservableCollection(); Recipe.PulsePowerSupplySteps = new ObservableCollection(); 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; int platingsteps = 0; int totaltime = 0; double totalcurrent = 0; foreach(var obj in Recipe.CurrentRampProfileSteps) { totaltime += obj.CurrentRampDurartionSeconds; totalcurrent += (obj.CurrentRampDurartionSeconds * obj.ForwardAmps); platingsteps++; } //计算Deposition PlatingSteps Recipe.DepositionPlatingSteps = platingsteps; //计算Deposition Totaltimes string date = string.Empty; var seconds = (int)(totaltime % 60); var minutes = (int)(totaltime / 60) % 60; var hours = (int)(totaltime / 3600) % 60; date = string.Format("{0:00}:{1:00}:{2:00}", hours + "h", minutes + "m", seconds + "s"); Recipe.DepositionTotalTime = date; //计算Deposition TotalCurrent Recipe.DepositionTotalCurrent = totalcurrent / 3600; //计算TotalTime Recipe.TotalTime = totaltime + Recipe.PlatingDelaySeconds; try { _uiRecipeManager.SaveRecipe(ENGINEERING, Recipe.Ppid,"dep", 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 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 UpdateDataGridShow() { if(Recipe!=null) { if(Recipe.AnodeType==0) { MultiZoneShow = true; } else { MultiZoneShow = false; } } } #region Ramp按钮 /// /// 增加 /// /// private void AddBelowAction(object param) { if (Recipe != null) { CurrentRampProfile currentRampProfile = new CurrentRampProfile(); Recipe.CurrentRampProfileSteps.Insert(SelectedRampIndex + 1, currentRampProfile); SelectedRampIndex++; } } /// /// 增加 /// /// private void AddAboveAction(object param) { if (Recipe != null) { CurrentRampProfile currentRampProfile = new CurrentRampProfile(); if (SelectedRampIndex == -1) { Recipe.CurrentRampProfileSteps.Add(currentRampProfile); SelectedRampIndex = 0; } else { Recipe.CurrentRampProfileSteps.Insert(SelectedRampIndex, currentRampProfile); SelectedRampIndex--; } } } /// /// 上移 /// /// private void MoveUpAction(object param) { if (Recipe != null) { if(SelectedRampIndex>0) { int currentIndex = SelectedRampIndex; CurrentRampProfile currentRampProfile = Recipe.CurrentRampProfileSteps[SelectedRampIndex]; Recipe.CurrentRampProfileSteps.RemoveAt(SelectedRampIndex); Recipe.CurrentRampProfileSteps.Insert(currentIndex - 1,currentRampProfile); SelectedRampIndex = currentIndex - 1; } } } /// /// 下移 /// /// private void MoveDownAction(object param) { if (Recipe != null) { if (SelectedRampIndex>=0&&SelectedRampIndex 1) { int currentIndex = SelectedRampIndex; CurrentRampProfile currentRampProfile = Recipe.CurrentRampProfileSteps[SelectedRampIndex]; Recipe.CurrentRampProfileSteps.RemoveAt(SelectedRampIndex); Recipe.CurrentRampProfileSteps.Insert(currentIndex + 1, currentRampProfile); SelectedRampIndex = currentIndex + 1; } } } /// /// 删除 /// /// private void DeleteAction(object param) { if (SelectedRampIndex != -1) { if (Recipe != null && Recipe.CurrentRampProfileSteps.Count > SelectedRampIndex) { Recipe.CurrentRampProfileSteps.RemoveAt(SelectedRampIndex); } } } #endregion #region Pulse按钮 /// /// 增加 /// /// private void AddBelowPulseAction(object param) { if (Recipe != null) { if (Recipe.PulsePowerSupplySteps.Count < 4) { PulsePowerSupplyStep pulsePowerSupplyStep = new PulsePowerSupplyStep(); Recipe.PulsePowerSupplySteps.Insert(SelectedPulseIndex + 1, pulsePowerSupplyStep); SelectedPulseIndex++; } } } /// /// 增加 /// /// private void AddAbovePulseAction(object param) { if (Recipe != null) { if (Recipe.PulsePowerSupplySteps.Count < 4) { PulsePowerSupplyStep pulsePowerSupplyStep = new PulsePowerSupplyStep(); if (SelectedPulseIndex == -1) { Recipe.PulsePowerSupplySteps.Add(pulsePowerSupplyStep); SelectedPulseIndex = 0; } else { Recipe.PulsePowerSupplySteps.Insert(SelectedPulseIndex, pulsePowerSupplyStep); SelectedPulseIndex--; } } } } /// /// 上移 /// /// private void MoveUpPulseAction(object param) { if (Recipe != null) { if (SelectedPulseIndex > 0) { int currentIndex = SelectedPulseIndex; PulsePowerSupplyStep pulsePowerSupplyStep = Recipe.PulsePowerSupplySteps[currentIndex]; Recipe.PulsePowerSupplySteps.RemoveAt(currentIndex); Recipe.PulsePowerSupplySteps.Insert(currentIndex - 1, pulsePowerSupplyStep); SelectedPulseIndex = currentIndex - 1; } } } /// /// 下移 /// /// private void MoveDownPulseAction(object param) { if (Recipe != null) { if (SelectedPulseIndex >= 0 && SelectedPulseIndex < Recipe.PulsePowerSupplySteps.Count - 1 && Recipe.PulsePowerSupplySteps.Count > 1) { int currentIndex = SelectedPulseIndex; PulsePowerSupplyStep pulsePowerSupplyStep = Recipe.PulsePowerSupplySteps[currentIndex]; Recipe.PulsePowerSupplySteps.RemoveAt(currentIndex); Recipe.PulsePowerSupplySteps.Insert(currentIndex + 1, pulsePowerSupplyStep); SelectedPulseIndex = currentIndex + 1; } } } /// /// 删除 /// /// private void DeletePulseAction(object param) { if (Recipe != null) { if(SelectedPulseIndex!=-1&&Recipe.PulsePowerSupplySteps.Count>SelectedPulseIndex) { Recipe.PulsePowerSupplySteps.RemoveAt(SelectedPulseIndex); } } } #endregion #endregion } }