ZM_QS.cs 11 KB

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