123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673 |
- using Aitex.Core.RT.SCCore;
- using Caliburn.Micro;
- using Caliburn.Micro.Core;
- 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;
- using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
- using MECF.Framework.UI.Client.ClientBase;
- using OpenSEMI.ClientBase;
- using SciChart.Core.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace MECF.Framework.UI.Client.CenterViews.Parameter
- {
- public class MainParameterEditViewModel : ModuleUiViewModelBase, ISupportMultipleSystem
- {
- public bool IsPermission { get => this.Permission == 3; }
- public List<ParamBase> ParameterTree { get; set; } = new List<ParamBase>();
- public ObservableCollection<TempSetData> HeadLst { get; set; } = new ObservableCollection<TempSetData>();
- public ObservableCollection<TempSetData> PIDHeadLst { get; set; } = new ObservableCollection<TempSetData>();
- public ObservableCollection<ConfigItem> StepNames { get; set; } = new ObservableCollection<ConfigItem>();
- private ConfigNode _currentNode;
- public ConfigNode CurrentNode
- {
- get { return _currentNode; }
- set { _currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); }
- }
- private string _allZoneValue = "0";
- public string AllZoneValue
- {
- get { return _allZoneValue; }
- set { _allZoneValue = value; this.NotifyOfPropertyChange(nameof(AllZoneValue)); }
- }
- private ConfigNode _currentSubNode;
- public ConfigNode CurrentSubNode
- {
- get { return _currentSubNode; }
- set { _currentSubNode = value; this.NotifyOfPropertyChange(nameof(CurrentSubNode)); }
- }
- private ConfigNode _currentTwoSubNode;
- public ConfigNode CurrentTwoSubNode
- {
- get { return _currentTwoSubNode; }
- set { _currentTwoSubNode = value; this.NotifyOfPropertyChange(nameof(CurrentTwoSubNode)); }
- }
- private List<ConfigNode> _ConfigNodes = new List<ConfigNode>();
- public List<ConfigNode> ConfigNodes
- {
- get { return _ConfigNodes; }
- set { _ConfigNodes = value; NotifyOfPropertyChange("ConfigNodes"); }
- }
- private string _defaultUnit = "Pa";
- public string DefaultUnit
- {
- get
- {
- return _defaultUnit;
- }
- set
- {
- _defaultUnit = value;
- NotifyOfPropertyChange("DefaultUnit");
- }
- }
- private ConfigNode _rootNode;
- private string _CurrentNodeName = string.Empty;
- private string path;
- private string currentValue;
- private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();
- private ObservableCollection<PageValue> newValueList { get; set; } = new ObservableCollection<PageValue>();
- protected override void OnInitialize()
- {
- base.OnInitialize();
- this.SystemName = "System";
- ConfigNodes = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
- _rootNode = SystemConfigProvider.Instance.GetConfig(true);
- InitTree();
- }
- protected override void OnActivate()
- {
- base.OnActivate();
- }
- private void InitTree()
- {
- var node = SystemConfigProvider.Instance.GetConfigTree(SystemName).SubNodes;
- ParameterTree.Add(new ParamBase() { ID = 1, ParentID = 0, Name = "StepName", ConfigName = "StepName" });
- ParameterTree.Add(new ParamBase() { ID = 2, ParentID = 0, Name = "StepGroup", ConfigName = "StepGroup" });
- //ParameterTree.Add(new ParamBase() { ID = 2, ParentID = 0, Name = "TempSetting", ConfigName = "TempSetting" });
- //ParameterTree.Add(new ParamBase() { ID = 3, ParentID = 0, Name = "TempSetting", ConfigName = "TempSetting" });
- ParameterTree = this.LoadTreeView(0);
- foreach (var item in ParameterTree)
- {
- InitAllParameterTree(item);
- }
- var stepNameNode = FindNodeByName(_rootNode, $"{strHeader}.StepName");
- if (stepNameNode != null && stepNameNode.Items.Count > 0)
- {
- stepNameNode.Items.ForEach(x => StepNames.Add(x));
- CurrentNode = stepNameNode;
- }
- this.GetHeaderConfig();
- }
- string strHeader = "PM1.RecipeEditParameter";
- private void InitAllParameterTree(ParamBase para)
- {
- CurrentNode = new ConfigNode();
- CurrentNode = FindNodeByName(_rootNode, $"{strHeader}.{para.ConfigName}");
- InitItemsCurrentValue(CurrentNode, true);
- if (CurrentNode.SubNodes != null)
- {
- foreach (var item in CurrentNode.SubNodes)
- {
- InitItemsCurrentValue(item, true);
- }
- }
- }
- private Visibility _stepNameVisibility = Visibility.Visible;
- public Visibility StepNameVisibility
- {
- get => _stepNameVisibility;
- set
- {
- _stepNameVisibility = value;
- NotifyOfPropertyChange(nameof(StepNameVisibility));
- }
- }
- private Visibility _stepGroupSettingVisibility = Visibility.Hidden;
- public Visibility StepGroupSettingVisibility
- {
- get => _stepGroupSettingVisibility;
- set
- {
- _stepGroupSettingVisibility = value;
- NotifyOfPropertyChange(nameof(StepGroupSettingVisibility));
- }
- }
- private Visibility _tempSettingeVisibility = Visibility.Hidden;
- public Visibility TempSettingVisibility
- {
- get => _tempSettingeVisibility;
- set
- {
- _tempSettingeVisibility = value;
- NotifyOfPropertyChange(nameof(TempSettingVisibility));
- }
- }
- private List<ParamBase> LoadTreeView(int id)
- {
- List<ParamBase> node = ParameterTree.FindAll(s => s.ParentID.Equals(id));
- foreach (var item in node)
- {
- item.Children = LoadTreeView(item.ID);
- }
- return node;
- }
- public void HideAllCanvas()
- {
- StepNameVisibility = Visibility.Hidden;
- TempSettingVisibility = Visibility.Hidden;
- StepGroupSettingVisibility = Visibility.Hidden;
- }
- public void TreeViewSelectedItemChanged(object obj)
- {
- valueList.Clear();
- var view = GetView() as MainParameterEditView;
- HideAllCanvas();
- ParamBase para = obj as ParamBase;
- string strHeader = "PM1.RecipeEditParameter";
- switch (para.ConfigName)
- {
- case "StepName":
- StepNameVisibility = Visibility.Visible;
- break;
- case "StepGroup":
- CurrentNode = FindNodeByName(_rootNode, $"{strHeader}.{para.ConfigName}");
- StepGroupSettingVisibility = Visibility.Visible;
- break;
- case "TempSetting":
- CurrentNode = FindNodeByName(_rootNode, $"{strHeader}.{para.ConfigName}");
- TempSettingVisibility = Visibility.Visible;
- if (CurrentNode.SubNodes.Where(x => x.StabilizeBoolValue == true).Count() <= 0)
- {
- CurrentNode.SubNodes[0].StabilizeBoolValue = true;
- }
- CurrentSubNode = CurrentNode.SubNodes.FirstOrDefault(x => x.StabilizeBoolValue);
- break;
- }
- }
- public void StepGroupEdit(string groupName)
- {
- var windowManager = IoC.Get<IWindowManager>();
- var groupList = CurrentNode.Items.Where(a => a.Display != groupName).Select(a => a.Path).ToList();
- List<string> hasSelectStepIdList = new List<string>();
- foreach (var item in QueryDataClient.Instance.Service.PollConfig(groupList).Values)
- {
- hasSelectStepIdList.AddRange( item.ToString().Split(',').ToList());
- }
- StepGroupEditViewModel recipeStepNameViewModel = new StepGroupEditViewModel();
- recipeStepNameViewModel.StepGroupName = groupName;
- recipeStepNameViewModel.HasSelectStepIds = hasSelectStepIdList;
- if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepNameViewModel, null, "Step Group Edit"))
- {
- var selectStepId = recipeStepNameViewModel.StepIdList.Where(a => a.IsExpanded).Select(a => a.Name).ToList();
- InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", $"PM1.RecipeEditParameter.StepGroup.{groupName}", string.Join(",", selectStepId.ToArray()));
- }
- }
- private void InitItemsCurrentValue(ConfigNode node, bool initSubItems = true)
- {
- if (node == null) return;
- _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{node.Name}";
- if (node.Items == null || node.Items.Count <= 0)
- {
- if (!initSubItems) return;
- foreach (var item in node.SubNodes)
- {
- InitItemsCurrentValue(item);
- }
- }
- else
- {
- GetDataOfConfigItems(node);
- }
- }
- private void GetDataOfConfigItems(ConfigNode node)
- {
- if (node.Items == null)
- return;
- List<string> allItems = new List<string>();
- for (int i = 0; i < node.Items.Count; i++)
- {
- string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", node.Items[i].Name);
- allItems.Add(key);
- }
- List<string> newallItems = allItems.Distinct().ToList();
- var DictItems = QueryDataClient.Instance.Service.PollConfig(newallItems);
- for (int i = 0; i < node.Items.Count; i++)
- {
- string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", node.Items[i].Name);
- node.Items[i].CurrentValue = DictItems.ContainsKey(key) ? DictItems[key].ToString() : "";
- node.Items[i].Path = key;
- //if (CurrenItems[i].Path.Contains("PM1.RecipeEditParameter.PressureStabilizeTable"))
- // DefaultUnit = CurrenItems[i].Unit;
- if (node.Items[i].Type == DataType.Bool)
- {
- bool value;
- if (bool.TryParse(node.Items[i].CurrentValue, out value))
- {
- node.Items[i].BoolValue = value;
- node.Items[i].CurrentValue = value ? "Yes" : "No";
- }
- }
- else
- node.Items[i].StringValue = node.Items[i].CurrentValue;
- }
- }
- public void MenuCommand(object obj, object menuLevel)
- {
- RadioButton radioButton = obj as RadioButton;
- switch ((string)menuLevel)
- {
- case "LevelOne":
- CurrentSubNode = CurrentNode.SubNodes.Find((x) => x.Name == radioButton.ToolTip.ToString());
- break;
- case "LevelTwo":
- CurrentTwoSubNode = CurrentSubNode.SubNodes.Find((x) => x.Name == radioButton.ToolTip.ToString());
- break;
- default:
- break;
- }
- }
- public void SetValue(object obj)
- {
- if (CurrentNode.Items == null || CurrentNode.Items.Count == 0) return;
- ConfigItem item = null;
- if (obj is Control)
- item = CurrentNode.Items.ToList().Find((x) => x.Name == (obj as Control).ToolTip.ToString());
- else
- item = obj as ConfigItem;
- if (item == null) return;
- if (item.Type == DataType.String)
- {
- currentValue = item.CurrentValue;
- path = item.Path;
- FullKeyboard fullKeyboard = new FullKeyboard("", currentValue);
- if ((bool)fullKeyboard.ShowDialog())
- {
- InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", path, fullKeyboard.ValueString);
- currentValue = fullKeyboard.ValueString;
- item.CurrentValue = fullKeyboard.ValueString;
- }
- valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
- }
- else
- {
- InputDialogViewModel dialog = new InputDialogViewModel();
- dialog.Item = item;
- dialog.DisplayName = "Set Value";
- WindowManager wm = new WindowManager();
- bool? bret = wm.ShowDialog(dialog);
- 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.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
- value = item.StringValue;
- }
- string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);
- path = item.Path;
- currentValue = value;
- valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
- }
- }
- }
- public void AllZoneTextChanged()
- {
- if (CurrentSubNode.Items == null || CurrentSubNode.Items.Count == 0) return;
- newValueList = new ObservableCollection<PageValue>();
- valueList = new ObservableCollection<PageValue>();
- foreach (var item in CurrentSubNode.Items)
- {
- item.CurrentValue = AllZoneValue;
- newValueList.Add(new PageValue() { Path = item.Path, CurrentValue = AllZoneValue });
- }
- }
- public void SetCurrentSubNodeValue(object obj)
- {
- if (CurrentSubNode.Items == null || CurrentSubNode.Items.Count == 0) return;
- ConfigItem item = null;
- if (obj is Control)
- item = CurrentSubNode.Items.ToList().Find((x) => x.Name == (obj as Control).ToolTip.ToString());
- else
- item = obj as ConfigItem;
- if (item == null) return;
- if (item.Type == DataType.String)
- {
- currentValue = item.CurrentValue;
- path = item.Path;
- FullKeyboard fullKeyboard = new FullKeyboard("", currentValue);
- if ((bool)fullKeyboard.ShowDialog())
- {
- InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", path, fullKeyboard.ValueString);
- currentValue = fullKeyboard.ValueString;
- item.CurrentValue = fullKeyboard.ValueString;
- }
- valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
- }
- else
- {
- InputDialogViewModel dialog = new InputDialogViewModel();
- dialog.Item = item;
- dialog.DisplayName = "Set Value";
- WindowManager wm = new WindowManager();
- bool? bret = wm.ShowDialog(dialog);
- 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.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
- value = item.StringValue;
- }
- path = item.Path;
- currentValue = value;
- valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
- }
- }
- }
- public void SetStepNameValue(object obj, MouseButtonEventArgs e)
- {
- e.Handled = true;
- if (StepNames == null || StepNames.Count == 0) return;
- ConfigItem item = null;
- if (obj is Control)
- item = StepNames.ToList().Find((x) => x.Name == (obj as Control).ToolTip.ToString());
- else
- item = obj as ConfigItem;
- if (item == null) return;
- if (item.Type == DataType.String)
- {
- currentValue = item.CurrentValue;
- path = item.Path;
- FullKeyboard fullKeyboard = new FullKeyboard("", currentValue);
- if ((bool)fullKeyboard.ShowDialog())
- {
- InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", path, fullKeyboard.ValueString);
- currentValue = fullKeyboard.ValueString;
- item.CurrentValue = fullKeyboard.ValueString;
- }
- valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
- }
- else
- {
- InputDialogViewModel dialog = new InputDialogViewModel();
- dialog.Item = item;
- dialog.DisplayName = "Set Value";
- WindowManager wm = new WindowManager();
- bool? bret = wm.ShowDialog(dialog);
- if ((bool)bret)
- {
- item.StringValue = dialog.DialogResult;
- //key :System.IsSimulatorMode
- //value: true or false 都是字符串
- //input check
- string value;
- value = item.StringValue;
- path = item.Path;
- currentValue = value;
- valueList.Add(new PageValue() { Path = path, CurrentValue = currentValue });
- }
- }
- }
- public void SaveParameter()
- {
- if (newValueList != null && newValueList.Count > 0)
- {
- var one = newValueList[0];
- if (one.Path.Contains("TempSetting"))
- {
- foreach (var item in valueList)
- {
- newValueList.Add(item);
- }
- valueList.Clear();
- valueList = newValueList;
- }
- }
- foreach (var item in valueList)
- {
- InvokeClient.Instance.Service.DoOperation($"{SystemName}.SetConfig", item.Path, item.CurrentValue);
- }
- valueList = new ObservableCollection<PageValue>();
- newValueList = new ObservableCollection<PageValue>();
- }
- private string[] HeaterNameList = new string[5] { "HeaterU", "HeaterCU", "HeaterC", "HeaterCL", "HeaterL" };
- public void GetHeaderConfig()
- {
- HeadLst.Clear();
- for (int i = 0; i < 5; i++)
- {
- var configHeater = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.Heater.{HeaterNameList[i]}.DisplayName");
- TempSetData item = new TempSetData(configHeater);
- item.SetValue.Value = configHeater;
- HeadLst.Add(item);
- }
- }
- private ConfigNode FindNodeByName(ConfigNode parentNode, string strName)
- {
- string strCates = strName.Split('.')[0];
- ConfigNode node = parentNode.SubNodes.Find((x) => x.Name == strCates);
- if (node == null)
- return parentNode;
- else
- return FindNodeByName(node, strName.Replace(strCates + ".", ""));
- }
- }
- public class ParamBase
- {
- public int ID { get; set; }
- public string Name { get; set; }
- public int ParentID { get; set; }
- public string ConfigName { get; set; }
- public List<ParamBase> Children { get; set; }
- public ParamBase()
- {
- Children = new List<ParamBase>();
- }
- }
- public class ParameterConvert : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- return value.ToString().Replace("Table", "").Replace("LineNo", "");
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|