123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- 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 内部变量
- /// <summary>
- /// Recipe节点字典
- /// </summary>
- private Dictionary<string, RecipeNode> _recipeNodeDic = new Dictionary<string, RecipeNode>();
- /// <summary>
- /// 属性检验结果字典
- /// </summary>
- private Dictionary<string, bool> _propertyValidResultDic = new Dictionary<string, bool>();
- /// <summary>
- /// Recipe节点集合
- /// </summary>
- private ObservableCollection<RecipeNode> _recipeNodes;
- /// <summary>
- /// uiRecipeManager
- /// </summary>
- private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
- /// <summary>
- /// recipe
- /// </summary>
- private DepRecipe _recipe;
- /// <summary>
- /// 编辑可用性
- /// </summary>
- private bool _editEnable;
- /// <summary>
- /// 创建可用性
- /// </summary>
- private bool _createEnable;
- /// <summary>
- /// 当前节点
- /// </summary>
- private RecipeNode _currentNode;
- /// <summary>
- /// 是否可用
- /// </summary>
- private bool _enable = false;
- /// <summary>
- /// 是否为编辑(true-Edit,false-add)
- /// </summary>
- private bool _isEdit = false;
- /// <summary>
- /// 化学液集合
- /// </summary>
- private List<string> _chemistryLst = new List<string>();
- /// <summary>
- /// 显示MultiZone列
- /// </summary>
- private bool _multiZoneShow = false;
- /// <summary>
- /// 显示SingleZone列
- /// </summary>
- private bool _singleZoneShow = false;
- /// <summary>
- /// 选择AnodeType
- /// </summary>
- private string _selectAnodeType;
- /// <summary>
- /// Ramp DataGrid选择索引
- /// </summary>
- private int _selectedRampIndex = -1;
- /// <summary>
- /// Pulse DataGrid选择索引
- /// </summary>
- private int _selectedPulseIndex = -1;
- /// <summary>
- /// Pulse类型集合
- /// </summary>
- private List<string> _pulseTypeList = new List<string>();
- #endregion
- #region 属性
- public ObservableCollection<RecipeNode> RecipeNodes
- {
- get { return _recipeNodes; }
- set { SetProperty(ref _recipeNodes, value); }
- }
- /// <summary>
- /// Recipe
- /// </summary>
- public DepRecipe Recipe
- {
- get { return _recipe; }
- set { SetProperty(ref _recipe, value); }
- }
- /// <summary>
- /// 创建可用性
- /// </summary>
- public bool CreateEnable
- {
- get { return _createEnable; }
- set { SetProperty(ref _createEnable, value);}
- }
- /// <summary>
- /// 编辑可用性
- /// </summary>
- public bool EditEnable
- {
- get { return _editEnable; }
- set { SetProperty(ref _editEnable, value);}
- }
- /// <summary>
- /// 当前节点
- /// </summary>
- public RecipeNode CurrentNode
- {
- get { return _currentNode; }
- set { SetProperty(ref _currentNode, value);}
- }
- /// <summary>
- /// 可用性
- /// </summary>
- public bool Enable
- {
- get { return _enable; }
- set { SetProperty(ref _enable, value); }
- }
- /// <summary>
- /// 属性数据检验结果
- /// </summary>
- public Dictionary<string, bool> PropertyValidResultDic
- {
- get { return _propertyValidResultDic; }
- set { SetProperty(ref _propertyValidResultDic, value); }
- }
- /// <summary>
- /// 化学液集合
- /// </summary>
- public List<string> ChemistryLst
- {
- get { return _chemistryLst; }
- set { SetProperty(ref _chemistryLst, value); }
- }
- /// <summary>
- /// MultiZone 显示
- /// </summary>
- public bool MultiZoneShow
- {
- get { return _multiZoneShow; }
- set
- {
- SetProperty(ref _multiZoneShow, value);
- SingleZoneShow = !value;
- }
- }
- /// <summary>
- /// SingleZone显示列
- /// </summary>
- public bool SingleZoneShow
- {
- get { return _singleZoneShow; }
- set { SetProperty(ref _singleZoneShow, value);}
- }
- /// <summary>
- /// 选择Anode Type
- /// </summary>
- public string SelectedAnodeType
- {
- get { return _selectAnodeType; }
- set
- {
- SetProperty(ref _selectAnodeType, value);
- UpdateDataGridShow();
- }
- }
- /// <summary>
- /// DataGrid 索引
- /// </summary>
- public int SelectedRampIndex
- {
- get { return _selectedRampIndex; }
- set { SetProperty(ref _selectedRampIndex, value);}
- }
- /// <summary>
- /// Pulse Datagrid选择索引
- /// </summary>
- public int SelectedPulseIndex
- {
- get { return _selectedPulseIndex; }
- set { SetProperty(ref _selectedPulseIndex, value); }
- }
- public List<string> 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
- /// <summary>
- /// 构造函数
- /// </summary>
- public DepRecipeViewModel()
- {
- OperationCommand = new DelegateCommand<object>(SelectionChangedAction);
- CreateCommand = new DelegateCommand<object>(CreateAction);
- EditCommand = new DelegateCommand<object>(EditAction);
- SaveRecipeCommand = new DelegateCommand<object>(SaveAction);
- AddBelowCommand = new DelegateCommand<object>(AddBelowAction);
- AddAboveCommand = new DelegateCommand<object>(AddAboveAction);
- MoveUpCommand=new DelegateCommand<object>(MoveUpAction);
- MoveDownCommand=new DelegateCommand<object>(MoveDownAction);
- DeleteCommand=new DelegateCommand<object>(DeleteAction);
- AddBelowPulseCommand = new DelegateCommand<object>(AddBelowPulseAction);
- AddAbovePulseCommand = new DelegateCommand<object>(AddAbovePulseAction);
- MoveUpPulseCommand=new DelegateCommand<object>(MoveUpPulseAction);
- MoveDownPulseCommand = new DelegateCommand<object>(MoveDownPulseAction);
- DeletePulseCommand =new DelegateCommand<object>(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();
- }
- /// <summary>
- /// 初始化属性数据检验结果字典
- /// </summary>
- private void InitializeProprtyValidResultDictionary()
- {
- PropertyValidResultDic["CurrentWarningLevel"] = false;
- PropertyValidResultDic["FaultPercent"] = false;
- PropertyValidResultDic["VolatageLimitMin"] = false;
- PropertyValidResultDic["VolatageLimitMax"] = false;
- PropertyValidResultDic["VoltageWarningLevel"] = false;
- PropertyValidResultDic["PlatingDelaySeconds"] = false;
-
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadRecipeData()
- {
- RecipeNodes = _uiRecipeManager.GetRecipesByType(DEP);
- _recipeNodeDic.Clear();
- InitializeDictionary(RecipeNodes);
- }
- /// <summary>
- /// 初始化字典
- /// </summary>
- /// <param name="nodes"></param>
- private void InitializeDictionary(ObservableCollection<RecipeNode> nodes)
- {
- if (nodes != null)
- {
- foreach (var node in nodes)
- {
- if (node.NodeType == RecipeNodeType.File)
- {
- _recipeNodeDic[node.Name] = node;
- }
- InitializeDictionary(node.Children);
- }
- }
- }
- /// <summary>
- /// 操作
- /// </summary>
- /// <param name="param"></param>
- 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<DepRecipe>(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
- /// <summary>
- /// 创建
- /// </summary>
- /// <param name="param"></param>
- 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<CurrentRampProfile>();
- Recipe.PulsePowerSupplySteps = new ObservableCollection<PulsePowerSupplyStep>();
- Enable = true;
- _isEdit = false;
- }
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="param"></param>
- private void EditAction(object param)
- {
- Enable = true;
- _isEdit= false;
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="param"></param>
- 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<DepRecipe>(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);
- }
- }
- }
- /// <summary>
- /// 检验合法性
- /// </summary>
- /// <param name="editType"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 更新表格显示
- /// </summary>
- private void UpdateDataGridShow()
- {
- if(Recipe!=null)
- {
- if(Recipe.AnodeType==0)
- {
- MultiZoneShow = true;
- }
- else
- {
- MultiZoneShow = false;
- }
- }
- }
- #region Ramp按钮
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="param"></param>
- private void AddBelowAction(object param)
- {
- if (Recipe != null)
- {
- CurrentRampProfile currentRampProfile = new CurrentRampProfile();
- Recipe.CurrentRampProfileSteps.Insert(SelectedRampIndex + 1, currentRampProfile);
- SelectedRampIndex++;
- }
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="param"></param>
- 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--;
- }
- }
- }
- /// <summary>
- /// 上移
- /// </summary>
- /// <param name="param"></param>
- 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;
- }
- }
- }
- /// <summary>
- /// 下移
- /// </summary>
- /// <param name="param"></param>
- private void MoveDownAction(object param)
- {
- if (Recipe != null)
- {
- if (SelectedRampIndex>=0&&SelectedRampIndex <Recipe.CurrentRampProfileSteps.Count-1 &&Recipe.CurrentRampProfileSteps.Count>1)
- {
- int currentIndex = SelectedRampIndex;
- CurrentRampProfile currentRampProfile = Recipe.CurrentRampProfileSteps[SelectedRampIndex];
- Recipe.CurrentRampProfileSteps.RemoveAt(SelectedRampIndex);
- Recipe.CurrentRampProfileSteps.Insert(currentIndex + 1, currentRampProfile);
- SelectedRampIndex = currentIndex + 1;
- }
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="param"></param>
- private void DeleteAction(object param)
- {
- if (SelectedRampIndex != -1)
- {
- if (Recipe != null && Recipe.CurrentRampProfileSteps.Count > SelectedRampIndex)
- {
- Recipe.CurrentRampProfileSteps.RemoveAt(SelectedRampIndex);
- }
- }
- }
- #endregion
- #region Pulse按钮
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="param"></param>
- private void AddBelowPulseAction(object param)
- {
- if (Recipe != null)
- {
- if (Recipe.PulsePowerSupplySteps.Count < 4)
- {
- PulsePowerSupplyStep pulsePowerSupplyStep = new PulsePowerSupplyStep();
- Recipe.PulsePowerSupplySteps.Insert(SelectedPulseIndex + 1, pulsePowerSupplyStep);
- SelectedPulseIndex++;
- }
- }
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="param"></param>
- 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--;
- }
- }
- }
- }
- /// <summary>
- /// 上移
- /// </summary>
- /// <param name="param"></param>
- 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;
- }
- }
- }
- /// <summary>
- /// 下移
- /// </summary>
- /// <param name="param"></param>
- 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;
- }
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="param"></param>
- private void DeletePulseAction(object param)
- {
- if (Recipe != null)
- {
- if(SelectedPulseIndex!=-1&&Recipe.PulsePowerSupplySteps.Count>SelectedPulseIndex)
- {
- Recipe.PulsePowerSupplySteps.RemoveAt(SelectedPulseIndex);
- }
- }
- }
- #endregion
- #endregion
- }
- }
|