using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using System.Windows.Input; using System.Xml; using Aitex.Core.RT.Log; using Aitex.Core.RT.RecipeCenter; using Aitex.Core.RT.SCCore; using Aitex.Core.UI.MVVM; using Aitex.UI.RecipeEditor; using MECF.Framework.Common.DataCenter; using OpenSEMI.ClientBase; using VirgoUI.Client.Models.Sys; namespace VirgoUI.Client.Models.PMs { class RecipeEditorViewModel : ModuleUiViewModelBase, ISupportMultipleSystem { #region 控件used public ICommand OpenLocalRecipeCommand { get; set; } public ICommand RightClickCommand { get; set; } public ICommand RecipeHelpDocCommand { get; set; } public ICommand SaveRecipeCommand { get; set; } public ICommand UndoCommand { get; set; } public ICommand RedoCommand { get; set; } public ICommand ExpandGroupCommand { get; set; } public ICommand CollapseGroupCommand { get; set; } public ICommand ToggleHideSameCommand { get; set; } public ICommand RecipeExport2ExcelCommand { get; set; } public ICommand ShowDetailedErrInfoCommand { get; set; } public ICommand EditRecipeInfoCommand { get; set; } public Visibility SingleAppElementVisibility { get; set; } public Visibility RecipeInfoTextVisibility { get; set; } public bool IsUndoEnabled { get; set; } public bool IsRedoEnabled { get; set; } public object RecipeHead { get; set; } public string Errors { get; set; } public string RecipeInfo { get; set; } public ObservableCollection RecipeRows { get; set; } public Visibility IsBarcodeVisibility { get; set; } #endregion 控件used private IUiRecipeManager _recipeManager; private string _chamberId; private SCValue _config = new SCValue(); private string _currentRecipeName = string.Empty; public bool _recipeSplit { get { return (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit"); } } public RecipeEditorViewModel() { // _config.SetKeys(new List() { SCName.BarcodeConfig_EnableBarcode }); } public RecipeEditorViewModel(IUiRecipeManager recipeManager, string chamberId) { _recipeManager = recipeManager; _chamberId = chamberId; // _config.SetKeys(new List() { SCName.BarcodeConfig_EnableBarcode }); } public string ChamberId { set { _chamberId = value; } get { return _chamberId; } } public int ProcessTypeIndexSelection { get; set; } = (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit") ? 1 : 0; public Visibility RecipeSplitEnable => (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit") ? Visibility.Visible : Visibility.Collapsed; public Visibility RecipeSplitDisable => (bool)QueryDataClient.Instance.Service.GetConfig("System.RecipeSplit") ? Visibility.Collapsed : Visibility.Visible; /// /// Recipe template /// public string RecipeTemplate { get { return _recipeManager.GetRecipeTemplate(_chamberId); } } public bool IsBarcodeEnabled { get { return false; } } public Dictionary RecipePermission { get { try { string recipetemplate = RecipeTemplate; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(RecipeTemplate); Dictionary ret = new Dictionary(); XmlNodeList nodeList = doc.SelectNodes("TableRecipeData/Step"); foreach (XmlNode node in nodeList) { AitexTableRecipeFormatCatalogGroup group = new AitexTableRecipeFormatCatalogGroup(); if (node.BaseURI.ToLower() != "mos") { group.DisplayName = node.BaseURI; bool hasper = false; bool.TryParse(node.Attributes["Permission"].Value, out hasper); group.HasPermission = hasper; ret.Add(group.DisplayName, group); } } return ret; } catch (Exception ex) { LOG.Write(ex); } return new Dictionary(); } } public string RecipeVersion() { try { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(RecipeTemplate); return doc.DocumentElement.Attributes["RecipeVersion"].Value; } catch (Exception ex) { LOG.Write(ex); } return "1.0"; } /// /// Recipe format /// public string RecipeFormat { get { return _recipeManager.GetRecipeFormatXml(_chamberId); } } /// /// Name list of all recipes. /// public IEnumerable RecipeNames { get { return _recipeManager.GetRecipes(_chamberId, true); } } /// /// Name list of all recipes. /// public string CurrentRecipeName { get { return _currentRecipeName; } set { if (value != _currentRecipeName) _currentRecipeName = value; InvokePropertyChanged("CurrentRecipeName"); } } /// /// Load recipe data by recipe name /// /// /// public string LoadRecipe(string receipeName, string rcpType) { if (_recipeSplit) { return _recipeManager.LoadRecipe(_chamberId + "\\" + rcpType, receipeName); } return _recipeManager.LoadRecipe(_chamberId, receipeName); } /// /// Get a list of all recipe names. /// /// public IEnumerable GetRecipes(string rcpType) { if (_recipeSplit) { return _recipeManager.GetRecipes(_chamberId + "\\" + rcpType, true); } return _recipeManager.GetRecipes(_chamberId, true); } /// /// delete a recipe by recipe name /// /// /// public bool DeleteRecipe(string recipeName, string rcpType) { if (_recipeSplit) { return _recipeManager.DeleteRecipe(_chamberId + "\\" + rcpType, recipeName); } return _recipeManager.DeleteRecipe(_chamberId, recipeName); } /// /// Save recipe by recipe name and recipe data /// /// /// /// public bool SaveRecipe(string recipeName, string rcpType, string recipeContent) { if (_recipeSplit) { return _recipeManager.SaveRecipe(_chamberId + "\\" + rcpType, recipeName, recipeContent); } return _recipeManager.SaveRecipe(_chamberId, recipeName, recipeContent); } /// /// Save recipe by recipe name and recipe data /// /// /// /// public bool SaveRecipeDouble(string recipeName, string rcpType, string recipeContent) { if (_recipeSplit) { return _recipeManager.SaveRecipe(_chamberId + "\\" + rcpType, recipeName, recipeContent) && _recipeManager.SaveRecipe((_chamberId == "PMA" ? "PMB" : "PMA") + "\\" + rcpType, recipeName, recipeContent); } return _recipeManager.SaveRecipe(_chamberId, recipeName, recipeContent) && _recipeManager.SaveRecipe((_chamberId == "PMA" ? "PMB" : "PMA"), recipeName, recipeContent); } /// /// SaveAs recipe by recipe name and recipe data /// /// /// /// public bool SaveAsRecipe(string recipeName, string rcpType, string recipeContent) { if (_recipeSplit) { return _recipeManager.SaveAsRecipe(_chamberId + "\\" + rcpType, recipeName, recipeContent); } return _recipeManager.SaveAsRecipe(_chamberId, recipeName, recipeContent); } /// /// Rename recipe /// /// /// /// public bool RenameRecipe(string oldName, string rcpType, string newName) { if (_recipeSplit) { return _recipeManager.RenameRecipe(_chamberId + "\\" + rcpType, oldName, newName); } return _recipeManager.RenameRecipe(_chamberId, oldName, newName); } /// /// Create recipe folder /// /// /// /// public bool CreateFolder(string folderName, string rcpType) { if (_recipeSplit) { return _recipeManager.CreateFolder(_chamberId + "\\" + rcpType, folderName); } return _recipeManager.CreateFolder(_chamberId, folderName); } /// /// move recipe file /// /// /// /// public bool MoveRecipeFile(string folderName, string rcpType, string tragetFolderName) { if (_recipeSplit) { return _recipeManager.MoveRecipeFile(_chamberId + "\\" + rcpType, folderName, tragetFolderName); } return _recipeManager.MoveRecipeFile(_chamberId, folderName, tragetFolderName); } /// /// Get recipe list in xml format /// /// public string GetXmlRecipeList(string rcpType) { if (_recipeSplit) { return _recipeManager.GetXmlRecipeList(_chamberId + "\\" + rcpType, true) ?? ""; } return _recipeManager.GetXmlRecipeList(_chamberId, true) ?? ""; } /// /// Delete recipe folder /// /// /// public bool DeleteFolder(string foldName, string rcpType) { if (_recipeSplit) { return _recipeManager.DeleteFolder(_chamberId, foldName); } return _recipeManager.DeleteFolder(_chamberId + "\\" + rcpType, foldName); } /// /// Rename recipe folder /// /// /// /// public bool RenameFolder(string oldName, string rcpType, string newName) { if (_recipeSplit) { return _recipeManager.RenameFolder(_chamberId + "\\" + rcpType, oldName, newName); } return _recipeManager.RenameFolder(_chamberId, oldName, newName); } public void UpdateAllConfig() { //_config.Update(VirgoUiSystem.Instance.WCF.Query.PollConfig(_config.GetKeys())); } } }