SingleDetailItem.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. using MeterVision.db;
  2. using MeterVision.FreeAi;
  3. using MeterVision.Util;
  4. using System;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Windows;
  8. namespace MeterVision.model
  9. {
  10. public class SingleDetailItem : INotifyPropertyChanged
  11. {
  12. public event PropertyChangedEventHandler PropertyChanged;
  13. // 触发属性变更通知
  14. protected virtual void OnPropertyChanged(string propertyName)
  15. {
  16. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  17. }
  18. private int _index;
  19. public int Index
  20. {
  21. get => _index;
  22. set
  23. {
  24. if (_index != value)
  25. {
  26. _index = value;
  27. OnPropertyChanged(nameof(Index));
  28. }
  29. }
  30. }
  31. private string _singleDetailId;
  32. public string SingleDetailId
  33. {
  34. get => _singleDetailId;
  35. set
  36. {
  37. if (_singleDetailId != value)
  38. {
  39. _singleDetailId = value;
  40. OnPropertyChanged(nameof(SingleDetailId));
  41. }
  42. }
  43. }
  44. private string _createTime;
  45. public string CreateTime
  46. {
  47. get => _createTime;
  48. set
  49. {
  50. if (_createTime != value)
  51. {
  52. _createTime = value;
  53. OnPropertyChanged(nameof(CreateTime));
  54. }
  55. }
  56. }
  57. private string _srcImage;
  58. public string SrcImage
  59. {
  60. get => _srcImage;
  61. set
  62. {
  63. if (_srcImage != value)
  64. {
  65. _srcImage = value;
  66. OnPropertyChanged(nameof(SrcImage));
  67. }
  68. }
  69. }
  70. private int _runFlag;
  71. public int RunFlag
  72. {
  73. get => _runFlag;
  74. set
  75. {
  76. if (_runFlag != value)
  77. {
  78. _runFlag = value;
  79. OnPropertyChanged(nameof(RunFlag));
  80. OnPropertyChanged(nameof(ResultVisiable)); // 依赖 RunFlag 更新 ResultVisiable
  81. }
  82. }
  83. }
  84. private string _runTime;
  85. public string RunTime
  86. {
  87. get => _runTime;
  88. set
  89. {
  90. if (_runTime != value)
  91. {
  92. _runTime = value;
  93. OnPropertyChanged(nameof(RunTime));
  94. OnPropertyChanged(nameof(RunTime_date)); // 依赖 RunTime 更新 RunTIme_date
  95. OnPropertyChanged(nameof(RunTime_time)); // 依赖 RunTime 更新 RunTIme_time
  96. }
  97. }
  98. }
  99. public string RunTime_date => ThisApp.ConvertDateFormat_Date(RunTime);
  100. public string RunTime_time => ThisApp.ConvertDateFormat_Time(RunTime);
  101. private string _dstIamge;
  102. public string DstImage
  103. {
  104. get => _dstIamge;
  105. set
  106. {
  107. if (_dstIamge != value)
  108. {
  109. _dstIamge = value;
  110. OnPropertyChanged(nameof(DstImage));
  111. }
  112. }
  113. }
  114. private int _meterType;
  115. public int MeterType
  116. {
  117. get => _meterType;
  118. set
  119. {
  120. if (_meterType != value)
  121. {
  122. _meterType = value;
  123. OnPropertyChanged(nameof(MeterType));
  124. OnPropertyChanged(nameof(MeterTypeName)); // 依赖 MeterType 更新 MeterTypeName
  125. OnPropertyChanged(nameof(FeatureRegionName));
  126. OnPropertyChanged(nameof(MeterRegionName));
  127. OnPropertyChanged(nameof(NumInUpper));
  128. OnPropertyChanged(nameof(LastUnitName2));
  129. OnPropertyChanged(nameof(FinalValueName2));
  130. }
  131. }
  132. }
  133. public string MeterTypeName => Get_MeterTypeName();
  134. private int _digitCount;
  135. public int DigitCount
  136. {
  137. get => _digitCount;
  138. set
  139. {
  140. if (_digitCount != value)
  141. {
  142. _digitCount = value;
  143. OnPropertyChanged(nameof(DigitCount));
  144. OnPropertyChanged(nameof(NumCountName)); // 依赖 DigitCount 更新 NumCountName
  145. }
  146. }
  147. }
  148. private int _pointerCount;
  149. public int PointerCount
  150. {
  151. get => _pointerCount;
  152. set
  153. {
  154. if (_pointerCount != value)
  155. {
  156. _pointerCount = value;
  157. OnPropertyChanged(nameof(PointerCount));
  158. OnPropertyChanged(nameof(NumCountName)); // 依赖 PointerCount 更新 NumCountName
  159. }
  160. }
  161. }
  162. public string NumCountName => Get_NumCountName();
  163. private double _lastUnit;
  164. public double LastUnit
  165. {
  166. get => _lastUnit;
  167. set
  168. {
  169. if (_lastUnit != value)
  170. {
  171. _lastUnit = value;
  172. OnPropertyChanged(nameof(LastUnit));
  173. OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
  174. OnPropertyChanged(nameof(FinalValueName2));
  175. OnPropertyChanged(nameof(LastUnitName2));
  176. }
  177. }
  178. }
  179. public string LastUnitName
  180. {
  181. get
  182. {
  183. if(MeterType > 0)
  184. {
  185. return $"尾数: {LastUnit}m³";
  186. }
  187. else
  188. {
  189. return "";
  190. }
  191. }
  192. }
  193. public string LastUnitName2
  194. {
  195. get
  196. {
  197. if(LastUnit == double.MaxValue)
  198. {
  199. return "";
  200. }
  201. return LastUnit.ToString();
  202. }
  203. }
  204. public int _numInUpper;
  205. public int NumInUpper
  206. {
  207. get => _numInUpper;
  208. set
  209. {
  210. if(_numInUpper != value)
  211. {
  212. _numInUpper = value;
  213. OnPropertyChanged(nameof(NumInUpper));
  214. OnPropertyChanged(nameof(NumInUpperName));
  215. }
  216. }
  217. }
  218. public string NumInUpperName
  219. {
  220. get
  221. {
  222. if (MeterType == 1 || MeterType == 3)
  223. {
  224. return $"数字在上: {(NumInUpper == 1 ? "是" : "否")}";
  225. }
  226. else
  227. {
  228. return "";
  229. }
  230. }
  231. }
  232. private int _resultType;
  233. public int ResultType
  234. {
  235. get => _resultType;
  236. set
  237. {
  238. if (_resultType != value)
  239. {
  240. _resultType = value;
  241. OnPropertyChanged(nameof(ResultType));
  242. OnPropertyChanged(nameof(ResultTypeColor)); // 依赖 ResultType 更新 ResultTypeColor
  243. }
  244. }
  245. }
  246. public string ResultTypeColor => Get_ResultTypeColor();
  247. private long _rawValue;
  248. public long RawValue
  249. {
  250. get => _rawValue;
  251. set
  252. {
  253. if (_rawValue != value)
  254. {
  255. _rawValue = value;
  256. if (MeterType == 0)
  257. {
  258. _rawValue = -1;
  259. }
  260. OnPropertyChanged(nameof(RawValue));
  261. }
  262. }
  263. }
  264. private long _finalValue;
  265. public long FinalValue
  266. {
  267. get => _finalValue;
  268. set
  269. {
  270. if (_finalValue != value)
  271. {
  272. _finalValue = value;
  273. //if(MeterType == 0)
  274. //{
  275. // _finalValue = "";
  276. //}
  277. OnPropertyChanged(nameof(FinalValue));
  278. OnPropertyChanged(nameof(FinalValue2));
  279. OnPropertyChanged(nameof(FinalValueName2));
  280. OnPropertyChanged(nameof(LastUnitName2));
  281. }
  282. }
  283. }
  284. //public double FinalValue2 => (double)(FinalValue / (double)10000);
  285. public string FinalValue2
  286. {
  287. get
  288. {
  289. if(FinalValue == long.MaxValue)
  290. {
  291. return "";
  292. }
  293. else
  294. {
  295. return ((double)(FinalValue / (double)10000)).ToString();
  296. }
  297. }
  298. }
  299. public string FinalValueName2
  300. {
  301. get
  302. {
  303. if (FinalValue == long.MaxValue)
  304. {
  305. return "";
  306. }
  307. else
  308. {
  309. if (LastUnit != double.MaxValue)
  310. {
  311. string valueStr = LastUnit.ToString(); //LastUnit.ToString("G17");
  312. int decimalIndex = valueStr.IndexOf('.');
  313. int decimalPlaces = 0;
  314. if (decimalIndex == -1)
  315. {
  316. decimalPlaces = 0;
  317. }
  318. else
  319. {
  320. decimalPlaces = valueStr.Length - decimalIndex - 1;
  321. }
  322. int iValue = (int)(FinalValue / (FaConstant.CUBE_VALUE * LastUnit));
  323. double dValue = iValue * LastUnit;
  324. return dValue.ToString($"F{decimalPlaces}");
  325. }
  326. else
  327. {
  328. return ((double)FinalValue / FaConstant.CUBE_VALUE).ToString();
  329. }
  330. }
  331. }
  332. }
  333. private long _completeValue;
  334. public long CompleteValue
  335. {
  336. get => _completeValue;
  337. set
  338. {
  339. if(_completeValue != value)
  340. {
  341. _completeValue = value;
  342. OnPropertyChanged(nameof(CompleteValue));
  343. }
  344. }
  345. }
  346. //AI识别出的水表类型
  347. private int _resultMeter;
  348. public int ResultMeter
  349. {
  350. get => _resultMeter;
  351. set
  352. {
  353. if (_resultMeter != value)
  354. {
  355. _resultMeter = value;
  356. OnPropertyChanged(nameof(ResultMeter));
  357. }
  358. }
  359. }
  360. private string _aiVer;
  361. public string AiVer
  362. {
  363. get => _aiVer;
  364. set
  365. {
  366. if (_aiVer != value)
  367. {
  368. _aiVer = value;
  369. OnPropertyChanged(nameof(AiVer));
  370. }
  371. }
  372. }
  373. private string _debugInfo;
  374. public string DebugInfo
  375. {
  376. get => _debugInfo;
  377. set
  378. {
  379. if (_debugInfo != value)
  380. {
  381. _debugInfo = value;
  382. OnPropertyChanged(nameof(DebugInfo));
  383. OnPropertyChanged(nameof(AI_result_array)); // 依赖 DebugInfo 更新 AI_result_array
  384. }
  385. }
  386. }
  387. public string[] AI_result_array => Get_DebugInfoArray();
  388. private string _logPath;
  389. public string LogPath
  390. {
  391. get => _logPath;
  392. set
  393. {
  394. if (_logPath != value)
  395. {
  396. _logPath = value;
  397. OnPropertyChanged(nameof(LogPath));
  398. }
  399. }
  400. }
  401. private string _memo;
  402. public string Memo
  403. {
  404. get => _memo;
  405. set
  406. {
  407. if (_memo != value)
  408. {
  409. _memo = value;
  410. OnPropertyChanged(nameof(Memo));
  411. }
  412. }
  413. }
  414. private double _brightVal;
  415. public double BrightVal
  416. {
  417. get => _brightVal;
  418. set
  419. {
  420. if(_brightVal != value)
  421. {
  422. _brightVal = value;
  423. OnPropertyChanged(nameof(BrightVal));
  424. OnPropertyChanged(nameof(BrightValName));
  425. }
  426. }
  427. }
  428. public string BrightValName => $"亮度: {BrightVal}";
  429. private int _flowRate;
  430. public int FlowRate
  431. {
  432. get => _flowRate;
  433. set
  434. {
  435. if(_flowRate != value)
  436. {
  437. _flowRate = value;
  438. OnPropertyChanged(nameof(FlowRate));
  439. OnPropertyChanged(nameof(FlowRateName));
  440. }
  441. }
  442. }
  443. public string FlowRateName
  444. {
  445. get => $"最大流量: {FlowRate}";
  446. }
  447. private string _meterRegion;
  448. public string MeterRegion
  449. {
  450. get => _meterRegion;
  451. set
  452. {
  453. if(_meterRegion != value)
  454. {
  455. _meterRegion = value;
  456. OnPropertyChanged(nameof(MeterRegion));
  457. OnPropertyChanged(nameof(MeterRegionName));
  458. }
  459. }
  460. }
  461. public string MeterRegionName
  462. {
  463. get
  464. {
  465. if (!string.IsNullOrEmpty(MeterRegion))
  466. {
  467. return $"表盘: {MeterRegion}";
  468. }
  469. return "";
  470. }
  471. }
  472. private string _featureRegion;
  473. public string FeatureRegion
  474. {
  475. get => _featureRegion;
  476. set
  477. {
  478. if(_featureRegion != value)
  479. {
  480. _featureRegion = value;
  481. OnPropertyChanged(nameof(FeatureRegion));
  482. OnPropertyChanged(nameof(FeatureRegionName));
  483. }
  484. }
  485. }
  486. public string FeatureRegionName
  487. {
  488. get
  489. {
  490. if (!string.IsNullOrEmpty(FeatureRegion))
  491. {
  492. if (MeterType == 1 || MeterType == 3)
  493. {
  494. return "数字区域: \n" + FeatureRegion;
  495. }
  496. else if (MeterType == 2)
  497. {
  498. return "首位指针: \n" + FeatureRegion;
  499. }
  500. else
  501. {
  502. return "";
  503. }
  504. }
  505. else
  506. {
  507. return "";
  508. }
  509. }
  510. }
  511. private double _lastValue;
  512. public double LastValue
  513. {
  514. get => _lastValue;
  515. set
  516. {
  517. if(_lastValue != value)
  518. {
  519. _lastValue = value;
  520. OnPropertyChanged(nameof(LastValue));
  521. OnPropertyChanged(nameof(LastValueName));
  522. }
  523. }
  524. }
  525. public string LastValueName => $"初值: {LastValue}";
  526. private string _lastTime;
  527. public string LastTime
  528. {
  529. get => _lastTime;
  530. set
  531. {
  532. if(_lastTime != value)
  533. {
  534. _lastTime = value;
  535. OnPropertyChanged(nameof(LastTime));
  536. OnPropertyChanged(nameof(LastTimeName1));
  537. OnPropertyChanged(nameof(LastTimeName2));
  538. }
  539. }
  540. }
  541. public string LastTimeName1 => ThisApp.ConvertDateFormat_Date(LastTime);
  542. public string LastTimeName2 => ThisApp.ConvertDateFormat_Time(LastTime);
  543. private string _deviceSn;
  544. public string DeviceSn
  545. {
  546. get => _deviceSn;
  547. set
  548. {
  549. if(_deviceSn != value)
  550. {
  551. _deviceSn = value;
  552. OnPropertyChanged(nameof(DeviceSn));
  553. }
  554. }
  555. }
  556. private string _sampleTime;
  557. public string SampleTime
  558. {
  559. get => _sampleTime;
  560. set
  561. {
  562. if(_sampleTime != value)
  563. {
  564. _sampleTime = value;
  565. OnPropertyChanged(nameof(SampleTime));
  566. }
  567. }
  568. }
  569. public Visibility ResultVisiable => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
  570. public SingleDetailItem() { }
  571. public SingleDetailItem(TSingleDetail singleDetail)
  572. {
  573. ObjectHelper.CopyMatchingFields(singleDetail, this);
  574. }
  575. private string Get_MeterTypeName()
  576. {
  577. switch (MeterType)
  578. {
  579. case 0:
  580. return "未识别出";
  581. case 1:
  582. return "数字+指针";
  583. case 2:
  584. return "全指针";
  585. case 3:
  586. return "全数字";
  587. case 4:
  588. return "LED表";
  589. case 5:
  590. return "压力表";
  591. case 88:
  592. return "无法摆正";
  593. case 90:
  594. return "概率太低";
  595. default:
  596. if(MeterType == int.MaxValue)
  597. {
  598. return "";
  599. }
  600. else
  601. {
  602. return "未知值";
  603. }
  604. //return "";
  605. //return "非水表";
  606. }
  607. }
  608. private string Get_NumCountName()
  609. {
  610. switch (MeterType)
  611. {
  612. case 1:
  613. return $"数字: {DigitCount} 指针: {PointerCount}";
  614. case 2:
  615. return $"指针: {PointerCount}";
  616. case 3:
  617. return $"数字: {DigitCount}";
  618. default:
  619. return string.Empty;
  620. }
  621. }
  622. private string Get_ResultTypeColor()
  623. {
  624. switch (ResultType)
  625. {
  626. case 1:
  627. case 2:
  628. case 7:
  629. case 8:
  630. return "#67c23a"; // 绿色
  631. default:
  632. return "#e6a23c"; // 橙色
  633. }
  634. }
  635. private string[] Get_DebugInfoArray()
  636. {
  637. string[] sInfos = DebugInfo.Split(',');
  638. if (sInfos.Length != 24)
  639. {
  640. sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
  641. }
  642. return sInfos.ToArray();
  643. //return sInfos.Select(s => s == "88" ? "" : s).ToArray();
  644. }
  645. // complete_value = @CompleteValue,
  646. // result_meter = @ResultMeter,
  647. // new SQLiteParameter("@CompleteValue", detail.CompleteValue),
  648. // new SQLiteParameter("@ResultMeter", detail.ResultMeter),
  649. //CompleteValue = reader.GetString(reader.GetOrdinal("complete_value")),
  650. //ResultMeter = reader.GetInt32(reader.GetOrdinal("result_meter")),
  651. //DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
  652. //SampleTime = reader.GetString(reader.GetOrdinal("sample_time")),
  653. //-------------------------------------------------
  654. }
  655. }