using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Windows; using Caliburn.Micro; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using MECF.Framework.UI.Client.CenterViews.Dialogs; using MECF.Framework.UI.Client.CenterViews.Editors.Recipe; using MECF.Framework.UI.Client.CenterViews.Editors.Sequence; using MECF.Framework.UI.Client.ClientBase; using OpenSEMI.ClientBase; using OpenSEMI.ClientBase.Command; using FurnaceUI.Views.Parameter; namespace FurnaceUI.Views.Configs { public class SystemConfigViewModel : ModuleUiViewModelBase, ISupportMultipleSystem { #region Properties public bool IsPermission { get => this.Permission == 3; } private Visibility _isShowTable = Visibility.Hidden; public Visibility IsShowTable { get => _isShowTable; set { _isShowTable = value; NotifyOfPropertyChange(nameof(IsShowTable)); } } private Visibility _isShowData = Visibility.Hidden; public Visibility IsShowData { get => _isShowData; set { _isShowData = value; NotifyOfPropertyChange(nameof(IsShowData)); } } private List _ConfigNodes = new List(); public List ConfigNodes { get { return _ConfigNodes; } set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); } } private List _configItems = null; public List ConfigItems { get { return _configItems; } set { _configItems = value; NotifyOfPropertyChange("ConfigItems"); } } string _CurrentNodeName = string.Empty; public BaseCommand TreeViewSelectedItemChangedCmd { private set; get; } private ObservableCollection valueList { get; set; } = new ObservableCollection(); private string _currentCriteria = String.Empty; public string CurrentCriteria { get { return _currentCriteria; } set { if (value == _currentCriteria) return; _currentCriteria = value; NotifyOfPropertyChange("CurrentCriteria"); ApplyFilter(); } } private void ApplyFilter() { foreach (var node in ConfigNodes) node.ApplyCriteria(CurrentCriteria, new Stack()); } #endregion #region Functions public SystemConfigViewModel() { this.DisplayName = "System Config"; TreeViewSelectedItemChangedCmd = new BaseCommand(TreeViewSelectedItemChanged); } protected override void OnInitialize() { base.OnInitialize(); ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes; } protected override void OnActivate() { base.OnActivate(); ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes; } private void TreeViewSelectedItemChanged(ConfigNode node) { valueList.Clear(); _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}"; ConfigItems = node.Items; if (_CurrentNodeName == "PM1.WaferCycleTime") { IsShowTable = Visibility.Visible; IsShowData = Visibility.Hidden; } else { IsShowTable = Visibility.Hidden; IsShowData = Visibility.Visible; } GetDataOfConfigItems(); } private void GetDataOfConfigItems() { if (ConfigItems == null) return; for (int i = 0; i < ConfigItems.Count; i++) { string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", ConfigItems[i].Name); ConfigItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(SystemName, key); if (ConfigItems[i].Type == DataType.Bool) { bool value; if (bool.TryParse(ConfigItems[i].CurrentValue, out value)) { ConfigItems[i].BoolValue = value; ConfigItems[i].CurrentValue = value ? "Yes" : "No"; } } else ConfigItems[i].StringValue = ConfigItems[i].CurrentValue; } } public void SetValue(ConfigItem item) { InputDialogViewModel dialog = new InputDialogViewModel(); RecipeSelectDialogViewModel selectDialog = new RecipeSelectDialogViewModel(); WindowManager wm = new WindowManager(); bool? bret = null; if (item.Name == "Idle Recipe" || item.Name == "Abort Recipe") { selectDialog.DisplayName = "Select Recipe"; var recipeProvider = new RecipeProvider(); string selectRecipeType = ""; if (item.Name == "Idle Recipe") selectRecipeType = "Idle"; else selectRecipeType = "Abort"; var processType = QueryDataClient.Instance.Service.GetConfig($"System.Recipe.{selectRecipeType}"); if (processType == null) { processType = selectRecipeType; } var ProcessTypeFileList = new ObservableCollection(); string[] recipeProcessType = ((string)processType).Split(','); for (int i = 0; i < recipeProcessType.Length; i++) { var type = new ProcessTypeFileItem(); type.ProcessType = recipeProcessType[i]; var prefix = $"Furnace\\{recipeProcessType[i]}"; var recipes = recipeProvider.GetXmlRecipeList(prefix); type.FileListByProcessType = RecipeSequenceTreeBuilder.BuildFileNode(prefix, "", false, recipes)[0].Files; ProcessTypeFileList.Add(type); } selectDialog.ProcessTypeFileList = ProcessTypeFileList; bret = wm.ShowDialog(selectDialog); } else { if (item.Type == DataType.String) dialog.KeyboardType = "FullKeyboard"; dialog.Item = item; dialog.DisplayName = "Set Value"; bret = wm.ShowDialog(dialog); } string strOldValue = item.CurrentValue; if ((bool)bret) { item.StringValue = dialog.DialogResult; //key :System.IsSimulatorMode //value: true or false 都是字符串 //input check string value; if (item.Type == DataType.Bool) { if (item.StringValue.Equals("Yes", StringComparison.CurrentCultureIgnoreCase)) item.BoolValue = true; else if (item.StringValue.Equals("No", StringComparison.CurrentCultureIgnoreCase)) item.BoolValue = false; else { DialogBox.ShowWarning("The Value Should be Yes Or No."); return; } value = item.BoolValue.ToString().ToLower(); } else { //if (item.TextSaved && item.Tag != "ReadOnlySelection") //if (item.Tag == "ReadOnlySelection") // return; if (item.Type == DataType.Int) { int iValue; if (int.TryParse(item.StringValue, out iValue)) { if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min)) { if (iValue > item.Max || iValue < item.Min) { DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString())); return; } } } else { DialogBox.ShowWarning("Please input valid data."); return; } value = item.StringValue; } else if (item.Type == DataType.Double) { double fValue; if (double.TryParse(item.StringValue, out fValue)) { if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min)) { if (fValue > item.Max || fValue < item.Min) { DialogBox.ShowWarning(string.Format("The value should be between {0} and {1}.", item.Min.ToString(), item.Max.ToString())); return; } string[] box = fValue.ToString().Split('.'); if (box.Length > 1 && box[1].Length > 3) { DialogBox.ShowWarning(string.Format("The value should be more than three decimal places")); return; } } } else { DialogBox.ShowWarning("Please input valid data."); return; } value = item.StringValue; } else { if (item.StringValue != null) value = item.StringValue; else value = selectDialog.DialogResult; } } if (_CurrentNodeName == "System.ShutDown" && item.StringValue == "ShutDown") { InvokeClient.Instance.Service.DoOperation("System.ShutDown"); } //压力单位改变时候,已有设置根据改变进行值转换 if (item.Name == "PressureUnit" && strOldValue != value) ChangePressureUnit(value); string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name); //InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", key, value); valueList.Add(new PageValue() { Path = key, CurrentValue = value }); //Reload(); } } private void ChangePressureUnit(string strNewValue) { double dValue = 0; if (strNewValue.Equals("Torr"))//从Pa转换成Torr dValue = 0.0075006; else //从Torr转换成Pa dValue = 133.322; } public void Reload() { GetDataOfConfigItems(); } public void SaveAll() { if (ConfigItems == null) return; ConfigItems.ForEach(item => SetValue(item)); } public void SaveParameter() { foreach (var item in valueList) { InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", item.Path, item.CurrentValue); } Reload(); } public void Cancel() { valueList.Clear(); Reload(); } public void CollapseAll() { SetExpand(ConfigNodes, false); } public void ExpandAll() { SetExpand(ConfigNodes, true); } public void ClearFilter() { CurrentCriteria = ""; } public void SetExpand(List configs, bool expand) { if (configs == null) return; foreach (var configNode in configs) { configNode.IsExpanded = expand; if (configNode.SubNodes != null) SetExpand(configNode.SubNodes, expand); } } #endregion } }