StandDetailItem.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. using MeterVision.db;
  2. using MeterVision.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace MeterVision.model
  11. {
  12. public class StandDetailItem : INotifyPropertyChanged
  13. {
  14. public event PropertyChangedEventHandler PropertyChanged;
  15. public static Dictionary<int, double> LastUnitMapping = new Dictionary<int, double>
  16. {
  17. {0,0.0001 },
  18. {1,0.001 },
  19. {2,0.01 },
  20. {3,0.1 },
  21. {4,1 },
  22. {5,10 },
  23. {6,100 },
  24. {7,1000 },
  25. {8,10000 }
  26. };
  27. // 触发属性变更通知
  28. protected virtual void OnPropertyChanged(string propertyName)
  29. {
  30. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  31. }
  32. private int _index;
  33. public int Index
  34. {
  35. get => _index;
  36. set
  37. {
  38. if (_index != value)
  39. {
  40. _index = value;
  41. OnPropertyChanged(nameof(Index));
  42. }
  43. }
  44. }
  45. public string StandId { get; set; }
  46. public string StandDetailId { get; set; }
  47. public string SrcImage { get; set; }
  48. private string _standValue;
  49. public string StandValue
  50. {
  51. get => _standValue;
  52. set
  53. {
  54. if (_standValue != value)
  55. {
  56. _standValue = value;
  57. OnPropertyChanged(nameof(StandValue));
  58. }
  59. }
  60. }
  61. private string _stationId;
  62. public string StationId
  63. {
  64. get => _stationId;
  65. set
  66. {
  67. if (_stationId != value)
  68. {
  69. _stationId = value;
  70. OnPropertyChanged(nameof(StationId));
  71. //OnPropertyChanged(nameof(StationIdColor));
  72. }
  73. }
  74. }
  75. public string StationIdColor
  76. {
  77. get
  78. {
  79. if (MeterType > 0)
  80. {
  81. return "#FF6347";
  82. }
  83. return "black";
  84. }
  85. }
  86. private string _deviceSn;
  87. public string DeviceSn
  88. {
  89. get => _deviceSn;
  90. set
  91. {
  92. if (_deviceSn != value)
  93. {
  94. _deviceSn = value;
  95. OnPropertyChanged(nameof(DeviceSn));
  96. }
  97. }
  98. }
  99. private string _sampleTime;
  100. public string SampleTime
  101. {
  102. get => _sampleTime;
  103. set
  104. {
  105. if (_sampleTime != value)
  106. {
  107. _sampleTime = value;
  108. OnPropertyChanged(nameof(SampleTime));
  109. OnPropertyChanged(nameof(SampleTime1));
  110. OnPropertyChanged(nameof(SampleTime2));
  111. }
  112. }
  113. }
  114. public string SampleTime1 => ThisApp.ConvertDateFormat_Date2(SampleTime);
  115. public string SampleTime2 => ThisApp.ConvertDateFormat_Time2(SampleTime);
  116. //Excel中的数据
  117. private int _eNumCount;
  118. public int ENumCount
  119. {
  120. get => _eNumCount;
  121. set
  122. {
  123. if (_eNumCount != value)
  124. {
  125. _eNumCount = value;
  126. OnPropertyChanged(nameof(ENumCount));
  127. }
  128. }
  129. }
  130. private int _eLastUnit;
  131. public int ELastUnit
  132. {
  133. get => _eLastUnit;
  134. set
  135. {
  136. if (_eLastUnit != value)
  137. {
  138. _eLastUnit = value;
  139. OnPropertyChanged(nameof(ELastUnit));
  140. //OnPropertyChanged(nameof(ELastUnitName));
  141. }
  142. }
  143. }
  144. //public string ELastUnitName
  145. //{
  146. // get
  147. // {
  148. // if(LastUnitMapping.TryGetValue(ELastUnit,out double lastUnit))
  149. // {
  150. // return lastUnit + "";
  151. // }
  152. // return "";
  153. // }
  154. //}
  155. private int _meterType;
  156. public int MeterType
  157. {
  158. get => _meterType;
  159. set
  160. {
  161. if (_meterType != value)
  162. {
  163. _meterType = value;
  164. OnPropertyChanged(nameof(MeterType));
  165. OnPropertyChanged(nameof(MeterTypeName));
  166. OnPropertyChanged(nameof(LastUnitName));
  167. OnPropertyChanged(nameof(FeatureRegionName));
  168. OnPropertyChanged(nameof(CountName));
  169. OnPropertyChanged(nameof(BrightValName));
  170. OnPropertyChanged(nameof(LastValueName));
  171. OnPropertyChanged(nameof(DialRegionName));
  172. OnPropertyChanged(nameof(FlowRateName));
  173. OnPropertyChanged(nameof(NumInUpper));
  174. OnPropertyChanged(nameof(StationIdColor));
  175. }
  176. }
  177. }
  178. public string MeterTypeName => Get_MeterTypeName();
  179. private double _brightVal;
  180. public double BrightVal
  181. {
  182. get => _brightVal;
  183. set
  184. {
  185. if (_brightVal != value)
  186. {
  187. _brightVal = value;
  188. OnPropertyChanged(nameof(BrightVal));
  189. OnPropertyChanged(nameof(BrightValName));
  190. }
  191. }
  192. }
  193. public string BrightValName
  194. {
  195. get
  196. {
  197. if(MeterType > 0)
  198. {
  199. return $"亮度: {BrightVal}";
  200. }
  201. return "";
  202. }
  203. }
  204. private int _flowRate;
  205. public int FlowRate
  206. {
  207. get => _flowRate;
  208. set
  209. {
  210. if (_flowRate != value)
  211. {
  212. _flowRate = value;
  213. OnPropertyChanged(nameof(FlowRate));
  214. OnPropertyChanged(nameof(FlowRateName));
  215. }
  216. }
  217. }
  218. public string FlowRateName
  219. {
  220. get
  221. {
  222. if(MeterType > 0)
  223. {
  224. return $"小时流量: {FlowRate}";
  225. }
  226. return "";
  227. }
  228. }
  229. private string _dialRegion;
  230. public string DialRegion
  231. {
  232. get => _dialRegion;
  233. set
  234. {
  235. if (_dialRegion != value)
  236. {
  237. _dialRegion = value;
  238. OnPropertyChanged(nameof(DialRegion));
  239. OnPropertyChanged(nameof(DialRegionName));
  240. }
  241. }
  242. }
  243. public string DialRegionName
  244. {
  245. get
  246. {
  247. if (!string.IsNullOrEmpty(DialRegion))
  248. {
  249. return $"表盘: {DialRegion}";
  250. }
  251. return "";
  252. }
  253. }
  254. private int _numCount;
  255. public int NumCount
  256. {
  257. get => _numCount;
  258. set
  259. {
  260. if (_numCount != value)
  261. {
  262. _numCount = value;
  263. OnPropertyChanged(nameof(NumCount));
  264. OnPropertyChanged(nameof(CountName));
  265. }
  266. }
  267. }
  268. private int _indCount;
  269. public int IndCount
  270. {
  271. get => _indCount;
  272. set
  273. {
  274. if (_indCount != value)
  275. {
  276. _indCount = value;
  277. OnPropertyChanged(nameof(IndCount));
  278. OnPropertyChanged(nameof(CountName));
  279. }
  280. }
  281. }
  282. public string CountName
  283. {
  284. get
  285. {
  286. if (MeterType == 1)
  287. {
  288. return "数字: " + NumCount + " ;指针: " + IndCount;
  289. }
  290. else if (MeterType == 2)
  291. {
  292. return "指针: " + IndCount;
  293. }
  294. else if (MeterType == 3)
  295. {
  296. return "数字: " + NumCount;
  297. }
  298. else
  299. {
  300. return "";
  301. }
  302. }
  303. }
  304. private string _featureRegion;
  305. public string FeatureRegion
  306. {
  307. get => _featureRegion;
  308. set
  309. {
  310. if (_featureRegion != value)
  311. {
  312. _featureRegion = value;
  313. OnPropertyChanged(nameof(FeatureRegion));
  314. OnPropertyChanged(nameof(FeatureRegionName));
  315. }
  316. }
  317. }
  318. public string FeatureRegionName
  319. {
  320. get
  321. {
  322. if (!string.IsNullOrEmpty(FeatureRegion))
  323. {
  324. if (MeterType == 1 || MeterType == 3)
  325. {
  326. return "数字区域: \n" + FeatureRegion;
  327. }
  328. else if (MeterType == 2)
  329. {
  330. return "首位指针: \n" + FeatureRegion;
  331. }
  332. else
  333. {
  334. return "";
  335. }
  336. }
  337. else
  338. {
  339. return "";
  340. }
  341. }
  342. }
  343. private double _lastUnit;
  344. public double LastUnit
  345. {
  346. get => _lastUnit;
  347. set
  348. {
  349. if (_lastUnit != value)
  350. {
  351. _lastUnit = value;
  352. OnPropertyChanged(nameof(LastUnit));
  353. OnPropertyChanged(nameof(LastUnitName));
  354. }
  355. }
  356. }
  357. public int _numInUpper;
  358. public int NumInUpper
  359. {
  360. get => _numInUpper;
  361. set
  362. {
  363. if (_numInUpper != value)
  364. {
  365. _numInUpper = value;
  366. OnPropertyChanged(nameof(NumInUpper));
  367. OnPropertyChanged(nameof(NumInUpperName));
  368. }
  369. }
  370. }
  371. public string NumInUpperName
  372. {
  373. get
  374. {
  375. if (MeterType == 1 || MeterType == 3)
  376. {
  377. return $"数字在上: {(NumInUpper == 1 ? "是" : "否")}";
  378. }
  379. else
  380. {
  381. return "";
  382. }
  383. }
  384. }
  385. public string LastUnitName
  386. {
  387. get
  388. {
  389. if (MeterType > 0)
  390. {
  391. return $"尾数: {LastUnit}m³";
  392. }
  393. else
  394. {
  395. return "";
  396. }
  397. }
  398. }
  399. private double _lastValue;
  400. public double LastValue
  401. {
  402. get => _lastValue;
  403. set
  404. {
  405. if (_lastValue != value)
  406. {
  407. _lastValue = value;
  408. OnPropertyChanged(nameof(LastValue));
  409. OnPropertyChanged(nameof(LastValueName));
  410. }
  411. }
  412. }
  413. public string LastValueName
  414. {
  415. get
  416. {
  417. if (MeterType > 0)
  418. {
  419. if (string.IsNullOrEmpty(LastTime))
  420. {
  421. return "";
  422. }
  423. else
  424. {
  425. return "初值: " + LastValue;
  426. }
  427. }
  428. return "";
  429. }
  430. }
  431. private string _lastTime;
  432. public string LastTime
  433. {
  434. //get => ThisApp.ConvertDateFormat(_lastTime);
  435. get => _lastTime;
  436. set
  437. {
  438. if (_lastTime != value)
  439. {
  440. _lastTime = value;
  441. OnPropertyChanged(nameof(LastTime));
  442. OnPropertyChanged(nameof(LastTimeName));
  443. OnPropertyChanged(nameof(LastValueName));
  444. }
  445. }
  446. }
  447. public string LastTimeName => ThisApp.ConvertDateFormat(LastTime);
  448. public StandDetailItem()
  449. {
  450. }
  451. public StandDetailItem(TStandDetail standDetail)
  452. {
  453. //StandId = standDetail.StandId;
  454. //StandDetailId = standDetail.StandDetailId;
  455. //SrcImage = standDetail.SrcImage;
  456. //StandValue = standDetail.StandValue;
  457. //StationId = standDetail.StationId;
  458. //SampleTime = standDetail.SampleTime;
  459. //NumCount = standDetail.NumCount;
  460. //LastUnit = standDetail.LastUnit;
  461. ObjectHelper.CopyMatchingFields(standDetail, this);
  462. }
  463. private string Get_MeterTypeName()
  464. {
  465. switch (MeterType)
  466. {
  467. case 1:
  468. return "数字+指针";
  469. case 2:
  470. return "全指针";
  471. case 3:
  472. return "全数字";
  473. case 4:
  474. return "LED表";
  475. case 5:
  476. return "压力表";
  477. default:
  478. return "";
  479. //return "非水表";
  480. }
  481. }
  482. ///////////////////////////////////////////////////////////
  483. }
  484. }