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 valueList { get; set; } = new ObservableCollection(); public string ResultParameterStr { get; set; } public ObservableCollection StepNames { get; set; } = new ObservableCollection(); 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 allItems = new List(); 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 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; } } }