MatrixTop.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11. using log4net;
  12. using IntelligentControlForsx.Service;
  13. using IntelligentControlForsx.Model;
  14. using WisdomClient.data;
  15. using WisdomClient;
  16. namespace IntelligentControlForsx.MyControls
  17. {
  18. public partial class MatrixTop : UserControl
  19. {
  20. private ILog logger = LogManager.GetLogger("AppInfoLog");
  21. public MatrixTop()
  22. {
  23. InitializeComponent();
  24. }
  25. double zfdl;
  26. double nfdl;
  27. double yfdl;
  28. double rfdl;
  29. double power;
  30. double windSpeed;
  31. double fhl;
  32. int cntAll;
  33. int cntBW;
  34. int cntSD;
  35. int cntTJ;
  36. int cntDJ;
  37. int cntGZ;
  38. int cntWH;
  39. int cntLX;
  40. int cntQD;
  41. #region 指标属性
  42. [Browsable(true), Category("Data")]
  43. public double WindSpeed
  44. {
  45. get
  46. {
  47. return windSpeed;
  48. }
  49. set
  50. {
  51. windSpeed = value;
  52. lblWindSpeed.Text = Convert.ToDouble(value).ToString("0.00");
  53. }
  54. }
  55. [Browsable(true), Category("Data")]
  56. public double Power
  57. {
  58. get
  59. {
  60. return power;
  61. }
  62. set
  63. {
  64. power = value;
  65. lblPower.Text = Convert.ToDouble(value).ToString("0.00");
  66. }
  67. }
  68. [Browsable(true), Category("Data")]
  69. public double ZFDL
  70. {
  71. get
  72. {
  73. return zfdl;
  74. }
  75. set
  76. {
  77. zfdl = value;
  78. // lblZFDL.Text = Convert.ToDouble(value).ToString("0.00");
  79. }
  80. }
  81. [Browsable(true), Category("Data")]
  82. public double NFDL
  83. {
  84. get
  85. {
  86. return nfdl;
  87. }
  88. set
  89. {
  90. nfdl = value;
  91. lblNFDL.Text = Convert.ToDouble(value).ToString("0.00");
  92. }
  93. }
  94. [Browsable(true), Category("Data")]
  95. public double YFDL
  96. {
  97. get
  98. {
  99. return yfdl;
  100. }
  101. set
  102. {
  103. yfdl = value;
  104. lblYFDL.Text = Convert.ToDouble(value).ToString("0.00");
  105. }
  106. }
  107. [Browsable(true), Category("Data")]
  108. public double RFDL
  109. {
  110. get
  111. {
  112. return rfdl;
  113. }
  114. set
  115. {
  116. rfdl = value;
  117. lblRFDL.Text = Convert.ToDouble(value).ToString("0.00");
  118. }
  119. }
  120. [Browsable(true), Category("Data")]
  121. public double FHL
  122. {
  123. get
  124. {
  125. return fhl;
  126. }
  127. set
  128. {
  129. fhl = value;
  130. lblFHL.Text = Convert.ToDouble(value).ToString("0.00");
  131. }
  132. }
  133. #endregion
  134. #region 状态台数
  135. [Browsable(true), Category("Data")]
  136. public int CntAll
  137. {
  138. get
  139. {
  140. return cntAll;
  141. }
  142. set
  143. {
  144. cntAll = value;
  145. lblCntAll.Text = value.ToString();
  146. }
  147. }
  148. [Browsable(true), Category("Data")]
  149. public int CntBW
  150. {
  151. get
  152. {
  153. return cntBW;
  154. }
  155. set
  156. {
  157. cntBW = value;
  158. lblCntAll.Text = value.ToString();
  159. }
  160. }
  161. [Browsable(true), Category("Data")]
  162. public int CntSD
  163. {
  164. get
  165. {
  166. return cntSD;
  167. }
  168. set
  169. {
  170. cntSD = value;
  171. lblCntSD.Text = value.ToString();
  172. }
  173. }
  174. [Browsable(true), Category("Data")]
  175. public int CntTJ
  176. {
  177. get
  178. {
  179. return cntTJ;
  180. }
  181. set
  182. {
  183. cntTJ = value;
  184. lblCntTJ.Text = value.ToString();
  185. }
  186. }
  187. [Browsable(true), Category("Data")]
  188. public int CntDJ
  189. {
  190. get
  191. {
  192. return cntDJ;
  193. }
  194. set
  195. {
  196. cntDJ = value;
  197. lblCntDJ.Text = value.ToString();
  198. }
  199. }
  200. [Browsable(true), Category("Data")]
  201. public int CntGZ
  202. {
  203. get
  204. {
  205. return cntGZ;
  206. }
  207. set
  208. {
  209. cntGZ = value;
  210. lblCntGZ.Text = value.ToString();
  211. }
  212. }
  213. [Browsable(true), Category("Data")]
  214. public int CntWH
  215. {
  216. get
  217. {
  218. return cntWH;
  219. }
  220. set
  221. {
  222. cntWH = value;
  223. lblCntWH.Text = value.ToString();
  224. }
  225. }
  226. [Browsable(true), Category("Data")]
  227. public int CntLX
  228. {
  229. get
  230. {
  231. return cntLX;
  232. }
  233. set
  234. {
  235. cntLX = value;
  236. lblCntLX.Text = value.ToString();
  237. }
  238. }
  239. [Browsable(true), Category("Data")]
  240. public int CntQD
  241. {
  242. get
  243. {
  244. return cntQD;
  245. }
  246. set
  247. {
  248. cntQD = value;
  249. lblCntQD.Text = value.ToString();
  250. }
  251. }
  252. #endregion
  253. public void DeActive()
  254. {
  255. this.Hide();
  256. timer1.Stop();
  257. }
  258. public void Active()
  259. {
  260. this.Show();
  261. Thread ayscThread = new Thread(LoadData);
  262. ayscThread.IsBackground = true;
  263. ayscThread.Start();
  264. timer1.Start();
  265. }
  266. #region 异步加载数据
  267. private void timer1_Tick(object sender, EventArgs e)
  268. {
  269. if (isLoadding) return;
  270. Thread ayscThread = new Thread(LoadData);
  271. ayscThread.IsBackground = true;
  272. ayscThread.Start();
  273. LoadData();
  274. Thread statusCountThread = new Thread(BindFormThread);
  275. statusCountThread.IsBackground = true;
  276. statusCountThread.Start();
  277. }
  278. private bool isLoadding = false;
  279. private void LoadData()
  280. {
  281. isLoadding = true;
  282. try
  283. {
  284. UpdateStationStates();
  285. }
  286. catch (Exception ex)
  287. {
  288. logger.Info("读取实时数据失败!ex=" + ex.Message);
  289. }
  290. finally
  291. {
  292. isLoadding = false;
  293. }
  294. }
  295. private void UpdateStationStates()
  296. {
  297. var dict = CacheService.Instance.MatrixPointMap;
  298. if (dict == null)
  299. return;
  300. var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == "-1").ToArray();
  301. var points = pmms.Select(q => q.PointId).ToArray();
  302. Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
  303. //foreach (var tmp in dictResult)
  304. //{
  305. // logger.Info(tmp.Key);
  306. // logger.Info(tmp.Value.ts);
  307. // logger.Info(tmp.Value.doubleValue);
  308. //}
  309. lock (this)
  310. {
  311. this.BeginInvoke(
  312. (Action)delegate
  313. {
  314. for (int i = 0; i < points.Length; i++)
  315. {
  316. if (dictResult.ContainsKey(points[i]) == false)
  317. continue;
  318. double value = dictResult[points[i]].doubleValue.Value;
  319. pmms[i].Value = value;
  320. switch (pmms[i].UniformCode)
  321. {
  322. #region Switch
  323. //"YXTS", //运行台数
  324. //"TXZD", //通讯中断
  325. //"DJTS", //待机台数
  326. //"WHTJ", //维护台数
  327. //"GZTJ", //故障台数
  328. //"XDTS", //限电台数
  329. //"SSFS", //实时平均风速
  330. //"SSZGL", //实时总功率
  331. //"RFDL", //日发电量
  332. //"YFDL", //月发电量
  333. //"NFDL", //年发电量
  334. //"ZFDL" //总发电量
  335. case "BWTS8":
  336. lblCntBW.Text = value.ToString("f0");
  337. break;
  338. case "LXTS8":
  339. lblCntLX.Text = value.ToString("f0");
  340. break;
  341. case "DJTS8":
  342. lblCntDJ.Text = value.ToString("f0");
  343. break;
  344. case "WHTS8":
  345. lblCntWH.Text = value.ToString("f0");
  346. break;
  347. case "GZTS8":
  348. lblCntGZ.Text = value.ToString("f0");
  349. break;
  350. case "QDTS8":
  351. lblCntQD.Text = value.ToString("f0");
  352. break;
  353. case "SDTS8":
  354. lblCntSD.Text = value.ToString("f0");
  355. break;
  356. case "TJTS8":
  357. lblCntTJ.Text = value.ToString("f0");
  358. break;
  359. case "RFDL":
  360. lblRFDL.Text = value.ToString("f2");
  361. break;
  362. case "YFDL":
  363. lblYFDL.Text = value.ToString("f2");
  364. break;
  365. case "NFDL":
  366. lblNFDL.Text = value.ToString("f2");
  367. break;
  368. case "SFDL":
  369. // lblZFDL.Text = value.ToString("f2");
  370. break;
  371. case "SSFS":
  372. lblWindSpeed.Text = value.ToString("f2");
  373. break;
  374. case "SSZGL":
  375. lblPower.Text = value.ToString("f2");
  376. double fh = value / 684.5;
  377. double fhl = fh*100;
  378. lblFHL.Text = fhl.ToString("f2");
  379. break;
  380. #endregion
  381. }
  382. }
  383. });
  384. }
  385. }
  386. #endregion
  387. #region 异步加载初始化数据
  388. private void MatrixTop_Load(object sender, EventArgs e)
  389. {
  390. Thread ayscThread = new Thread(LoadInitData);
  391. ayscThread.IsBackground = true;
  392. ayscThread.Start();
  393. }
  394. private void LoadInitData()
  395. {
  396. try
  397. {
  398. UpdateLblCntAll();
  399. }
  400. catch (Exception ex)
  401. {
  402. logger.Info("读取实时数据失败!ex=" + ex.Message);
  403. }
  404. }
  405. private void UpdateLblCntAll()
  406. {
  407. int count = CacheService.Instance.WindturbineList.Count();
  408. lock (this.lblCntAll)
  409. {
  410. this.lblCntAll.BeginInvoke(
  411. (Action)delegate
  412. {
  413. lblCntAll.Text = count.ToString();
  414. });
  415. }
  416. }
  417. #endregion
  418. private delegate void UpdateGridViewDelegate();
  419. public void BindFormThread()
  420. {
  421. UpdateGridViewDelegate del = new UpdateGridViewDelegate(UpdateWindturbineStatusCount);
  422. if (this.InvokeRequired)
  423. {
  424. this.BeginInvoke(del, new object[] { });
  425. }
  426. else
  427. {
  428. UpdateWindturbineStatusCount();
  429. }
  430. }
  431. private void UpdateWindturbineStatusCount()
  432. {
  433. string[] uniformCode = new string[] { "TJTS8", "SDTS8", "DJTS8", "QDTS8", "BWTS8", "GZTS8", "WHTS8", "LXTS8" };
  434. Dictionary<string, TsData> dictResult_SBQ = RestfulClient.findLatestByThingCodes("station", "SBQ_FDC",
  435. uniformCode);
  436. Dictionary<string, TsData> dictResult_MHS = RestfulClient.findLatestByThingCodes("station", "MHS_FDC",
  437. uniformCode);
  438. Dictionary<string, TsData> dictResult_NSS = RestfulClient.findLatestByThingCodes("station", "NSS_FDC",
  439. uniformCode);
  440. Dictionary<string, TsData> dictResult_QS = RestfulClient.findLatestByThingCodes("station", "QS_FDC",
  441. uniformCode);
  442. Dictionary<string, TsData> dictResult_XS = RestfulClient.findLatestByThingCodes("station", "XS_FDC",
  443. uniformCode);
  444. int stopCount = 0;
  445. int onPowerCount = 0;
  446. int standByCount = 0;
  447. int startCount = 0;
  448. int onlineCount = 0;
  449. int faultCount = 0;
  450. int maintainCount = 0;
  451. int offlineCount = 0;
  452. stopCount = GetCount("TJTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  453. onPowerCount = GetCount("SDTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  454. standByCount = GetCount("DJTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  455. startCount = GetCount("QDTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  456. onlineCount = GetCount("BWTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  457. faultCount = GetCount("GZTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  458. maintainCount = GetCount("WHTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  459. offlineCount = GetCount("LXTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
  460. lblCntBW.Text = onlineCount.ToString();
  461. lblCntDJ.Text = standByCount.ToString();
  462. lblCntSD.Text = onPowerCount.ToString();
  463. lblCntQD.Text = startCount.ToString();
  464. lblCntGZ.Text = faultCount.ToString();
  465. lblCntWH.Text = maintainCount.ToString();
  466. lblCntLX.Text = offlineCount.ToString();
  467. lblCntTJ.Text = stopCount.ToString();
  468. }
  469. private int GetCount(string unifromCode, Dictionary<string, TsData> dic_SBQ, Dictionary<string, TsData> dic_MHS, Dictionary<string, TsData> dic_XS, Dictionary<string, TsData> dic_QS, Dictionary<string, TsData> dic_NSS)
  470. {
  471. int resultCount = 0;
  472. try
  473. {
  474. if (dic_SBQ.ContainsKey(unifromCode))
  475. {
  476. int count = Convert.ToInt32(dic_SBQ[unifromCode].getValue());
  477. resultCount = resultCount + count;
  478. }
  479. if (dic_MHS.ContainsKey(unifromCode))
  480. {
  481. int count = Convert.ToInt32(dic_MHS[unifromCode].getValue());
  482. resultCount = resultCount + count;
  483. }
  484. if (dic_XS.ContainsKey(unifromCode))
  485. {
  486. int count = Convert.ToInt32(dic_XS[unifromCode].getValue());
  487. resultCount = resultCount + count;
  488. }
  489. if (dic_QS.ContainsKey(unifromCode))
  490. {
  491. int count = Convert.ToInt32(dic_QS[unifromCode].getValue());
  492. resultCount = resultCount + count;
  493. }
  494. if (dic_NSS.ContainsKey(unifromCode))
  495. {
  496. int count = Convert.ToInt32(dic_NSS[unifromCode].getValue());
  497. resultCount = resultCount + count;
  498. }
  499. return resultCount;
  500. }
  501. catch (Exception ex)
  502. {
  503. logger.Info("MatrixTop中全区风机状态数量统计转换错误" + ex);
  504. return 0;
  505. }
  506. }
  507. }
  508. }