SunAGC.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using IntelligentControlForsx.Code;
  12. using IntelligentControlForsx.Service.AGC;
  13. using IntelligentControlForsx.Service.AGC.Domain;
  14. using WisdomClient.data;
  15. namespace IntelligentControlForsx.MyControls.agc
  16. {
  17. public partial class SunAGC : UserControl
  18. {
  19. private bool isUpdateDataOver = true;
  20. private bool isBindFormOver = true;
  21. private bool isUpdateLineDataOver = true;
  22. private bool isBindLineFormOver = true;
  23. public SunAGC()
  24. {
  25. InitializeComponent();
  26. }
  27. public void DeActive()
  28. {
  29. timer1.Stop();
  30. timer2.Stop();
  31. }
  32. public void Active()
  33. {
  34. this.Show();
  35. timer1.Start();
  36. timer2.Start();
  37. }
  38. private void timer1_Tick(object sender, EventArgs e)
  39. {
  40. if (isBindFormOver)//绑定form
  41. {
  42. isBindFormOver = false;
  43. Thread bindDataThread = new Thread(BindFormInvoke);
  44. bindDataThread.Start();
  45. }
  46. if (isUpdateDataOver)//更新数据
  47. {
  48. Thread ayscThread = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetLatestAgcDataInfo));
  49. ayscThread.IsBackground = true;
  50. ayscThread.Start(false);
  51. }
  52. }
  53. public delegate void UpdateFormInfoDelegate();
  54. public void BindFormInvoke()
  55. {
  56. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind);
  57. if (this.InvokeRequired)
  58. {
  59. this.BeginInvoke(del, new object[] { });
  60. }
  61. else
  62. {
  63. FormDataBind();
  64. }
  65. }
  66. public void FormDataBind()
  67. {
  68. string path = UserTools.Path;
  69. string green_img_path = path + @"\images\green.png";
  70. string red_img_path = path + @"\images\red.png";
  71. #region 石嘴山5
  72. AgcEntity szs5 = AgcInfoSvc.agcDataList.Where(s => s.StationName == "SZS5").FirstOrDefault();
  73. if (szs5 != null)
  74. {
  75. lblPowerSet_SZS5.LableText = szs5.PowerSetValue.ToString("f2");
  76. lblActualPower_SZS5.LableText = szs5.ActualPowerValue.ToString("f2");
  77. lblAgcUp_SZS5.LableText = szs5.AgcUp .ToString("f2");
  78. lblAgcLower_SZS5.LableText = szs5.AgcLower.ToString("f2");
  79. lblForecastPower_SZS5.LableText = szs5.ForecastPower.ToString("f2");
  80. if (szs5.AgcIn)
  81. picAgcOut_SZS5.Image = Image.FromFile(red_img_path);
  82. else
  83. picAgcOut_SZS5.Image = Image.FromFile(green_img_path);
  84. if (szs5.AgcFar)
  85. picAgcFar_SZS5.Image = Image.FromFile(red_img_path);
  86. else
  87. picAgcFar_SZS5.Image = Image.FromFile(green_img_path);
  88. }
  89. #endregion
  90. #region 平罗3
  91. AgcEntity pl3 = AgcInfoSvc.agcDataList.Where(s => s.StationName == "PL3").FirstOrDefault();
  92. if (pl3 != null)
  93. {
  94. lblPowerSet_PL3.LableText = pl3.PowerSetValue .ToString("f2");
  95. lblActualPower_PL3.LableText = pl3.ActualPowerValue.ToString("f2");
  96. lblAgcUp_PL3.LableText = pl3.AgcUp .ToString("f2");
  97. lblAgcLower_PL3.LableText = pl3.AgcLower .ToString("f2");
  98. lblForecastPower_PL3.LableText = pl3.ForecastPower.ToString("f2");
  99. if (pl3.AgcIn)
  100. picAgcOut_PL3.Image = Image.FromFile(red_img_path);
  101. else
  102. picAgcOut_PL3.Image = Image.FromFile(green_img_path);
  103. if (pl3.AgcFar)
  104. picAgcFar_PL3.Image = Image.FromFile(red_img_path);
  105. else
  106. picAgcFar_PL3.Image = Image.FromFile(green_img_path);
  107. }
  108. #endregion
  109. #region 中卫6
  110. AgcEntity zw6 = AgcInfoSvc.agcDataList.Where(s => s.StationName == "ZW6").FirstOrDefault();
  111. if (zw6 != null)
  112. {
  113. lblPowerSet_ZW6.LableText = zw6.PowerSetValue .ToString("f2");
  114. lblActualPower_ZW6.LableText = zw6.ActualPowerValue.ToString("f2");
  115. lblAgcUp_ZW6.LableText = zw6.AgcUp .ToString("f2");
  116. lblAgcLower_ZW6.LableText = zw6.AgcLower .ToString("f2");
  117. lblForecastPower_ZW6.LableText = zw6.ForecastPower.ToString("f2");
  118. if (zw6.AgcIn)
  119. picAgcOut_ZW6.Image = Image.FromFile(red_img_path);
  120. else
  121. picAgcOut_ZW6.Image = Image.FromFile(green_img_path);
  122. if (zw6.AgcFar)
  123. picAgcFar_ZW6.Image = Image.FromFile(red_img_path);
  124. else
  125. picAgcFar_ZW6.Image = Image.FromFile(green_img_path);
  126. }
  127. #endregion
  128. isBindFormOver = true;
  129. }
  130. private void timer2_Tick(object sender, EventArgs e)
  131. {
  132. if (isBindLineFormOver)//绑定form
  133. {
  134. isBindLineFormOver = false;
  135. Thread bindDataThread = new Thread(BindFormLineInvoke);
  136. bindDataThread.Start();
  137. }
  138. if (isUpdateLineDataOver)//更新数据
  139. {
  140. Thread ayscThread = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetHistoryLineData));
  141. ayscThread.IsBackground = true;
  142. ayscThread.Start(false);
  143. }
  144. }
  145. public void BindFormLineInvoke()
  146. {
  147. UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormLineDataBind);
  148. if (this.InvokeRequired)
  149. {
  150. this.BeginInvoke(del, new object[] { });
  151. }
  152. else
  153. {
  154. FormLineDataBind();
  155. }
  156. }
  157. public void FormLineDataBind()
  158. {
  159. PowerActual powerActual_szs5 = AgcInfoSvc.powerActualList.Where(s => s.StationName == "SZS5").FirstOrDefault();
  160. PowerSet powerSet_szs5 = AgcInfoSvc.powerSetList.Where(s => s.StationName == "SZS5").FirstOrDefault();
  161. if (powerActual_szs5 != null && powerSet_szs5 != null)
  162. {
  163. IList<TsData> pstList = new List<TsData>();
  164. IList<TsData> actlList = new List<TsData>();
  165. for (int i = 0; i < powerSet_szs5.TsDataList.Count; i++)
  166. {
  167. TsData tsData = new TsData();
  168. tsData.ts = powerSet_szs5.TsDataList[i].ts;
  169. double tValue = powerSet_szs5.TsDataList[i].doubleValue.HasValue
  170. ? powerSet_szs5.TsDataList[i].doubleValue.Value
  171. : 0.0;
  172. tsData.doubleValue = tValue;
  173. pstList.Add(tsData);
  174. }
  175. for (int i = 0; i < powerActual_szs5.TsDataList.Count; i++)
  176. {
  177. TsData tsData = new TsData();
  178. tsData.ts = powerActual_szs5.TsDataList[i].ts;
  179. double tValue = powerActual_szs5.TsDataList[i].doubleValue.HasValue
  180. ? powerActual_szs5.TsDataList[i].doubleValue.Value
  181. : 0.0;
  182. tsData.doubleValue = tValue;
  183. actlList.Add(tsData);
  184. }
  185. lineChar_SZS5.DataBind(actlList, pstList);
  186. }
  187. PowerActual powerActual_pl3 = AgcInfoSvc.powerActualList.Where(s => s.StationName == "PL3").FirstOrDefault();
  188. PowerSet powerSet_pl3 = AgcInfoSvc.powerSetList.Where(s => s.StationName == "PL3").FirstOrDefault();
  189. if (powerActual_pl3 != null && powerSet_pl3 != null)
  190. {
  191. IList<TsData> pstList = new List<TsData>();
  192. IList<TsData> actlList = new List<TsData>();
  193. for (int i = 0; i < powerSet_pl3.TsDataList.Count; i++)
  194. {
  195. TsData tsData = new TsData();
  196. tsData.ts = powerSet_pl3.TsDataList[i].ts;
  197. double tValue = powerSet_pl3.TsDataList[i].doubleValue.HasValue
  198. ? powerSet_pl3.TsDataList[i].doubleValue.Value
  199. : 0.0;
  200. tsData.doubleValue = tValue;
  201. pstList.Add(tsData);
  202. }
  203. for (int i = 0; i < powerActual_pl3.TsDataList.Count; i++)
  204. {
  205. TsData tsData = new TsData();
  206. tsData.ts = powerActual_pl3.TsDataList[i].ts;
  207. double tValue = powerActual_pl3.TsDataList[i].doubleValue.HasValue
  208. ? powerActual_pl3.TsDataList[i].doubleValue.Value
  209. : 0.0;
  210. tsData.doubleValue = tValue;
  211. actlList.Add(tsData);
  212. }
  213. lineChar_PL3.DataBind(actlList, pstList);
  214. }
  215. PowerActual powerActual_zw6 = AgcInfoSvc.powerActualList.Where(s => s.StationName == "ZW6").FirstOrDefault();
  216. PowerSet powerSet_zw6 = AgcInfoSvc.powerSetList.Where(s => s.StationName == "ZW6").FirstOrDefault();
  217. if (powerActual_zw6 != null && powerSet_zw6 != null)
  218. {
  219. IList<TsData> pstList = new List<TsData>();
  220. IList<TsData> actlList = new List<TsData>();
  221. for (int i = 0; i < powerSet_zw6.TsDataList.Count; i++)
  222. {
  223. TsData tsData = new TsData();
  224. tsData.ts = powerSet_zw6.TsDataList[i].ts;
  225. double tValue = powerSet_zw6.TsDataList[i].doubleValue.HasValue
  226. ? powerSet_zw6.TsDataList[i].doubleValue.Value
  227. : 0.0;
  228. tsData.doubleValue = tValue;
  229. pstList.Add(tsData);
  230. }
  231. for (int i = 0; i < powerActual_zw6.TsDataList.Count; i++)
  232. {
  233. TsData tsData = new TsData();
  234. tsData.ts = powerActual_zw6.TsDataList[i].ts;
  235. double tValue = powerActual_zw6.TsDataList[i].doubleValue.HasValue
  236. ? powerActual_zw6.TsDataList[i].doubleValue.Value
  237. : 0.0;
  238. tsData.doubleValue = tValue;
  239. actlList.Add(tsData);
  240. }
  241. lineChar_ZW6.DataBind(actlList, pstList);
  242. }
  243. isBindLineFormOver = true;
  244. }
  245. private void SunAGC_Load(object sender, EventArgs e)
  246. {
  247. Thread ayscThread1 = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetLatestAgcDataInfo));
  248. ayscThread1.IsBackground = true;
  249. ayscThread1.Start(true);
  250. Thread ayscThread2 = new Thread(new ParameterizedThreadStart(AgcInfoSvc.GetHistoryLineData));
  251. ayscThread2.IsBackground = true;
  252. ayscThread2.Start(true);
  253. }
  254. }
  255. }