PatchDetailItem.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. using MeterVision.db;
  2. using MeterVision.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Media;
  11. namespace MeterVision.model
  12. {
  13. public class PatchDetailItem : INotifyPropertyChanged
  14. {
  15. public event PropertyChangedEventHandler PropertyChanged;
  16. protected void OnPropertyChanged(string propertyName)
  17. {
  18. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  19. }
  20. private int _index;
  21. public int Index
  22. {
  23. get => _index;
  24. set
  25. {
  26. if (_index != value)
  27. {
  28. _index = value;
  29. OnPropertyChanged(nameof(Index));
  30. }
  31. }
  32. }
  33. private string _patchDetailId;
  34. public string PatchDetailId
  35. {
  36. get => _patchDetailId;
  37. set
  38. {
  39. if (_patchDetailId != value)
  40. {
  41. _patchDetailId = value;
  42. OnPropertyChanged(nameof(PatchDetailId));
  43. }
  44. }
  45. }
  46. private string _patchId;
  47. public string PatchId
  48. {
  49. get => _patchId;
  50. set
  51. {
  52. if(_patchId != value)
  53. {
  54. _patchId = value;
  55. OnPropertyChanged(nameof(PatchId));
  56. }
  57. }
  58. }
  59. private string _createTime;
  60. public string CreateTime
  61. {
  62. get => _createTime;
  63. set
  64. {
  65. if (_createTime != value)
  66. {
  67. _createTime = value;
  68. OnPropertyChanged(nameof(CreateTime));
  69. }
  70. }
  71. }
  72. private string _standDetailId;
  73. public string StandDetailId
  74. {
  75. get => _standDetailId;
  76. set
  77. {
  78. if(_standDetailId != value)
  79. {
  80. _standDetailId = value;
  81. OnPropertyChanged(nameof(StandDetailId));
  82. }
  83. }
  84. }
  85. private string _standResult;
  86. public string StandValue
  87. {
  88. get => _standResult;
  89. set
  90. {
  91. if (_standResult != value)
  92. {
  93. _standResult = value;
  94. OnPropertyChanged(nameof(StandValue));
  95. }
  96. }
  97. }
  98. private string _srcImage;
  99. public string SrcImage
  100. {
  101. get => _srcImage;
  102. set
  103. {
  104. if (_srcImage != value)
  105. {
  106. _srcImage = value;
  107. OnPropertyChanged(nameof(SrcImage));
  108. }
  109. }
  110. }
  111. //1: 已识别处理 0:还未识别
  112. private int _runFlag;
  113. public int RunFlag
  114. {
  115. get => _runFlag;
  116. set
  117. {
  118. if (_runFlag != value)
  119. {
  120. _runFlag = value;
  121. OnPropertyChanged(nameof(RunFlag));
  122. OnPropertyChanged(nameof(ResultVisiable));
  123. OnPropertyChanged(nameof(RunFlagName));
  124. OnPropertyChanged(nameof(RunFlagColor));
  125. }
  126. }
  127. }
  128. public string RunFlagName
  129. {
  130. get => RunFlag == 1 ? "🚩":"";
  131. }
  132. public string RunFlagColor
  133. {
  134. //get => RunFlag == 1 ? "#007bff" : "Tranparent";
  135. get => RunFlag == 1 ? "Black" : "Transparent";
  136. }
  137. private string _runTime;
  138. public string RunTime
  139. {
  140. get => _runTime;
  141. set
  142. {
  143. if (_runTime != value)
  144. {
  145. _runTime = value;
  146. OnPropertyChanged(nameof(RunTime));
  147. OnPropertyChanged(nameof(RunTime_date)); // 依赖 RunTime 更新 RunTIme_date
  148. OnPropertyChanged(nameof(RunTime_time)); // 依赖 RunTime 更新 RunTIme_time
  149. }
  150. }
  151. }
  152. public string RunTime_date => ThisApp.ConvertDateFormat_Date(RunTime);
  153. public string RunTime_time => ThisApp.ConvertDateFormat_Time(RunTime);
  154. private string _dstIamge;
  155. public string DstImage
  156. {
  157. get => _dstIamge;
  158. set
  159. {
  160. if (_dstIamge != value)
  161. {
  162. _dstIamge = value;
  163. OnPropertyChanged(nameof(DstImage));
  164. }
  165. }
  166. }
  167. private int _meterType;
  168. public int MeterType
  169. {
  170. get => _meterType;
  171. set
  172. {
  173. if (_meterType != value)
  174. {
  175. _meterType = value;
  176. OnPropertyChanged(nameof(MeterType));
  177. OnPropertyChanged(nameof(MeterTypeName)); // 依赖 MeterType 更新 MeterTypeName
  178. }
  179. }
  180. }
  181. public string MeterTypeName => Get_MeterTypeName();
  182. private int _digitCount;
  183. public int DigitCount
  184. {
  185. get => _digitCount;
  186. set
  187. {
  188. if (_digitCount != value)
  189. {
  190. _digitCount = value;
  191. OnPropertyChanged(nameof(DigitCount));
  192. OnPropertyChanged(nameof(NumCountName)); // 依赖 DigitCount 更新 NumCountName
  193. }
  194. }
  195. }
  196. private int _pointerCount;
  197. public int PointerCount
  198. {
  199. get => _pointerCount;
  200. set
  201. {
  202. if (_pointerCount != value)
  203. {
  204. _pointerCount = value;
  205. OnPropertyChanged(nameof(PointerCount));
  206. OnPropertyChanged(nameof(NumCountName)); // 依赖 PointerCount 更新 NumCountName
  207. }
  208. }
  209. }
  210. public string NumCountName => Get_NumCountName();
  211. private string _lastUnit;
  212. public string LastUnit
  213. {
  214. get => _lastUnit;
  215. set
  216. {
  217. if (_lastUnit != value)
  218. {
  219. _lastUnit = value;
  220. OnPropertyChanged(nameof(LastUnit));
  221. OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
  222. }
  223. }
  224. }
  225. public string LastUnitName
  226. {
  227. get
  228. {
  229. if (MeterType > 0)
  230. {
  231. return $"尾数: {LastUnit}m³";
  232. }
  233. else
  234. {
  235. return "";
  236. }
  237. }
  238. }
  239. private int _resultType;
  240. public int ResultType
  241. {
  242. get => _resultType;
  243. set
  244. {
  245. if (_resultType != value)
  246. {
  247. _resultType = value;
  248. OnPropertyChanged(nameof(ResultType));
  249. OnPropertyChanged(nameof(ResultTypeColor)); // 依赖 ResultType 更新 ResultTypeColor
  250. }
  251. }
  252. }
  253. public Color ResultTypeColor
  254. {
  255. //=> Get_ResultTypeColor();
  256. get
  257. {
  258. return (Color)ColorConverter.ConvertFromString(Get_ResultTypeColor());
  259. }
  260. }
  261. private string _rawValue;
  262. public string RawValue
  263. {
  264. get => _rawValue;
  265. set
  266. {
  267. if (_rawValue != value)
  268. {
  269. _rawValue = value;
  270. if (MeterType == 0)
  271. {
  272. _rawValue = "";
  273. }
  274. OnPropertyChanged(nameof(RawValue));
  275. }
  276. }
  277. }
  278. private string _finalValue;
  279. public string FinalValue
  280. {
  281. get => _finalValue;
  282. set
  283. {
  284. if (_finalValue != value)
  285. {
  286. _finalValue = value;
  287. if (MeterType == 0)
  288. {
  289. _finalValue = "";
  290. }
  291. OnPropertyChanged(nameof(FinalValue));
  292. }
  293. }
  294. }
  295. public string FinalValueColor => GetFinalValueColor();
  296. //0不等,1相等 2:整数相等
  297. private int _equalFlag;
  298. public int EqualFlag
  299. {
  300. get => _equalFlag;
  301. set
  302. {
  303. if(_equalFlag != value)
  304. {
  305. _equalFlag = value;
  306. OnPropertyChanged(nameof(EqualFlag));
  307. OnPropertyChanged(nameof(EqaulFlagName));
  308. OnPropertyChanged(nameof(EqualFlagColor));
  309. OnPropertyChanged(nameof(FinalValueColor));
  310. }
  311. }
  312. }
  313. public string EqaulFlagName => GetEqualFlagName();
  314. public string EqualFlagColor => GetEqualFlagColor();
  315. private string _aiVer;
  316. public string AiVer
  317. {
  318. get => _aiVer;
  319. set
  320. {
  321. if (_aiVer != value)
  322. {
  323. _aiVer = value;
  324. OnPropertyChanged(nameof(AiVer));
  325. }
  326. }
  327. }
  328. private string _debugInfo;
  329. public string DebugInfo
  330. {
  331. get => _debugInfo;
  332. set
  333. {
  334. if (_debugInfo != value)
  335. {
  336. _debugInfo = value;
  337. OnPropertyChanged(nameof(DebugInfo));
  338. OnPropertyChanged(nameof(AI_result_array)); // 依赖 DebugInfo 更新 AI_result_array
  339. }
  340. }
  341. }
  342. //--------------------------------
  343. public string[] AI_result_array => Get_DebugInfoArray();
  344. private string _logPath;
  345. public string LogPath
  346. {
  347. get => _logPath;
  348. set
  349. {
  350. if (_logPath != value)
  351. {
  352. _logPath = value;
  353. OnPropertyChanged(nameof(LogPath));
  354. }
  355. }
  356. }
  357. private string _memo;
  358. public string Memo
  359. {
  360. get => _memo;
  361. set
  362. {
  363. if(_memo != value)
  364. {
  365. _memo = value;
  366. OnPropertyChanged(nameof(Memo));
  367. }
  368. }
  369. }
  370. public Visibility ResultVisiable
  371. {
  372. get => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
  373. }
  374. public PatchDetailItem() { }
  375. public PatchDetailItem(TPatchDetail patchDetail)
  376. {
  377. ObjectHelper.CopyMatchingFields(patchDetail, this);
  378. }
  379. public string GetEqualFlagName()
  380. {
  381. if (string.IsNullOrWhiteSpace(StandValue))
  382. {
  383. return "-";
  384. }
  385. else
  386. {
  387. if(EqualFlag == 1)
  388. {
  389. //return "✔️";
  390. return "√";
  391. }
  392. else
  393. {
  394. //return "✖️";
  395. return "×";
  396. }
  397. }
  398. }
  399. public string GetEqualFlagColor()
  400. {
  401. if (string.IsNullOrWhiteSpace(StandValue))
  402. {
  403. //flag = 2
  404. return "#666666";
  405. }
  406. else
  407. {
  408. if (EqualFlag == 1)
  409. {
  410. //flag = 1
  411. return "#28a745 ";
  412. }
  413. else
  414. {
  415. //flag = 0
  416. return "#dc3545 ";
  417. }
  418. }
  419. }
  420. private string Get_ResultTypeColor()
  421. {
  422. switch (ResultType)
  423. {
  424. case 1:
  425. case 2:
  426. case 7:
  427. case 8:
  428. return "#67c23a"; // 绿色
  429. default:
  430. return "#e6a23c"; // 橙色
  431. }
  432. }
  433. private string GetFinalValueColor()
  434. {
  435. if (EqualFlag == 1)
  436. {
  437. return "Green";
  438. }else if(EqualFlag == 2)
  439. {
  440. return "#000000";
  441. }
  442. else
  443. {
  444. return "#FF4C4C"; //淡红色
  445. }
  446. // if (string.IsNullOrWhiteSpace(StandValue))
  447. //{
  448. // return "#666666";
  449. //}
  450. //else
  451. //{
  452. // if (EqualFlag == 1)
  453. // {
  454. // return "#28a745 ";
  455. // }
  456. // else
  457. // {
  458. // return "#dc3545 ";
  459. // }
  460. //}
  461. }
  462. private string Get_NumCountName()
  463. {
  464. switch (MeterType)
  465. {
  466. case 1:
  467. return $"数字: {DigitCount} 指针{PointerCount}";
  468. case 2:
  469. return $"指针: {PointerCount}";
  470. default:
  471. return string.Empty;
  472. }
  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. }
  491. }
  492. private string[] Get_DebugInfoArray()
  493. {
  494. //string[] sInfos = DebugInfo.Split(',');
  495. //if (sInfos.Length != 24)
  496. //{
  497. // sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
  498. //}
  499. //return sInfos.Select(s => s == "88" ? "" : s).ToArray();
  500. // 将 DebugInfo 按逗号分割成字符串数组
  501. string[] sInfos = DebugInfo.Split(',');
  502. // 如果数组长度不等于24,则创建一个新的长度为24的数组并初始化为空字符串
  503. if (sInfos.Length != 24)
  504. {
  505. sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
  506. }
  507. // 对每个字符串进行处理:如果它是 "88" 则转为空字符串,
  508. // 如果它是单个数字,则在前面补零
  509. return sInfos.Select(s =>
  510. {
  511. // 如果是 "88" 返回空字符串
  512. if (s == "88") return "";
  513. // 如果字符串长度为1,则在前面补零
  514. if (s.Length == 1)
  515. {
  516. return "0" + s;
  517. }
  518. // 否则返回原字符串
  519. return s;
  520. }).ToArray();
  521. }
  522. public static bool CheckEquailityWithStandValue(string standValue,string finalValue)
  523. {
  524. ////return standValue.Equals(FinalValue);
  525. //string finalValue = FinalValue;
  526. // 获取整数部分
  527. string standIntegerPart = standValue.Split('.')[0];
  528. string finalIntegerPart = finalValue.Split('.')[0];
  529. // 比较整数部分
  530. if (standIntegerPart != finalIntegerPart)
  531. {
  532. return false;
  533. }
  534. // 获取小数部分,若没有小数部分,则默认为空字符串
  535. string standDecimalPart = standValue.Contains(".") ? standValue.Split('.')[1] : "";
  536. string finalDecimalPart = finalValue.Contains(".") ? finalValue.Split('.')[1] : "";
  537. // 如果standValue有小数部分,则根据其小数位数调整finalValue的小数部分
  538. if (!string.IsNullOrEmpty(standDecimalPart))
  539. {
  540. // 获取standValue小数部分的位数
  541. int decimalPlaces = standDecimalPart.Length;
  542. // 截取FinalValue的小数部分,或者补充零
  543. if (finalDecimalPart.Length > decimalPlaces)
  544. {
  545. // 截取多余的小数位
  546. finalDecimalPart = finalDecimalPart.Substring(0, decimalPlaces);
  547. }
  548. else if (finalDecimalPart.Length < decimalPlaces)
  549. {
  550. // 补充零
  551. finalDecimalPart = finalDecimalPart.PadRight(decimalPlaces, '0');
  552. }
  553. // 比较调整后的小数部分
  554. return standDecimalPart == finalDecimalPart;
  555. }
  556. // 如果standValue没有小数部分,只比较整数部分
  557. return true;
  558. }
  559. /////////////////////////////
  560. }
  561. }