| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 | using Caliburn.Micro;using FurnaceUI.Models;using MECF.Framework.Common.OperationCenter;using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;using MECF.Framework.UI.Client.CenterViews.Dialogs;using OpenSEMI.ClientBase;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;namespace FurnaceUI.Views.Editors{    public class TempAlarmWatchTableSettingViewModel : FurnaceUIViewModelBase    {        public string SelectAlarmWatchTable { get; set; } = "None";        public bool IsSave { get; set; } = false;        private ConfigNode levelOneNode;        public ConfigNode LevelOneNode        {            get { return levelOneNode; }            set { levelOneNode = value; this.NotifyOfPropertyChange(nameof(LevelOneNode)); }        }        private ConfigNode levelTwoNode;        public ConfigNode LevelTwoNode        {            get { return levelTwoNode; }            set { levelTwoNode = value; this.NotifyOfPropertyChange(nameof(LevelTwoNode)); }        }        private List<ConfigItem> currenItems;        public List<ConfigItem> CurrenItems        {            get { return currenItems; }            set { currenItems = value; this.NotifyOfPropertyChange(nameof(CurrenItems)); }        }        private string _CurrentNodeName = string.Empty;        private ConfigNode _rootNode;        public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式        private bool _isAlarmNoneChecked;        public bool IsAlarmNoneChecked        {            get => _isAlarmNoneChecked;            set            {                _isAlarmNoneChecked = value;                NotifyOfPropertyChange(nameof(IsAlarmNoneChecked));            }        }        public Visibility isForbid;        public Visibility IsForbid        {            get { return isForbid; }            set { isForbid = value; this.NotifyOfPropertyChange(nameof(IsForbid)); }        }        public bool isAvailabled;        public bool IsAvailabled        {            get { return isAvailabled; }            set { isAvailabled = value; this.NotifyOfPropertyChange(nameof(IsAvailabled)); }        }        protected override void OnViewLoaded(object view)        {            base.OnViewLoaded(view);            IsAlarmNoneChecked = SelectAlarmWatchTable == "None";            _rootNode = SystemConfigProvider.Instance.GetConfig(true);            LevelOneNode = new ConfigNode();            LevelOneNode = FindNodeByName(_rootNode, "PM1.RecipeEditParameter.AlarmWatchTable.PressureAlarmWatch");            LevelTwoNode = LevelOneNode.SubNodes.FirstOrDefault();            IsForbid = IsAlarmNoneChecked ? Visibility.Hidden : Visibility.Visible;            if (SelectAlarmWatchTable != "None")            {                LevelOneNode.SubNodes[int.Parse(SelectAlarmWatchTable) - 1].AlarmWatchBoolValue = true;            }            InitItemsCurrentValue(LevelTwoNode, true);        }        //public void SetAlarmWatchTable(string nameCmd)        //{        //    int iTableIndex = 0;        //    if (nameCmd != "None")        //    {        //        iTableIndex = int.Parse(nameCmd);        //    }        //    var windowManager = IoC.Get<IWindowManager>();        //    RecipeAlarmActionViewModel recipeAlarmActionViewModel = new RecipeAlarmActionViewModel() { TableIndex = iTableIndex };        //    (windowManager as WindowManager)?.ShowLiftCenterScreenDialogWithTitle(recipeAlarmActionViewModel, null, "Alarm Action");        //    SelectAlarmWatchTable = nameCmd;        //}        private void InitItemsCurrentValue(ConfigNode node, bool initSubItems = true)        {            if (node == null) return;            CurrenItems = node.Items;            _CurrentNodeName = string.IsNullOrEmpty(node.Path) ? node.Name : $"{node.Path}.{"Table" + SelectAlarmWatchTable}";            if (CurrenItems == null || CurrenItems.Count <= 0)            {                if (!initSubItems) return;                foreach (var item in node.SubNodes)                {                    InitItemsCurrentValue(item);                }            }            else            {                GetDataOfConfigItems();            }        }        private void GetDataOfConfigItems()        {            if (CurrenItems == null)                return;            for (int i = 0; i < CurrenItems.Count; i++)            {                string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", CurrenItems[i].Name);                CurrenItems[i].CurrentValue = SystemConfigProvider.Instance.GetValueByName(key);                CurrenItems[i].Path = key;                CurrenItems[i].StringValue = CurrenItems[i].CurrentValue;            }        }        public void MenuCommand(object obj, object menuLevel)        {            RadioButton radioButton = obj as RadioButton;            ConfigNode currentNode = null;            SelectAlarmWatchTable = radioButton.Content.ToString();            IsForbid = Visibility.Visible;            IsAvailabled = true;            //IsAlarmNoneChecked = false;            if (radioButton.Content.ToString() == "None")            {                IsForbid = Visibility.Hidden;                IsAvailabled = false;                return;            }            switch (menuLevel.ToString())            {                case "LevelOne":                    currentNode = LevelTwoNode = LevelOneNode.SubNodes.Find((x) => x.Name == radioButton.ToolTip.ToString());                    break;            }            InitItemsCurrentValue(currentNode);        }        public void SetValue(object obj)        {            if (CurrenItems == null || currenItems.Count == 0) return;            ConfigItem item = null;            if (obj is Control)                item = CurrenItems.Find((x) => x.Name == (obj as Control).ToolTip.ToString());            else                item = obj as ConfigItem;            InputDialogViewModel dialog = new InputDialogViewModel();            dialog.Item = item;            dialog.DisplayName = "Set Value";            WindowManager wm = new WindowManager();            bool? bret = wm.ShowDialog(dialog);            if ((bool)bret)            {                item.StringValue = dialog.DialogResult;                string value;                if (item.Type == DataType.Int)                {                    int iValue;                    if (int.TryParse(item.StringValue, out iValue))                    {                        if (!double.IsNaN(item.Max) && !double.IsNaN(item.Min))                        {                            if (iValue > item.Max || iValue < item.Min)                            {                                DialogBox.ShowWarning(string.Format("The value should be between {0}  and {1}.", ((int)item.Min).ToString(), ((int)item.Max).ToString()));                                return;                            }                        }                    }                    else                    {                        DialogBox.ShowWarning("Please input valid data.");                        return;                    }                    value = item.StringValue;                }                value = item.StringValue;                string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", item.Name);                InvokeClient.Instance.Service.DoOperation("System.SetConfig", item.Path, value);            }        }        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 SaveCmd()        {            IsSave = true;            ((Window)GetView()).DialogResult = true;        }        public void CloseCmd()        {            IsSave = false;            ((Window)GetView()).DialogResult = false;        }    }}
 |