| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 | 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<ConfigNode> _ConfigNodes = new List<ConfigNode>();        public List<ConfigNode> ConfigNodes        {            get { return _ConfigNodes; }            set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); }        }        private List<ConfigItem> _configItems = null;        public List<ConfigItem> ConfigItems        {            get { return _configItems; }            set { _configItems = value; NotifyOfPropertyChange("ConfigItems"); }        }        string _CurrentNodeName = string.Empty;        public BaseCommand<ConfigNode> TreeViewSelectedItemChangedCmd { private set; get; }        private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();        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<ConfigNode>());        }        #endregion        #region Functions        public SystemConfigViewModel()        {            this.DisplayName = "System Config";            TreeViewSelectedItemChangedCmd = new BaseCommand<ConfigNode>(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<ProcessTypeFileItem>();                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<ConfigNode> configs, bool expand)        {            if (configs == null)                return;            foreach (var configNode in configs)            {                configNode.IsExpanded = expand;                if (configNode.SubNodes != null)                    SetExpand(configNode.SubNodes, expand);            }        }        #endregion    }}
 |