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 MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig; using FurnaceUI.Models; namespace FurnaceUI.Views.Editors { public class TempAllZoneValueSetViewModel : FurnaceUIViewModelBase { public bool IsSave { get; set; } = false; public List CurrentNodeItems { get; set; } = new List(); private ConfigNode _currentNode; public ConfigNode CurrentNode { get { return _currentNode; } set { _currentNode = value; this.NotifyOfPropertyChange(nameof(CurrentNode)); } } public ConfigNode SelectedNode { get; set; } public string RecipeType { get; set; } public Visibility IsVisibilityContinue { get; set; } = Visibility.Visible; protected override void OnInitialize() { base.OnInitialize(); //if (RecipeType == "Sub" || RecipeType == "Abort Sub" || RecipeType == "Abort") // IsVisibilityContinue = Visibility.Visible; GetDataOfConfigItems(); } //private bool isValueButtonEnable; //public bool IsValueButtonEnable //{ // get // { // isValueButtonEnable = true; // for (int i = 0; i < 5; i++) // { // if (string.IsNullOrEmpty((((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt{i + 1}") as TextBox).Text)) // { // isValueButtonEnable = false; // break; // } // } // return isValueButtonEnable; // } // set { isValueButtonEnable = value; this.NotifyOfPropertyChange(nameof(IsValueButtonEnable)); } //} private bool _isValueButtonEnable; public bool IsValueButtonEnable { get => _isValueButtonEnable; set { _isValueButtonEnable = value; NotifyOfPropertyChange("IsValueButtonEnable"); } } private string _TempModel; public string TempModel { get { return _TempModel; } set { _TempModel = value; NotifyOfPropertyChange("TempModel"); } } public bool IsEnable => false;// CGlobal.RecipeProcessEditViewEnable;//是否是View模式 public void ValueTextChanged() { //this.NotifyOfPropertyChange(nameof(IsValueButtonEnable)); } private void GetDataOfConfigItems() { ConfigNode rootNode = SystemConfigProvider.Instance.GetConfig(true); CurrentNode = FindNodeByName(rootNode, "PM1.RecipeEditParameter.TempSetting"); foreach (var node in CurrentNode.SubNodes) { List temperature = new List(); CurrentNodeItems = node.Items; foreach (var item in node.Items) { string strPath = $"PM1.RecipeEditParameter.TempSetting.{node.Name}.{item.Name}"; item.CurrentValue = SystemConfigProvider.Instance.GetValueByName(strPath); item.Path = strPath; } } } 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 SetTempValue(object obj) { if (obj is ConfigNode) { IsValueButtonEnable = false; TempModel = "Temp"; SelectedNode = obj as ConfigNode; for (int i = 0; i < SelectedNode.Items.Count; i++) { (((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt{i + 1}") as TextBox).Text = SelectedNode.Items[i].CurrentValue; } } else if (obj.ToString() == "Continue") { ConfigNode node = new ConfigNode(); node.Items = new List(); for (int i = 0; i < 5; i++) { node.Items.Add(new ConfigItem() { CurrentValue = obj.ToString() }); } SelectedNode = node; } else { IsValueButtonEnable = true; TempModel = "Value"; for (int i = 0; i < 5; i++) { (((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt{i + 1}") as TextBox).Text = ""; } } } public void SaveCmd() { if (TempModel == "Value") { ConfigNode node = new ConfigNode(); node.Items = new List(); node.Items.Add(new ConfigItem() { CurrentValue = (((TempAllZoneValueSetView)(((Window)GetView()).Content)).FindName($"Txt6") as TextBox).Text }); SelectedNode = node; } IsSave = true; ((Window)GetView()).DialogResult = true; } public void CloseCmd() { IsSave = false; ((Window)GetView()).DialogResult = false; } } }