using Aitex.Core.Util; using Caliburn.Micro; using MECF.Framework.Common.IOCore; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using OpenSEMI.ClientBase; using Caliburn.Micro.Core; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Xml; using System.Windows.Media; using MECF.Framework.Common.CommonData; using Aitex.Core.RT.Log; using FurnaceUI.Models; namespace FurnaceUI.Views.Operations { public class InterlockViewModel : FurnaceModuleUIViewModelBase { public bool IsPermission { get => this.Permission == 3; } private ObservableCollection _interlockTreePM = new ObservableCollection(); public ObservableCollection InterlockTreePM { get => _interlockTreePM; set { _interlockTreePM = value; NotifyOfPropertyChange(nameof(InterlockTreePM)); } } private SolidColorBrush _greenFill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF07FF07")); private SolidColorBrush _redFill = new SolidColorBrush(Colors.Red); private SolidColorBrush _grayFill = new SolidColorBrush(Colors.Gray); private ObservableCollection _interlockTreeEdit = new ObservableCollection(); public ObservableCollection InterlockTreeEdit { get => _interlockTreeEdit; set { _interlockTreeEdit = value; NotifyOfPropertyChange(nameof(InterlockTreeEdit)); } } public InterlockBase CurrentInterlock = new InterlockBase(); public ObservableCollection InterlockLimits { get; set; } = new ObservableCollection(); private int _interlockLimitsSelectIndex; public int InterlockLimitSelectIndex { get => _interlockLimitsSelectIndex; set { _interlockLimitsSelectIndex = value; NotifyOfPropertyChange(nameof(InterlockLimitSelectIndex)); } } private bool _isShowInterlockPM = true; public bool IsShowInterlockPM { get => _isShowInterlockPM; set { _isShowInterlockPM = value; NotifyOfPropertyChange(nameof(IsShowInterlockPM)); } } private bool _isShowInterlockEdit = false; public bool IsShowInterlockEdit { get => _isShowInterlockEdit; set { _isShowInterlockEdit = value; NotifyOfPropertyChange(nameof(IsShowInterlockEdit)); } } private bool _isShowInterlockEditDetail = false; public bool IsShowInterlockEditDetail { get => _isShowInterlockEditDetail; set { _isShowInterlockEditDetail = value; NotifyOfPropertyChange(nameof(IsShowInterlockEditDetail)); } } private List _interlockEditAction = new List(); public List InterlockEditAction { get => _interlockEditAction; set { _interlockEditAction = value; NotifyOfPropertyChange(nameof(InterlockEditAction)); } } private string _interlockEditActionSelect; public string InterLockEditActionSelect { get => _interlockEditActionSelect; set { _interlockEditActionSelect = value; NotifyOfPropertyChange(nameof(InterLockEditActionSelect)); } } private List _interlockEditLimit = new List(); public List InterlockEditLimit { get => _interlockEditLimit; set { _interlockEditLimit = value; NotifyOfPropertyChange(nameof(InterlockEditLimit)); } } private string _interlockEditLimitSelect; public string InterLockEditLimitSelect { get => _interlockEditLimitSelect; set { _interlockEditLimitSelect = value; NotifyOfPropertyChange(nameof(InterLockEditLimitSelect)); } } private int _interlockEditLimitSelectIndex; public int InterlockEditLimitSelectIndex { get => _interlockEditLimitSelectIndex; set { _interlockEditLimitSelectIndex = value; NotifyOfPropertyChange(nameof(InterlockEditLimitSelectIndex)); } } private bool _actionValueTrue; public bool ActionValueTrue { get => _actionValueTrue; set { _actionValueTrue = value; NotifyOfPropertyChange(nameof(ActionValueTrue)); } } private bool _actionValueFalse; public bool ActionValueFalse { get => _actionValueFalse; set { _actionValueFalse = value; NotifyOfPropertyChange(nameof(ActionValueFalse)); } } private bool _limitValueTrue; public bool LimitValueTrue { get => _limitValueTrue; set { _limitValueTrue = value; NotifyOfPropertyChange(nameof(LimitValueTrue)); } } private bool _limitValueFalse; public bool LimitValueFalse { get => _limitValueFalse; set { _limitValueFalse = value; NotifyOfPropertyChange(nameof(LimitValueFalse)); } } private string _limitValueTrueName = "true"; public string LimitValueTrueName { get => _limitValueTrueName; set { _limitValueTrueName = value; NotifyOfPropertyChange(nameof(LimitValueTrueName)); } } private string _limitValueFalseName = "false"; public string LimitValueFalseName { get => _limitValueFalseName; set { _limitValueFalseName = value; NotifyOfPropertyChange(nameof(LimitValueFalseName)); } } private bool _limitConditionAND; public bool LimitConditionAND { get => _limitConditionAND; set { _limitConditionAND = value; NotifyOfPropertyChange(nameof(LimitConditionAND)); } } private bool _limitConditionOR; public bool LimitConditionOR { get => _limitConditionOR; set { _limitConditionOR = value; NotifyOfPropertyChange(nameof(LimitConditionOR)); } } private Visibility _isShowLimitValue = Visibility.Hidden; public Visibility IsShowLimitValue { get => _isShowLimitValue; set { _isShowLimitValue = value; NotifyOfPropertyChange(nameof(IsShowLimitValue)); } } private bool _isInterlockEdit; public bool IsInterlockEdit { get => _isInterlockEdit; set { _isInterlockEdit = value; NotifyOfPropertyChange(nameof(IsInterlockEdit)); } } private bool _isInterlockEditCancel; public bool IsInterlockEditCancel { get => _isInterlockEditCancel; set { _isInterlockEditCancel = value; NotifyOfPropertyChange(nameof(IsInterlockEditCancel)); } } private bool _isInterlockEditSet = false; private List _moduleName = new List() { "PM1" }; private string _actionItem = "BLANK"; public string ActionItem { get => _actionItem; set { _actionItem = value; NotifyOfPropertyChange(nameof(ActionItem)); } } private string _actionCheck = "BLANK"; public string ActionCheck { get => _actionCheck; set { _actionCheck = value; NotifyOfPropertyChange(nameof(ActionCheck)); } } private string _actionTimeCheck = "Time"; public string ActionTimeCheck { get => _actionTimeCheck; set { _actionTimeCheck = value; NotifyOfPropertyChange(nameof(ActionTimeCheck)); } } private string _actionValue; public string ActionValue { get => _actionValue; set { _actionValue = value; NotifyOfPropertyChange(nameof(ActionValue)); } } private string _actionTimeValue = "0"; public string ActionTimeValue { get => _actionTimeValue; set { _actionTimeValue = value; NotifyOfPropertyChange(nameof(ActionTimeValue)); } } private bool _isEnabledActionTimeValue; public bool IsEnabledActionTimeValue { get => _isEnabledActionTimeValue; set { _isEnabledActionTimeValue = value; NotifyOfPropertyChange(nameof(IsEnabledActionTimeValue)); } } private string _limitItem = "BLANK"; public string LimitItem { get => _limitItem; set { _limitItem = value; NotifyOfPropertyChange(nameof(LimitItem)); } } private string _limitCondition = "AND"; public string LimitCondition { get => _limitCondition; set { _limitCondition = value; NotifyOfPropertyChange(nameof(LimitCondition)); } } private string _limitCheck = "BLANK"; public string LimitCheck { get => _limitCheck; set { _limitCheck = value; NotifyOfPropertyChange(nameof(LimitCheck)); } } private string _limitValue = "0"; public string LimitValue { get => _limitValue; set { _limitValue = value; NotifyOfPropertyChange(nameof(LimitValue)); } } private string _limitUnit; public string LimitUnit { get => _limitUnit; set { _limitUnit = value; NotifyOfPropertyChange(nameof(LimitUnit)); } } private bool _isEnabledLimitValue; public bool IsEnabledLimitValue { get => _isEnabledLimitValue; set { _isEnabledLimitValue = value; NotifyOfPropertyChange(nameof(IsEnabledLimitValue)); } } private Dictionary _editInterlockFlagNameReferenceDic; private Dictionary _editLimitCheckReferenceDic; private string _diKey; private string _doKey; private string _aiKey; [Subscription("PM1.LZonePV")] public double LZonePV { get; set; } [Subscription("PM1.CLZonePV")] public double CLZonePV { get; set; } [Subscription("PM1.CZonePV")] public double CZonePV { get; set; } [Subscription("PM1.CUZonePV")] public double CUZonePV { get; set; } [Subscription("PM1.UZonePV")] public double UZonePV { get; set; } private List _paramNames = new List() { "PM1.LZonePV", "PM1.CLZonePV", "PM1.CZonePV", "PM1.CUZonePV", "PM1.UZonePV" }; private Dictionary _flagCurrentValues = new Dictionary(); public InterlockViewModel() { } protected override void OnInitialize() { base.OnInitialize(); _diKey = $"System.PM1.DIList"; _doKey = $"System.PM1.DOList"; _aiKey = $"System.PM1.AIList"; Subscribe(_aiKey); Subscribe(_diKey); Subscribe(_doKey); InitEditInterlockIODic(); InitPMTree(""); InitEditTree(""); InitActionLists(); InitLimitLists(); } private void InitEditInterlockIODic() { _editInterlockFlagNameReferenceDic = new Dictionary() { //{ "FLAG001", "TAG5" }, //{ "FLAG002", "A/S CLS STS" }, //{ "FLAG003", "CAP CLOSE1 STS" }, //{ "FLAG004", "ATM FLAG" }, //{ "FLAG005", "TUBE OVER PRS" }, //{ "FLAG006", "TAG25" }, //{ "FLAG007", "LA-T ATM" }, //{ "FLAG008", "TAG10" }, //{ "FLAG009", "GAS DET HZD ALM" }, //{ "FLAG010", "TAG1" }, //{ "FLAG011", "TAG14" }, //{ "FLAG012", "TAG15" }, //{ "FLAG013", "TAG19" }, //{ "FLAG014", "CAP I/L ON CMD" }, //{ "FLAG015", "TAG12" }, //{ "FLAG030", "I-ALM464" }, //{ "FLAG031", "I-ALM467" }, //{ "FLAG032", "I-ALM470" }, //{ "FLAG040", "I-ALM514" }, //{ "FLAG041", "I-ALM517" }, //{ "FLAG042", "I-ALM520" }, //{ "SetSensorCAPOpen", "LED1" }, //{ "SetSensorCAPOpenEnable", "LED2" }, //{ "FLAG020", "LED3" }, //{ "FLAG021", "LED4" }, //{ "FLAG022", "LED13" }, //{ "FLAG023", "LED14" }, }; _editLimitCheckReferenceDic = new Dictionary() { { ">=", "H" }, { "<", "L" }, }; } private void InitActionLists() { _interlockEditAction = new List(); foreach (var name in _moduleName) { GetActionList(name); } } private void InitLimitLists() { _interlockEditLimit = new List(); foreach (var name in _moduleName) { GetLimitDiList(name); } GetLimitAiList(_moduleName[0]); foreach (var name in _moduleName) { GetLimitDoList(name); } } private void GetActionList(string module) { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.{module}"); for (int i = 0; i < notifiableIoItems.Count; i++) { _interlockEditAction.Add(notifiableIoItems[i].Name); } } private void GetLimitDiList(string module) { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.{module}"); for (int i = 0; i < notifiableIoItems.Count; i++) { _interlockEditLimit.Add(notifiableIoItems[i].Name); } } private void GetLimitAiList(string module) { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.{module}"); for (int i = 0; i < notifiableIoItems.Count; i++) { _interlockEditLimit.Add(notifiableIoItems[i].Name); } } private void GetLimitDoList(string module) { List notifiableIoItems = new List(); notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.{module}"); for (int i = 0; i < notifiableIoItems.Count; i++) { _interlockEditLimit.Add(notifiableIoItems[i].Name); } } private void InitPMTree(string key) { try { XmlDocument xmlConfig = new XmlDocument(); xmlConfig.LoadXml(QueryDataClient.Instance.Service.GetInterlockConfigContent()); // // // // XmlNode nodeInterlock = xmlConfig.SelectSingleNode("Interlock"); InterlockTreePM.Clear(); foreach (XmlNode item in nodeInterlock.ChildNodes) { InterlockBase interlock = new InterlockBase(); if (item.NodeType == XmlNodeType.Comment) continue; XmlElement actionNode = item as XmlElement; if (actionNode == null) continue; if (actionNode.Name != "Action") { continue; } if (!actionNode.GetAttribute("do").Contains("PM1")) continue; if (!string.IsNullOrEmpty(key) && !actionNode.GetAttribute("do").Contains(key)) continue; interlock.Name = !string.IsNullOrEmpty(actionNode.GetAttribute("tip"))? actionNode.GetAttribute("tip"): actionNode.GetAttribute("do"); interlock.SetValue = actionNode.GetAttribute("value"); interlock.InterlockOKFill = _grayFill; //string doName = actionNode.GetAttribute("do"); //bool value = Convert.ToBoolean(actionNode.GetAttribute("value")); //string tip = actionNode.GetAttribute("tip"); foreach (XmlElement limitNode in actionNode.ChildNodes) { if (limitNode.Name != "Limit") { continue; } string action = string.Empty; string condition = limitNode.GetAttribute("condition"); condition = string.IsNullOrEmpty(condition) ? "AND" : condition; string limitTip = string.Empty; if (limitNode.HasAttribute("tip")) { action = limitNode.GetAttribute("tip"); } if (limitNode.HasAttribute("di")) { action = limitNode.GetAttribute("di"); limitTip = string.IsNullOrEmpty(limitTip) ? limitNode.GetAttribute("di") : limitTip; } if (limitNode.HasAttribute("do")) { action = limitNode.GetAttribute("do"); limitTip = string.IsNullOrEmpty(limitTip) ? limitNode.GetAttribute("do") : limitTip; } if (limitNode.HasAttribute("poll")) { action = limitNode.GetAttribute("do"); limitTip = string.IsNullOrEmpty(limitTip) ? limitNode.GetAttribute("poll") : limitTip; } interlock.Children.Add(new InterlockBase() { Action = action, Name = limitTip, LimitValue = limitNode.GetAttribute("value"), Condition = condition, InterlockOKFill = _greenFill }); } InterlockTreePM.Add(interlock); } } catch (Exception ex) { } } private void InitEditTree(string key) { try { XmlDocument xmlConfig = new XmlDocument(); xmlConfig.LoadXml(QueryDataClient.Instance.Service.GetInterlockUserDefineConfigContent()); XmlNode nodeInterlock = xmlConfig.SelectSingleNode("Interlock"); InterlockTreeEdit.Clear(); foreach (XmlNode item in nodeInterlock.ChildNodes) { InterlockBase interlock = new InterlockBase(); if (item.NodeType == XmlNodeType.Comment) continue; XmlElement actionNode = item as XmlElement; if (actionNode == null) continue; if (actionNode.Name != "Action") { continue; } if (!string.IsNullOrEmpty(key) && !actionNode.GetAttribute("Name").Contains(key)) continue; interlock.Action= actionNode.GetAttribute("Name"); //interlock.Name = actionNode.GetAttribute("Name"); //if (actionNode.GetAttribute("Name").Contains("FLAG")) // interlock.Action = actionNode.GetAttribute("Name"); //else // interlock.Action = _editInterlockIOReferenceDic.Where(x => x.Value == actionNode.GetAttribute("Name"))?.FirstOrDefault().Key; if (_editInterlockFlagNameReferenceDic.ContainsKey(interlock.Action)) interlock.Name = _editInterlockFlagNameReferenceDic[interlock.Action]; else interlock.Name = interlock.Action; interlock.SetValue = actionNode.GetAttribute("Value"); interlock.InterlockOKFill = _grayFill; //string doName = actionNode.GetAttribute("do"); //bool value = Convert.ToBoolean(actionNode.GetAttribute("value")); //string tip = actionNode.GetAttribute("tip"); foreach (XmlElement limitNode in actionNode.ChildNodes) { if (limitNode.Name != "Limit") { continue; } string action = string.Empty; if (limitNode.HasAttribute("Name")) { action = limitNode.GetAttribute("Name"); //if (limitNode.GetAttribute("Name").Contains("FLAG")) // action = limitNode.GetAttribute("Name"); //else // action = _editInterlockIOReferenceDic.Where(x => x.Value == limitNode.GetAttribute("Name"))?.FirstOrDefault().Key; } string condition = limitNode.GetAttribute("Condition"); condition = string.IsNullOrEmpty(condition) ? "AND" : condition; string name = string.Empty; if (_editInterlockFlagNameReferenceDic.ContainsKey(action)) name = _editInterlockFlagNameReferenceDic[action]; else name = action; interlock.Children.Add(new InterlockBase() { Action = action, Name = name, LimitValue = limitNode.GetAttribute("Value"), Condition = condition, InterlockOKFill = _greenFill }); } InterlockTreeEdit.Add(interlock); } } catch (Exception ex) { } } protected override void InvokeAfterUpdateProperty(Dictionary data) { base.InvokeAfterUpdateProperty(data); try { if (data.ContainsKey(_aiKey) && data[_aiKey] != null) { List lstData = (List)data[_aiKey]; Dictionary dicValues = new Dictionary(); for (int i = 0; i < lstData.Count; i++) { dicValues[lstData[i].Name] = lstData[i].FloatValue; } } if (data.ContainsKey(_diKey) && data[_diKey] != null) { List lstData = (List)data[_diKey]; Dictionary dicValues = new Dictionary(); for (int i = 0; i < lstData.Count; i++) { //dicValues[lstData[i].Name] = lstData[i].BoolValue; for (int j = 0; j < InterlockTreePM.Count; j++) { bool setValue = false; if (InterlockTreePM[j].Children[0].Condition.ToLower() == "or") { setValue = false; } else { setValue = true; } for (int k = 0; k < InterlockTreePM[j].Children.Count; k++) { if (lstData[i].Name.Contains(InterlockTreePM[j].Children[k].Action)) { InterlockTreePM[j].Children[k].InterlockOK = lstData[i].BoolValue.ToString().ToLower() == InterlockTreePM[j].Children[k].LimitValue.ToLower(); InterlockTreePM[j].Children[k].InterlockOKFill = InterlockTreePM[j].Children[k].InterlockOK ? _greenFill : _grayFill; } if (InterlockTreePM[j].Children[k].Condition.ToLower() == "or") { setValue = setValue || InterlockTreePM[j].Children[k].InterlockOK; } else { setValue = setValue && InterlockTreePM[j].Children[k].InterlockOK; } } InterlockTreePM[j].InterlockOK = setValue; ; InterlockTreePM[j].InterlockOKFill = InterlockTreePM[j].InterlockOK ? _greenFill : _grayFill; } } } if (data.ContainsKey(_doKey) && data[_doKey] != null) { List lstData = (List)data[_doKey]; Dictionary dicValues = new Dictionary(); for (int i = 0; i < lstData.Count; i++) { dicValues[lstData[i].Name] = lstData[i].BoolValue; } } RefreshInterlockEdit(); } catch (Exception ex) { } } private void RefreshInterlockEdit() { if (InterlockTreeEdit.Count == 0) return; Dictionary> keyValuePairs = new Dictionary>(); List notifiableIoItems = new List(); foreach (var name in _moduleName) { notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.{name}"); keyValuePairs.Add($"{name}.DI_", notifiableIoItems); notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.{name}"); keyValuePairs.Add($"{name}.DO_", notifiableIoItems); } notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.PM1"); keyValuePairs.Add($"PM1.AI_", notifiableIoItems); for (int i = 0; i < InterlockTreeEdit.Count; i++) { bool setValue = false; if (InterlockTreeEdit[i].Children[0].Condition.ToLower() == "or") { setValue = false; } else { setValue = true; } var doAction = InterlockTreeEdit[i].Action; for (int j = 0; j < InterlockTreeEdit[i].Children.Count; j++) { var action = InterlockTreeEdit[i].Children[j].Action; var limitValue = InterlockTreeEdit[i].Children[j].LimitValue; if (_paramNames.Contains(action)) { var values = (double)this.GetType().GetProperty(action.Replace("PM1.", "")).GetValue(this); if (limitValue.Contains("H")) { limitValue = limitValue.Replace("H", ""); InterlockTreeEdit[i].Children[j].InterlockOK = values > float.Parse(limitValue); InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill; } else { limitValue = limitValue.Replace("L", ""); InterlockTreeEdit[i].Children[j].InterlockOK = values < float.Parse(limitValue); InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill; } } else if (action.ToUpper().Contains("FLAG")) { InterlockTreeEdit[i].Children[j].InterlockOK = GetFlagActionInterlockOK(action, limitValue); InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill; } else { foreach (var key in keyValuePairs.Keys) { if (action.Contains(key)) { var values = keyValuePairs[key].Where(x => x.Name == action).FirstOrDefault(); if (values != null) { if (action.Contains("AI_")) { if (limitValue.Contains("H")) { limitValue = limitValue.Replace("H", ""); InterlockTreeEdit[i].Children[j].InterlockOK = values.FloatValue > float.Parse(limitValue); InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill; } else { limitValue = limitValue.Replace("L", ""); InterlockTreeEdit[i].Children[j].InterlockOK = values.FloatValue < float.Parse(limitValue); InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill; } } else { InterlockTreeEdit[i].Children[j].InterlockOK = values.BoolValue ? InterlockTreeEdit[i].Children[j].LimitValue.ToLower().Contains("on") : InterlockTreeEdit[i].Children[j].LimitValue.ToLower().Contains("off"); InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill; } } } } } if (InterlockTreeEdit[i].Children[j].Condition.ToLower() == "or") { setValue = setValue || InterlockTreeEdit[i].Children[j].InterlockOK; } else { setValue = setValue && InterlockTreeEdit[i].Children[j].InterlockOK; } } if (doAction.ToUpper().Contains("FLAG")) { if (setValue) { if (InterlockTreeEdit[i].SetValue.ToUpper().Contains("ON")) { if (!_flagCurrentValues.ContainsKey(doAction)) { _flagCurrentValues.Add(doAction, true); } else { _flagCurrentValues[doAction] = true; } } else { if (!_flagCurrentValues.ContainsKey(doAction)) { _flagCurrentValues.Add(doAction, false); } else { _flagCurrentValues[doAction] = false; } } InterlockTreeEdit[i].InterlockOK = setValue; InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill; } } else { InterlockTreeEdit[i].InterlockOK = setValue; InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill; } } for (int i = 0; i < InterlockTreeEdit.Count; i++) { var doAction = InterlockTreeEdit[i].Action; var setValue = InterlockTreeEdit[i].SetValue; var interlcokOk = InterlockTreeEdit[i].InterlockOK; if (doAction.ToUpper().Contains("FLAG") && _flagCurrentValues.ContainsKey(doAction)) { bool actionValue = _flagCurrentValues[doAction]; if (actionValue) { if (setValue.ToUpper().Contains("OFF") && interlcokOk) { InterlockTreeEdit[i].InterlockOK = false; InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill; } } else { if (setValue.ToUpper().Contains("ON") && interlcokOk) { InterlockTreeEdit[i].InterlockOK = false; InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill; } } } } } public bool GetFlagActionInterlockOK(string action, string limitValue) { if (_flagCurrentValues.ContainsKey(action)) { if (limitValue.ToUpper().Contains("ON")) { return _flagCurrentValues[action]; } else { return !_flagCurrentValues[action]; } } return false; } public void CollapseAll() { SetExpand(InterlockTreePM, false); SetExpand(InterlockTreeEdit, false); } public void ExpandAll() { SetExpand(InterlockTreePM, true); SetExpand(InterlockTreeEdit, true); } public void SetExpand(ObservableCollection interlockbase, bool expand) { if (interlockbase == null) return; foreach (var interlock in interlockbase) { interlock.IsExpanded = expand; if (interlock.Children != null) SetExpand(interlock.Children, expand); } } public void EditTreeSelectChanged(InterlockBase interlock) { CurrentInterlock = interlock; if (CurrentInterlock != null && CurrentInterlock.Children.Count > 0) { InterlockLimits.Clear(); foreach (var limit in CurrentInterlock.Children) { InterlockLimits.Add(new InterlockLimit() { LimitName = limit.Action, LimitValue = limit.LimitValue, LimitCondition = limit.Condition }); } InterlockLimitSelectIndex = 0; SelectLimit(); ActionItem = CurrentInterlock.Action; var value = CurrentInterlock.SetValue.Split(';').ToList(); if (value.Count > 1) { if (value[0].Contains("KEEP")) { ActionTimeCheck = "KEEP"; ActionTimeValue = value[0].Replace("KEEP", ""); IsEnabledActionTimeValue = true; } else { ActionTimeCheck = "DELAY"; ActionTimeValue = value[0].Replace("DELAY", ""); IsEnabledActionTimeValue = true; } ActionCheck = value[1]; } else { ActionCheck = value[0]; ActionTimeCheck = "Time"; ActionTimeValue = "0"; IsEnabledActionTimeValue = false; } } } public void InterlockEdit() { if (!_isInterlockEditSet) { _isInterlockEditSet = !_isInterlockEditSet; IsInterlockEdit = true; } else { IsInterlockEdit = false; IsInterlockEditCancel = true; _isInterlockEditSet = !_isInterlockEditSet; } } public void ActionSelect() { var temp = InterlockTreeEdit.Where(x => x.Action == InterLockEditActionSelect).FirstOrDefault(); if (temp == null) { InterlockLimits.Clear(); InterlockEditLimitSelectIndex = -1; } else { InterlockLimits.Clear(); foreach (var limit in temp.Children) { InterlockLimits.Add(new InterlockLimit() { LimitName = limit.Action, LimitValue = limit.LimitValue, LimitCondition = limit.Condition }); } InterlockEditLimitSelectIndex = InterlockEditLimit.IndexOf(InterlockLimits.First().LimitName); } } public void LimitSelect() { if (string.IsNullOrEmpty(InterLockEditLimitSelect)) return; if (InterLockEditLimitSelect.Contains("AI_")) { LimitValueTrueName = ">="; LimitValueFalseName = "<"; IsShowLimitValue = Visibility.Visible; } else { LimitValueTrueName = "true"; LimitValueFalseName = "false"; IsShowLimitValue = Visibility.Hidden; } } public void SelectItem(string itemType) { var windowManager = IoC.Get(); InterlockSelectItemViewModel interlockSelectItemViewModel = new InterlockSelectItemViewModel(itemType); (windowManager as WindowManager)?.ShowDialogWithTitle(interlockSelectItemViewModel, null, "Interlock SelectItem View"); string selectedItem = interlockSelectItemViewModel.SelectedItem; if (!string.IsNullOrEmpty(selectedItem)) { switch (itemType) { case "Action": ActionItem = selectedItem; break; case "Limit": if (selectedItem.Contains("FLAG")) { if (InterlockTreeEdit.Where(x => x.Action == selectedItem).FirstOrDefault() == null) { DialogBox.ShowWarning($"{selectedItem} item is not exist!"); return; } } LimitItem = selectedItem; if (LimitItem.Contains("MFC") || LimitItem.Contains("MFM") || LimitItem.Contains("APC") || LimitItem.Contains("TEMP") || LimitItem.Contains("VG")) { IsEnabledLimitValue = true; if (LimitCheck.Contains("ON") || LimitCheck.Contains("OFF")) LimitCheck = "BLANK"; } else { IsEnabledLimitValue = false; LimitValue = ""; if (LimitCheck.Contains(">=") || LimitCheck.Contains("<")) LimitCheck = "BLANK"; } if (LimitItem.Contains("MFC") || LimitItem.Contains("MFM")) { LimitUnit = "SCCM"; } else if (LimitItem.Contains("APC")) { LimitUnit = "Torr"; } else if (LimitItem.Contains("TEMP")) { LimitUnit = "℃"; } else if (LimitItem.Contains("VG")) { LimitUnit = "kPa"; } else { LimitUnit = ""; } break; } } } public void SelectCheck(string value) { string itemType = string.Empty; switch (value) { case "Action": itemType = ActionItem; break; case "Limit": itemType = LimitItem; break; case "TIME": itemType = value; break; } var windowManager = IoC.Get(); InterlockCheckViewModel interlockCheckViewModel = new InterlockCheckViewModel(itemType); if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(interlockCheckViewModel, null, "Interlock Check View")) { if (value == "Action") { ActionCheck = interlockCheckViewModel.CheckSelected; } else if (value == "Limit") { LimitCheck = interlockCheckViewModel.CheckSelected; if (LimitCheck == ">=" || LimitCheck == "<") IsEnabledLimitValue = true; else IsEnabledLimitValue = false; } else { ActionTimeCheck = interlockCheckViewModel.CheckSelected; if (ActionTimeCheck == "DELAY" || ActionTimeCheck == "KEEP") IsEnabledActionTimeValue = true; else IsEnabledActionTimeValue = false; } } } public void SelectCondition() { var windowManager = IoC.Get(); InterlockConditionViewModel interlockConditionViewModel = new InterlockConditionViewModel(); if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(interlockConditionViewModel, null, "Interlock Condition View")) { LimitCondition = interlockConditionViewModel.ConditionSelected; } } public void SelectLimit() { if (InterlockLimitSelectIndex != -1 && InterlockLimits.Count > 0) { LimitItem = InterlockLimits[InterlockLimitSelectIndex].LimitName; LimitCondition = InterlockLimits[InterlockLimitSelectIndex].LimitCondition; var value = InterlockLimits[InterlockLimitSelectIndex].LimitValue; if (value.Contains("H")) { LimitCheck = ">="; LimitValue = value.Replace("H", ""); IsEnabledLimitValue = true; } else if (value.Contains("L")) { LimitCheck = "<"; LimitValue = value.Replace("L", ""); IsEnabledLimitValue = true; } else { LimitCheck = value; LimitValue = "0"; IsEnabledLimitValue = false; } if (LimitItem.Contains("MFC") || LimitItem.Contains("MFM")) { LimitUnit = "SCCM"; } else if (LimitItem.Contains("APC")) { LimitUnit = "Torr"; } else if (LimitItem.Contains("TEMP")) { LimitUnit = "℃"; } else { LimitUnit = ""; } } } public void ChangeLimit() { if (InterlockLimitSelectIndex != -1 && InterlockLimits.Count > 0) { if (string.IsNullOrEmpty(LimitItem) || LimitItem == "BLANK") { DialogBox.ShowWarning("Limit item is empty,can not add!"); return; } if (string.IsNullOrEmpty(LimitCondition)) { DialogBox.ShowWarning("Limit condition is empty,can not add!"); return; } if (string.IsNullOrEmpty(LimitCheck) || LimitCheck == "BLANK") { DialogBox.ShowWarning("Limit check is empty,can not add!"); return; } if (IsEnabledLimitValue && string.IsNullOrEmpty(LimitValue)) { DialogBox.ShowWarning("Limit value is empty,can not add!"); return; } //if (InterlockLimits.Any(x => x.LimitCondition == "BLANK") && LimitCondition == "BLANK" && InterlockLimits[InterlockLimitSelectIndex].LimitCondition != "BLANK") //{ // DialogBox.ShowWarning("Alreay have condition is BLANK,can not add!"); // return; //} InterlockLimits[InterlockLimitSelectIndex].LimitName = LimitItem; InterlockLimits[InterlockLimitSelectIndex].LimitCondition = LimitCondition; //InterlockLimits[InterlockLimitSelectIndex].LimitValue = IsEnabledLimitValue ? LimitCheck + LimitValue : LimitCheck; InterlockLimits[InterlockLimitSelectIndex].LimitValue = IsEnabledLimitValue ? LimitValue + _editLimitCheckReferenceDic[LimitCheck] : LimitCheck; } } public void AddLimit() { if (string.IsNullOrEmpty(LimitItem) || LimitItem == "BLANK") { DialogBox.ShowWarning("Limit item is empty,can not add!"); return; } if (string.IsNullOrEmpty(LimitCondition)) { DialogBox.ShowWarning("Limit condition is empty,can not add!"); return; } if (string.IsNullOrEmpty(LimitCheck) || LimitCheck == "BLANK") { DialogBox.ShowWarning("Limit check is empty,can not add!"); return; } if (IsEnabledLimitValue && string.IsNullOrEmpty(LimitValue)) { DialogBox.ShowWarning("Limit value is empty,can not add!"); return; } //if (InterlockLimits.Any(x => x.LimitCondition == "BLANK") && LimitCondition == "BLANK") //{ // DialogBox.ShowWarning("Alreay have condition is BLANK,can not add!"); // return; //} InterlockLimit interlockLimit = new InterlockLimit(); interlockLimit.LimitName = LimitItem; interlockLimit.LimitCondition = LimitCondition; //interlockLimit.LimitValue = IsEnabledLimitValue ? LimitCheck + LimitValue : LimitCheck; interlockLimit.LimitValue = IsEnabledLimitValue ? LimitValue + _editLimitCheckReferenceDic[LimitCheck] : LimitCheck; if (InterlockLimits.Where(x => x.LimitName == LimitItem).FirstOrDefault() != null) { DialogBox.ShowWarning($"Limit [{LimitItem}] is already existed"); return; } else { InterlockLimits.Add(interlockLimit); } } public void DeleteLimit() { if (InterlockLimitSelectIndex != -1 && InterlockLimits.Count > 0) { if (!DialogBox.Confirm($"Are you sure delete limit [{InterlockLimits[InterlockLimitSelectIndex].LimitName}]")) return; InterlockLimits.RemoveAt(InterlockLimitSelectIndex); if (InterlockLimits.Count == 0) { LimitItem = "BLANK"; LimitCheck = "BLANK"; LimitValue = "0"; LimitUnit = ""; LimitCondition = "AND"; IsEnabledLimitValue = false; } } } public void Update() { if (CurrentInterlock == null) return; if (InterlockLimits.Count == 0) { DialogBox.ShowWarning("Condition is empty,can not save!"); return; } if (string.IsNullOrEmpty(ActionItem) || ActionItem == "BLANK") { DialogBox.ShowWarning("Action item is empty,can not save!"); return; } if (string.IsNullOrEmpty(ActionCheck) || ActionCheck == "BLANK") { DialogBox.ShowWarning("Action check is empty,can not save!"); return; } if (IsEnabledActionTimeValue && string.IsNullOrEmpty(ActionTimeValue)) { DialogBox.ShowWarning("Time value is empty,can not save!"); return; } //if (InterlockLimits[InterlockLimits.Count - 1].LimitCondition != "BLANK") //{ // DialogBox.ShowWarning("The last condition must be 'BLANK',can not save!"); // return; //} InterlockBase interlock = new InterlockBase(); interlock.Action = ActionItem; interlock.SetValue = IsEnabledActionTimeValue ? $"{ActionTimeCheck}{ActionTimeValue};" : ""; interlock.SetValue += ActionCheck; interlock.InterlockOKFill = _greenFill; for (int i = 0; i < InterlockLimits.Count; i++) { interlock.Children.Add(new InterlockBase() { Action = InterlockLimits[i].LimitName, LimitValue = InterlockLimits[i].LimitValue, Condition = InterlockLimits[i].LimitCondition, InterlockOKFill = _greenFill }); } InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action && x.SetValue == CurrentInterlock.SetValue).FirstOrDefault().SetValue = interlock.SetValue; InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action && x.SetValue == CurrentInterlock.SetValue).FirstOrDefault().InterlockOKFill = interlock.InterlockOKFill; InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action && x.SetValue == CurrentInterlock.SetValue).FirstOrDefault().Children = interlock.Children; QueryDataClient.Instance.Service.SetInterlockConfigContent(GetXmlString()); InvokeClient.Instance.Service.DoOperation($"System.UpdateUserDefineInterlock", ""); InterlockLimits.Clear(); InterlockParamClear(); } public void Save() { if (InterlockLimits.Count == 0) { DialogBox.ShowWarning("Condition is empty,can not save!"); return; } if (string.IsNullOrEmpty(ActionItem) || ActionItem == "BLANK") { DialogBox.ShowWarning("Action item is empty,can not save!"); return; } if (string.IsNullOrEmpty(ActionCheck) || ActionCheck == "BLANK") { DialogBox.ShowWarning("Action check is empty,can not save!"); return; } if (IsEnabledActionTimeValue && string.IsNullOrEmpty(ActionTimeValue)) { DialogBox.ShowWarning("Time value is empty,can not save!"); return; } //if (InterlockLimits[InterlockLimits.Count - 1].LimitCondition != "BLANK") //{ // DialogBox.ShowWarning("The last condition must be 'BLANK',can not save!"); // return; //} InterlockBase interlock = new InterlockBase(); interlock.Action = ActionItem; interlock.SetValue = IsEnabledActionTimeValue ? $"{ActionTimeCheck}{ActionTimeValue};" : ""; interlock.SetValue += ActionCheck; interlock.InterlockOKFill = _greenFill; for (int i = 0; i < InterlockLimits.Count; i++) { interlock.Children.Add(new InterlockBase() { Action = InterlockLimits[i].LimitName, LimitValue = InterlockLimits[i].LimitValue, Condition = InterlockLimits[i].LimitCondition, InterlockOKFill = _greenFill }); } if (InterlockTreeEdit.Any(x => x.Action == interlock.Action && x.SetValue == interlock.SetValue)) { DialogBox.ShowWarning($"Action [{interlock.Action}] condition {interlock.SetValue} is already existed"); return; } else { InterlockTreeEdit.Add(interlock); } QueryDataClient.Instance.Service.SetInterlockConfigContent(GetXmlString()); InvokeClient.Instance.Service.DoOperation($"System.UpdateUserDefineInterlock", ""); InterlockLimits.Clear(); InterlockParamClear(); } private string GetXmlString() { if (InterlockTreeEdit == null) return string.Empty; XmlDocument doc = new XmlDocument(); XmlElement node = doc.CreateElement("Interlock"); doc.AppendChild(node); XmlNode nodeData = doc.SelectSingleNode("Interlock"); foreach (InterlockBase interlock in InterlockTreeEdit) { XmlElement actionnode = doc.CreateElement("Action"); actionnode.SetAttribute("Name", interlock.Action); //if (interlock.Action.Contains("FLAG")) // actionnode.SetAttribute("Name", interlock.Action); //else // actionnode.SetAttribute("Name", _editInterlockIOReferenceDic[interlock.Action]); actionnode.SetAttribute("Value", interlock.SetValue); nodeData.AppendChild(actionnode); foreach (InterlockBase limit in interlock.Children) { XmlElement limitnode = doc.CreateElement("Limit"); limitnode.SetAttribute("Name", limit.Action); //if (limit.Action.Contains("FLAG")) // limitnode.SetAttribute("Name", limit.Action); //else // limitnode.SetAttribute("Name", _editInterlockIOReferenceDic[limit.Action]); limitnode.SetAttribute("Value", limit.LimitValue); limitnode.SetAttribute("Condition", limit.Condition); actionnode.AppendChild(limitnode); } } return doc.OuterXml; } public void Export() { try { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.DefaultExt = ".xml"; // Default file extension dlg.FileName = $"InterlockUserDefine_{DateTime.Now:yyyyMMdd_HHmmss}"; dlg.Filter = "xml数据文件(*.xml)|*.xml"; // Filter files by extension Nullable result = dlg.ShowDialog();// Show open file dialog box if (result == true) // Process open file dialog box results { XmlDocument xml = new XmlDocument(); xml.LoadXml(GetXmlString()); xml.Save(dlg.FileName); MessageBox.Show($"Export succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { LOG.Write(ex); MessageBox.Show("导出自定义Interlock发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning); } } //public void Import() //{ // try // { // string filepath = ""; // System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog(); // fd.Multiselect = false; // fd.Title = "Please Select File"; // fd.Filter = "xml⽂件|*.xml"; // if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK) // { // filepath = fd.FileName; // } // XmlDocument xmlConfig = new XmlDocument(); // xmlConfig.Load(filepath); // XmlNode nodeInterlock = xmlConfig.SelectSingleNode("Interlock"); // foreach (XmlNode item in nodeInterlock.ChildNodes) // { // InterlockBase interlock = new InterlockBase(); // if (item.NodeType == XmlNodeType.Comment) // continue; // XmlElement actionNode = item as XmlElement; // if (actionNode == null) continue; // if (actionNode.Name != "Action") // { // continue; // } // if (IsSameActionName(actionNode.GetAttribute("Name"))) // continue; // interlock.Action = actionNode.GetAttribute("Name"); // interlock.Name = actionNode.GetAttribute("Name"); // interlock.SetValue = actionNode.GetAttribute("Value"); // interlock.InterlockOKFill = _greenFill; // //string doName = actionNode.GetAttribute("do"); // //bool value = Convert.ToBoolean(actionNode.GetAttribute("value")); // //string tip = actionNode.GetAttribute("tip"); // foreach (XmlElement limitNode in actionNode.ChildNodes) // { // if (limitNode.Name != "Limit") // { // continue; // } // string action = string.Empty; // if (limitNode.HasAttribute("Name")) // { // action = limitNode.GetAttribute("Name"); // } // string condition = limitNode.GetAttribute("Condition"); // condition = string.IsNullOrEmpty(condition) ? "AND" : condition; // interlock.Children.Add(new InterlockBase() { Action = action, Name = limitNode.GetAttribute("Name"), LimitValue = limitNode.GetAttribute("Value"), Condition = condition, InterlockOKFill = _greenFill }); // } // InterlockTreeEdit.Add(interlock); // } // } // catch (Exception ex) // { // LOG.Write(ex); // MessageBox.Show("导入自定义Interlock发生错误", "导入失败", MessageBoxButton.OK, MessageBoxImage.Warning); // } //} private bool IsSameActionName(string actionName) { bool isSame = false; foreach (InterlockBase interlock in InterlockTreeEdit) { if (interlock.Action == actionName) { isSame = true; break; } } return isSame; } public void Delete() { if (CurrentInterlock == null) return; var interlock = InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action).FirstOrDefault(); if (interlock != null) { if (!DialogBox.Confirm($"Are you sure delete Interlock [{CurrentInterlock.Action}]")) return; InterlockTreeEdit.Remove(CurrentInterlock); QueryDataClient.Instance.Service.SetInterlockConfigContent(GetXmlString()); InvokeClient.Instance.Service.DoOperation($"System.UpdateUserDefineInterlock", ""); InterlockLimits.Clear(); InterlockParamClear(); } } private void InterlockParamClear() { LimitItem = "BLANK"; LimitCheck = "BLANK"; LimitValue = "0"; LimitUnit = ""; LimitCondition = "AND"; ActionTimeCheck = "Time"; ActionTimeValue = "0"; ActionItem = "BLANK"; ActionCheck = "BLANK"; IsEnabledLimitValue = false; IsEnabledActionTimeValue = false; } public void InterlockFind(string findKey) { if (string.IsNullOrWhiteSpace(findKey) || string.IsNullOrEmpty(findKey)) { if (IsShowInterlockPM) { InitPMTree(""); } if (IsShowInterlockEdit || IsShowInterlockEditDetail) { InitEditTree(""); } } else { if (IsShowInterlockPM) { InitPMTree(findKey); } if (IsShowInterlockEdit || IsShowInterlockEditDetail) { InitEditTree(findKey); } } } } public class InterlockLimit : NotifiableItem { private string _limitName; public string LimitName { get => _limitName; set { _limitName = value; InvokePropertyChanged(nameof(LimitName)); } } private string _limitCondition; public string LimitCondition { get => _limitCondition; set { _limitCondition = value; InvokePropertyChanged(nameof(LimitCondition)); } } private string _limitValue; public string LimitValue { get => _limitValue; set { _limitValue = value; InvokePropertyChanged(nameof(LimitValue)); } } } public class InterlockBase : PropertyChangedBase { private string _name; public string Name { get => _name; set { _name = value; NotifyOfPropertyChange(nameof(Name)); } } private string _action; public string Action { get => _action; set { _action = value; NotifyOfPropertyChange(nameof(Action)); } } private string _setValue; public string SetValue { get => _setValue; set { _setValue = value; NotifyOfPropertyChange(nameof(SetValue)); } } private string _limitValue; public string LimitValue { get => _limitValue; set { _limitValue = value; NotifyOfPropertyChange(nameof(LimitValue)); } } private bool _interlockOK; public bool InterlockOK { get => _interlockOK; set { _interlockOK = value; NotifyOfPropertyChange(nameof(InterlockOK)); } } private SolidColorBrush _interlockOKFill; public SolidColorBrush InterlockOKFill { get => _interlockOKFill; set { _interlockOKFill = value; NotifyOfPropertyChange(nameof(InterlockOKFill)); } } private string _condition; public string Condition { get => _condition; set { _condition = value; NotifyOfPropertyChange(nameof(Condition)); } } private bool _isExpanded; public bool IsExpanded { get => _isExpanded; set { _isExpanded = value; NotifyOfPropertyChange(nameof(IsExpanded)); } } private ObservableCollection _children; public ObservableCollection Children { get => _children; set { _children = value; NotifyOfPropertyChange(nameof(Children)); } } public InterlockBase() { Children = new ObservableCollection(); } } }