MFCVerificationViewModel.cs 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Core.Util;
  4. using MECF.Framework.Common.CommonData;
  5. using MECF.Framework.Common.DataCenter;
  6. using MECF.Framework.Common.OperationCenter;
  7. using OpenSEMI.ClientBase;
  8. using SciChart.Charting.Model.DataSeries;
  9. using SciChart.Charting.Visuals.Axes;
  10. using SciChart.Charting.Visuals.RenderableSeries;
  11. using SciChart.Data.Model;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.ComponentModel;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. using System.Windows.Media;
  21. using VirgoUI.Client.Models.Sys;
  22. namespace VirgoUI.Client.Models.PMs
  23. {
  24. public class MFCVerificationDataListItem : NotifiableItem
  25. {
  26. private float _Setpoint;
  27. public float Setpoint
  28. {
  29. get
  30. {
  31. return _Setpoint;
  32. }
  33. set
  34. {
  35. _Setpoint = value;
  36. InvokePropertyChanged("Setpoint");
  37. }
  38. }
  39. private float _CalculateValue;
  40. public float CalculateValue
  41. {
  42. get
  43. {
  44. return _CalculateValue;
  45. }
  46. set
  47. {
  48. _CalculateValue = value;
  49. InvokePropertyChanged("CalculateValue");
  50. }
  51. }
  52. private float _ElapseTime;
  53. public float ElapseTime
  54. {
  55. get
  56. {
  57. return _ElapseTime;
  58. }
  59. set
  60. {
  61. _ElapseTime = value;
  62. InvokePropertyChanged("ElapseTime");
  63. }
  64. }
  65. private float _deviation;
  66. public float Deviation
  67. {
  68. get
  69. {
  70. return _deviation;
  71. }
  72. set
  73. {
  74. _deviation = value;
  75. InvokePropertyChanged("Deviation");
  76. }
  77. }
  78. private string _result;
  79. public string Result
  80. {
  81. get
  82. {
  83. return Convert.ToBoolean(_result) ? "OK" : "Failed";
  84. }
  85. set
  86. {
  87. _result = value;
  88. InvokePropertyChanged("Result");
  89. }
  90. }
  91. private string _resultBackground;
  92. public string ResultBackground
  93. {
  94. get
  95. {
  96. return _resultBackground;
  97. }
  98. set
  99. {
  100. _resultBackground = value;
  101. InvokePropertyChanged("ResultBackground");
  102. }
  103. }
  104. private float _pressure;
  105. public float Pressure
  106. {
  107. get
  108. {
  109. return _pressure;
  110. }
  111. set
  112. {
  113. _pressure = value;
  114. InvokePropertyChanged("Pressure");
  115. }
  116. }
  117. }
  118. public class MFCVerificationErrorRateListItem : NotifiableItem
  119. {
  120. public float Setpoint { get; set; }
  121. public float CalculateValue { get; set; }
  122. public float ErrorRate { get; set; }
  123. public float ElapsedTime { get; set; }
  124. public float Deviation { get; set; }
  125. public string Result { get; set; }
  126. }
  127. public class MFCVerificationData : NotifiableItem
  128. {
  129. public string Module { get; set; }
  130. public string Name { get; set; }
  131. public string Time { get; set; }
  132. public float Percent10Setpoint { get; set; }
  133. public float Percent10Calculate { get; set; }
  134. public float Percent20Setpoint { get; set; }
  135. public float Percent20Calculate { get; set; }
  136. public float Percent30Setpoint { get; set; }
  137. public float Percent30Calculate { get; set; }
  138. public float Percent40Setpoint { get; set; }
  139. public float Percent40Calculate { get; set; }
  140. public float Percent50Setpoint { get; set; }
  141. public float Percent50Calculate { get; set; }
  142. public float Percent60Setpoint { get; set; }
  143. public float Percent60Calculate { get; set; }
  144. public float Percent70Setpoint { get; set; }
  145. public float Percent70Calculate { get; set; }
  146. public float Percent80Setpoint { get; set; }
  147. public float Percent80Calculate { get; set; }
  148. public float Percent90Setpoint { get; set; }
  149. public float Percent90Calculate { get; set; }
  150. public float Percent100Setpoint { get; set; }
  151. public float Percent100Calculate { get; set; }
  152. public float Setpoint { get; set; }
  153. public float Calculate { get; set; }
  154. }
  155. public class MFCVerificationViewModel : ModuleUiViewModelBase, ISupportMultipleSystem
  156. {
  157. public MFCVerificationViewModel()
  158. {
  159. var now = DateTime.Today;
  160. SearchBeginTime = now;
  161. SearchEndTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
  162. }
  163. #region MFCs
  164. #region MFCData
  165. private AITMfcData _mfc1DeviceData;
  166. [Subscription("MfcGas1")]
  167. public AITMfcData MFC1DeviceData
  168. {
  169. get
  170. {
  171. return _mfc1DeviceData;
  172. }
  173. set
  174. {
  175. if (_mfc1DeviceData == null || _mfc1DeviceData.Scale != value.Scale)
  176. {
  177. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  178. {
  179. int delta = (int)value.Scale / 10;
  180. if (MFC1VerificationPoints != null)
  181. MFC1VerificationPoints.Clear();
  182. else
  183. MFC1VerificationPoints = new ObservableCollection<int>();
  184. //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range
  185. for (int i = 0; i < 10; i++)
  186. {
  187. MFC1VerificationPoints.Add(delta + delta * i);
  188. }
  189. }));
  190. }
  191. _mfc1DeviceData = value;
  192. }
  193. }
  194. private AITMfcData _mfc2DeviceData;
  195. [Subscription("MfcGas2")]
  196. public AITMfcData MFC2DeviceData
  197. {
  198. get
  199. {
  200. return _mfc2DeviceData;
  201. }
  202. set
  203. {
  204. if (_mfc2DeviceData == null || _mfc2DeviceData.Scale != value.Scale)
  205. {
  206. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  207. {
  208. int delta = (int)value.Scale / 10;
  209. if (MFC2VerificationPoints != null)
  210. MFC2VerificationPoints.Clear();
  211. else
  212. MFC2VerificationPoints = new ObservableCollection<int>();
  213. //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range
  214. for (int i = 0; i < 10; i++)
  215. {
  216. MFC2VerificationPoints.Add(delta + delta * i);
  217. }
  218. }));
  219. }
  220. _mfc2DeviceData = value;
  221. }
  222. }
  223. private AITMfcData _mfc3DeviceData;
  224. [Subscription("MfcGas3")]
  225. public AITMfcData MFC3DeviceData
  226. {
  227. get
  228. {
  229. return _mfc3DeviceData;
  230. }
  231. set
  232. {
  233. if (_mfc3DeviceData == null || _mfc3DeviceData.Scale != value.Scale)
  234. {
  235. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  236. {
  237. int delta = (int)value.Scale / 10;
  238. if (MFC3VerificationPoints != null)
  239. MFC3VerificationPoints.Clear();
  240. else
  241. MFC3VerificationPoints = new ObservableCollection<int>();
  242. //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range
  243. for (int i = 0; i < 10; i++)
  244. {
  245. MFC3VerificationPoints.Add(delta + delta * i);
  246. }
  247. }));
  248. }
  249. _mfc3DeviceData = value;
  250. }
  251. }
  252. private AITMfcData _mfc4DeviceData;
  253. [Subscription("MfcGas4")]
  254. public AITMfcData MFC4DeviceData
  255. {
  256. get
  257. {
  258. return _mfc4DeviceData;
  259. }
  260. set
  261. {
  262. if (_mfc4DeviceData == null || _mfc4DeviceData.Scale != value.Scale)
  263. {
  264. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  265. {
  266. int delta = (int)value.Scale / 10;
  267. if (MFC4VerificationPoints != null)
  268. MFC4VerificationPoints.Clear();
  269. else
  270. MFC4VerificationPoints = new ObservableCollection<int>();
  271. //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range
  272. for (int i = 0; i < 10; i++)
  273. {
  274. MFC4VerificationPoints.Add(delta + delta * i);
  275. }
  276. }));
  277. }
  278. _mfc4DeviceData = value;
  279. }
  280. }
  281. private AITMfcData _mfc5DeviceData;
  282. [Subscription("MfcGas5")]
  283. public AITMfcData MFC5DeviceData
  284. {
  285. get
  286. {
  287. return _mfc5DeviceData;
  288. }
  289. set
  290. {
  291. if (_mfc5DeviceData == null || _mfc5DeviceData.Scale != value.Scale)
  292. {
  293. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  294. {
  295. int delta = (int)value.Scale / 10;
  296. if (MFC5VerificationPoints != null)
  297. MFC5VerificationPoints.Clear();
  298. else
  299. MFC5VerificationPoints = new ObservableCollection<int>();
  300. //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range
  301. for (int i = 0; i < 10; i++)
  302. {
  303. MFC5VerificationPoints.Add(delta + delta * i);
  304. }
  305. }));
  306. }
  307. _mfc5DeviceData = value;
  308. }
  309. }
  310. #endregion
  311. #region MFCVerificationResult
  312. private string _MFC1VerificationResult;
  313. [Subscription("MfcGas1.VerificationResult")]
  314. public string MFC1VerificationResult
  315. {
  316. get
  317. {
  318. return _MFC1VerificationResult;
  319. }
  320. set
  321. {
  322. if(_MFC1VerificationResult != value)
  323. {
  324. var results = value.Split(';');
  325. if(results != null && results.Length > 0)
  326. {
  327. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  328. {
  329. MFC1VerificationData.Clear();
  330. foreach (var item in results)
  331. {
  332. var onePoint = item.Split(',');
  333. if (onePoint != null && onePoint.Length >= 5)
  334. {
  335. MFC1VerificationData.Add(new MFCVerificationDataListItem()
  336. {
  337. Setpoint = Convert.ToSingle(onePoint[0]),
  338. CalculateValue = Convert.ToSingle(onePoint[1]),
  339. ElapseTime = Convert.ToSingle(onePoint[2]),
  340. Deviation = Convert.ToSingle(onePoint[3]),
  341. Result = onePoint[4],
  342. ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green":"Red",
  343. });
  344. }
  345. else
  346. {
  347. if (onePoint != null && onePoint.Length >= 2)
  348. {
  349. MFC1VerificationData.Add(new MFCVerificationDataListItem()
  350. {
  351. Setpoint = Convert.ToSingle(onePoint[0]),
  352. CalculateValue = Convert.ToSingle(onePoint[1]),
  353. });
  354. }
  355. }
  356. }
  357. }));
  358. }
  359. }
  360. _MFC1VerificationResult = value;
  361. }
  362. }
  363. private string _MFC2VerificationResult;
  364. [Subscription("MfcGas2.VerificationResult")]
  365. public string MFC2VerificationResult
  366. {
  367. get
  368. {
  369. return _MFC2VerificationResult;
  370. }
  371. set
  372. {
  373. if (_MFC2VerificationResult != value)
  374. {
  375. var results = value.Split(';');
  376. if (results != null && results.Length > 0)
  377. {
  378. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  379. {
  380. MFC2VerificationData.Clear();
  381. foreach (var item in results)
  382. {
  383. var onePoint = item.Split(',');
  384. if (onePoint != null && onePoint.Length >= 5)
  385. {
  386. MFC2VerificationData.Add(new MFCVerificationDataListItem()
  387. {
  388. Setpoint = Convert.ToSingle(onePoint[0]),
  389. CalculateValue = Convert.ToSingle(onePoint[1]),
  390. ElapseTime = Convert.ToSingle(onePoint[2]),
  391. Deviation = Convert.ToSingle(onePoint[3]),
  392. Result = onePoint[4],
  393. ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red",
  394. });
  395. }
  396. else
  397. {
  398. if (onePoint != null && onePoint.Length >= 2)
  399. {
  400. MFC2VerificationData.Add(new MFCVerificationDataListItem()
  401. {
  402. Setpoint = Convert.ToSingle(onePoint[0]),
  403. CalculateValue = Convert.ToSingle(onePoint[1]),
  404. });
  405. }
  406. }
  407. }
  408. }));
  409. }
  410. }
  411. _MFC2VerificationResult = value;
  412. }
  413. }
  414. private string _MFC3VerificationResult;
  415. [Subscription("MfcGas3.VerificationResult")]
  416. public string MFC3VerificationResult
  417. {
  418. get
  419. {
  420. return _MFC3VerificationResult;
  421. }
  422. set
  423. {
  424. if (_MFC3VerificationResult != value)
  425. {
  426. var results = value.Split(';');
  427. if (results != null && results.Length > 0)
  428. {
  429. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  430. {
  431. MFC3VerificationData.Clear();
  432. foreach (var item in results)
  433. {
  434. var onePoint = item.Split(',');
  435. if (onePoint != null && onePoint.Length >= 5)
  436. {
  437. MFC3VerificationData.Add(new MFCVerificationDataListItem()
  438. {
  439. Setpoint = Convert.ToSingle(onePoint[0]),
  440. CalculateValue = Convert.ToSingle(onePoint[1]),
  441. ElapseTime = Convert.ToSingle(onePoint[2]),
  442. Deviation = Convert.ToSingle(onePoint[3]),
  443. Result = onePoint[4],
  444. ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red",
  445. });
  446. }
  447. else
  448. {
  449. if (onePoint != null && onePoint.Length >= 2)
  450. {
  451. MFC3VerificationData.Add(new MFCVerificationDataListItem()
  452. {
  453. Setpoint = Convert.ToSingle(onePoint[0]),
  454. CalculateValue = Convert.ToSingle(onePoint[1]),
  455. });
  456. }
  457. }
  458. }
  459. }));
  460. }
  461. }
  462. _MFC3VerificationResult = value;
  463. }
  464. }
  465. private string _MFC4VerificationResult;
  466. [Subscription("MfcGas4.VerificationResult")]
  467. public string MFC4VerificationResult
  468. {
  469. get
  470. {
  471. return _MFC4VerificationResult;
  472. }
  473. set
  474. {
  475. if (_MFC4VerificationResult != value)
  476. {
  477. var results = value.Split(';');
  478. if (results != null && results.Length > 0)
  479. {
  480. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  481. {
  482. MFC4VerificationData.Clear();
  483. foreach (var item in results)
  484. {
  485. var onePoint = item.Split(',');
  486. if (onePoint != null && onePoint.Length >= 5)
  487. {
  488. MFC4VerificationData.Add(new MFCVerificationDataListItem()
  489. {
  490. Setpoint = Convert.ToSingle(onePoint[0]),
  491. CalculateValue = Convert.ToSingle(onePoint[1]),
  492. ElapseTime = Convert.ToSingle(onePoint[2]),
  493. Deviation = Convert.ToSingle(onePoint[3]),
  494. Result = onePoint[4],
  495. ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red",
  496. });
  497. }
  498. else
  499. {
  500. if (onePoint != null && onePoint.Length >= 2)
  501. {
  502. MFC4VerificationData.Add(new MFCVerificationDataListItem()
  503. {
  504. Setpoint = Convert.ToSingle(onePoint[0]),
  505. CalculateValue = Convert.ToSingle(onePoint[1]),
  506. });
  507. }
  508. }
  509. }
  510. }));
  511. }
  512. }
  513. _MFC4VerificationResult = value;
  514. }
  515. }
  516. private string _MFC5VerificationResult;
  517. [Subscription("MfcGas5.VerificationResult")]
  518. public string MFC5VerificationResult
  519. {
  520. get
  521. {
  522. return _MFC5VerificationResult;
  523. }
  524. set
  525. {
  526. if (_MFC5VerificationResult != value)
  527. {
  528. var results = value.Split(';');
  529. if (results != null && results.Length > 0)
  530. {
  531. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  532. {
  533. MFC5VerificationData.Clear();
  534. foreach (var item in results)
  535. {
  536. var onePoint = item.Split(',');
  537. if (onePoint != null && onePoint.Length >= 5)
  538. {
  539. MFC5VerificationData.Add(new MFCVerificationDataListItem()
  540. {
  541. Setpoint = Convert.ToSingle(onePoint[0]),
  542. CalculateValue = Convert.ToSingle(onePoint[1]),
  543. ElapseTime = Convert.ToSingle(onePoint[2]),
  544. Deviation = Convert.ToSingle(onePoint[3]),
  545. Result = onePoint[4],
  546. ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red",
  547. });
  548. }
  549. else
  550. {
  551. if (onePoint != null && onePoint.Length >= 2)
  552. {
  553. MFC5VerificationData.Add(new MFCVerificationDataListItem()
  554. {
  555. Setpoint = Convert.ToSingle(onePoint[0]),
  556. CalculateValue = Convert.ToSingle(onePoint[1]),
  557. });
  558. }
  559. }
  560. }
  561. }));
  562. }
  563. }
  564. _MFC5VerificationResult = value;
  565. }
  566. }
  567. #endregion
  568. public bool MFC1IsEnable { get; set; }
  569. public bool MFC2IsEnable { get; set; }
  570. public bool MFC3IsEnable { get; set; }
  571. public bool MFC4IsEnable { get; set; }
  572. public bool MFC5IsEnable { get; set; }
  573. public bool IsMfc1Checked { get; set; }
  574. public bool IsMfc2Checked { get; set; }
  575. public bool IsMfc3Checked { get; set; }
  576. public bool IsMfc4Checked { get; set; }
  577. public bool IsMfc5Checked { get; set; }
  578. public bool[] IsMfcChecked
  579. {
  580. get
  581. {
  582. bool[] isMfcCheck = new bool[]
  583. {
  584. IsMfc1Checked,
  585. IsMfc2Checked,
  586. IsMfc3Checked,
  587. IsMfc4Checked,
  588. };
  589. return isMfcCheck;
  590. }
  591. }
  592. #endregion
  593. private string _pmStatus;
  594. [Subscription("FsmState")]
  595. public string PMStatus
  596. {
  597. get
  598. {
  599. return _pmStatus;
  600. }
  601. set
  602. {
  603. if (_pmStatus != value)
  604. Query();
  605. _pmStatus = value;
  606. }
  607. }
  608. [Subscription("IsOnline")]
  609. public bool IsOnline { get; set; }
  610. public string Setpoint { get; set; }
  611. public bool IsVerificationButtonEnable => PMStatus == "Idle" && !IsOnline;
  612. public bool IsPermission { get => this.Permission == 3; }
  613. public Visibility MFCQueryVisibility
  614. {
  615. get; set;
  616. }
  617. public ObservableCollection<IRenderableSeries> SelectedData { get; set; }
  618. private IRange _xValueRange;
  619. public IRange XValueRange
  620. {
  621. get { return _xValueRange; }
  622. set { _xValueRange = value; NotifyOfPropertyChange("XValueRange"); }
  623. }
  624. private IRange _yValueRange;
  625. public IRange YValueRange
  626. {
  627. get { return _yValueRange; }
  628. set { _yValueRange = value; NotifyOfPropertyChange("YValueRange"); }
  629. }
  630. public AutoRange ChartAutoRange
  631. {
  632. get { return EnableAutoZoom ? AutoRange.Always : AutoRange.Never; }
  633. }
  634. private bool _enableAutoZoom = true;
  635. public bool EnableAutoZoom
  636. {
  637. get { return _enableAutoZoom; }
  638. set
  639. {
  640. _enableAutoZoom = value;
  641. NotifyOfPropertyChange(nameof(EnableAutoZoom));
  642. NotifyOfPropertyChange(nameof(ChartAutoRange));
  643. }
  644. }
  645. private AutoRange _autoRangeX;
  646. public AutoRange AutoRangeX
  647. {
  648. get => _autoRangeX;
  649. set { _autoRangeX = value; NotifyOfPropertyChange(nameof(AutoRangeX)); }
  650. }
  651. private AutoRange _autoRangeY;
  652. public AutoRange AutoRangeY
  653. {
  654. get => _autoRangeY;
  655. set { _autoRangeY = value; NotifyOfPropertyChange(nameof(AutoRangeY)); }
  656. }
  657. public ObservableCollection<MFCVerificationDataListItem> MFC1VerificationData { get; set; }
  658. public ObservableCollection<MFCVerificationDataListItem> MFC2VerificationData { get; set; }
  659. public ObservableCollection<MFCVerificationDataListItem> MFC3VerificationData { get; set; }
  660. public ObservableCollection<MFCVerificationDataListItem> MFC4VerificationData { get; set; }
  661. public ObservableCollection<MFCVerificationDataListItem> MFC5VerificationData { get; set; }
  662. public ObservableCollection<MFCVerificationErrorRateListItem> VerificationErrorRate { get; set; }
  663. public ObservableCollection<int> MFC1VerificationPoints { get; set; }
  664. public ObservableCollection<int> MFC2VerificationPoints { get; set; }
  665. public ObservableCollection<int> MFC3VerificationPoints { get; set; }
  666. public ObservableCollection<int> MFC4VerificationPoints { get; set; }
  667. public ObservableCollection<int> MFC5VerificationPoints { get; set; }
  668. public ObservableCollection<MFCVerificationData> VerificationDataRecords { get; set; }//read form db
  669. private MFCVerificationData selectedVerificationData;
  670. public MFCVerificationData SelectedVerificationData
  671. {
  672. get { return this.selectedVerificationData; }
  673. set
  674. {
  675. this.selectedVerificationData = value;
  676. }
  677. }
  678. public DateTime SearchBeginTime { get; set; }
  679. public DateTime SearchEndTime { get; set; }
  680. private MFCVerificationView view;
  681. public Visibility MFC1Visibility => MFC1IsEnable ? Visibility.Visible : Visibility.Collapsed;
  682. public Visibility MFC2Visibility => MFC2IsEnable ? Visibility.Visible : Visibility.Collapsed;
  683. public Visibility MFC3Visibility => MFC3IsEnable ? Visibility.Visible : Visibility.Collapsed;
  684. public Visibility MFC4Visibility => MFC4IsEnable ? Visibility.Visible : Visibility.Collapsed;
  685. public string MFC1BackGround => !MFC1IsEnable ? "Gold" : "White";
  686. public string MFC2BackGround => !MFC2IsEnable ? "Gold" : "White";
  687. public string MFC3BackGround => !MFC3IsEnable ? "Gold" : "White";
  688. public string MFC4BackGround => !MFC4IsEnable ? "Gold" : "White";
  689. protected override void OnInitialize()
  690. {
  691. MFC1VerificationData = new ObservableCollection<MFCVerificationDataListItem>();
  692. MFC2VerificationData = new ObservableCollection<MFCVerificationDataListItem>();
  693. MFC3VerificationData = new ObservableCollection<MFCVerificationDataListItem>();
  694. MFC4VerificationData = new ObservableCollection<MFCVerificationDataListItem>();
  695. MFC5VerificationData = new ObservableCollection<MFCVerificationDataListItem>();
  696. MFC1VerificationPoints = new ObservableCollection<int>();
  697. MFC2VerificationPoints = new ObservableCollection<int>();
  698. MFC3VerificationPoints = new ObservableCollection<int>();
  699. MFC4VerificationPoints = new ObservableCollection<int>();
  700. MFC5VerificationPoints = new ObservableCollection<int>();
  701. MFCQueryVisibility = Visibility.Collapsed;
  702. base.OnInitialize();
  703. YValueRange = new DoubleRange(0, 100);
  704. SelectedData = new ObservableCollection<IRenderableSeries>();
  705. AutoRangeX = AutoRange.Always;
  706. AutoRangeY = AutoRange.Always;//(bool)QueryDataClient.Instance.Service.GetConfig("System.IsCycleMode");
  707. }
  708. protected override void OnActivate()
  709. {
  710. XValueRange = new DoubleRange(0, MFC1DeviceData != null ? MFC1DeviceData.Scale : 100);
  711. base.OnActivate();
  712. Query();
  713. MFC1IsEnable = true;
  714. MFC2IsEnable = true;
  715. MFC3IsEnable = true;
  716. MFC4IsEnable = true;
  717. MFC5IsEnable = true;
  718. }
  719. protected override void OnViewLoaded(object _view)
  720. {
  721. base.OnViewLoaded(_view);
  722. this.view = (MFCVerificationView)_view;
  723. this.view.wfTimeFrom.Value = this.SearchBeginTime;
  724. this.view.wfTimeTo.Value = this.SearchEndTime;
  725. Query();
  726. }
  727. protected override void OnDeactivate(bool close)
  728. {
  729. base.OnDeactivate(close);
  730. }
  731. public void StartVerification(object oj1, object oj2, object oj3)
  732. {
  733. string gasName = oj1.ToString();
  734. float.TryParse(oj2.ToString(), out float flow);
  735. int.TryParse(oj3.ToString(), out int flowCount);
  736. InvokeClient.Instance.Service.DoOperation($"{SystemName}.MFCVerification", gasName, flow, flowCount);
  737. }
  738. public void StartAllCali()
  739. {
  740. bool IsSelectedMFC = false;
  741. foreach (bool IsCheck in IsMfcChecked)
  742. {
  743. if (IsCheck)
  744. IsSelectedMFC = true;
  745. }
  746. if (!IsSelectedMFC)
  747. {
  748. MessageBox.Show("Please select at least one Gas.", "Calibration", MessageBoxButton.OK, MessageBoxImage.Warning);
  749. return;
  750. }
  751. string[] gasName = new string[] { "MFC1", "MFC2", "MFC3", "MFC4" };
  752. InvokeClient.Instance.Service.DoOperation($"{SystemName}.AllMFCVerification", gasName, IsMfcChecked);
  753. }
  754. public void AcceptAll(object o)
  755. {
  756. string gasName = o.ToString();
  757. InvokeClient.Instance.Service.DoOperation($"{SystemName}.{gasName}.AcceptAllMFCVerification", gasName);
  758. }
  759. public void Back()
  760. {
  761. MFCQueryVisibility = Visibility.Collapsed;
  762. NotifyOfPropertyChange("RFCalVisibility");
  763. NotifyOfPropertyChange("MFCQueryVisibility");
  764. }
  765. public void SelectHistory()
  766. {
  767. if (SelectedVerificationData != null)
  768. {
  769. try
  770. {
  771. if (SelectedVerificationData.Name.Contains("Gas1"))
  772. XValueRange = new DoubleRange(0, MFC1DeviceData.Scale);
  773. else if (SelectedVerificationData.Name.Contains("Gas2"))
  774. XValueRange = new DoubleRange(0, MFC2DeviceData.Scale);
  775. else if (SelectedVerificationData.Name.Contains("Gas3"))
  776. XValueRange = new DoubleRange(0, MFC3DeviceData.Scale);
  777. else
  778. XValueRange = new DoubleRange(0, MFC4DeviceData.Scale);
  779. MFCQueryVisibility = Visibility.Visible;
  780. NotifyOfPropertyChange("MFCQueryVisibility");
  781. VerificationErrorRate = new ObservableCollection<MFCVerificationErrorRateListItem>();
  782. MFCVerificationErrorRateListItem errorRate = new MFCVerificationErrorRateListItem()
  783. {
  784. Setpoint = SelectedVerificationData.Percent10Setpoint,
  785. CalculateValue = SelectedVerificationData.Percent10Calculate,
  786. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent10Setpoint - SelectedVerificationData.Percent10Calculate) / SelectedVerificationData.Percent10Setpoint * 100, 3))
  787. };
  788. VerificationErrorRate.Add(errorRate);
  789. errorRate = new MFCVerificationErrorRateListItem()
  790. {
  791. Setpoint = SelectedVerificationData.Percent20Setpoint,
  792. CalculateValue = SelectedVerificationData.Percent20Calculate,
  793. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent20Setpoint - SelectedVerificationData.Percent20Calculate) / SelectedVerificationData.Percent20Setpoint * 100, 3))
  794. };
  795. VerificationErrorRate.Add(errorRate);
  796. errorRate = new MFCVerificationErrorRateListItem()
  797. {
  798. Setpoint = SelectedVerificationData.Percent30Setpoint,
  799. CalculateValue = SelectedVerificationData.Percent30Calculate,
  800. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent30Setpoint - SelectedVerificationData.Percent30Calculate) / SelectedVerificationData.Percent30Setpoint * 100, 3))
  801. };
  802. VerificationErrorRate.Add(errorRate);
  803. errorRate = new MFCVerificationErrorRateListItem()
  804. {
  805. Setpoint = SelectedVerificationData.Percent40Setpoint,
  806. CalculateValue = SelectedVerificationData.Percent40Calculate,
  807. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent40Setpoint - SelectedVerificationData.Percent40Calculate) / SelectedVerificationData.Percent40Setpoint * 100, 3))
  808. };
  809. VerificationErrorRate.Add(errorRate);
  810. errorRate = new MFCVerificationErrorRateListItem()
  811. {
  812. Setpoint = SelectedVerificationData.Percent50Setpoint,
  813. CalculateValue = SelectedVerificationData.Percent50Calculate,
  814. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent50Setpoint - SelectedVerificationData.Percent50Calculate) / SelectedVerificationData.Percent50Setpoint * 100, 3))
  815. };
  816. VerificationErrorRate.Add(errorRate);
  817. errorRate = new MFCVerificationErrorRateListItem()
  818. {
  819. Setpoint = SelectedVerificationData.Percent60Setpoint,
  820. CalculateValue = SelectedVerificationData.Percent60Calculate,
  821. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent60Setpoint - SelectedVerificationData.Percent60Calculate) / SelectedVerificationData.Percent60Setpoint * 100, 3))
  822. };
  823. VerificationErrorRate.Add(errorRate);
  824. errorRate = new MFCVerificationErrorRateListItem()
  825. {
  826. Setpoint = SelectedVerificationData.Percent70Setpoint,
  827. CalculateValue = SelectedVerificationData.Percent70Calculate,
  828. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent70Setpoint - SelectedVerificationData.Percent70Calculate) / SelectedVerificationData.Percent70Setpoint * 100, 3))
  829. };
  830. VerificationErrorRate.Add(errorRate);
  831. errorRate = new MFCVerificationErrorRateListItem()
  832. {
  833. Setpoint = SelectedVerificationData.Percent80Setpoint,
  834. CalculateValue = SelectedVerificationData.Percent80Calculate,
  835. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent80Setpoint - SelectedVerificationData.Percent80Calculate) / SelectedVerificationData.Percent80Setpoint * 100, 3))
  836. };
  837. VerificationErrorRate.Add(errorRate);
  838. errorRate = new MFCVerificationErrorRateListItem()
  839. {
  840. Setpoint = SelectedVerificationData.Percent90Setpoint,
  841. CalculateValue = SelectedVerificationData.Percent90Calculate,
  842. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent90Setpoint - SelectedVerificationData.Percent90Calculate) / SelectedVerificationData.Percent90Setpoint * 100, 3))
  843. };
  844. VerificationErrorRate.Add(errorRate);
  845. errorRate = new MFCVerificationErrorRateListItem()
  846. {
  847. Setpoint = SelectedVerificationData.Percent100Setpoint,
  848. CalculateValue = SelectedVerificationData.Percent100Calculate,
  849. ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent100Setpoint - SelectedVerificationData.Percent100Calculate) / SelectedVerificationData.Percent100Setpoint * 100, 3))
  850. };
  851. VerificationErrorRate.Add(errorRate);//SelectedData
  852. ChartDataLine line = new ChartDataLine("MFCCalibration");
  853. VerificationErrorRate.ToList().ForEach(x => line.Append(x.Setpoint, x.ErrorRate));
  854. //foreach(var item in VerificationErrorRate)
  855. //{
  856. // line.Append(item.Setpoint,item.ErrorRate);
  857. //}
  858. SelectedData.Clear();
  859. SelectedData.Add(line);
  860. }
  861. catch (Exception ex)
  862. {
  863. LOG.Write(ex);
  864. }
  865. }
  866. }
  867. /// <summary>
  868. /// 查询
  869. /// </summary>
  870. public void Query()
  871. {
  872. if (view == null || view.wfTimeFrom == null || view.wfTimeFrom == null)
  873. return;
  874. try
  875. {
  876. this.SearchBeginTime = (System.DateTime)this.view.wfTimeFrom.Value;
  877. this.SearchEndTime = (System.DateTime)this.view.wfTimeTo.Value;
  878. if (SearchBeginTime > SearchEndTime)
  879. {
  880. MessageBox.Show("Time range invalid, start time should be early than end time");
  881. return;
  882. }
  883. string sql = string.Format(
  884. "SELECT * FROM \"mfc_verification_data\" where \"operate_time\" >= '{0}' and \"operate_time\" <= '{1}' and \"module\" = '{2}' order by \"operate_time\" ASC;",
  885. SearchBeginTime.ToString("yyyyMMdd HHmmss"), SearchEndTime.ToString("yyyyMMdd HHmmss"), SystemName);
  886. var result = QueryDataClient.Instance.Service.QueryData(sql);
  887. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  888. {
  889. VerificationDataRecords = new ObservableCollection<MFCVerificationData>();
  890. for (int i = 0; i < result.Rows.Count; i++)
  891. {
  892. MFCVerificationData data = new MFCVerificationData()
  893. {
  894. Module = result.Rows[i]["module"].ToString(),
  895. Name = result.Rows[i]["name"].ToString(),
  896. Time = ((DateTime)result.Rows[i]["operate_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff"),
  897. Percent10Setpoint = float.Parse(result.Rows[i]["percent10_setpoint"].ToString()),
  898. Percent10Calculate = float.Parse(result.Rows[i]["percent10_calculate"].ToString()),
  899. Percent20Setpoint = float.Parse(result.Rows[i]["percent20_setpoint"].ToString()),
  900. Percent20Calculate = float.Parse(result.Rows[i]["percent20_calculate"].ToString()),
  901. Percent30Setpoint = float.Parse(result.Rows[i]["percent30_setpoint"].ToString()),
  902. Percent30Calculate = float.Parse(result.Rows[i]["percent30_calculate"].ToString()),
  903. Percent40Setpoint = float.Parse(result.Rows[i]["percent40_setpoint"].ToString()),
  904. Percent40Calculate = float.Parse(result.Rows[i]["percent40_calculate"].ToString()),
  905. Percent50Setpoint = float.Parse(result.Rows[i]["percent50_setpoint"].ToString()),
  906. Percent50Calculate = float.Parse(result.Rows[i]["percent50_calculate"].ToString()),
  907. Percent60Setpoint = float.Parse(result.Rows[i]["percent60_setpoint"].ToString()),
  908. Percent60Calculate = float.Parse(result.Rows[i]["percent60_calculate"].ToString()),
  909. Percent70Setpoint = float.Parse(result.Rows[i]["percent70_setpoint"].ToString()),
  910. Percent70Calculate = float.Parse(result.Rows[i]["percent70_calculate"].ToString()),
  911. Percent80Setpoint = float.Parse(result.Rows[i]["percent80_setpoint"].ToString()),
  912. Percent80Calculate = float.Parse(result.Rows[i]["percent80_calculate"].ToString()),
  913. Percent90Setpoint = float.Parse(result.Rows[i]["percent90_setpoint"].ToString()),
  914. Percent90Calculate = float.Parse(result.Rows[i]["percent90_calculate"].ToString()),
  915. Percent100Setpoint = float.Parse(result.Rows[i]["percent100_setpoint"].ToString()),
  916. Percent100Calculate = float.Parse(result.Rows[i]["percent100_calculate"].ToString()),
  917. Setpoint = float.Parse(result.Rows[i]["setpoint"].ToString()),
  918. Calculate = float.Parse(result.Rows[i]["calculate"].ToString()),
  919. };
  920. VerificationDataRecords.Add(data);
  921. }
  922. NotifyOfPropertyChange("VerificationDataRecords");
  923. }));
  924. }
  925. catch (Exception ex)
  926. {
  927. LOG.Write(ex);
  928. }
  929. }
  930. public void SetAsCurrent(object o)
  931. {
  932. int.TryParse(o.ToString(), out int selectIndex);
  933. if (selectIndex < 0 || selectIndex >= VerificationDataRecords.Count)
  934. {
  935. MessageBox.Show("Please select a row to set.", "Calibration", MessageBoxButton.OK, MessageBoxImage.Warning);
  936. return;
  937. }
  938. InvokeClient.Instance.Service.DoOperation($"{SystemName}.{VerificationDataRecords[selectIndex].Name}.UpdateCalibrationInfo",
  939. VerificationDataRecords[selectIndex].Percent10Calculate,
  940. VerificationDataRecords[selectIndex].Percent20Calculate,
  941. VerificationDataRecords[selectIndex].Percent30Calculate,
  942. VerificationDataRecords[selectIndex].Percent40Calculate,
  943. VerificationDataRecords[selectIndex].Percent50Calculate,
  944. VerificationDataRecords[selectIndex].Percent60Calculate,
  945. VerificationDataRecords[selectIndex].Percent70Calculate,
  946. VerificationDataRecords[selectIndex].Percent80Calculate,
  947. VerificationDataRecords[selectIndex].Percent90Calculate,
  948. VerificationDataRecords[selectIndex].Percent100Calculate);
  949. }
  950. public void Abort()
  951. {
  952. InvokeClient.Instance.Service.DoOperation($"{SystemName}.Abort");
  953. }
  954. }
  955. public class ChartDataLine : FastLineRenderableSeries, INotifyPropertyChanged
  956. {
  957. #region PropertyChanged
  958. public event PropertyChangedEventHandler PropertyChanged;
  959. public void InvokePropertyChanged(string propertyName)
  960. {
  961. PropertyChangedEventArgs eventArgs = new PropertyChangedEventArgs(propertyName);
  962. PropertyChangedEventHandler changed = PropertyChanged;
  963. if (changed != null)
  964. {
  965. changed(this, eventArgs);
  966. }
  967. }
  968. public void InvokePropertyChanged()
  969. {
  970. Type t = this.GetType();
  971. var ps = t.GetProperties();
  972. foreach (var p in ps)
  973. {
  974. InvokePropertyChanged(p.Name);
  975. }
  976. }
  977. #endregion
  978. public string UniqueId { get; set; }
  979. public List<Tuple<double, double>> Points
  980. {
  981. get
  982. {
  983. lock (_lockData)
  984. {
  985. return _queueRawData.ToList();
  986. }
  987. }
  988. }
  989. public string DataSource { get; set; }
  990. public string DataName { get; set; }
  991. public string DisplayName
  992. {
  993. get
  994. {
  995. return DataSeries.SeriesName;
  996. }
  997. set
  998. {
  999. DataSeries.SeriesName = value;
  1000. }
  1001. }
  1002. public double LineThickness
  1003. {
  1004. get
  1005. {
  1006. return StrokeThickness;
  1007. }
  1008. set
  1009. {
  1010. var i = Convert.ToInt32(value);
  1011. if (i < 1) i = 1;
  1012. if (i > 100) i = 100;
  1013. StrokeThickness = i;
  1014. InvokePropertyChanged("LineThickness");
  1015. }
  1016. }
  1017. private double _dataFactor = 1.0;
  1018. public double DataFactor
  1019. {
  1020. get => _dataFactor;
  1021. set
  1022. {
  1023. if (Math.Abs(_dataFactor - value) > 0.001)
  1024. {
  1025. _dataFactor = value;
  1026. InvokePropertyChanged(nameof(DataFactor));
  1027. UpdateChartSeriesValue();
  1028. }
  1029. }
  1030. }
  1031. private double _dataOffset = 0;
  1032. public double DataOffset
  1033. {
  1034. get => _dataOffset;
  1035. set
  1036. {
  1037. if (Math.Abs(_dataOffset - value) > 0.001)
  1038. {
  1039. _dataOffset = value;
  1040. InvokePropertyChanged(nameof(DataFactor));
  1041. UpdateChartSeriesValue();
  1042. }
  1043. }
  1044. }
  1045. private int _capacity = 10000;
  1046. public int Capacity
  1047. {
  1048. get { return _capacity; }
  1049. set
  1050. {
  1051. _capacity = value;
  1052. DataSeries.FifoCapacity = value;
  1053. }
  1054. }
  1055. private object _lockData = new object();
  1056. private FixSizeQueue<Tuple<double, double>> _queueRawData;
  1057. public ChartDataLine(string dataName)
  1058. : this(dataName, dataName, Colors.Blue)
  1059. {
  1060. }
  1061. public ChartDataLine(string dataName, string displayName, Color seriesColor)
  1062. {
  1063. UniqueId = Guid.NewGuid().ToString();
  1064. _queueRawData = new FixSizeQueue<Tuple<double, double>>(_capacity);
  1065. XAxisId = "DefaultAxisId";
  1066. YAxisId = "DefaultAxisId";
  1067. DataSeries = new XyDataSeries<double, double>(_capacity);
  1068. DisplayName = displayName;
  1069. DataName = dataName;
  1070. Stroke = seriesColor;
  1071. IsVisible = true;
  1072. DataOffset = 0;
  1073. LineThickness = 1;
  1074. DataFactor = 1;
  1075. }
  1076. public void Append(double dt, double value)
  1077. {
  1078. lock (_lockData)
  1079. {
  1080. _queueRawData.Enqueue(Tuple.Create(dt, value));
  1081. (DataSeries as XyDataSeries<double, double>)?.Append(dt, value * _dataFactor + _dataOffset);
  1082. }
  1083. }
  1084. public void UpdateChartSeriesValue()
  1085. {
  1086. lock (_lockData)
  1087. {
  1088. using (DataSeries.SuspendUpdates())
  1089. {
  1090. XyDataSeries<double, double> s = DataSeries as XyDataSeries<double, double>;
  1091. for (int i = 0; i < s.Count; i++)
  1092. {
  1093. s.Update(i, _queueRawData.ElementAt(i).Item2 * _dataFactor + _dataOffset);
  1094. }
  1095. }
  1096. }
  1097. }
  1098. public void ClearData()
  1099. {
  1100. lock (_lockData)
  1101. {
  1102. _queueRawData.Clear();
  1103. (DataSeries as XyDataSeries<double, double>)?.Clear();
  1104. }
  1105. }
  1106. }
  1107. }