InterlockViewModel.cs 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  1. using Aitex.Core.Util;
  2. using Caliburn.Micro;
  3. using MECF.Framework.Common.IOCore;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.OperationCenter;
  6. using OpenSEMI.ClientBase;
  7. using Caliburn.Micro.Core;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Windows;
  13. using System.Xml;
  14. using System.Windows.Media;
  15. using MECF.Framework.Common.CommonData;
  16. using Aitex.Core.RT.Log;
  17. using FurnaceUI.Models;
  18. namespace FurnaceUI.Views.Operations
  19. {
  20. public class InterlockViewModel : FurnaceModuleUIViewModelBase
  21. {
  22. public bool IsPermission { get => this.Permission == 3; }
  23. private ObservableCollection<InterlockBase> _interlockTreePM = new ObservableCollection<InterlockBase>();
  24. public ObservableCollection<InterlockBase> InterlockTreePM
  25. {
  26. get => _interlockTreePM;
  27. set
  28. {
  29. _interlockTreePM = value;
  30. NotifyOfPropertyChange(nameof(InterlockTreePM));
  31. }
  32. }
  33. private SolidColorBrush _greenFill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF07FF07"));
  34. private SolidColorBrush _redFill = new SolidColorBrush(Colors.Red);
  35. private SolidColorBrush _grayFill = new SolidColorBrush(Colors.Gray);
  36. private ObservableCollection<InterlockBase> _interlockTreeEdit = new ObservableCollection<InterlockBase>();
  37. public ObservableCollection<InterlockBase> InterlockTreeEdit
  38. {
  39. get => _interlockTreeEdit;
  40. set
  41. {
  42. _interlockTreeEdit = value;
  43. NotifyOfPropertyChange(nameof(InterlockTreeEdit));
  44. }
  45. }
  46. public InterlockBase CurrentInterlock = new InterlockBase();
  47. public ObservableCollection<InterlockLimit> InterlockLimits { get; set; } = new ObservableCollection<InterlockLimit>();
  48. private int _interlockLimitsSelectIndex;
  49. public int InterlockLimitSelectIndex
  50. {
  51. get => _interlockLimitsSelectIndex;
  52. set
  53. {
  54. _interlockLimitsSelectIndex = value;
  55. NotifyOfPropertyChange(nameof(InterlockLimitSelectIndex));
  56. }
  57. }
  58. private bool _isShowInterlockPM = true;
  59. public bool IsShowInterlockPM
  60. {
  61. get => _isShowInterlockPM;
  62. set
  63. {
  64. _isShowInterlockPM = value;
  65. NotifyOfPropertyChange(nameof(IsShowInterlockPM));
  66. }
  67. }
  68. private bool _isShowInterlockEdit = false;
  69. public bool IsShowInterlockEdit
  70. {
  71. get => _isShowInterlockEdit;
  72. set
  73. {
  74. _isShowInterlockEdit = value;
  75. NotifyOfPropertyChange(nameof(IsShowInterlockEdit));
  76. }
  77. }
  78. private bool _isShowInterlockEditDetail = false;
  79. public bool IsShowInterlockEditDetail
  80. {
  81. get => _isShowInterlockEditDetail;
  82. set
  83. {
  84. _isShowInterlockEditDetail = value;
  85. NotifyOfPropertyChange(nameof(IsShowInterlockEditDetail));
  86. }
  87. }
  88. private List<string> _interlockEditAction = new List<string>();
  89. public List<string> InterlockEditAction
  90. {
  91. get => _interlockEditAction;
  92. set
  93. {
  94. _interlockEditAction = value;
  95. NotifyOfPropertyChange(nameof(InterlockEditAction));
  96. }
  97. }
  98. private string _interlockEditActionSelect;
  99. public string InterLockEditActionSelect
  100. {
  101. get => _interlockEditActionSelect;
  102. set
  103. {
  104. _interlockEditActionSelect = value;
  105. NotifyOfPropertyChange(nameof(InterLockEditActionSelect));
  106. }
  107. }
  108. private List<string> _interlockEditLimit = new List<string>();
  109. public List<string> InterlockEditLimit
  110. {
  111. get => _interlockEditLimit;
  112. set
  113. {
  114. _interlockEditLimit = value;
  115. NotifyOfPropertyChange(nameof(InterlockEditLimit));
  116. }
  117. }
  118. private string _interlockEditLimitSelect;
  119. public string InterLockEditLimitSelect
  120. {
  121. get => _interlockEditLimitSelect;
  122. set
  123. {
  124. _interlockEditLimitSelect = value;
  125. NotifyOfPropertyChange(nameof(InterLockEditLimitSelect));
  126. }
  127. }
  128. private int _interlockEditLimitSelectIndex;
  129. public int InterlockEditLimitSelectIndex
  130. {
  131. get => _interlockEditLimitSelectIndex;
  132. set
  133. {
  134. _interlockEditLimitSelectIndex = value;
  135. NotifyOfPropertyChange(nameof(InterlockEditLimitSelectIndex));
  136. }
  137. }
  138. private bool _actionValueTrue;
  139. public bool ActionValueTrue
  140. {
  141. get => _actionValueTrue;
  142. set
  143. {
  144. _actionValueTrue = value;
  145. NotifyOfPropertyChange(nameof(ActionValueTrue));
  146. }
  147. }
  148. private bool _actionValueFalse;
  149. public bool ActionValueFalse
  150. {
  151. get => _actionValueFalse;
  152. set
  153. {
  154. _actionValueFalse = value;
  155. NotifyOfPropertyChange(nameof(ActionValueFalse));
  156. }
  157. }
  158. private bool _limitValueTrue;
  159. public bool LimitValueTrue
  160. {
  161. get => _limitValueTrue;
  162. set
  163. {
  164. _limitValueTrue = value;
  165. NotifyOfPropertyChange(nameof(LimitValueTrue));
  166. }
  167. }
  168. private bool _limitValueFalse;
  169. public bool LimitValueFalse
  170. {
  171. get => _limitValueFalse;
  172. set
  173. {
  174. _limitValueFalse = value;
  175. NotifyOfPropertyChange(nameof(LimitValueFalse));
  176. }
  177. }
  178. private string _limitValueTrueName = "true";
  179. public string LimitValueTrueName
  180. {
  181. get => _limitValueTrueName;
  182. set
  183. {
  184. _limitValueTrueName = value;
  185. NotifyOfPropertyChange(nameof(LimitValueTrueName));
  186. }
  187. }
  188. private string _limitValueFalseName = "false";
  189. public string LimitValueFalseName
  190. {
  191. get => _limitValueFalseName;
  192. set
  193. {
  194. _limitValueFalseName = value;
  195. NotifyOfPropertyChange(nameof(LimitValueFalseName));
  196. }
  197. }
  198. private bool _limitConditionAND;
  199. public bool LimitConditionAND
  200. {
  201. get => _limitConditionAND;
  202. set
  203. {
  204. _limitConditionAND = value;
  205. NotifyOfPropertyChange(nameof(LimitConditionAND));
  206. }
  207. }
  208. private bool _limitConditionOR;
  209. public bool LimitConditionOR
  210. {
  211. get => _limitConditionOR;
  212. set
  213. {
  214. _limitConditionOR = value;
  215. NotifyOfPropertyChange(nameof(LimitConditionOR));
  216. }
  217. }
  218. private Visibility _isShowLimitValue = Visibility.Hidden;
  219. public Visibility IsShowLimitValue
  220. {
  221. get => _isShowLimitValue;
  222. set
  223. {
  224. _isShowLimitValue = value;
  225. NotifyOfPropertyChange(nameof(IsShowLimitValue));
  226. }
  227. }
  228. private bool _isInterlockEdit;
  229. public bool IsInterlockEdit
  230. {
  231. get => _isInterlockEdit;
  232. set
  233. {
  234. _isInterlockEdit = value;
  235. NotifyOfPropertyChange(nameof(IsInterlockEdit));
  236. }
  237. }
  238. private bool _isInterlockEditCancel;
  239. public bool IsInterlockEditCancel
  240. {
  241. get => _isInterlockEditCancel;
  242. set
  243. {
  244. _isInterlockEditCancel = value;
  245. NotifyOfPropertyChange(nameof(IsInterlockEditCancel));
  246. }
  247. }
  248. private bool _isInterlockEditSet = false;
  249. private List<string> _moduleName = new List<string>() { "PM1" };
  250. private string _actionItem = "BLANK";
  251. public string ActionItem
  252. {
  253. get => _actionItem;
  254. set
  255. {
  256. _actionItem = value;
  257. NotifyOfPropertyChange(nameof(ActionItem));
  258. }
  259. }
  260. private string _actionCheck = "BLANK";
  261. public string ActionCheck
  262. {
  263. get => _actionCheck;
  264. set
  265. {
  266. _actionCheck = value;
  267. NotifyOfPropertyChange(nameof(ActionCheck));
  268. }
  269. }
  270. private string _actionTimeCheck = "Time";
  271. public string ActionTimeCheck
  272. {
  273. get => _actionTimeCheck;
  274. set
  275. {
  276. _actionTimeCheck = value;
  277. NotifyOfPropertyChange(nameof(ActionTimeCheck));
  278. }
  279. }
  280. private string _actionValue;
  281. public string ActionValue
  282. {
  283. get => _actionValue;
  284. set
  285. {
  286. _actionValue = value;
  287. NotifyOfPropertyChange(nameof(ActionValue));
  288. }
  289. }
  290. private string _actionTimeValue = "0";
  291. public string ActionTimeValue
  292. {
  293. get => _actionTimeValue;
  294. set
  295. {
  296. _actionTimeValue = value;
  297. NotifyOfPropertyChange(nameof(ActionTimeValue));
  298. }
  299. }
  300. private bool _isEnabledActionTimeValue;
  301. public bool IsEnabledActionTimeValue
  302. {
  303. get => _isEnabledActionTimeValue;
  304. set
  305. {
  306. _isEnabledActionTimeValue = value;
  307. NotifyOfPropertyChange(nameof(IsEnabledActionTimeValue));
  308. }
  309. }
  310. private string _limitItem = "BLANK";
  311. public string LimitItem
  312. {
  313. get => _limitItem;
  314. set
  315. {
  316. _limitItem = value;
  317. NotifyOfPropertyChange(nameof(LimitItem));
  318. }
  319. }
  320. private string _limitCondition = "AND";
  321. public string LimitCondition
  322. {
  323. get => _limitCondition;
  324. set
  325. {
  326. _limitCondition = value;
  327. NotifyOfPropertyChange(nameof(LimitCondition));
  328. }
  329. }
  330. private string _limitCheck = "BLANK";
  331. public string LimitCheck
  332. {
  333. get => _limitCheck;
  334. set
  335. {
  336. _limitCheck = value;
  337. NotifyOfPropertyChange(nameof(LimitCheck));
  338. }
  339. }
  340. private string _limitValue = "0";
  341. public string LimitValue
  342. {
  343. get => _limitValue;
  344. set
  345. {
  346. _limitValue = value;
  347. NotifyOfPropertyChange(nameof(LimitValue));
  348. }
  349. }
  350. private string _limitUnit;
  351. public string LimitUnit
  352. {
  353. get => _limitUnit;
  354. set
  355. {
  356. _limitUnit = value;
  357. NotifyOfPropertyChange(nameof(LimitUnit));
  358. }
  359. }
  360. private bool _isEnabledLimitValue;
  361. public bool IsEnabledLimitValue
  362. {
  363. get => _isEnabledLimitValue;
  364. set
  365. {
  366. _isEnabledLimitValue = value;
  367. NotifyOfPropertyChange(nameof(IsEnabledLimitValue));
  368. }
  369. }
  370. private Dictionary<string, string> _editInterlockFlagNameReferenceDic;
  371. private Dictionary<string, string> _editLimitCheckReferenceDic;
  372. private string _diKey;
  373. private string _doKey;
  374. private string _aiKey;
  375. [Subscription("PM1.LZonePV")]
  376. public double LZonePV { get; set; }
  377. [Subscription("PM1.CLZonePV")]
  378. public double CLZonePV { get; set; }
  379. [Subscription("PM1.CZonePV")]
  380. public double CZonePV { get; set; }
  381. [Subscription("PM1.CUZonePV")]
  382. public double CUZonePV { get; set; }
  383. [Subscription("PM1.UZonePV")]
  384. public double UZonePV { get; set; }
  385. private List<string> _paramNames = new List<string>() { "PM1.LZonePV", "PM1.CLZonePV", "PM1.CZonePV", "PM1.CUZonePV", "PM1.UZonePV" };
  386. private Dictionary<string, bool> _flagCurrentValues = new Dictionary<string, bool>();
  387. public InterlockViewModel()
  388. {
  389. }
  390. protected override void OnInitialize()
  391. {
  392. base.OnInitialize();
  393. _diKey = $"System.PM1.DIList";
  394. _doKey = $"System.PM1.DOList";
  395. _aiKey = $"System.PM1.AIList";
  396. Subscribe(_aiKey);
  397. Subscribe(_diKey);
  398. Subscribe(_doKey);
  399. InitEditInterlockIODic();
  400. InitPMTree("");
  401. InitEditTree("");
  402. InitActionLists();
  403. InitLimitLists();
  404. }
  405. private void InitEditInterlockIODic()
  406. {
  407. _editInterlockFlagNameReferenceDic = new Dictionary<string, string>()
  408. {
  409. //{ "FLAG001", "TAG5" },
  410. //{ "FLAG002", "A/S CLS STS" },
  411. //{ "FLAG003", "CAP CLOSE1 STS" },
  412. //{ "FLAG004", "ATM FLAG" },
  413. //{ "FLAG005", "TUBE OVER PRS" },
  414. //{ "FLAG006", "TAG25" },
  415. //{ "FLAG007", "LA-T ATM" },
  416. //{ "FLAG008", "TAG10" },
  417. //{ "FLAG009", "GAS DET HZD ALM" },
  418. //{ "FLAG010", "TAG1" },
  419. //{ "FLAG011", "TAG14" },
  420. //{ "FLAG012", "TAG15" },
  421. //{ "FLAG013", "TAG19" },
  422. //{ "FLAG014", "CAP I/L ON CMD" },
  423. //{ "FLAG015", "TAG12" },
  424. //{ "FLAG030", "I-ALM464" },
  425. //{ "FLAG031", "I-ALM467" },
  426. //{ "FLAG032", "I-ALM470" },
  427. //{ "FLAG040", "I-ALM514" },
  428. //{ "FLAG041", "I-ALM517" },
  429. //{ "FLAG042", "I-ALM520" },
  430. //{ "SetSensorCAPOpen", "LED1" },
  431. //{ "SetSensorCAPOpenEnable", "LED2" },
  432. //{ "FLAG020", "LED3" },
  433. //{ "FLAG021", "LED4" },
  434. //{ "FLAG022", "LED13" },
  435. //{ "FLAG023", "LED14" },
  436. };
  437. _editLimitCheckReferenceDic = new Dictionary<string, string>()
  438. {
  439. { ">=", "H" },
  440. { "<", "L" },
  441. };
  442. }
  443. private void InitActionLists()
  444. {
  445. _interlockEditAction = new List<string>();
  446. foreach (var name in _moduleName)
  447. {
  448. GetActionList(name);
  449. }
  450. }
  451. private void InitLimitLists()
  452. {
  453. _interlockEditLimit = new List<string>();
  454. foreach (var name in _moduleName)
  455. {
  456. GetLimitDiList(name);
  457. }
  458. GetLimitAiList(_moduleName[0]);
  459. foreach (var name in _moduleName)
  460. {
  461. GetLimitDoList(name);
  462. }
  463. }
  464. private void GetActionList(string module)
  465. {
  466. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  467. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.{module}");
  468. for (int i = 0; i < notifiableIoItems.Count; i++)
  469. {
  470. _interlockEditAction.Add(notifiableIoItems[i].Name);
  471. }
  472. }
  473. private void GetLimitDiList(string module)
  474. {
  475. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  476. notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.{module}");
  477. for (int i = 0; i < notifiableIoItems.Count; i++)
  478. {
  479. _interlockEditLimit.Add(notifiableIoItems[i].Name);
  480. }
  481. }
  482. private void GetLimitAiList(string module)
  483. {
  484. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  485. notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.{module}");
  486. for (int i = 0; i < notifiableIoItems.Count; i++)
  487. {
  488. _interlockEditLimit.Add(notifiableIoItems[i].Name);
  489. }
  490. }
  491. private void GetLimitDoList(string module)
  492. {
  493. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  494. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.{module}");
  495. for (int i = 0; i < notifiableIoItems.Count; i++)
  496. {
  497. _interlockEditLimit.Add(notifiableIoItems[i].Name);
  498. }
  499. }
  500. private void InitPMTree(string key)
  501. {
  502. try
  503. {
  504. XmlDocument xmlConfig = new XmlDocument();
  505. xmlConfig.LoadXml(QueryDataClient.Instance.Service.GetInterlockConfigContent());
  506. //<Action do="DO_RF_power_on_off" value="true" tip="" tip.zh-CN="" tip.en-US="">
  507. // <Limit di="DI_RF_hardware_interlock" value="true" tip="" tip.zh-CN="" tip.en-US="" />
  508. // <Limit di="DI_Chamber_door_sw" value="true" tip="" tip.zh-CN="" tip.en-US="" />
  509. //</Action>
  510. XmlNode nodeInterlock = xmlConfig.SelectSingleNode("Interlock");
  511. InterlockTreePM.Clear();
  512. foreach (XmlNode item in nodeInterlock.ChildNodes)
  513. {
  514. InterlockBase interlock = new InterlockBase();
  515. if (item.NodeType == XmlNodeType.Comment)
  516. continue;
  517. XmlElement actionNode = item as XmlElement;
  518. if (actionNode == null) continue;
  519. if (actionNode.Name != "Action")
  520. {
  521. continue;
  522. }
  523. if (!actionNode.GetAttribute("do").Contains("PM1"))
  524. continue;
  525. if (!string.IsNullOrEmpty(key) && !actionNode.GetAttribute("do").Contains(key))
  526. continue;
  527. interlock.Name = !string.IsNullOrEmpty(actionNode.GetAttribute("tip"))? actionNode.GetAttribute("tip"): actionNode.GetAttribute("do");
  528. interlock.SetValue = actionNode.GetAttribute("value");
  529. interlock.InterlockOKFill = _grayFill;
  530. //string doName = actionNode.GetAttribute("do");
  531. //bool value = Convert.ToBoolean(actionNode.GetAttribute("value"));
  532. //string tip = actionNode.GetAttribute("tip");
  533. foreach (XmlElement limitNode in actionNode.ChildNodes)
  534. {
  535. if (limitNode.Name != "Limit")
  536. {
  537. continue;
  538. }
  539. string action = string.Empty;
  540. string condition = limitNode.GetAttribute("condition");
  541. condition = string.IsNullOrEmpty(condition) ? "AND" : condition;
  542. string limitTip = string.Empty;
  543. if (limitNode.HasAttribute("tip"))
  544. {
  545. action = limitNode.GetAttribute("tip");
  546. }
  547. if (limitNode.HasAttribute("di"))
  548. {
  549. action = limitNode.GetAttribute("di");
  550. limitTip = string.IsNullOrEmpty(limitTip) ? limitNode.GetAttribute("di") : limitTip;
  551. }
  552. if (limitNode.HasAttribute("do"))
  553. {
  554. action = limitNode.GetAttribute("do");
  555. limitTip = string.IsNullOrEmpty(limitTip) ? limitNode.GetAttribute("do") : limitTip;
  556. }
  557. if (limitNode.HasAttribute("poll"))
  558. {
  559. action = limitNode.GetAttribute("do");
  560. limitTip = string.IsNullOrEmpty(limitTip) ? limitNode.GetAttribute("poll") : limitTip;
  561. }
  562. interlock.Children.Add(new InterlockBase() { Action = action, Name = limitTip, LimitValue = limitNode.GetAttribute("value"), Condition = condition, InterlockOKFill = _greenFill });
  563. }
  564. InterlockTreePM.Add(interlock);
  565. }
  566. }
  567. catch (Exception ex)
  568. {
  569. }
  570. }
  571. private void InitEditTree(string key)
  572. {
  573. try
  574. {
  575. XmlDocument xmlConfig = new XmlDocument();
  576. xmlConfig.LoadXml(QueryDataClient.Instance.Service.GetInterlockUserDefineConfigContent());
  577. XmlNode nodeInterlock = xmlConfig.SelectSingleNode("Interlock");
  578. InterlockTreeEdit.Clear();
  579. foreach (XmlNode item in nodeInterlock.ChildNodes)
  580. {
  581. InterlockBase interlock = new InterlockBase();
  582. if (item.NodeType == XmlNodeType.Comment)
  583. continue;
  584. XmlElement actionNode = item as XmlElement;
  585. if (actionNode == null) continue;
  586. if (actionNode.Name != "Action")
  587. {
  588. continue;
  589. }
  590. if (!string.IsNullOrEmpty(key) && !actionNode.GetAttribute("Name").Contains(key))
  591. continue;
  592. interlock.Action= actionNode.GetAttribute("Name");
  593. //interlock.Name = actionNode.GetAttribute("Name");
  594. //if (actionNode.GetAttribute("Name").Contains("FLAG"))
  595. // interlock.Action = actionNode.GetAttribute("Name");
  596. //else
  597. // interlock.Action = _editInterlockIOReferenceDic.Where(x => x.Value == actionNode.GetAttribute("Name"))?.FirstOrDefault().Key;
  598. if (_editInterlockFlagNameReferenceDic.ContainsKey(interlock.Action))
  599. interlock.Name = _editInterlockFlagNameReferenceDic[interlock.Action];
  600. else
  601. interlock.Name = interlock.Action;
  602. interlock.SetValue = actionNode.GetAttribute("Value");
  603. interlock.InterlockOKFill = _grayFill;
  604. //string doName = actionNode.GetAttribute("do");
  605. //bool value = Convert.ToBoolean(actionNode.GetAttribute("value"));
  606. //string tip = actionNode.GetAttribute("tip");
  607. foreach (XmlElement limitNode in actionNode.ChildNodes)
  608. {
  609. if (limitNode.Name != "Limit")
  610. {
  611. continue;
  612. }
  613. string action = string.Empty;
  614. if (limitNode.HasAttribute("Name"))
  615. {
  616. action = limitNode.GetAttribute("Name");
  617. //if (limitNode.GetAttribute("Name").Contains("FLAG"))
  618. // action = limitNode.GetAttribute("Name");
  619. //else
  620. // action = _editInterlockIOReferenceDic.Where(x => x.Value == limitNode.GetAttribute("Name"))?.FirstOrDefault().Key;
  621. }
  622. string condition = limitNode.GetAttribute("Condition");
  623. condition = string.IsNullOrEmpty(condition) ? "AND" : condition;
  624. string name = string.Empty;
  625. if (_editInterlockFlagNameReferenceDic.ContainsKey(action))
  626. name = _editInterlockFlagNameReferenceDic[action];
  627. else
  628. name = action;
  629. interlock.Children.Add(new InterlockBase() { Action = action, Name = name, LimitValue = limitNode.GetAttribute("Value"), Condition = condition, InterlockOKFill = _greenFill });
  630. }
  631. InterlockTreeEdit.Add(interlock);
  632. }
  633. }
  634. catch (Exception ex)
  635. {
  636. }
  637. }
  638. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  639. {
  640. base.InvokeAfterUpdateProperty(data);
  641. try
  642. {
  643. if (data.ContainsKey(_aiKey) && data[_aiKey] != null)
  644. {
  645. List<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_aiKey];
  646. Dictionary<string, float> dicValues = new Dictionary<string, float>();
  647. for (int i = 0; i < lstData.Count; i++)
  648. {
  649. dicValues[lstData[i].Name] = lstData[i].FloatValue;
  650. }
  651. }
  652. if (data.ContainsKey(_diKey) && data[_diKey] != null)
  653. {
  654. List<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_diKey];
  655. Dictionary<string, bool> dicValues = new Dictionary<string, bool>();
  656. for (int i = 0; i < lstData.Count; i++)
  657. {
  658. //dicValues[lstData[i].Name] = lstData[i].BoolValue;
  659. for (int j = 0; j < InterlockTreePM.Count; j++)
  660. {
  661. bool setValue = false;
  662. if (InterlockTreePM[j].Children[0].Condition.ToLower() == "or")
  663. {
  664. setValue = false;
  665. }
  666. else
  667. {
  668. setValue = true;
  669. }
  670. for (int k = 0; k < InterlockTreePM[j].Children.Count; k++)
  671. {
  672. if (lstData[i].Name.Contains(InterlockTreePM[j].Children[k].Action))
  673. {
  674. InterlockTreePM[j].Children[k].InterlockOK = lstData[i].BoolValue.ToString().ToLower() == InterlockTreePM[j].Children[k].LimitValue.ToLower();
  675. InterlockTreePM[j].Children[k].InterlockOKFill = InterlockTreePM[j].Children[k].InterlockOK ? _greenFill : _grayFill;
  676. }
  677. if (InterlockTreePM[j].Children[k].Condition.ToLower() == "or")
  678. {
  679. setValue = setValue || InterlockTreePM[j].Children[k].InterlockOK;
  680. }
  681. else
  682. {
  683. setValue = setValue && InterlockTreePM[j].Children[k].InterlockOK;
  684. }
  685. }
  686. InterlockTreePM[j].InterlockOK = setValue; ;
  687. InterlockTreePM[j].InterlockOKFill = InterlockTreePM[j].InterlockOK ? _greenFill : _grayFill;
  688. }
  689. }
  690. }
  691. if (data.ContainsKey(_doKey) && data[_doKey] != null)
  692. {
  693. List<NotifiableIoItem> lstData = (List<NotifiableIoItem>)data[_doKey];
  694. Dictionary<string, bool> dicValues = new Dictionary<string, bool>();
  695. for (int i = 0; i < lstData.Count; i++)
  696. {
  697. dicValues[lstData[i].Name] = lstData[i].BoolValue;
  698. }
  699. }
  700. RefreshInterlockEdit();
  701. }
  702. catch (Exception ex)
  703. {
  704. }
  705. }
  706. private void RefreshInterlockEdit()
  707. {
  708. if (InterlockTreeEdit.Count == 0)
  709. return;
  710. Dictionary<string, List<NotifiableIoItem>> keyValuePairs = new Dictionary<string, List<NotifiableIoItem>>();
  711. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  712. foreach (var name in _moduleName)
  713. {
  714. notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.{name}");
  715. keyValuePairs.Add($"{name}.DI_", notifiableIoItems);
  716. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.{name}");
  717. keyValuePairs.Add($"{name}.DO_", notifiableIoItems);
  718. }
  719. notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.PM1");
  720. keyValuePairs.Add($"PM1.AI_", notifiableIoItems);
  721. for (int i = 0; i < InterlockTreeEdit.Count; i++)
  722. {
  723. bool setValue = false;
  724. if (InterlockTreeEdit[i].Children[0].Condition.ToLower() == "or")
  725. {
  726. setValue = false;
  727. }
  728. else
  729. {
  730. setValue = true;
  731. }
  732. var doAction = InterlockTreeEdit[i].Action;
  733. for (int j = 0; j < InterlockTreeEdit[i].Children.Count; j++)
  734. {
  735. var action = InterlockTreeEdit[i].Children[j].Action;
  736. var limitValue = InterlockTreeEdit[i].Children[j].LimitValue;
  737. if (_paramNames.Contains(action))
  738. {
  739. var values = (double)this.GetType().GetProperty(action.Replace("PM1.", "")).GetValue(this);
  740. if (limitValue.Contains("H"))
  741. {
  742. limitValue = limitValue.Replace("H", "");
  743. InterlockTreeEdit[i].Children[j].InterlockOK = values > float.Parse(limitValue);
  744. InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill;
  745. }
  746. else
  747. {
  748. limitValue = limitValue.Replace("L", "");
  749. InterlockTreeEdit[i].Children[j].InterlockOK = values < float.Parse(limitValue);
  750. InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill;
  751. }
  752. }
  753. else if (action.ToUpper().Contains("FLAG"))
  754. {
  755. InterlockTreeEdit[i].Children[j].InterlockOK = GetFlagActionInterlockOK(action, limitValue);
  756. InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill;
  757. }
  758. else
  759. {
  760. foreach (var key in keyValuePairs.Keys)
  761. {
  762. if (action.Contains(key))
  763. {
  764. var values = keyValuePairs[key].Where(x => x.Name == action).FirstOrDefault();
  765. if (values != null)
  766. {
  767. if (action.Contains("AI_"))
  768. {
  769. if (limitValue.Contains("H"))
  770. {
  771. limitValue = limitValue.Replace("H", "");
  772. InterlockTreeEdit[i].Children[j].InterlockOK = values.FloatValue > float.Parse(limitValue);
  773. InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill;
  774. }
  775. else
  776. {
  777. limitValue = limitValue.Replace("L", "");
  778. InterlockTreeEdit[i].Children[j].InterlockOK = values.FloatValue < float.Parse(limitValue);
  779. InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill;
  780. }
  781. }
  782. else
  783. {
  784. InterlockTreeEdit[i].Children[j].InterlockOK = values.BoolValue ? InterlockTreeEdit[i].Children[j].LimitValue.ToLower().Contains("on") : InterlockTreeEdit[i].Children[j].LimitValue.ToLower().Contains("off");
  785. InterlockTreeEdit[i].Children[j].InterlockOKFill = InterlockTreeEdit[i].Children[j].InterlockOK ? _greenFill : _grayFill;
  786. }
  787. }
  788. }
  789. }
  790. }
  791. if (InterlockTreeEdit[i].Children[j].Condition.ToLower() == "or")
  792. {
  793. setValue = setValue || InterlockTreeEdit[i].Children[j].InterlockOK;
  794. }
  795. else
  796. {
  797. setValue = setValue && InterlockTreeEdit[i].Children[j].InterlockOK;
  798. }
  799. }
  800. if (doAction.ToUpper().Contains("FLAG"))
  801. {
  802. if (setValue)
  803. {
  804. if (InterlockTreeEdit[i].SetValue.ToUpper().Contains("ON"))
  805. {
  806. if (!_flagCurrentValues.ContainsKey(doAction))
  807. {
  808. _flagCurrentValues.Add(doAction, true);
  809. }
  810. else
  811. {
  812. _flagCurrentValues[doAction] = true;
  813. }
  814. }
  815. else
  816. {
  817. if (!_flagCurrentValues.ContainsKey(doAction))
  818. {
  819. _flagCurrentValues.Add(doAction, false);
  820. }
  821. else
  822. {
  823. _flagCurrentValues[doAction] = false;
  824. }
  825. }
  826. InterlockTreeEdit[i].InterlockOK = setValue;
  827. InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill;
  828. }
  829. }
  830. else
  831. {
  832. InterlockTreeEdit[i].InterlockOK = setValue;
  833. InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill;
  834. }
  835. }
  836. for (int i = 0; i < InterlockTreeEdit.Count; i++)
  837. {
  838. var doAction = InterlockTreeEdit[i].Action;
  839. var setValue = InterlockTreeEdit[i].SetValue;
  840. var interlcokOk = InterlockTreeEdit[i].InterlockOK;
  841. if (doAction.ToUpper().Contains("FLAG") && _flagCurrentValues.ContainsKey(doAction))
  842. {
  843. bool actionValue = _flagCurrentValues[doAction];
  844. if (actionValue)
  845. {
  846. if (setValue.ToUpper().Contains("OFF") && interlcokOk)
  847. {
  848. InterlockTreeEdit[i].InterlockOK = false;
  849. InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill;
  850. }
  851. }
  852. else
  853. {
  854. if (setValue.ToUpper().Contains("ON") && interlcokOk)
  855. {
  856. InterlockTreeEdit[i].InterlockOK = false;
  857. InterlockTreeEdit[i].InterlockOKFill = InterlockTreeEdit[i].InterlockOK ? _greenFill : _grayFill;
  858. }
  859. }
  860. }
  861. }
  862. }
  863. public bool GetFlagActionInterlockOK(string action, string limitValue)
  864. {
  865. if (_flagCurrentValues.ContainsKey(action))
  866. {
  867. if (limitValue.ToUpper().Contains("ON"))
  868. {
  869. return _flagCurrentValues[action];
  870. }
  871. else
  872. {
  873. return !_flagCurrentValues[action];
  874. }
  875. }
  876. return false;
  877. }
  878. public void CollapseAll()
  879. {
  880. SetExpand(InterlockTreePM, false);
  881. SetExpand(InterlockTreeEdit, false);
  882. }
  883. public void ExpandAll()
  884. {
  885. SetExpand(InterlockTreePM, true);
  886. SetExpand(InterlockTreeEdit, true);
  887. }
  888. public void SetExpand(ObservableCollection<InterlockBase> interlockbase, bool expand)
  889. {
  890. if (interlockbase == null)
  891. return;
  892. foreach (var interlock in interlockbase)
  893. {
  894. interlock.IsExpanded = expand;
  895. if (interlock.Children != null)
  896. SetExpand(interlock.Children, expand);
  897. }
  898. }
  899. public void EditTreeSelectChanged(InterlockBase interlock)
  900. {
  901. CurrentInterlock = interlock;
  902. if (CurrentInterlock != null && CurrentInterlock.Children.Count > 0)
  903. {
  904. InterlockLimits.Clear();
  905. foreach (var limit in CurrentInterlock.Children)
  906. {
  907. InterlockLimits.Add(new InterlockLimit() { LimitName = limit.Action, LimitValue = limit.LimitValue, LimitCondition = limit.Condition });
  908. }
  909. InterlockLimitSelectIndex = 0;
  910. SelectLimit();
  911. ActionItem = CurrentInterlock.Action;
  912. var value = CurrentInterlock.SetValue.Split(';').ToList();
  913. if (value.Count > 1)
  914. {
  915. if (value[0].Contains("KEEP"))
  916. {
  917. ActionTimeCheck = "KEEP";
  918. ActionTimeValue = value[0].Replace("KEEP", "");
  919. IsEnabledActionTimeValue = true;
  920. }
  921. else
  922. {
  923. ActionTimeCheck = "DELAY";
  924. ActionTimeValue = value[0].Replace("DELAY", "");
  925. IsEnabledActionTimeValue = true;
  926. }
  927. ActionCheck = value[1];
  928. }
  929. else
  930. {
  931. ActionCheck = value[0];
  932. ActionTimeCheck = "Time";
  933. ActionTimeValue = "0";
  934. IsEnabledActionTimeValue = false;
  935. }
  936. }
  937. }
  938. public void InterlockEdit()
  939. {
  940. if (!_isInterlockEditSet)
  941. {
  942. _isInterlockEditSet = !_isInterlockEditSet;
  943. IsInterlockEdit = true;
  944. }
  945. else
  946. {
  947. IsInterlockEdit = false;
  948. IsInterlockEditCancel = true;
  949. _isInterlockEditSet = !_isInterlockEditSet;
  950. }
  951. }
  952. public void ActionSelect()
  953. {
  954. var temp = InterlockTreeEdit.Where(x => x.Action == InterLockEditActionSelect).FirstOrDefault();
  955. if (temp == null)
  956. {
  957. InterlockLimits.Clear();
  958. InterlockEditLimitSelectIndex = -1;
  959. }
  960. else
  961. {
  962. InterlockLimits.Clear();
  963. foreach (var limit in temp.Children)
  964. {
  965. InterlockLimits.Add(new InterlockLimit() { LimitName = limit.Action, LimitValue = limit.LimitValue, LimitCondition = limit.Condition });
  966. }
  967. InterlockEditLimitSelectIndex = InterlockEditLimit.IndexOf(InterlockLimits.First().LimitName);
  968. }
  969. }
  970. public void LimitSelect()
  971. {
  972. if (string.IsNullOrEmpty(InterLockEditLimitSelect))
  973. return;
  974. if (InterLockEditLimitSelect.Contains("AI_"))
  975. {
  976. LimitValueTrueName = ">=";
  977. LimitValueFalseName = "<";
  978. IsShowLimitValue = Visibility.Visible;
  979. }
  980. else
  981. {
  982. LimitValueTrueName = "true";
  983. LimitValueFalseName = "false";
  984. IsShowLimitValue = Visibility.Hidden;
  985. }
  986. }
  987. public void SelectItem(string itemType)
  988. {
  989. var windowManager = IoC.Get<IWindowManager>();
  990. InterlockSelectItemViewModel interlockSelectItemViewModel = new InterlockSelectItemViewModel(itemType);
  991. (windowManager as WindowManager)?.ShowDialogWithTitle(interlockSelectItemViewModel, null, "Interlock SelectItem View");
  992. string selectedItem = interlockSelectItemViewModel.SelectedItem;
  993. if (!string.IsNullOrEmpty(selectedItem))
  994. {
  995. switch (itemType)
  996. {
  997. case "Action":
  998. ActionItem = selectedItem;
  999. break;
  1000. case "Limit":
  1001. if (selectedItem.Contains("FLAG"))
  1002. {
  1003. if (InterlockTreeEdit.Where(x => x.Action == selectedItem).FirstOrDefault() == null)
  1004. {
  1005. DialogBox.ShowWarning($"{selectedItem} item is not exist!");
  1006. return;
  1007. }
  1008. }
  1009. LimitItem = selectedItem;
  1010. if (LimitItem.Contains("MFC") || LimitItem.Contains("MFM") || LimitItem.Contains("APC") || LimitItem.Contains("TEMP") || LimitItem.Contains("VG"))
  1011. {
  1012. IsEnabledLimitValue = true;
  1013. if (LimitCheck.Contains("ON") || LimitCheck.Contains("OFF"))
  1014. LimitCheck = "BLANK";
  1015. }
  1016. else
  1017. {
  1018. IsEnabledLimitValue = false;
  1019. LimitValue = "";
  1020. if (LimitCheck.Contains(">=") || LimitCheck.Contains("<"))
  1021. LimitCheck = "BLANK";
  1022. }
  1023. if (LimitItem.Contains("MFC") || LimitItem.Contains("MFM"))
  1024. {
  1025. LimitUnit = "SCCM";
  1026. }
  1027. else if (LimitItem.Contains("APC"))
  1028. {
  1029. LimitUnit = "Torr";
  1030. }
  1031. else if (LimitItem.Contains("TEMP"))
  1032. {
  1033. LimitUnit = "℃";
  1034. }
  1035. else if (LimitItem.Contains("VG"))
  1036. {
  1037. LimitUnit = "kPa";
  1038. }
  1039. else
  1040. {
  1041. LimitUnit = "";
  1042. }
  1043. break;
  1044. }
  1045. }
  1046. }
  1047. public void SelectCheck(string value)
  1048. {
  1049. string itemType = string.Empty;
  1050. switch (value)
  1051. {
  1052. case "Action":
  1053. itemType = ActionItem;
  1054. break;
  1055. case "Limit":
  1056. itemType = LimitItem;
  1057. break;
  1058. case "TIME":
  1059. itemType = value;
  1060. break;
  1061. }
  1062. var windowManager = IoC.Get<IWindowManager>();
  1063. InterlockCheckViewModel interlockCheckViewModel = new InterlockCheckViewModel(itemType);
  1064. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(interlockCheckViewModel, null, "Interlock Check View"))
  1065. {
  1066. if (value == "Action")
  1067. {
  1068. ActionCheck = interlockCheckViewModel.CheckSelected;
  1069. }
  1070. else if (value == "Limit")
  1071. {
  1072. LimitCheck = interlockCheckViewModel.CheckSelected;
  1073. if (LimitCheck == ">=" || LimitCheck == "<")
  1074. IsEnabledLimitValue = true;
  1075. else
  1076. IsEnabledLimitValue = false;
  1077. }
  1078. else
  1079. {
  1080. ActionTimeCheck = interlockCheckViewModel.CheckSelected;
  1081. if (ActionTimeCheck == "DELAY" || ActionTimeCheck == "KEEP")
  1082. IsEnabledActionTimeValue = true;
  1083. else
  1084. IsEnabledActionTimeValue = false;
  1085. }
  1086. }
  1087. }
  1088. public void SelectCondition()
  1089. {
  1090. var windowManager = IoC.Get<IWindowManager>();
  1091. InterlockConditionViewModel interlockConditionViewModel = new InterlockConditionViewModel();
  1092. if ((bool)(windowManager as WindowManager)?.ShowDialogWithTitle(interlockConditionViewModel, null, "Interlock Condition View"))
  1093. {
  1094. LimitCondition = interlockConditionViewModel.ConditionSelected;
  1095. }
  1096. }
  1097. public void SelectLimit()
  1098. {
  1099. if (InterlockLimitSelectIndex != -1 && InterlockLimits.Count > 0)
  1100. {
  1101. LimitItem = InterlockLimits[InterlockLimitSelectIndex].LimitName;
  1102. LimitCondition = InterlockLimits[InterlockLimitSelectIndex].LimitCondition;
  1103. var value = InterlockLimits[InterlockLimitSelectIndex].LimitValue;
  1104. if (value.Contains("H"))
  1105. {
  1106. LimitCheck = ">=";
  1107. LimitValue = value.Replace("H", "");
  1108. IsEnabledLimitValue = true;
  1109. }
  1110. else if (value.Contains("L"))
  1111. {
  1112. LimitCheck = "<";
  1113. LimitValue = value.Replace("L", "");
  1114. IsEnabledLimitValue = true;
  1115. }
  1116. else
  1117. {
  1118. LimitCheck = value;
  1119. LimitValue = "0";
  1120. IsEnabledLimitValue = false;
  1121. }
  1122. if (LimitItem.Contains("MFC") || LimitItem.Contains("MFM"))
  1123. {
  1124. LimitUnit = "SCCM";
  1125. }
  1126. else if (LimitItem.Contains("APC"))
  1127. {
  1128. LimitUnit = "Torr";
  1129. }
  1130. else if (LimitItem.Contains("TEMP"))
  1131. {
  1132. LimitUnit = "℃";
  1133. }
  1134. else
  1135. {
  1136. LimitUnit = "";
  1137. }
  1138. }
  1139. }
  1140. public void ChangeLimit()
  1141. {
  1142. if (InterlockLimitSelectIndex != -1 && InterlockLimits.Count > 0)
  1143. {
  1144. if (string.IsNullOrEmpty(LimitItem) || LimitItem == "BLANK")
  1145. {
  1146. DialogBox.ShowWarning("Limit item is empty,can not add!");
  1147. return;
  1148. }
  1149. if (string.IsNullOrEmpty(LimitCondition))
  1150. {
  1151. DialogBox.ShowWarning("Limit condition is empty,can not add!");
  1152. return;
  1153. }
  1154. if (string.IsNullOrEmpty(LimitCheck) || LimitCheck == "BLANK")
  1155. {
  1156. DialogBox.ShowWarning("Limit check is empty,can not add!");
  1157. return;
  1158. }
  1159. if (IsEnabledLimitValue && string.IsNullOrEmpty(LimitValue))
  1160. {
  1161. DialogBox.ShowWarning("Limit value is empty,can not add!");
  1162. return;
  1163. }
  1164. //if (InterlockLimits.Any(x => x.LimitCondition == "BLANK") && LimitCondition == "BLANK" && InterlockLimits[InterlockLimitSelectIndex].LimitCondition != "BLANK")
  1165. //{
  1166. // DialogBox.ShowWarning("Alreay have condition is BLANK,can not add!");
  1167. // return;
  1168. //}
  1169. InterlockLimits[InterlockLimitSelectIndex].LimitName = LimitItem;
  1170. InterlockLimits[InterlockLimitSelectIndex].LimitCondition = LimitCondition;
  1171. //InterlockLimits[InterlockLimitSelectIndex].LimitValue = IsEnabledLimitValue ? LimitCheck + LimitValue : LimitCheck;
  1172. InterlockLimits[InterlockLimitSelectIndex].LimitValue = IsEnabledLimitValue ? LimitValue + _editLimitCheckReferenceDic[LimitCheck] : LimitCheck;
  1173. }
  1174. }
  1175. public void AddLimit()
  1176. {
  1177. if (string.IsNullOrEmpty(LimitItem) || LimitItem == "BLANK")
  1178. {
  1179. DialogBox.ShowWarning("Limit item is empty,can not add!");
  1180. return;
  1181. }
  1182. if (string.IsNullOrEmpty(LimitCondition))
  1183. {
  1184. DialogBox.ShowWarning("Limit condition is empty,can not add!");
  1185. return;
  1186. }
  1187. if (string.IsNullOrEmpty(LimitCheck) || LimitCheck == "BLANK")
  1188. {
  1189. DialogBox.ShowWarning("Limit check is empty,can not add!");
  1190. return;
  1191. }
  1192. if (IsEnabledLimitValue && string.IsNullOrEmpty(LimitValue))
  1193. {
  1194. DialogBox.ShowWarning("Limit value is empty,can not add!");
  1195. return;
  1196. }
  1197. //if (InterlockLimits.Any(x => x.LimitCondition == "BLANK") && LimitCondition == "BLANK")
  1198. //{
  1199. // DialogBox.ShowWarning("Alreay have condition is BLANK,can not add!");
  1200. // return;
  1201. //}
  1202. InterlockLimit interlockLimit = new InterlockLimit();
  1203. interlockLimit.LimitName = LimitItem;
  1204. interlockLimit.LimitCondition = LimitCondition;
  1205. //interlockLimit.LimitValue = IsEnabledLimitValue ? LimitCheck + LimitValue : LimitCheck;
  1206. interlockLimit.LimitValue = IsEnabledLimitValue ? LimitValue + _editLimitCheckReferenceDic[LimitCheck] : LimitCheck;
  1207. if (InterlockLimits.Where(x => x.LimitName == LimitItem).FirstOrDefault() != null)
  1208. {
  1209. DialogBox.ShowWarning($"Limit [{LimitItem}] is already existed");
  1210. return;
  1211. }
  1212. else
  1213. {
  1214. InterlockLimits.Add(interlockLimit);
  1215. }
  1216. }
  1217. public void DeleteLimit()
  1218. {
  1219. if (InterlockLimitSelectIndex != -1 && InterlockLimits.Count > 0)
  1220. {
  1221. if (!DialogBox.Confirm($"Are you sure delete limit [{InterlockLimits[InterlockLimitSelectIndex].LimitName}]"))
  1222. return;
  1223. InterlockLimits.RemoveAt(InterlockLimitSelectIndex);
  1224. if (InterlockLimits.Count == 0)
  1225. {
  1226. LimitItem = "BLANK";
  1227. LimitCheck = "BLANK";
  1228. LimitValue = "0";
  1229. LimitUnit = "";
  1230. LimitCondition = "AND";
  1231. IsEnabledLimitValue = false;
  1232. }
  1233. }
  1234. }
  1235. public void Update()
  1236. {
  1237. if (CurrentInterlock == null)
  1238. return;
  1239. if (InterlockLimits.Count == 0)
  1240. {
  1241. DialogBox.ShowWarning("Condition is empty,can not save!");
  1242. return;
  1243. }
  1244. if (string.IsNullOrEmpty(ActionItem) || ActionItem == "BLANK")
  1245. {
  1246. DialogBox.ShowWarning("Action item is empty,can not save!");
  1247. return;
  1248. }
  1249. if (string.IsNullOrEmpty(ActionCheck) || ActionCheck == "BLANK")
  1250. {
  1251. DialogBox.ShowWarning("Action check is empty,can not save!");
  1252. return;
  1253. }
  1254. if (IsEnabledActionTimeValue && string.IsNullOrEmpty(ActionTimeValue))
  1255. {
  1256. DialogBox.ShowWarning("Time value is empty,can not save!");
  1257. return;
  1258. }
  1259. //if (InterlockLimits[InterlockLimits.Count - 1].LimitCondition != "BLANK")
  1260. //{
  1261. // DialogBox.ShowWarning("The last condition must be 'BLANK',can not save!");
  1262. // return;
  1263. //}
  1264. InterlockBase interlock = new InterlockBase();
  1265. interlock.Action = ActionItem;
  1266. interlock.SetValue = IsEnabledActionTimeValue ? $"{ActionTimeCheck}{ActionTimeValue};" : "";
  1267. interlock.SetValue += ActionCheck;
  1268. interlock.InterlockOKFill = _greenFill;
  1269. for (int i = 0; i < InterlockLimits.Count; i++)
  1270. {
  1271. interlock.Children.Add(new InterlockBase() { Action = InterlockLimits[i].LimitName, LimitValue = InterlockLimits[i].LimitValue, Condition = InterlockLimits[i].LimitCondition, InterlockOKFill = _greenFill });
  1272. }
  1273. InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action && x.SetValue == CurrentInterlock.SetValue).FirstOrDefault().SetValue = interlock.SetValue;
  1274. InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action && x.SetValue == CurrentInterlock.SetValue).FirstOrDefault().InterlockOKFill = interlock.InterlockOKFill;
  1275. InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action && x.SetValue == CurrentInterlock.SetValue).FirstOrDefault().Children = interlock.Children;
  1276. QueryDataClient.Instance.Service.SetInterlockConfigContent(GetXmlString());
  1277. InvokeClient.Instance.Service.DoOperation($"System.UpdateUserDefineInterlock", "");
  1278. InterlockLimits.Clear();
  1279. InterlockParamClear();
  1280. }
  1281. public void Save()
  1282. {
  1283. if (InterlockLimits.Count == 0)
  1284. {
  1285. DialogBox.ShowWarning("Condition is empty,can not save!");
  1286. return;
  1287. }
  1288. if (string.IsNullOrEmpty(ActionItem) || ActionItem == "BLANK")
  1289. {
  1290. DialogBox.ShowWarning("Action item is empty,can not save!");
  1291. return;
  1292. }
  1293. if (string.IsNullOrEmpty(ActionCheck) || ActionCheck == "BLANK")
  1294. {
  1295. DialogBox.ShowWarning("Action check is empty,can not save!");
  1296. return;
  1297. }
  1298. if (IsEnabledActionTimeValue && string.IsNullOrEmpty(ActionTimeValue))
  1299. {
  1300. DialogBox.ShowWarning("Time value is empty,can not save!");
  1301. return;
  1302. }
  1303. //if (InterlockLimits[InterlockLimits.Count - 1].LimitCondition != "BLANK")
  1304. //{
  1305. // DialogBox.ShowWarning("The last condition must be 'BLANK',can not save!");
  1306. // return;
  1307. //}
  1308. InterlockBase interlock = new InterlockBase();
  1309. interlock.Action = ActionItem;
  1310. interlock.SetValue = IsEnabledActionTimeValue ? $"{ActionTimeCheck}{ActionTimeValue};" : "";
  1311. interlock.SetValue += ActionCheck;
  1312. interlock.InterlockOKFill = _greenFill;
  1313. for (int i = 0; i < InterlockLimits.Count; i++)
  1314. {
  1315. interlock.Children.Add(new InterlockBase() { Action = InterlockLimits[i].LimitName, LimitValue = InterlockLimits[i].LimitValue, Condition = InterlockLimits[i].LimitCondition, InterlockOKFill = _greenFill });
  1316. }
  1317. if (InterlockTreeEdit.Any(x => x.Action == interlock.Action && x.SetValue == interlock.SetValue))
  1318. {
  1319. DialogBox.ShowWarning($"Action [{interlock.Action}] condition {interlock.SetValue} is already existed");
  1320. return;
  1321. }
  1322. else
  1323. {
  1324. InterlockTreeEdit.Add(interlock);
  1325. }
  1326. QueryDataClient.Instance.Service.SetInterlockConfigContent(GetXmlString());
  1327. InvokeClient.Instance.Service.DoOperation($"System.UpdateUserDefineInterlock", "");
  1328. InterlockLimits.Clear();
  1329. InterlockParamClear();
  1330. }
  1331. private string GetXmlString()
  1332. {
  1333. if (InterlockTreeEdit == null)
  1334. return string.Empty;
  1335. XmlDocument doc = new XmlDocument();
  1336. XmlElement node = doc.CreateElement("Interlock");
  1337. doc.AppendChild(node);
  1338. XmlNode nodeData = doc.SelectSingleNode("Interlock");
  1339. foreach (InterlockBase interlock in InterlockTreeEdit)
  1340. {
  1341. XmlElement actionnode = doc.CreateElement("Action");
  1342. actionnode.SetAttribute("Name", interlock.Action);
  1343. //if (interlock.Action.Contains("FLAG"))
  1344. // actionnode.SetAttribute("Name", interlock.Action);
  1345. //else
  1346. // actionnode.SetAttribute("Name", _editInterlockIOReferenceDic[interlock.Action]);
  1347. actionnode.SetAttribute("Value", interlock.SetValue);
  1348. nodeData.AppendChild(actionnode);
  1349. foreach (InterlockBase limit in interlock.Children)
  1350. {
  1351. XmlElement limitnode = doc.CreateElement("Limit");
  1352. limitnode.SetAttribute("Name", limit.Action);
  1353. //if (limit.Action.Contains("FLAG"))
  1354. // limitnode.SetAttribute("Name", limit.Action);
  1355. //else
  1356. // limitnode.SetAttribute("Name", _editInterlockIOReferenceDic[limit.Action]);
  1357. limitnode.SetAttribute("Value", limit.LimitValue);
  1358. limitnode.SetAttribute("Condition", limit.Condition);
  1359. actionnode.AppendChild(limitnode);
  1360. }
  1361. }
  1362. return doc.OuterXml;
  1363. }
  1364. public void Export()
  1365. {
  1366. try
  1367. {
  1368. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  1369. dlg.DefaultExt = ".xml"; // Default file extension
  1370. dlg.FileName = $"InterlockUserDefine_{DateTime.Now:yyyyMMdd_HHmmss}";
  1371. dlg.Filter = "xml数据文件(*.xml)|*.xml"; // Filter files by extension
  1372. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  1373. if (result == true) // Process open file dialog box results
  1374. {
  1375. XmlDocument xml = new XmlDocument();
  1376. xml.LoadXml(GetXmlString());
  1377. xml.Save(dlg.FileName);
  1378. MessageBox.Show($"Export succeed, file save as {dlg.FileName}", "Export", MessageBoxButton.OK, MessageBoxImage.Information);
  1379. }
  1380. }
  1381. catch (Exception ex)
  1382. {
  1383. LOG.Write(ex);
  1384. MessageBox.Show("导出自定义Interlock发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  1385. }
  1386. }
  1387. //public void Import()
  1388. //{
  1389. // try
  1390. // {
  1391. // string filepath = "";
  1392. // System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog();
  1393. // fd.Multiselect = false;
  1394. // fd.Title = "Please Select File";
  1395. // fd.Filter = "xml⽂件|*.xml";
  1396. // if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1397. // {
  1398. // filepath = fd.FileName;
  1399. // }
  1400. // XmlDocument xmlConfig = new XmlDocument();
  1401. // xmlConfig.Load(filepath);
  1402. // XmlNode nodeInterlock = xmlConfig.SelectSingleNode("Interlock");
  1403. // foreach (XmlNode item in nodeInterlock.ChildNodes)
  1404. // {
  1405. // InterlockBase interlock = new InterlockBase();
  1406. // if (item.NodeType == XmlNodeType.Comment)
  1407. // continue;
  1408. // XmlElement actionNode = item as XmlElement;
  1409. // if (actionNode == null) continue;
  1410. // if (actionNode.Name != "Action")
  1411. // {
  1412. // continue;
  1413. // }
  1414. // if (IsSameActionName(actionNode.GetAttribute("Name")))
  1415. // continue;
  1416. // interlock.Action = actionNode.GetAttribute("Name");
  1417. // interlock.Name = actionNode.GetAttribute("Name");
  1418. // interlock.SetValue = actionNode.GetAttribute("Value");
  1419. // interlock.InterlockOKFill = _greenFill;
  1420. // //string doName = actionNode.GetAttribute("do");
  1421. // //bool value = Convert.ToBoolean(actionNode.GetAttribute("value"));
  1422. // //string tip = actionNode.GetAttribute("tip");
  1423. // foreach (XmlElement limitNode in actionNode.ChildNodes)
  1424. // {
  1425. // if (limitNode.Name != "Limit")
  1426. // {
  1427. // continue;
  1428. // }
  1429. // string action = string.Empty;
  1430. // if (limitNode.HasAttribute("Name"))
  1431. // {
  1432. // action = limitNode.GetAttribute("Name");
  1433. // }
  1434. // string condition = limitNode.GetAttribute("Condition");
  1435. // condition = string.IsNullOrEmpty(condition) ? "AND" : condition;
  1436. // interlock.Children.Add(new InterlockBase() { Action = action, Name = limitNode.GetAttribute("Name"), LimitValue = limitNode.GetAttribute("Value"), Condition = condition, InterlockOKFill = _greenFill });
  1437. // }
  1438. // InterlockTreeEdit.Add(interlock);
  1439. // }
  1440. // }
  1441. // catch (Exception ex)
  1442. // {
  1443. // LOG.Write(ex);
  1444. // MessageBox.Show("导入自定义Interlock发生错误", "导入失败", MessageBoxButton.OK, MessageBoxImage.Warning);
  1445. // }
  1446. //}
  1447. private bool IsSameActionName(string actionName)
  1448. {
  1449. bool isSame = false;
  1450. foreach (InterlockBase interlock in InterlockTreeEdit)
  1451. {
  1452. if (interlock.Action == actionName)
  1453. {
  1454. isSame = true;
  1455. break;
  1456. }
  1457. }
  1458. return isSame;
  1459. }
  1460. public void Delete()
  1461. {
  1462. if (CurrentInterlock == null)
  1463. return;
  1464. var interlock = InterlockTreeEdit.Where(x => x.Action == CurrentInterlock.Action).FirstOrDefault();
  1465. if (interlock != null)
  1466. {
  1467. if (!DialogBox.Confirm($"Are you sure delete Interlock [{CurrentInterlock.Action}]"))
  1468. return;
  1469. InterlockTreeEdit.Remove(CurrentInterlock);
  1470. QueryDataClient.Instance.Service.SetInterlockConfigContent(GetXmlString());
  1471. InvokeClient.Instance.Service.DoOperation($"System.UpdateUserDefineInterlock", "");
  1472. InterlockLimits.Clear();
  1473. InterlockParamClear();
  1474. }
  1475. }
  1476. private void InterlockParamClear()
  1477. {
  1478. LimitItem = "BLANK";
  1479. LimitCheck = "BLANK";
  1480. LimitValue = "0";
  1481. LimitUnit = "";
  1482. LimitCondition = "AND";
  1483. ActionTimeCheck = "Time";
  1484. ActionTimeValue = "0";
  1485. ActionItem = "BLANK";
  1486. ActionCheck = "BLANK";
  1487. IsEnabledLimitValue = false;
  1488. IsEnabledActionTimeValue = false;
  1489. }
  1490. public void InterlockFind(string findKey)
  1491. {
  1492. if (string.IsNullOrWhiteSpace(findKey) || string.IsNullOrEmpty(findKey))
  1493. {
  1494. if (IsShowInterlockPM)
  1495. {
  1496. InitPMTree("");
  1497. }
  1498. if (IsShowInterlockEdit || IsShowInterlockEditDetail)
  1499. {
  1500. InitEditTree("");
  1501. }
  1502. }
  1503. else
  1504. {
  1505. if (IsShowInterlockPM)
  1506. {
  1507. InitPMTree(findKey);
  1508. }
  1509. if (IsShowInterlockEdit || IsShowInterlockEditDetail)
  1510. {
  1511. InitEditTree(findKey);
  1512. }
  1513. }
  1514. }
  1515. }
  1516. public class InterlockLimit : NotifiableItem
  1517. {
  1518. private string _limitName;
  1519. public string LimitName
  1520. {
  1521. get => _limitName;
  1522. set
  1523. {
  1524. _limitName = value;
  1525. InvokePropertyChanged(nameof(LimitName));
  1526. }
  1527. }
  1528. private string _limitCondition;
  1529. public string LimitCondition
  1530. {
  1531. get => _limitCondition;
  1532. set
  1533. {
  1534. _limitCondition = value;
  1535. InvokePropertyChanged(nameof(LimitCondition));
  1536. }
  1537. }
  1538. private string _limitValue;
  1539. public string LimitValue
  1540. {
  1541. get => _limitValue;
  1542. set
  1543. {
  1544. _limitValue = value;
  1545. InvokePropertyChanged(nameof(LimitValue));
  1546. }
  1547. }
  1548. }
  1549. public class InterlockBase : PropertyChangedBase
  1550. {
  1551. private string _name;
  1552. public string Name
  1553. {
  1554. get => _name;
  1555. set
  1556. {
  1557. _name = value;
  1558. NotifyOfPropertyChange(nameof(Name));
  1559. }
  1560. }
  1561. private string _action;
  1562. public string Action
  1563. {
  1564. get => _action;
  1565. set
  1566. {
  1567. _action = value;
  1568. NotifyOfPropertyChange(nameof(Action));
  1569. }
  1570. }
  1571. private string _setValue;
  1572. public string SetValue
  1573. {
  1574. get => _setValue;
  1575. set
  1576. {
  1577. _setValue = value;
  1578. NotifyOfPropertyChange(nameof(SetValue));
  1579. }
  1580. }
  1581. private string _limitValue;
  1582. public string LimitValue
  1583. {
  1584. get => _limitValue;
  1585. set
  1586. {
  1587. _limitValue = value;
  1588. NotifyOfPropertyChange(nameof(LimitValue));
  1589. }
  1590. }
  1591. private bool _interlockOK;
  1592. public bool InterlockOK
  1593. {
  1594. get => _interlockOK;
  1595. set
  1596. {
  1597. _interlockOK = value;
  1598. NotifyOfPropertyChange(nameof(InterlockOK));
  1599. }
  1600. }
  1601. private SolidColorBrush _interlockOKFill;
  1602. public SolidColorBrush InterlockOKFill
  1603. {
  1604. get => _interlockOKFill;
  1605. set
  1606. {
  1607. _interlockOKFill = value;
  1608. NotifyOfPropertyChange(nameof(InterlockOKFill));
  1609. }
  1610. }
  1611. private string _condition;
  1612. public string Condition
  1613. {
  1614. get => _condition;
  1615. set
  1616. {
  1617. _condition = value;
  1618. NotifyOfPropertyChange(nameof(Condition));
  1619. }
  1620. }
  1621. private bool _isExpanded;
  1622. public bool IsExpanded
  1623. {
  1624. get => _isExpanded;
  1625. set
  1626. {
  1627. _isExpanded = value;
  1628. NotifyOfPropertyChange(nameof(IsExpanded));
  1629. }
  1630. }
  1631. private ObservableCollection<InterlockBase> _children;
  1632. public ObservableCollection<InterlockBase> Children
  1633. {
  1634. get => _children;
  1635. set
  1636. {
  1637. _children = value;
  1638. NotifyOfPropertyChange(nameof(Children));
  1639. }
  1640. }
  1641. public InterlockBase()
  1642. {
  1643. Children = new ObservableCollection<InterlockBase>();
  1644. }
  1645. }
  1646. }