ZM_NSS.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 log4net;
  11. using IntelligentControlForsx.Service;
  12. using IntelligentControlForsx.Common;
  13. using System.Threading;
  14. using IntelligentControlForsx.Common;
  15. using IntelligentControlForsx.Service;
  16. using IntelligentControlForsx.Model;
  17. using WisdomClient.data;
  18. using WisdomClient;
  19. using log4net;
  20. namespace IntelligentControlForsx.MyControls.zm
  21. {
  22. public partial class ZM_NSS : ZMControl
  23. {
  24. public ZM_NSS()
  25. {
  26. InitializeComponent();
  27. navSvc = NavService.Instance;
  28. }
  29. private string stationId = "NSS_FDC";
  30. private ILog logger = LogManager.GetLogger("AppInfoLog");
  31. private NavService navSvc;
  32. //key: 风机ID
  33. private Dictionary<string, WindturbineIcon> dictWindturbintIcon;
  34. public string StationId
  35. {
  36. get
  37. {
  38. return stationId;
  39. }
  40. }
  41. private void MHS_Load(object sender, EventArgs e)
  42. {
  43. dictWindturbintIcon = new Dictionary<string, WindturbineIcon>();
  44. foreach (var p in this.pnlLine.Controls)
  45. {
  46. WindturbineIcon pd = p as WindturbineIcon;
  47. if (pd != null &&
  48. String.IsNullOrWhiteSpace(pd.WindturbineId) == false &&
  49. dictWindturbintIcon.ContainsKey(pd.WindturbineId) == false)
  50. {
  51. dictWindturbintIcon.Add(pd.WindturbineId, pd);
  52. }
  53. }
  54. Thread ayscThread = new Thread(LoadInitData);
  55. ayscThread.IsBackground = true;
  56. ayscThread.Start();
  57. }
  58. // 风机点击事件
  59. private void Windturbine_MyClick(object sender, EventArgs e)
  60. {
  61. try
  62. {
  63. WindturbineIcon icon = (WindturbineIcon)sender;
  64. if (icon != null)
  65. {
  66. navSvc.NavForWindturbine("pictureBoxParamters", icon.WindturbineId, "NSS_FDC");
  67. }
  68. }
  69. catch (Exception ex)
  70. {
  71. MessageBox.Show(ex.Message);
  72. }
  73. }
  74. private void btnSYZ_Click(object sender, EventArgs e)
  75. {
  76. navSvc.NavForElectrical("pictureBoxSYZ", "NSS_FDC");
  77. }
  78. private void btnMap_Click(object sender, EventArgs e)
  79. {
  80. navSvc.NavForMap("MapForm", "NSS_FDC");
  81. }
  82. #region 加载数据
  83. private void timer1_Tick(object sender, EventArgs e)
  84. {
  85. if (isLoadding == true)
  86. return;
  87. Thread ayscThread = new Thread(LoadData);
  88. ayscThread.IsBackground = true;
  89. ayscThread.Start();
  90. }
  91. public override void DeActive()
  92. {
  93. timer1.Stop();
  94. this.stationPowerLine1.DeActive();
  95. }
  96. public override void Active()
  97. {
  98. Thread ayscThread = new Thread(LoadData);
  99. ayscThread.IsBackground = true;
  100. ayscThread.Start();
  101. timer1.Start();
  102. this.stationPowerLine1.Active();
  103. }
  104. private bool isLoadding = false;
  105. private void LoadData()
  106. {
  107. if (isLoadding == true)
  108. return;
  109. isLoadding = true;
  110. try
  111. {
  112. UpdateStationStates();
  113. UpdatePnlLine();
  114. }
  115. catch (Exception ex)
  116. {
  117. logger.Info("读取实时数据失败!ex=" + ex.Message);
  118. }
  119. finally
  120. {
  121. isLoadding = false;
  122. }
  123. }
  124. private void UpdatePnlLine()
  125. {
  126. if (dictWindturbintIcon == null || dictWindturbintIcon.Count < 1)
  127. return;
  128. var dict = CacheService.Instance.MatrixPointMap;
  129. if (dict == null)
  130. return;
  131. var pmms = dict.Values
  132. .Where(q => q.ThingType == PointType.Windturbine &&
  133. "FJZT8".Equals(q.UniformCode))
  134. .ToArray();
  135. var points = pmms.Select(q => q.PointId).ToArray();
  136. Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
  137. lock (this.pnlLine)
  138. {
  139. this.BeginInvoke(
  140. (Action)delegate
  141. {
  142. for (int i = 0; i < points.Length; i++)
  143. {
  144. if (dictResult.ContainsKey(points[i]) == false)
  145. continue;
  146. double value = dictResult[points[i]].doubleValue.Value;
  147. pmms[i].Value = value;
  148. String wtId = pmms[i].ThingId;
  149. string controlName = CommonMethod.GetLongWindturbineId(wtId);
  150. if (dictResult.ContainsKey(pmms[i].PointId) && dictWindturbintIcon.ContainsKey(controlName))
  151. {
  152. TsData tsData = dictResult[pmms[i].PointId];
  153. WindturbineIcon ctrl = dictWindturbintIcon[controlName];
  154. if (tsData.doubleValue.HasValue)
  155. ctrl.Status = (int)tsData.doubleValue.Value;
  156. }
  157. }
  158. });
  159. }
  160. }
  161. private void UpdateStationStates()
  162. {
  163. var dict = CacheService.Instance.MatrixPointMap;
  164. if (dict == null)
  165. return;
  166. var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == stationId).ToArray();
  167. var points = pmms.Select(q => q.PointId).ToArray();
  168. Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
  169. lock (this.pnlStat)
  170. {
  171. //this.BeginInvoke(
  172. this.Invoke(
  173. (Action)delegate
  174. {
  175. for (int i = 0; i < points.Length; i++)
  176. {
  177. if (dictResult.ContainsKey(points[i]) == false)
  178. continue;
  179. double value = dictResult[points[i]].doubleValue.Value;
  180. pmms[i].Value = value;
  181. switch (pmms[i].UniformCode)
  182. {
  183. #region Switch
  184. case "BWTS8":
  185. lblCntBW.LableText = value.ToString("f0");
  186. break;
  187. case "LXTS8":
  188. lblCntLX.LableText = value.ToString("f0");
  189. break;
  190. case "DJTS8":
  191. lblCntDJ.LableText = value.ToString("f0");
  192. break;
  193. case "WHTS8":
  194. lblCntWH.LableText = value.ToString("f0");
  195. break;
  196. case "GZTS8":
  197. lblCntGZ.LableText = value.ToString("f0");
  198. break;
  199. case "TJTS8":
  200. lblCntTJ.LableText = value.ToString("f0");
  201. break;
  202. case "QDTS8":
  203. lblCntQD.LableText = value.ToString("f0");
  204. break;
  205. case "SDTS8":
  206. lblCntSD.LableText = value.ToString("f0");
  207. break;
  208. case "SSFS":
  209. lblWindspeed.LableText = value.ToString("f2");
  210. break;
  211. case "SSZGL":
  212. lblPower.LableText = value.ToString("f2");
  213. break;
  214. #endregion
  215. }
  216. }
  217. });
  218. }
  219. }
  220. private void LoadInitData()
  221. {
  222. try
  223. {
  224. var stInfo = CacheService.Instance.getStationInfo(stationId);
  225. if (stInfo != null)
  226. {
  227. lock (this.pnlStat)
  228. {
  229. this.BeginInvoke(
  230. (Action)delegate
  231. {
  232. this.lblCapacity.LableText = stInfo.CAPACITY.ToString();
  233. this.lblCntAll.LableText = stInfo.QUANTITY.ToString();
  234. });
  235. }
  236. }
  237. }
  238. catch (Exception ex)
  239. {
  240. logger.Error(ex);
  241. }
  242. }
  243. #endregion
  244. #region 窗体样式事件
  245. private void pnlStat_Paint(object sender, PaintEventArgs e)
  246. {
  247. ControlPaint.DrawBorder(e.Graphics,
  248. this.pnlStat.ClientRectangle,
  249. Color.FromArgb(49, 185, 251),
  250. 1,
  251. ButtonBorderStyle.Solid,
  252. Color.FromArgb(49, 185, 251),
  253. 1,
  254. ButtonBorderStyle.Solid,
  255. Color.FromArgb(49, 185, 251),
  256. 1,
  257. ButtonBorderStyle.Solid,
  258. Color.FromArgb(49, 185, 251),
  259. 1,
  260. ButtonBorderStyle.Solid);
  261. }
  262. private void pnlLink_Paint(object sender, PaintEventArgs e)
  263. {
  264. ControlPaint.DrawBorder(e.Graphics,
  265. this.pnlLink.ClientRectangle,
  266. Color.FromArgb(49, 185, 251),
  267. 1,
  268. ButtonBorderStyle.Solid,
  269. Color.FromArgb(49, 185, 251),
  270. 1,
  271. ButtonBorderStyle.Solid,
  272. Color.FromArgb(49, 185, 251),
  273. 1,
  274. ButtonBorderStyle.Solid,
  275. Color.FromArgb(49, 185, 251),
  276. 1,
  277. ButtonBorderStyle.Solid);
  278. }
  279. private void btnSYZ_MouseHover(object sender, EventArgs e)
  280. {
  281. Button btn = sender as Button;
  282. btn.Image = global::IntelligentControlForsx.Properties.Resources.B01;
  283. //btn.FlatAppearance.BorderSize = 0;
  284. }
  285. private void btnMap_MouseHover(object sender, EventArgs e)
  286. {
  287. Button btn = sender as Button;
  288. btn.Image = global::IntelligentControlForsx.Properties.Resources.B01;
  289. }
  290. private void btnSYZ_MouseLeave(object sender, EventArgs e)
  291. {
  292. Button btn = sender as Button;
  293. btn.Image = global::IntelligentControlForsx.Properties.Resources.B02;
  294. }
  295. private void btnMap_MouseLeave(object sender, EventArgs e)
  296. {
  297. Button btn = sender as Button;
  298. btn.Image = global::IntelligentControlForsx.Properties.Resources.B02;
  299. }
  300. #endregion
  301. private void timer2_Tick(object sender, EventArgs e)
  302. {
  303. DateTime time = DateTime.Now;
  304. lblDate.Text = time.ToString("yyyy-MM-dd");
  305. lblTime.LableText = time.ToString("HH:mm:ss");
  306. }
  307. }
  308. }