SingleDetailItem.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. }
  127. }
  128. }
  129. public string MeterTypeName => Get_MeterTypeName();
  130. private int _digitCount;
  131. public int DigitCount
  132. {
  133. get => _digitCount;
  134. set
  135. {
  136. if (_digitCount != value)
  137. {
  138. _digitCount = value;
  139. OnPropertyChanged(nameof(DigitCount));
  140. OnPropertyChanged(nameof(NumCountName)); // 依赖 DigitCount 更新 NumCountName
  141. }
  142. }
  143. }
  144. private int _pointerCount;
  145. public int PointerCount
  146. {
  147. get => _pointerCount;
  148. set
  149. {
  150. if (_pointerCount != value)
  151. {
  152. _pointerCount = value;
  153. OnPropertyChanged(nameof(PointerCount));
  154. OnPropertyChanged(nameof(NumCountName)); // 依赖 PointerCount 更新 NumCountName
  155. }
  156. }
  157. }
  158. public string NumCountName => Get_NumCountName();
  159. private double _lastUnit;
  160. public double LastUnit
  161. {
  162. get => _lastUnit;
  163. set
  164. {
  165. if (_lastUnit != value)
  166. {
  167. _lastUnit = value;
  168. OnPropertyChanged(nameof(LastUnit));
  169. OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
  170. }
  171. }
  172. }
  173. public string LastUnitName
  174. {
  175. get
  176. {
  177. if(MeterType > 0)
  178. {
  179. return $"尾数: {LastUnit}m³";
  180. }
  181. else
  182. {
  183. return "";
  184. }
  185. }
  186. }
  187. private int _resultType;
  188. public int ResultType
  189. {
  190. get => _resultType;
  191. set
  192. {
  193. if (_resultType != value)
  194. {
  195. _resultType = value;
  196. OnPropertyChanged(nameof(ResultType));
  197. OnPropertyChanged(nameof(ResultTypeColor)); // 依赖 ResultType 更新 ResultTypeColor
  198. }
  199. }
  200. }
  201. public string ResultTypeColor => Get_ResultTypeColor();
  202. private long _rawValue;
  203. public long RawValue
  204. {
  205. get => _rawValue;
  206. set
  207. {
  208. if (_rawValue != value)
  209. {
  210. _rawValue = value;
  211. if (MeterType == 0)
  212. {
  213. _rawValue = -1;
  214. }
  215. OnPropertyChanged(nameof(RawValue));
  216. }
  217. }
  218. }
  219. private long _finalValue;
  220. public long FinalValue
  221. {
  222. get => _finalValue;
  223. set
  224. {
  225. if (_finalValue != value)
  226. {
  227. _finalValue = value;
  228. //if(MeterType == 0)
  229. //{
  230. // _finalValue = "";
  231. //}
  232. OnPropertyChanged(nameof(FinalValue));
  233. }
  234. }
  235. }
  236. private long _completeValue;
  237. public long CompleteValue
  238. {
  239. get => _completeValue;
  240. set
  241. {
  242. if(_completeValue != value)
  243. {
  244. _completeValue = value;
  245. OnPropertyChanged(nameof(CompleteValue));
  246. }
  247. }
  248. }
  249. //AI识别出的水表类型
  250. private int _resultMeter;
  251. public int ResultMeter
  252. {
  253. get => _resultMeter;
  254. set
  255. {
  256. if (_resultMeter != value)
  257. {
  258. _resultMeter = value;
  259. OnPropertyChanged(nameof(ResultMeter));
  260. }
  261. }
  262. }
  263. private string _aiVer;
  264. public string AiVer
  265. {
  266. get => _aiVer;
  267. set
  268. {
  269. if (_aiVer != value)
  270. {
  271. _aiVer = value;
  272. OnPropertyChanged(nameof(AiVer));
  273. }
  274. }
  275. }
  276. private string _debugInfo;
  277. public string DebugInfo
  278. {
  279. get => _debugInfo;
  280. set
  281. {
  282. if (_debugInfo != value)
  283. {
  284. _debugInfo = value;
  285. OnPropertyChanged(nameof(DebugInfo));
  286. OnPropertyChanged(nameof(AI_result_array)); // 依赖 DebugInfo 更新 AI_result_array
  287. }
  288. }
  289. }
  290. public string[] AI_result_array => Get_DebugInfoArray();
  291. private string _logPath;
  292. public string LogPath
  293. {
  294. get => _logPath;
  295. set
  296. {
  297. if (_logPath != value)
  298. {
  299. _logPath = value;
  300. OnPropertyChanged(nameof(LogPath));
  301. }
  302. }
  303. }
  304. private string _memo;
  305. public string Memo
  306. {
  307. get => _memo;
  308. set
  309. {
  310. if (_memo != value)
  311. {
  312. _memo = value;
  313. OnPropertyChanged(nameof(Memo));
  314. }
  315. }
  316. }
  317. private double _brightVal;
  318. public double BrightVal
  319. {
  320. get => _brightVal;
  321. set
  322. {
  323. if(_brightVal != value)
  324. {
  325. _brightVal = value;
  326. OnPropertyChanged(nameof(BrightVal));
  327. OnPropertyChanged(nameof(BrightValName));
  328. }
  329. }
  330. }
  331. public string BrightValName => $"亮度: {BrightVal}";
  332. private int _flowRate;
  333. public int FlowRate
  334. {
  335. get => _flowRate;
  336. set
  337. {
  338. if(_flowRate != value)
  339. {
  340. _flowRate = value;
  341. OnPropertyChanged(nameof(FlowRate));
  342. OnPropertyChanged(nameof(FlowRateName));
  343. }
  344. }
  345. }
  346. public string FlowRateName
  347. {
  348. get => $"最大流量: {FlowRate}";
  349. }
  350. private string _meterRegion;
  351. public string MeterRegion
  352. {
  353. get => _meterRegion;
  354. set
  355. {
  356. if(_meterRegion != value)
  357. {
  358. _meterRegion = value;
  359. OnPropertyChanged(nameof(MeterRegion));
  360. OnPropertyChanged(nameof(MeterRegionName));
  361. }
  362. }
  363. }
  364. public string MeterRegionName
  365. {
  366. get
  367. {
  368. if(MeterType == 1 || MeterType == 2 || MeterType == 3)
  369. {
  370. return $"表盘: {MeterRegion}";
  371. }
  372. else
  373. {
  374. return string.Empty;
  375. }
  376. }
  377. }
  378. private string _featureRegion;
  379. public string FeatureRegion
  380. {
  381. get => _featureRegion;
  382. set
  383. {
  384. if(_featureRegion != value)
  385. {
  386. _featureRegion = value;
  387. OnPropertyChanged(nameof(FeatureRegion));
  388. OnPropertyChanged(nameof(FeatureRegionName));
  389. }
  390. }
  391. }
  392. public string FeatureRegionName
  393. {
  394. get
  395. {
  396. if(MeterType == 1 || MeterType == 3)
  397. {
  398. return $"数字区域: {FeatureRegion}";
  399. }
  400. else if(MeterType == 2)
  401. {
  402. return $"首位指针: {FeatureRegion}";
  403. }
  404. else
  405. {
  406. return string.Empty;
  407. }
  408. }
  409. }
  410. private double _lastValue;
  411. public double LastValue
  412. {
  413. get => _lastValue;
  414. set
  415. {
  416. if(_lastValue != value)
  417. {
  418. _lastValue = value;
  419. OnPropertyChanged(nameof(LastValue));
  420. OnPropertyChanged(nameof(LastValueName));
  421. }
  422. }
  423. }
  424. public string LastValueName => $"初值: {LastValue}";
  425. private string _lastTime;
  426. public string LastTime
  427. {
  428. get => _lastTime;
  429. set
  430. {
  431. if(_lastTime != value)
  432. {
  433. _lastTime = value;
  434. OnPropertyChanged(nameof(LastTime));
  435. OnPropertyChanged(nameof(LastTimeName1));
  436. OnPropertyChanged(nameof(LastTimeName2));
  437. }
  438. }
  439. }
  440. public string LastTimeName1 => ThisApp.ConvertDateFormat_Date(LastTime);
  441. public string LastTimeName2 => ThisApp.ConvertDateFormat_Time(LastTime);
  442. private string _deviceSn;
  443. public string DeviceSn
  444. {
  445. get => _deviceSn;
  446. set
  447. {
  448. if(_deviceSn != value)
  449. {
  450. _deviceSn = value;
  451. OnPropertyChanged(nameof(DeviceSn));
  452. }
  453. }
  454. }
  455. private string _sampleTime;
  456. public string SampleTime
  457. {
  458. get => _sampleTime;
  459. set
  460. {
  461. if(_sampleTime != value)
  462. {
  463. _sampleTime = value;
  464. OnPropertyChanged(nameof(SampleTime));
  465. }
  466. }
  467. }
  468. public Visibility ResultVisiable => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
  469. public SingleDetailItem() { }
  470. public SingleDetailItem(TSingleDetail singleDetail)
  471. {
  472. ObjectHelper.CopyMatchingFields(singleDetail, this);
  473. }
  474. private string Get_MeterTypeName()
  475. {
  476. switch (MeterType)
  477. {
  478. case 1:
  479. return "数字+指针";
  480. case 2:
  481. return "全指针";
  482. case 3:
  483. return "全数字";
  484. case 4:
  485. return "LED表";
  486. case 5:
  487. return "压力表";
  488. default:
  489. //return "";
  490. return "非水表";
  491. }
  492. }
  493. private string Get_NumCountName()
  494. {
  495. switch (MeterType)
  496. {
  497. case 1:
  498. return $"数字: {DigitCount} 指针: {PointerCount}";
  499. case 2:
  500. return $"指针: {PointerCount}";
  501. case 3:
  502. return $"数字: {DigitCount}";
  503. default:
  504. return string.Empty;
  505. }
  506. }
  507. private string Get_ResultTypeColor()
  508. {
  509. switch (ResultType)
  510. {
  511. case 1:
  512. case 2:
  513. case 7:
  514. case 8:
  515. return "#67c23a"; // 绿色
  516. default:
  517. return "#e6a23c"; // 橙色
  518. }
  519. }
  520. private string[] Get_DebugInfoArray()
  521. {
  522. string[] sInfos = DebugInfo.Split(',');
  523. if (sInfos.Length != 24)
  524. {
  525. sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
  526. }
  527. return sInfos.ToArray();
  528. //return sInfos.Select(s => s == "88" ? "" : s).ToArray();
  529. }
  530. // complete_value = @CompleteValue,
  531. // result_meter = @ResultMeter,
  532. // new SQLiteParameter("@CompleteValue", detail.CompleteValue),
  533. // new SQLiteParameter("@ResultMeter", detail.ResultMeter),
  534. //CompleteValue = reader.GetString(reader.GetOrdinal("complete_value")),
  535. //ResultMeter = reader.GetInt32(reader.GetOrdinal("result_meter")),
  536. //DeviceSn = reader.GetString(reader.GetOrdinal("device_sn")),
  537. //SampleTime = reader.GetString(reader.GetOrdinal("sample_time")),
  538. //-------------------------------------------------
  539. }
  540. }