SingleDetailItem.cs 17 KB

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