| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 | using System.Collections.Generic;using System.Collections.ObjectModel;using System.Linq;using System.Text.RegularExpressions;using System.Windows;using MECF.Framework.Common.DataCenter;using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;using OpenSEMI.ClientBase;namespace FurnaceUI.Views.Recipes{    public class RecipeCompareSelectDialogViewModel : DialogViewModel<string>    {        public RecipeCompareSelectDialogViewModel()        {            var chamber = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");            Chambers = new ObservableCollection<string>(((string)chamber).Split(','));            SelectedChamber = Chambers[0];            var pmSupportedProcessAndCLeanType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessAndCLeanType");            if (pmSupportedProcessAndCLeanType != null)            {                string[] pmSPAndCTypeList = pmSupportedProcessAndCLeanType.ToString().Split(',');                if (RecipeProcessTypeDic == null)                    RecipeProcessTypeDic = new Dictionary<string, ObservableCollection<string>>();                foreach (string pm in Chambers)                {                    if (pmSPAndCTypeList.Contains(pm))                    {                        RecipeProcessTypeDic.Add(pm, new ObservableCollection<string>() { "Process", "Clean" });                    }                    else                    {                        RecipeProcessTypeDic.Add(pm, new ObservableCollection<string>() { "Process" });                    }                }            }            else            {                var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessType");                Processes = new ObservableCollection<string>(((string)processType).Split(','));                if (RecipeProcessTypeDic == null)                    RecipeProcessTypeDic = new Dictionary<string, ObservableCollection<string>>();                foreach (string pm in Chambers)                {                    ObservableCollection<string> recipeTypes = new ObservableCollection<string>();                    foreach (string recipeType in Processes)                    {                        recipeTypes.Add(recipeType);                    }                    RecipeProcessTypeDic.Add(pm, recipeTypes);                }            }            DicPMChamberType = new Dictionary<string, string>();            var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");            if (chamberType == null)            {                ChamberType = new ObservableCollection<string>() { "Default" };            }            else            {                ChamberType = new ObservableCollection<string>(((string)(chamberType)).Split(','));            }            ChamberTypeIndexSelection = 0;            foreach (var pm in Chambers)            {                var type = QueryDataClient.Instance.Service.GetConfig($"{pm}.ChamberType");                if (type == null)                {                    DicPMChamberType[pm] = ChamberType[0];                }                else                {                    DicPMChamberType[pm] = (string)type;                }            }            for (int i = 0; i < ChamberType.Count; i++)            {                if (ChamberType[i] == DicPMChamberType[SelectedChamber])                {                    ChamberTypeIndexSelection = i; // 修改当前腔体类型                }            }        }        public void ChamberSelectionChanged()        {            if (IsSelectedA)            {                for (int i = 0; i < ChamberType.Count; i++)                {                    if (ChamberType[i] == DicPMChamberType[SelectedChamber])                    {                        ChamberTypeIndexSelection = i; // 修改当前腔体类型                    }                }            }            if (IsSelectedA)            {                if (!string.IsNullOrEmpty(SelectedChamber))                {                    UpdateProcessTypeFileList(SelectedChamber);                }                else                {                    UpdateProcessTypeFileList(Chambers[0]);                }            }            else            {                if (!string.IsNullOrEmpty(SelectedChamber))                {                    UpdateProcessTypeBFileList(SelectedChamber);                }                else                {                    UpdateProcessTypeBFileList(Chambers[0]);                }            }            ProcessTypeIndexSelection = 0;            NotifyOfPropertyChange(nameof(ProcessTypeFileList));        }        public void ProcessSelectionChanged()        {            if (IsSelectedA)            {                for (int i = 0; i < ProcessType.Count; i++)                {                    if (ProcessType[i] == DicPMChamberType[SelectedProcess])                    {                        ChamberTypeIndexSelection = i; // 修改当前腔体类型                    }                }            }            if (IsSelectedA)            { UpdateProcessTypeFileList(SelectedProcess); }            else            {                UpdateProcessTypeBFileList(SelectedProcess);            }            ProcessTypeIndexSelection = 0;            NotifyOfPropertyChange(nameof(ProcessTypeFileList));        }        public void UpdateProcessTypeBFileList(string selectedChamber)        {            ProcessTypeFileList.Clear();            foreach (var item in Processes)            {                var type = new ProcessTypeFileItem();                type.ProcessType = item;                var prefix = $"{selectedChamber}\\{item}";                var recipes = _recipeProvider.GetXmlRestoreRecipeList(prefix);                // var prefix = $"{RestoreRecipeFolder}\\{recipeProcessType[i]}";                type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildRestoreFileNode(prefix, "", false, recipes)[0].Files;                ProcessTypeFileList.Add(type);            }        }        public void UpdateProcessTypeFileList(string selectedChamber)        {            //ProcessTypeFileList.Clear();            for (int i = 0; i < RecipeProcessTypeDic[selectedChamber].Count; i++)            {                var type = new ProcessTypeFileItem();                type.ProcessType = RecipeProcessTypeDic[selectedChamber][i];                var prefix = $"{ChamberType[ChamberTypeIndexSelection]}\\{Processes[i]}";                var recipes = _recipeProvider.GetXmlRecipeList(prefix);                string[] parts = Regex.Split(recipes, "<");                //string recipeChamber;                //recipeChamber = "<" + parts[1];                //foreach (string part in parts)                //{                //    if (CurrentChamberType == ChamberType[0] && (Chambers.Count > 1 && part.Contains($".{Chambers[1]}")) && (Chambers.Count > 2 && part.Contains($".{Chambers[2]}")))                //    {                //        string temp = part.Replace($".{Chambers[1]}", string.Empty);                //        temp = temp.Replace($".{Chambers[2]}", string.Empty);                //        recipeChamber += "<" + temp;                //    }                //    else if (part.Contains(_selectedChamberSuffix))                //    {                //        string temp = part.Replace(_selectedChamberSuffix, string.Empty);                //        recipeChamber += "<" + temp;                //    }                //}                //if (parts.Length > 2)                //{                //    recipeChamber += "<" + parts[parts.Length - 1];                //}                var recipesChamber = _recipeProvider.GetXmlRecipeList(prefix);                type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipesChamber)[0].Files;                ProcessTypeFileList.Add(type);            }            while (ProcessTypeFileList.Count > RecipeProcessTypeDic[SelectedChamber].Count)            {                ProcessTypeFileList.RemoveAt(0);            }            //for (int i = 0; i < ProcessTypeFileList.Count; i++)            //{            //    for (int j = ProcessTypeFileList[i].FileListByProcessType.Count - 1; j >= 0; j--)            //    {            //        if (!ProcessTypeFileList[i].FileListByProcessType[j].Name.Contains(selectedChamber))            //            ProcessTypeFileList[i].FileListByProcessType.RemoveAt(j);            //    }            //}        }        public string _selectedChamberSuffix => $".{SelectedChamber}";        public string CurrentChamberType        {            get            {                return ChamberType[ChamberTypeIndexSelection];            }        }        public string CurrentProcessType        {            get            {                return ProcessType[ChamberTypeIndexSelection];            }        }        public int ChamberTypeIndexSelection { get; set; }        private RecipeProvider _recipeProvider = new RecipeProvider();        public ObservableCollection<string> ChamberType { get; set; }        public ObservableCollection<string> ProcessType { get; set; }        public Dictionary<string, string> DicPMChamberType { get; set; }        public Dictionary<string, ObservableCollection<string>> RecipeProcessTypeDic { get; set; }        public ObservableCollection<string> Chambers { get; set; }        public ObservableCollection<string> Processes { get; set; }        public string _selectedChamber;        public string SelectedChamber        {            get { return _selectedChamber; }            set { _selectedChamber = value; NotifyOfPropertyChange("SelectedChamber"); }        }        public string _selectedProcess;        public string SelectedProcess        {            get { return _selectedProcess; }            set { _selectedProcess = value; NotifyOfPropertyChange("SelectedProcess"); }        }        public string _chamberSuffix => Chambers.Count > 2 ? $".{Chambers[1]}" + $".{Chambers[2]}" : string.Empty;        public ObservableCollection<ProcessTypeFileItem> ProcessTypeFileList { get; set; }        public FileNode CurrentFileNode { get; set; }        public bool IsSelectedA { get; set; } = true;        private int _processTypeIndexSelection;        public int ProcessTypeIndexSelection        {            get            {                return _processTypeIndexSelection;            }            set            {                _processTypeIndexSelection = value;                //ProcessSelectionChanged();            }        }        public ObservableCollection<FileNode> Files { get; set; }        private FileNode currentFileNode;        public void TreeSelectChanged(FileNode file)        {            this.currentFileNode = file;        }        public void TreeMouseDoubleClick(FileNode file)        {            this.currentFileNode = file;            OK();        }        public void OK()        {            if (this.currentFileNode != null)            {                if (this.currentFileNode.IsFile)                {                    this.DialogResult = currentFileNode.PrefixPath + "\\" + currentFileNode.FullPath;                    IsCancel = false;                    TryClose(true);                }            }        }        public void Cancel()        {            IsCancel = true;            TryClose(false);        }        public void Browser()        {            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();            openFileDialog.Title = "Select source file";            openFileDialog.Filter = string.Format("rcp|*.rcp", SelectedChamber);            openFileDialog.FileName = string.Empty;            // openFileDialog.DefaultExt = "xml";            if (openFileDialog.ShowDialog() == false)            {                return;            }            string xmlFile = openFileDialog.FileName;            this.DialogResult = xmlFile;            TryClose(true);        }    }}
 |