using Caliburn.Micro.Core; using DocumentFormat.OpenXml.Office2010.Excel; using FurnaceUI.Models; using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using System; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Controls; namespace FurnaceUI.Views.Editors { public class RecipeStepNameViewModel : FurnaceUIViewModelBase { public class StepInfo : PropertyChangedBase { private string _Name; public string Name { get { return _Name; } set { _Name = value; this.NotifyOfPropertyChange(nameof(Name)); } } private bool _IsChecked; public bool IsChecked { get { return _IsChecked; } set { _IsChecked = value; this.NotifyOfPropertyChange(nameof(IsChecked)); } } } public ObservableCollection Steps { get; set; }=new ObservableCollection(); public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式 public string SelectedStepName { get; set; } private ConfigNode _configNode; public ConfigNode ConfigNode { get { return _configNode; } set { _configNode = value; this.NotifyOfPropertyChange(nameof(ConfigNode)); } } protected override void OnInitialize() { base.OnInitialize(); ConfigNode _rootNode = SystemConfigProvider.Instance.GetConfig(true); string strHeader = "PM1.RecipeEditParameter.StepName"; ConfigNode = FindNodeByName(_rootNode, strHeader); for (int i = 0; i < ConfigNode.Items.Count; i++) { string key = String.Format("{0}.{1}", strHeader, ConfigNode.Items[i].Name); ConfigNode.Items[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key); } for (int i = 0; i < ConfigNode.Items.Count; i++) { Steps.Add(new StepInfo() { Name = $"{i + 1}:{ConfigNode.Items[i].CurrentValue}" }); } var step = Steps.FirstOrDefault(x => x.Name == SelectedStepName); if (step != null) { step.IsChecked = 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 Select(object para) { SelectedStepName = (para as RadioButton).Content.ToString(); ((Window)GetView()).DialogResult = true; } public void StepNameEdit(string cmdName) { switch (cmdName) { case "Close": ((Window)GetView()).DialogResult = false; break; case "Save": ((Window)GetView()).DialogResult = true; break; } } } }