| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609 | 
							- 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.Text;
 
- using System.Threading.Tasks;
 
- using System.Windows;
 
- using System.Windows.Input;
 
- namespace CyberX8_MainPages.ViewModels
 
- {
 
-     public class SequenceRecipeViewModel : BindableBase
 
-     {
 
-         #region 常量
 
-         private const string ENGINEERING = "Engineering";
 
-         private const string SEQUENCE = "seq";
 
-         #endregion
 
-         #region 内部变量
 
-         /// <summary>
 
-         /// Recipe节点字典
 
-         /// </summary>
 
-         private Dictionary<string, RecipeNode> _recipeNodeDic = new Dictionary<string, RecipeNode>();
 
-         /// <summary>
 
-         /// 可用RecipeType字典(key-ListBox内容,value-recipeType)
 
-         /// </summary>
 
-         private Dictionary<string, string> _aviableNodeTypeDic = new Dictionary<string, string>();
 
-         /// <summary>
 
-         /// Recipe节点集合
 
-         /// </summary>
 
-         private ObservableCollection<RecipeNode> _recipeNodes;
 
-         /// <summary>
 
-         /// 子Recipe节点集合
 
-         /// </summary>
 
-         private ObservableCollection<string> _subRecipeNodes;
 
-         /// <summary>
 
-         /// uiRecipeManager
 
-         /// </summary>
 
-         private UiRecipeManager _uiRecipeManager = new UiRecipeManager();
 
-         /// <summary>
 
-         /// recipe
 
-         /// </summary>
 
-         private SequenceRecipe _recipe;
 
-         /// <summary>
 
-         /// 编辑可用性
 
-         /// </summary>
 
-         private bool _editEnable;
 
-         /// <summary>
 
-         /// 创建可用性
 
-         /// </summary>
 
-         private bool _createEnable;
 
-         /// <summary>
 
-         /// 当前节点
 
-         /// </summary>
 
-         private RecipeNode _currentNode;
 
-         /// <summary>
 
-         /// 可用Recipe集合
 
-         /// </summary>
 
-         private List<string> _avaibleRecipeTypeLst;
 
-         /// <summary>
 
-         /// Process Recipe集合
 
-         /// </summary>
 
-         private ObservableCollection<string> _processRecipes;
 
-         /// <summary>
 
-         /// 选中可用RecipeType
 
-         /// </summary>
 
-         private string _selectAvaibleRecipeType;
 
-         /// <summary>
 
-         /// 选中子Recipe
 
-         /// </summary>
 
-         private string _selectSubRecipe;
 
-         /// <summary>
 
-         /// 选中索引
 
-         /// </summary>
 
-         private int _selectedProcessRecipeIndex;
 
-         /// <summary>
 
-         /// 选中Process Recipe
 
-         /// </summary>
 
-         private string _selectedProcessRecipe;
 
-         /// <summary>
 
-         /// <summary>
 
-         /// csr 类型集合
 
-         /// </summary>
 
-         private List<string> _crsTypeLst = null;
 
-         /// <summary>
 
-         /// Wafer尺寸集合
 
-         /// </summary>
 
-         private List<int> _waferSizeLst = null;
 
-         /// <summary>
 
-         /// 是否可用
 
-         /// </summary>
 
-         private bool _enable = false;
 
-         /// <summary>
 
-         /// 是否为编辑
 
-         /// </summary>
 
-         private bool _editAction = false;
 
-         /// <summary>
 
-         /// 是否为编辑(true-Edit,false-add)
 
-         /// </summary>
 
-         private bool _isEdit = false;
 
-         /// <summary>
 
-         /// 属性检验结果字典
 
-         /// </summary>
 
-         private Dictionary<string, bool> _propertyValidResultDic = new Dictionary<string, bool>();
 
-         #endregion
 
-         #region 属性
 
-         public ObservableCollection<RecipeNode> RecipeNodes
 
-         {
 
-             get { return _recipeNodes; }
 
-             set { SetProperty(ref _recipeNodes, value); }
 
-         }
 
-         /// <summary>
 
-         /// 子Recipe集合
 
-         /// </summary>
 
-         public ObservableCollection<string> SubRecipeNodes
 
-         {
 
-             get { return _subRecipeNodes; }
 
-             set { SetProperty(ref _subRecipeNodes, value); }
 
-         }
 
-         /// <summary>
 
-         /// Recipe
 
-         /// </summary>
 
-         public SequenceRecipe 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 List<string> AvaibleRecipeTypeLst
 
-         {
 
-             get { return _avaibleRecipeTypeLst; }
 
-             set { SetProperty(ref _avaibleRecipeTypeLst, value);}
 
-         }
 
-         /// <summary>
 
-         /// 选中
 
-         /// </summary>
 
-         public string SelectedAvaibleRecipeType
 
-         {
 
-             get { return _selectAvaibleRecipeType; }
 
-             set 
 
-             {
 
-                 SetProperty(ref _selectAvaibleRecipeType, value);
 
-                 LoadSubRecipeNodes(value);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 选中子Recipe
 
-         /// </summary>
 
-         public string SelectedSubRecipe
 
-         {
 
-             get { return _selectSubRecipe; }
 
-             set { SetProperty(ref _selectSubRecipe, value);}
 
-         }
 
-         /// <summary>
 
-         /// 选中Process Recipe索引
 
-         /// </summary>
 
-         public int SelectedProcessRecipeIndex
 
-         {
 
-             get { return _selectedProcessRecipeIndex; }
 
-             set { SetProperty(ref _selectedProcessRecipeIndex, value); }
 
-         }
 
-         /// <summary>
 
-         /// 选中Process Recipe
 
-         /// </summary>
 
-         public string SelectedProcessRecipe
 
-         {
 
-             get { return _selectedProcessRecipe; }
 
-             set { SetProperty(ref _selectedProcessRecipe, value); }
 
-         }
 
-         /// <summary>
 
-         /// Process Recipe集合
 
-         /// </summary>
 
-         public ObservableCollection<string> ProcessRecipes
 
-         {
 
-             get { return _processRecipes; }
 
-             set { SetProperty(ref _processRecipes,value); }
 
-         }
 
-         /// <summary>
 
-         /// crs类型集合
 
-         /// </summary>
 
-         public List<string> CrsTypeLst
 
-         {
 
-             get { return _crsTypeLst; }
 
-             set { SetProperty(ref _crsTypeLst, value); }
 
-         }
 
-         /// <summary>
 
-         /// Wafer 尺寸集合
 
-         /// </summary>
 
-         public List<int> WaferSizeLst
 
-         {
 
-             get { return _waferSizeLst; }
 
-             set { SetProperty(ref _waferSizeLst, 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); }
 
-         }
 
-         #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 AddRecipeCommand { get; private set; }
 
-         [IgnorePropertyChange]
 
-         public ICommand RemoveRecipeCommand { get; private set; }
 
-         [IgnorePropertyChange]
 
-         public ICommand MoveUpCommand { get; private set; }
 
-         [IgnorePropertyChange]
 
-         public ICommand MoveDownCommand { get; private set; }
 
-         [IgnorePropertyChange]
 
-         public ICommand SaveRecipeCommand { get; private set; }
 
-         [IgnorePropertyChange]
 
-         public ICommand SaveAsRecipeCommand { get; private set; }
 
-         #endregion
 
-         /// <summary>
 
-         /// 构造函数
 
-         /// </summary>
 
-         public SequenceRecipeViewModel()
 
-         {
 
-             OperationCommand = new DelegateCommand<object>(SelectionChangedAction);
 
-             CreateCommand = new DelegateCommand<object>(CreateAction);
 
-             EditCommand = new DelegateCommand<object>(EditAction);
 
-             AddRecipeCommand=new DelegateCommand<object>(AddRecipeAction);
 
-             RemoveRecipeCommand = new DelegateCommand<object>(RemoveRecipeAction);
 
-             MoveUpCommand=new DelegateCommand<object>(MoveUpAction);
 
-             MoveDownCommand=new DelegateCommand<object>(MoveDownAction);
 
-             SaveRecipeCommand = new DelegateCommand<object>(SaveAction);
 
-             GetAvaibleRecipeType();
 
-             GetComboxLst();
 
-             InitializeProprtyValidResultDictionary();
 
-         }
 
-         /// <summary>
 
-         /// 初始化属性数据检验结果字典
 
-         /// </summary>
 
-         private void InitializeProprtyValidResultDictionary()
 
-         {
 
-         }
 
-         /// <summary>
 
-         /// 加载下拉框集合
 
-         /// </summary>
 
-         private void GetComboxLst()
 
-         {
 
-             //Wafer尺寸集合
 
-             WaferSizeLst = new List<int>();
 
-             WaferSizeLst.Add(100);
 
-             WaferSizeLst.Add(150);
 
-             WaferSizeLst.Add(200);
 
-             WaferSizeLst.Add(300);
 
-             string crstypeContent = QueryDataClient.Instance.Service.GetConfig($"System.LSType").ToString();
 
-             if (!string.IsNullOrEmpty(crstypeContent))
 
-             {
 
-                 CrsTypeLst = crstypeContent.Split(',').ToList();
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 加载数据
 
-         /// </summary>
 
-         public void LoadRecipeData()
 
-         {
 
-             RecipeNodes = _uiRecipeManager.GetRecipesByType(SEQUENCE);
 
-             _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<SequenceRecipe>(CurrentNode.RecipeFullFileName);
 
-                 if (Recipe != null)
 
-                 {
 
-                     ProcessRecipes = new ObservableCollection<string>();
 
-                     if (Recipe.Recipes != null && Recipe.Recipes.Count != 0)
 
-                     {
 
-                         ProcessRecipes.AddRange(Recipe.Recipes);
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     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;
 
-                 ProcessRecipes = null;
 
-                 EditEnable = false;
 
-                 Enable = false;
 
-             }
 
-             _editAction = false;
 
-         }
 
-         #region Action
 
-         /// <summary>
 
-         /// 创建
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void CreateAction(object param)
 
-         {
 
-             RecipeNameDialog recipeNameDialog = new RecipeNameDialog();
 
-             if (recipeNameDialog.ShowDialog().Value)
 
-             {
 
-                 if (!CheckNameExist(recipeNameDialog.RecipeName))
 
-                 {
 
-                     Recipe = new SequenceRecipe();
 
-                     Recipe.CreateDate = DateTime.Now;
 
-                     Recipe.Ppid = recipeNameDialog.RecipeName;
 
-                     ProcessRecipes = new ObservableCollection<string>();
 
-                     Enable = true;
 
-                     _editAction = false;
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 编辑
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void EditAction(object param)
 
-         {
 
-             Enable = true;
 
-             _editAction= true;
 
-         }
 
-         /// <summary>
 
-         /// 增加Recipe
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void AddRecipeAction(object param)
 
-         {
 
-             if (!string.IsNullOrEmpty(SelectedSubRecipe))
 
-             {
 
-                 string[] strAry = SelectedSubRecipe.Split('.');
 
-                 if(strAry.Length>=3)
 
-                 {
 
-                     string str = $"{strAry[1]}.{strAry[2]}";
 
-                     if (strAry[1].ToLower() != "dep" && strAry[1].ToLower() != "qdr")
 
-                     {
 
-                         string first = ProcessRecipes.FirstOrDefault(O => O.Contains(str));
 
-                         if (!string.IsNullOrEmpty(first))
 
-                         {
 
-                             MessageBox.Show("已经存在同一类型Recipe", "Add Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
 
-                             return;
 
-                         }
 
-                     }
 
-                     else if(strAry[1].ToLower() == "dep")
 
-                     {
 
-                         string containResult = ProcessRecipes.FirstOrDefault(O => O == SelectedSubRecipe);
 
-                         if (!string.IsNullOrEmpty(containResult))
 
-                         {
 
-                             MessageBox.Show($"{SelectedSubRecipe}已经存在", "Add Recipe", MessageBoxButton.OK, MessageBoxImage.Error);
 
-                             return;
 
-                         }
 
-                     }
 
-                 }
 
-                 
 
-                 ProcessRecipes.Add(SelectedSubRecipe);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 移除Recipe
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void RemoveRecipeAction(object param)
 
-         {
 
-             if(!string.IsNullOrEmpty(SelectedProcessRecipe)&&ProcessRecipes.Contains(SelectedProcessRecipe))
 
-             {
 
-                 ProcessRecipes.Remove(SelectedProcessRecipe);
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 上移
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void MoveUpAction(object param)
 
-         {
 
-             int tmpIndex = SelectedProcessRecipeIndex;
 
-             if(SelectedProcessRecipeIndex>0)
 
-             {
 
-                 string up = ProcessRecipes[SelectedProcessRecipeIndex - 1];
 
-                 ProcessRecipes[SelectedProcessRecipeIndex - 1] = SelectedProcessRecipe;
 
-                 ProcessRecipes[SelectedProcessRecipeIndex] = up;
 
-                 SelectedProcessRecipeIndex = tmpIndex - 1;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 下移
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void MoveDownAction(object param)
 
-         {
 
-             int tmpIndex = SelectedProcessRecipeIndex;
 
-             if (SelectedProcessRecipeIndex <ProcessRecipes.Count-1)
 
-             {
 
-                 string up = ProcessRecipes[SelectedProcessRecipeIndex + 1];
 
-                 ProcessRecipes[SelectedProcessRecipeIndex + 1] = SelectedProcessRecipe;
 
-                 ProcessRecipes[SelectedProcessRecipeIndex] = up;
 
-                 SelectedProcessRecipeIndex = tmpIndex + 1;
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 保存
 
-         /// </summary>
 
-         /// <param name="param"></param>
 
-         private void SaveAction(object param)
 
-         {
 
-             if (CheckValid(_isEdit))
 
-             {
 
-                 Recipe.Recipes = new List<string>();
 
-                 Recipe.Recipes.AddRange(ProcessRecipes);
 
-                 Recipe.SaveDate = DateTime.Now;
 
-                 try
 
-                 {
 
-                     _uiRecipeManager.SaveRecipe<SequenceRecipe>(ENGINEERING, Recipe.Ppid, "seq",Recipe);
 
-                     if (!_editAction)
 
-                     {
 
-                         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>
 
-         /// <param name="name"></param>
 
-         /// <returns></returns>
 
-         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;
 
-         }
 
-         #endregion
 
-         /// <summary>
 
-         /// 选择可用RecipeType
 
-         /// </summary>
 
-         private void GetAvaibleRecipeType()
 
-         {
 
-             AvaibleRecipeTypeLst = new List<string>();
 
-             ActiveRecipeType[] values=(ActiveRecipeType[]) Enum.GetValues(typeof(ActiveRecipeType));
 
-             foreach (var item in values)
 
-             {
 
-                 object[] objAttrs = item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
 
-                 if (objAttrs != null &&objAttrs.Length > 0)
 
-                 {
 
-                     DescriptionAttribute descAttr = objAttrs[0] as DescriptionAttribute;
 
-                     AvaibleRecipeTypeLst.Add($"{item}({descAttr.Description})");
 
-                     _aviableNodeTypeDic.Add($"{item}({descAttr.Description})", item.ToString());
 
-                 }
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 加载子Recipe集合
 
-         /// </summary>
 
-         /// <param name="selectedRecipeType"></param>
 
-         private void LoadSubRecipeNodes(string selectedRecipeType)
 
-         {
 
-             if(_aviableNodeTypeDic.ContainsKey(selectedRecipeType))
 
-             {
 
-                 SubRecipeNodes = new ObservableCollection<string>();
 
-                 string recipeType = _aviableNodeTypeDic[selectedRecipeType].ToLower();
 
-                 ObservableCollection<RecipeNode> tmpRecipeNodes = _uiRecipeManager.GetEngineeringRecipesByType(recipeType);
 
-                 foreach(RecipeNode item in tmpRecipeNodes)
 
-                 {
 
-                     SubRecipeNodes.Add(item.FileName);
 
-                 }
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |