SingleDetailItem.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. }
  125. }
  126. }
  127. public string MeterTypeName => Get_MeterTypeName();
  128. private int _digitCount;
  129. public int DigitCount
  130. {
  131. get => _digitCount;
  132. set
  133. {
  134. if (_digitCount != value)
  135. {
  136. _digitCount = value;
  137. OnPropertyChanged(nameof(DigitCount));
  138. OnPropertyChanged(nameof(NumCountName)); // 依赖 DigitCount 更新 NumCountName
  139. }
  140. }
  141. }
  142. private int _pointerCount;
  143. public int PointerCount
  144. {
  145. get => _pointerCount;
  146. set
  147. {
  148. if (_pointerCount != value)
  149. {
  150. _pointerCount = value;
  151. OnPropertyChanged(nameof(PointerCount));
  152. OnPropertyChanged(nameof(NumCountName)); // 依赖 PointerCount 更新 NumCountName
  153. }
  154. }
  155. }
  156. public string NumCountName => Get_NumCountName();
  157. private string _lastUnit;
  158. public string LastUnit
  159. {
  160. get => _lastUnit;
  161. set
  162. {
  163. if (_lastUnit != value)
  164. {
  165. _lastUnit = value;
  166. OnPropertyChanged(nameof(LastUnit));
  167. OnPropertyChanged(nameof(LastUnitName)); // 依赖 LastUnit 更新 LastUnitName
  168. }
  169. }
  170. }
  171. public string LastUnitName
  172. {
  173. get
  174. {
  175. if(MeterType > 0)
  176. {
  177. return $"尾数: {LastUnit}m³";
  178. }
  179. else
  180. {
  181. return "";
  182. }
  183. }
  184. }
  185. private int _resultType;
  186. public int ResultType
  187. {
  188. get => _resultType;
  189. set
  190. {
  191. if (_resultType != value)
  192. {
  193. _resultType = value;
  194. OnPropertyChanged(nameof(ResultType));
  195. OnPropertyChanged(nameof(ResultTypeColor)); // 依赖 ResultType 更新 ResultTypeColor
  196. }
  197. }
  198. }
  199. public string ResultTypeColor => Get_ResultTypeColor();
  200. private string _rawValue;
  201. public string RawValue
  202. {
  203. get => _rawValue;
  204. set
  205. {
  206. if (_rawValue != value)
  207. {
  208. _rawValue = value;
  209. if (MeterType == 0)
  210. {
  211. _rawValue = "";
  212. }
  213. OnPropertyChanged(nameof(RawValue));
  214. }
  215. }
  216. }
  217. private string _finalValue;
  218. public string FinalValue
  219. {
  220. get => _finalValue;
  221. set
  222. {
  223. if (_finalValue != value)
  224. {
  225. _finalValue = value;
  226. if(MeterType == 0)
  227. {
  228. _finalValue = "";
  229. }
  230. OnPropertyChanged(nameof(FinalValue));
  231. }
  232. }
  233. }
  234. private string _aiVer;
  235. public string AiVer
  236. {
  237. get => _aiVer;
  238. set
  239. {
  240. if (_aiVer != value)
  241. {
  242. _aiVer = value;
  243. OnPropertyChanged(nameof(AiVer));
  244. }
  245. }
  246. }
  247. private string _debugInfo;
  248. public string DebugInfo
  249. {
  250. get => _debugInfo;
  251. set
  252. {
  253. if (_debugInfo != value)
  254. {
  255. _debugInfo = value;
  256. OnPropertyChanged(nameof(DebugInfo));
  257. OnPropertyChanged(nameof(AI_result_array)); // 依赖 DebugInfo 更新 AI_result_array
  258. }
  259. }
  260. }
  261. public string[] AI_result_array => Get_DebugInfoArray();
  262. private string _logPath;
  263. public string LogPath
  264. {
  265. get => _logPath;
  266. set
  267. {
  268. if (_logPath != value)
  269. {
  270. _logPath = value;
  271. OnPropertyChanged(nameof(LogPath));
  272. }
  273. }
  274. }
  275. private string _memo;
  276. public string Memo
  277. {
  278. get => _memo;
  279. set
  280. {
  281. if (_memo != value)
  282. {
  283. _memo = value;
  284. OnPropertyChanged(nameof(Memo));
  285. }
  286. }
  287. }
  288. public Visibility ResultVisiable => (RunFlag == 1) ? Visibility.Visible : Visibility.Hidden;
  289. public SingleDetailItem() { }
  290. public SingleDetailItem(TSingleDetail singleDetail)
  291. {
  292. ObjectHelper.CopyMatchingFields(singleDetail, this);
  293. }
  294. private string Get_MeterTypeName()
  295. {
  296. switch (MeterType)
  297. {
  298. case 1:
  299. return "数字+指针";
  300. case 2:
  301. return "全指针";
  302. case 3:
  303. return "全数字";
  304. case 4:
  305. return "LED表";
  306. case 5:
  307. return "压力表";
  308. default:
  309. return "非水表";
  310. }
  311. }
  312. private string Get_NumCountName()
  313. {
  314. switch (MeterType)
  315. {
  316. case 1:
  317. return $"数字: {DigitCount} 指针{PointerCount}";
  318. case 2:
  319. return $"指针: {PointerCount}";
  320. default:
  321. return string.Empty;
  322. }
  323. }
  324. private string Get_ResultTypeColor()
  325. {
  326. switch (ResultType)
  327. {
  328. case 1:
  329. case 2:
  330. case 7:
  331. case 8:
  332. return "#67c23a"; // 绿色
  333. default:
  334. return "#e6a23c"; // 橙色
  335. }
  336. }
  337. private string[] Get_DebugInfoArray()
  338. {
  339. string[] sInfos = DebugInfo.Split(',');
  340. if (sInfos.Length != 24)
  341. {
  342. sInfos = Enumerable.Range(0, 24).Select(_ => "").ToArray();
  343. }
  344. return sInfos.Select(s => s == "88" ? "" : s).ToArray();
  345. }
  346. //-------------------------------------------------
  347. }
  348. }