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 { public RecipeCompareSelectDialogViewModel() { var chamber = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType"); Chambers = new ObservableCollection(((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>(); foreach (string pm in Chambers) { if (pmSPAndCTypeList.Contains(pm)) { RecipeProcessTypeDic.Add(pm, new ObservableCollection() { "Process", "Clean" }); } else { RecipeProcessTypeDic.Add(pm, new ObservableCollection() { "Process" }); } } } else { var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessType"); Processes = new ObservableCollection(((string)processType).Split(',')); if (RecipeProcessTypeDic == null) RecipeProcessTypeDic = new Dictionary>(); foreach (string pm in Chambers) { ObservableCollection recipeTypes = new ObservableCollection(); foreach (string recipeType in Processes) { recipeTypes.Add(recipeType); } RecipeProcessTypeDic.Add(pm, recipeTypes); } } DicPMChamberType = new Dictionary(); var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType"); if (chamberType == null) { ChamberType = new ObservableCollection() { "Default" }; } else { ChamberType = new ObservableCollection(((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 ChamberType { get; set; } public ObservableCollection ProcessType { get; set; } public Dictionary DicPMChamberType { get; set; } public Dictionary> RecipeProcessTypeDic { get; set; } public ObservableCollection Chambers { get; set; } public ObservableCollection 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 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 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); } } }