| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 | using MECF.Framework.Common.CommonData;using MECF.Framework.Common.DataCenter;using MECF.Framework.Common.IOCore;using OpenSEMI.ClientBase;using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using FurnaceUI.Models;using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;using MECF.Framework.UI.Client.ClientBase;using Caliburn.Micro.Core;using Caliburn.Micro;using MECF.Framework.Common.OperationCenter;namespace FurnaceUI.Views.Operations{    public class ValveInterlockViewModel : FurnaceUIViewModelBase, ISupportMultipleSystem    {        public string ItemType { get; set; }        public ObservableCollection<ValveInterLock> InterlockNodes { get; set; } = new ObservableCollection<ValveInterLock>();        //      public ObservableCollection<ConfigItem> InterlockNodes { get; set; } = new ObservableCollection<ConfigItem>();        private ConfigNode _valveInterSelectedItem;        public ConfigNode ValveInterSelectedItem        {            get => _valveInterSelectedItem;            set            {                _valveInterSelectedItem = value;                NotifyOfPropertyChange(nameof(ValveInterSelectedItem));            }        }        public ValveInterlockViewModel()        {        }        protected override void OnInitialize()        {            base.OnInitialize();        }        string strHeader = "PM1.RecipeEditParameter";        private ConfigNode _rootNode;        protected override void OnViewLoaded(object view)        {            base.OnViewLoaded(view);            InitItem();        }        private void InitItem()        {            _CurrentNodeName = "";            _rootNode = SystemConfigProvider.Instance.GetConfig(true);            SystemConfigProvider.Instance.GetConfigTree("PM1");            var stepNameNode = FindNodeByName(_rootNode, $"{strHeader}.InterLock");            InterlockNodes.Clear();            if (stepNameNode != null && stepNameNode.SubNodes.Count > 0)            {                // stepNameNode.SubNodes.ForEach(x => InterlockNodes.Add(x.Items[0]));                foreach (var item in stepNameNode.SubNodes)                {                    ValveInterLock valveInterLock = new ValveInterLock();                    valveInterLock.Index = item.Name;                    foreach (var subitem in item.Items)                    {                        switch (subitem.Name)                        {                            case "Name":                                valveInterLock.Name = subitem;                                break;                            case "NoneOrExist":                                valveInterLock.NoneOrExist = subitem;                                break;                            case "Normaly0nOrOff":                                valveInterLock.Normaly0nOrOff = subitem;                                break;                            case "DelayOnTime":                                valveInterLock.DelayOnTime = subitem;                                break;                            case "DelayOffTime":                                valveInterLock.DelayOffTime = subitem;                                break;                            case "ILKTime":                                valveInterLock.ILKTime = subitem;                                break;                            default:                                break;                        }                    }                    InterlockNodes.Add(valveInterLock);                }            }            //    getValves.ToList().ForEach(x => InterlockNodes.Add(x));            GetDataOfConfigItems();        }        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 + ".", ""));        }        string _CurrentNodeName = string.Empty;        private void GetDataOfConfigItems()        {            if (InterlockNodes == null)                return;            _CurrentNodeName = "PM1.RecipeEditParameter.InterLock";            for (int i = 0; i < InterlockNodes.Count; i++)            {                string key = String.Format("{0}{1}{2}", _CurrentNodeName, ".", InterlockNodes[i].Index);                InterlockNodes[i].Name.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.Name");                var strNoneOrExist= SystemConfigProvider.Instance.GetValueByName($"{key}.NoneOrExist");                if (!string.IsNullOrEmpty(strNoneOrExist))                {                    bool.TryParse(strNoneOrExist, out bool noneOrExist);                    InterlockNodes[i].NoneOrExist.BoolValue = noneOrExist;                }                var strNormaly0nOrOff = SystemConfigProvider.Instance.GetValueByName($"{key}.Normaly0nOrOff");                if (!string.IsNullOrEmpty(strNormaly0nOrOff))                {                    bool.TryParse(strNormaly0nOrOff, out bool normaly0nOrOff);                    InterlockNodes[i].Normaly0nOrOff.BoolValue = normaly0nOrOff;                }                InterlockNodes[i].DelayOnTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.DelayOnTime");                InterlockNodes[i].DelayOffTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.DelayOffTime");                InterlockNodes[i].ILKTime.CurrentValue = SystemConfigProvider.Instance.GetValueByName($"{key}.ILKTime");            }        }        public void SelectItem()        {        }        private bool CheckValues()        {            bool rtn = true;            foreach (var item in InterlockNodes)            {                if (item.Name!=null && !string.IsNullOrEmpty(item.Name.CurrentValue))                {                    if ((item.NoneOrExist != null && item.NoneOrExist.BoolValue) && (item.Normaly0nOrOff != null && item.Normaly0nOrOff.BoolValue))                    {                        float _delayOnTime = 0;                        float _delayILKTime = 0;                        if (item.DelayOnTime != null)                        {                            var timeParas = item.DelayOnTime.CurrentValue.Split(':');                            if (timeParas.Length > 1)                            {                                float.TryParse(timeParas[0], out float min);                                float.TryParse(timeParas[1], out float sec);                                _delayOnTime = min * 60 * 1000 + sec * 1000;                            }                        }                        if (item.ILKTime != null )                        {                            var timeParas = item.ILKTime.CurrentValue.Split(':');                            if (timeParas.Length > 1)                            {                                float.TryParse(timeParas[0], out float min);                                float.TryParse(timeParas[1], out float sec);                                _delayILKTime = min * 60 * 1000 + sec * 1000;                            }                        }                        if (_delayILKTime != 0 && _delayOnTime > _delayILKTime)                        {                            DialogBox.ShowWarning($"Index:{item.Index},Name:{item.Name.CurrentValue} setup error,DelayOnTime: {item.DelayOnTime.CurrentValue} is greater than ILKTime: {item.ILKTime.CurrentValue}");                            rtn = false;                            return rtn;                        }                    }                }            }            return rtn;        }        public void SaveCmd()        {            if (InterlockNodes == null) return;          if  (!CheckValues()) return;            foreach (var item in InterlockNodes)            {                if (item.Name!=null && !item.Name.TextSaved)                {                    InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.Name.Path}.{item.Name.Name}", item.Name.CurrentValue);                    item.Name.TextSaved = true;                }                if (item.NoneOrExist != null && !item.NoneOrExist.TextSaved)                {                    InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.NoneOrExist.Path}.{item.NoneOrExist.Name}", item.NoneOrExist.BoolValue.ToString());                    item.NoneOrExist.TextSaved = true;                }                if (item.Normaly0nOrOff != null && !item.Normaly0nOrOff.TextSaved)                {                    InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.Normaly0nOrOff.Path}.{item.Normaly0nOrOff.Name}", item.Normaly0nOrOff.BoolValue.ToString());                    item.Normaly0nOrOff.TextSaved = true;                }                if (item.DelayOnTime != null && !item.DelayOnTime.TextSaved)                {                    InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.DelayOnTime.Path}.{item.DelayOnTime.Name}", item.DelayOnTime.CurrentValue);                    item.Name.TextSaved = true;                }                if (item.DelayOffTime != null && !item.DelayOffTime.TextSaved)                {                    InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.DelayOffTime.Path}.{item.DelayOffTime.Name}", item.DelayOffTime.CurrentValue);                    item.Name.TextSaved = true;                }                if (item.ILKTime != null && !item.ILKTime.TextSaved)                {                    InvokeClient.Instance.Service.DoOperation($"System.SetConfig", $"{item.ILKTime.Path}.{item.ILKTime.Name}", item.ILKTime.CurrentValue);                    item.Name.TextSaved = true;                }            }        }        public void CancelCmd()        {            // ((Window)GetView()).DialogResult = false;        }        public void Normaly0nOrOffClick(ConfigItem value)        {            value.BoolValue = !value.BoolValue;            value.TextSaved = false;        }        public void NoneOrExistClick(ConfigItem value)        {            value.BoolValue = !value.BoolValue;            value.TextSaved = false;        }        public void SaveTimeValue(ConfigItem value)        {            var windowManager = IoC.Get<IWindowManager>();            ValveInterlockTimeViewModel recipeStepTimeViewModel = new ValveInterlockTimeViewModel("DelayTime");            recipeStepTimeViewModel.SelectValueTime = value.CurrentValue;            (windowManager as WindowManager)?.ShowDialogWithTitle(recipeStepTimeViewModel, null, "Step Time Set");            if (recipeStepTimeViewModel.IsSave)            {                value.CurrentValue = recipeStepTimeViewModel.SelectValueTime;                value.TextSaved = false;            }        }        public void SetNameValue(ConfigItem value, ValveInterLock valveInterLock)        {            value.TextSaved = false;            valveInterLock.UpdataIsEndble();        }    }    public class ValveInterLock : PropertyChangedBase    {        public string Index { get; set; }        public ConfigItem Name { get; set; }        public void UpdataIsEndble()        {            NotifyOfPropertyChange(nameof(IsEndble));        }        public bool IsEndble        {            get            {                if (Name == null) return false;                if (string.IsNullOrEmpty(Name.CurrentValue.Trim()))                {                    return false;                }                return true;            }        }        public ConfigItem NoneOrExist { get; set; }        public ConfigItem Normaly0nOrOff { get; set; }        public ConfigItem DelayOnTime { get; set; }        public ConfigItem DelayOffTime { get; set; }        public ConfigItem ILKTime { get; set; }    }}
 |