12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832 |
- 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<InterlockBase> _interlockTreePM = new ObservableCollection<InterlockBase>();
- public ObservableCollection<InterlockBase> 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<InterlockBase> _interlockTreeEdit = new ObservableCollection<InterlockBase>();
- public ObservableCollection<InterlockBase> InterlockTreeEdit
- {
- get => _interlockTreeEdit;
- set
- {
- _interlockTreeEdit = value;
- NotifyOfPropertyChange(nameof(InterlockTreeEdit));
- }
- }
- public InterlockBase CurrentInterlock = new InterlockBase();
- public ObservableCollection<InterlockLimit> InterlockLimits { get; set; } = new ObservableCollection<InterlockLimit>();
- 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<string> _interlockEditAction = new List<string>();
- public List<string> 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<string> _interlockEditLimit = new List<string>();
- public List<string> 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<string> _moduleName = new List<string>() { "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<string, string> _editInterlockFlagNameReferenceDic;
- private Dictionary<string, string> _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<string> _paramNames = new List<string>() { "PM1.LZonePV", "PM1.CLZonePV", "PM1.CZonePV", "PM1.CUZonePV", "PM1.UZonePV" };
- private Dictionary<string, bool> _flagCurrentValues = new Dictionary<string, bool>();
- 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<string, string>()
- {
- //{ "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<string, string>()
- {
- { ">=", "H" },
- { "<", "L" },
- };
- }
- private void InitActionLists()
- {
- _interlockEditAction = new List<string>();
- foreach (var name in _moduleName)
- {
- GetActionList(name);
- }
- }
- private void InitLimitLists()
- {
- _interlockEditLimit = new List<string>();
- foreach (var name in _moduleName)
- {
- GetLimitDiList(name);
- }
- GetLimitAiList(_moduleName[0]);
- foreach (var name in _moduleName)
- {
- GetLimitDoList(name);
- }
- }
- private void GetActionList(string module)
- {
- List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
- 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<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
- 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<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
- 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<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
- 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());
- //<Action do="DO_RF_power_on_off" value="true" tip="" tip.zh-CN="" tip.en-US="">
- // <Limit di="DI_RF_hardware_interlock" value="true" tip="" tip.zh-CN="" tip.en-US="" />
- // <Limit di="DI_Chamber_door_sw" value="true" tip="" tip.zh-CN="" tip.en-US="" />
- //</Action>
- 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<string, object> data)
- {
- base.InvokeAfterUpdateProperty(data);
- try
- {
- if (data.ContainsKey(_aiKey) && data[_aiKey] != null)
- {
- List<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_aiKey];
- Dictionary<string, float> dicValues = new Dictionary<string, float>();
- for (int i = 0; i < lstData.Count; i++)
- {
- dicValues[lstData[i].Name] = lstData[i].FloatValue;
- }
- }
- if (data.ContainsKey(_diKey) && data[_diKey] != null)
- {
- List<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_diKey];
- Dictionary<string, bool> dicValues = new Dictionary<string, bool>();
- 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<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_doKey];
- Dictionary<string, bool> dicValues = new Dictionary<string, bool>();
- 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<string, List<NotifiableIoItem>> keyValuePairs = new Dictionary<string, List<NotifiableIoItem>>();
- List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
- 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> 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<IWindowManager>();
- 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<IWindowManager>();
- 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<IWindowManager>();
- 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<bool> 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<InterlockBase> _children;
- public ObservableCollection<InterlockBase> Children
- {
- get => _children;
- set
- {
- _children = value;
- NotifyOfPropertyChange(nameof(Children));
- }
- }
- public InterlockBase()
- {
- Children = new ObservableCollection<InterlockBase>();
- }
- }
- }
|