123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using Caliburn.Micro;
- 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.ClientBase;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Aitex.Core.RT.SCCore;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
- using OpenSEMI.ClientBase;
- using SciChart.Core.Extensions;
- using System.Globalization;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Threading;
- using FurnaceUI.Models;
- using FurnaceUI.Views.Parameter;
- namespace FurnaceUI.Views.Editors
- {
- public class AlarmErrorJumpStepViewModel : FurnaceUIViewModelBase
- {
- private ObservableCollection<PageValue> valueList { get; set; } = new ObservableCollection<PageValue>();
- public string ResultParameterStr { get; set; }
- public ObservableCollection<ConfigItem> StepNames { get; set; } = new ObservableCollection<ConfigItem>();
- private string currentValue;
- private string path;
- private ConfigNode _rootNode;
- private ConfigNode _currentNode;
- private string _CurrentNodeName = string.Empty;
- string strHeader = "PM1.RecipeEditParameter";
- public ConfigNode CurrentNode
- {
- get { return _currentNode; }
- set { _currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); }
- }
- public AlarmErrorJumpStepViewModel()
- {
- _rootNode = SystemConfigProvider.Instance.GetConfig(true);
- InitAllParameterTree(new ParamBase() { ID = 1, ParentID = 0, Name = "StepName", ConfigName = "StepName" });
- var stepNameNode = FindNodeByName(_rootNode, $"PM1.RecipeEditParameter.StepName");
- if (stepNameNode != null && stepNameNode.Items.Count > 0)
- {
- stepNameNode.Items.ForEach(x => StepNames.Add(x));
- }
- }
- 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;
- }
- }
- 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 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 void SetStepNameValue(object obj)
- {
- if (StepNames == null || StepNames.Count == 0) return;
- ConfigItem item = obj as ConfigItem;
- ResultParameterStr = $"{item.Name}:{item.CurrentValue}";
- ((Window)GetView()).DialogResult = true;
- }
- public void CloseCommand()
- {
- ((Window)GetView()).DialogResult = false;
- }
-
- }
- }
|