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 InterlockNodes { get; set; } = new ObservableCollection(); // public ObservableCollection InterlockNodes { get; set; } = new ObservableCollection(); 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(); 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; } } }