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