using Caliburn.Micro.Core; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using MECF.Framework.UI.Client.CenterViews.Dialogs; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using FurnaceUI.Models; namespace FurnaceUI.Views.Editors { public class RecipeGASSettingMFCAlarmViewModel : FurnaceUIViewModelBase { ConfigNode currentNode = SystemConfigProvider.Instance.GetConfig(true); public ConfigNode CurrentNode { get { return currentNode; } set { currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); } } private List currenItems; public List CurrenItems { get { return currenItems; } set { currenItems = value; this.NotifyOfPropertyChange(nameof(CurrenItems)); } } public string CurrentValue { get; set; } public RecipeGASSettingMFCAlarmViewModel(string strCurrentValue) { CurrentValue = strCurrentValue; } private Visibility visibilityShow; public Visibility VisibilityShow { get => visibilityShow; set { visibilityShow = value; NotifyOfPropertyChange(nameof(VisibilityShow)); } } protected override void OnInitialize() { base.OnInitialize(); CurrentNode = FindNodeByName(CurrentNode, "PM1.RecipeEditParameter.AlarmWatchTable.FlowAlarmWatch"); currentNode.SubNodes.Insert(0, new ConfigNode() { Name = "None", IsSelected = false }); ;//增加选项0 GetDataOfConfigItems(CurrentNode); if (CurrentValue == "None") { CurrenItems = CurrentNode.SubNodes[0].Items; CurrentNode.SubNodes[0].IsSelected = true; VisibilityShow = Visibility.Hidden; } else { CurrenItems = CurrentNode.SubNodes[int.Parse(CurrentValue)].Items; CurrentNode.SubNodes[int.Parse(CurrentValue)].IsSelected = true; VisibilityShow = Visibility.Visible; } } 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 + ".", "")); } private void GetDataOfConfigItems(ConfigNode node) { if (node.Items == null && node.SubNodes == null) return; if(node.Items.Count<=0) { foreach (var item in node.SubNodes) { GetDataOfConfigItems(item); } } else { foreach (var item in node.Items) { string key = String.Format("{0}.{1}.{2}", node.Path,node.Name, item.Name); item.CurrentValue = SystemConfigProvider.Instance.GetValueByName(key); item.Path = key; if (item.Type == DataType.Bool) { bool value; if (bool.TryParse(item.CurrentValue, out value)) { item.BoolValue = value; item.CurrentValue = value ? "Yes" : "No"; } } else item.StringValue = item.CurrentValue; } } } public void MenuCommand(object obj, object menuLevel) { RadioButton radioButton = obj as RadioButton; CurrentValue = radioButton.Content.ToString(); if (CurrentValue == "None") { CurrenItems = CurrentNode.SubNodes[0].Items; VisibilityShow = Visibility.Hidden; } else { CurrenItems = CurrentNode.SubNodes[int.Parse(CurrentValue)].Items; VisibilityShow = Visibility.Visible; } } public void Close() { ((Window)GetView()).DialogResult = false; } public void Save() { ((Window)GetView()).DialogResult = true; } } }