MatrixPopup.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.Service;
  14. using IntelligentControlForsx.Model;
  15. using WisdomClient.data;
  16. using WisdomClient;
  17. using log4net;
  18. using IntelligentControlForsx.ChildForms;
  19. using EntityDataSet;
  20. namespace IntelligentControlForsx.MyControls
  21. {
  22. public partial class MatrixPopup : UserControl
  23. {
  24. private ILog logger = LogManager.GetLogger("AppInfoLog");
  25. public MatrixPopup()
  26. {
  27. InitializeComponent();
  28. }
  29. private void btnClose_Click(object sender, EventArgs e)
  30. {
  31. ExitPopup();
  32. }
  33. private void btnCancel_Click(object sender, EventArgs e)
  34. {
  35. ExitPopup();
  36. }
  37. private void ExitPopup()
  38. {
  39. this.SendToBack();
  40. MatrixForm frm = this.Parent as MatrixForm;
  41. if (frm != null)
  42. {
  43. frm.FormMode = "matrix";
  44. frm.Active();
  45. }
  46. this.Visible = false;
  47. }
  48. private void btnClose_MouseHover(object sender, EventArgs e)
  49. {
  50. Button btn = sender as Button;
  51. btn.FlatAppearance.BorderSize = 1;
  52. }
  53. private void btnClose_MouseLeave(object sender, EventArgs e)
  54. {
  55. Button btn = sender as Button;
  56. btn.FlatAppearance.BorderSize = 0;
  57. }
  58. private void btnCancel_MouseHover(object sender, EventArgs e)
  59. {
  60. Button btn = sender as Button;
  61. btn.FlatAppearance.BorderSize = 1;
  62. }
  63. private void btnCancel_MouseLeave(object sender, EventArgs e)
  64. {
  65. Button btn = sender as Button;
  66. btn.FlatAppearance.BorderSize = 0;
  67. }
  68. private void btnConfirm_Click(object sender, EventArgs e)
  69. {
  70. user u = null;
  71. FingerCheck fc = new FingerCheck();
  72. fc.ShowDialog();
  73. u = FingerCheck.checkSuccessUser;
  74. if (u != null)
  75. {
  76. MessageBox.Show("命令发送成功");
  77. ExitPopup();
  78. }
  79. }
  80. private void btnConfirm_MouseHover(object sender, EventArgs e)
  81. {
  82. Button btn = sender as Button;
  83. btn.FlatAppearance.BorderSize = 1;
  84. }
  85. private void btnConfirm_MouseLeave(object sender, EventArgs e)
  86. {
  87. Button btn = sender as Button;
  88. btn.FlatAppearance.BorderSize = 0;
  89. }
  90. public string StationId
  91. {
  92. get
  93. {
  94. return this.stationRadio1.StationId;
  95. }
  96. set
  97. {
  98. this.stationRadio1.StationId = value;
  99. this.matrixPopupLine1.StationId = value;
  100. }
  101. }
  102. private void stationRadio1_StationIdChanged(object sender, EventArgs e)
  103. {
  104. //MessageBox.Show(StationId);
  105. this.matrixPopupLine1.StationId = StationId;
  106. Thread ayscThread2 = new Thread(LoadData2);
  107. ayscThread2.IsBackground = true;
  108. ayscThread2.Start();
  109. }
  110. public void DeActive()
  111. {
  112. timer1.Stop();
  113. timer2.Stop();
  114. this.matrixPopupLine1.DeActive();
  115. }
  116. public void Active()
  117. {
  118. Thread ayscThread = new Thread(LoadData);
  119. ayscThread.IsBackground = true;
  120. ayscThread.Start();
  121. timer1.Start();
  122. Thread ayscThread2 = new Thread(LoadData2);
  123. ayscThread2.IsBackground = true;
  124. ayscThread2.Start();
  125. timer2.Start();
  126. matrixPopupLine1.Active();
  127. }
  128. #region 异步加载AGC数据
  129. private void timer1_Tick(object sender, EventArgs e)
  130. {
  131. if (isLoadding) return;
  132. Thread ayscThread = new Thread(LoadData);
  133. ayscThread.IsBackground = true;
  134. ayscThread.Start();
  135. //LoadData();
  136. }
  137. private bool isLoadding = false;
  138. private void LoadData()
  139. {
  140. isLoadding = true;
  141. try
  142. {
  143. UpdateStationStates();
  144. }
  145. catch (Exception ex)
  146. {
  147. logger.Info("读取实时数据失败!ex=" + ex.Message);
  148. }
  149. finally
  150. {
  151. isLoadding = false;
  152. }
  153. }
  154. private void UpdateStationStates()
  155. {
  156. var dict = CacheService.Instance.MatrixPopupPointMap;
  157. if (dict == null)
  158. return;
  159. var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == StationId).ToArray();
  160. var points = pmms.Select(q => q.PointId).ToArray();
  161. Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
  162. //foreach (var tmp in dictResult)
  163. //{
  164. // logger.Info(tmp.Key);
  165. // logger.Info(tmp.Value.ts);
  166. // logger.Info(tmp.Value.doubleValue);
  167. //}
  168. lock (this)
  169. {
  170. this.BeginInvoke(
  171. (Action)delegate
  172. {
  173. for (int i = 0; i < points.Length; i++)
  174. {
  175. if (dictResult.ContainsKey(points[i]) == false)
  176. continue;
  177. double value = dictResult[points[i]].doubleValue == null ? 0 : dictResult[points[i]].doubleValue.Value;
  178. pmms[i].Value = value;
  179. switch (pmms[i].UniformCode)
  180. {
  181. #region Switch
  182. //"YGSDZ", //有功设定值
  183. //"SSZGL", //实时总功率
  184. //"ZLLGL", //总理论功率
  185. //"ZZSGL", //矫正后功率
  186. //"SSZGL", //15分钟预测功率
  187. //"SSZGL", //30分钟预测功率
  188. //"SSZGL", //1h预测功率
  189. //"SSZGL", //4h预测功率
  190. case "YGSDZ":
  191. lblAGCSetting.Text = value.ToString("f0");
  192. break;
  193. case "SSZGL":
  194. lblFactPower.Text = value.ToString("f0");
  195. break;
  196. case "ZLLGL":
  197. lblTheoryPower.Text = value.ToString("f0");
  198. break;
  199. case "ZZSGL":
  200. lblAdjustPower.Text = value.ToString("f0");
  201. break;
  202. case "FCFGCDQ0001":
  203. lblForecast15.Text = value.ToString("f2");
  204. break;
  205. case "FCFGCDQ0002":
  206. lblForecast30.Text = value.ToString("f2");
  207. break;
  208. case "FCFGCDQ0004":
  209. lblForecast1h.Text = value.ToString("f2");
  210. break;
  211. case "FCFGCDQ0016":
  212. lblForecast4h.Text = value.ToString("f2");
  213. break;
  214. #endregion
  215. }
  216. }
  217. });
  218. }
  219. }
  220. #endregion
  221. #region 异步加载启停推荐数据
  222. private void timer2_Tick(object sender, EventArgs e)
  223. {
  224. if (isLoadding2) return;
  225. Thread ayscThread = new Thread(LoadData2);
  226. ayscThread.IsBackground = true;
  227. ayscThread.Start();
  228. //LoadData();
  229. }
  230. private bool isLoadding2 = false;
  231. private void LoadData2()
  232. {
  233. isLoadding2 = true;
  234. try
  235. {
  236. UpdatePredictPanel();
  237. }
  238. catch (Exception ex)
  239. {
  240. logger.Info("读取实时数据失败!ex=" + ex.Message);
  241. }
  242. finally
  243. {
  244. isLoadding2 = false;
  245. }
  246. }
  247. private void UpdatePredictPanel()
  248. {
  249. var sp = PredictService.GetStationPredict(StationId);
  250. lock (this)
  251. {
  252. this.BeginInvoke(
  253. (Action)delegate
  254. {
  255. this.tlpCancelMaintain.Controls.Clear();
  256. this.tlpMaintain.Controls.Clear();
  257. this.tlpReset.Controls.Clear();
  258. this.tlpStartUp.Controls.Clear();
  259. if (sp.StartupList.Count > 0)
  260. {
  261. UpdateTablePanel(this.tlpStartUp, sp.StartupList);
  262. }
  263. if (sp.ResetList.Count > 0)
  264. {
  265. UpdateTablePanel(this.tlpReset, sp.ResetList);
  266. }
  267. if (sp.MaintainList.Count > 0)
  268. {
  269. UpdateTablePanel(this.tlpMaintain, sp.MaintainList);
  270. }
  271. if (sp.CancelMaintainList.Count > 0)
  272. {
  273. UpdateTablePanel(this.tlpCancelMaintain, sp.CancelMaintainList);
  274. }
  275. });
  276. }
  277. }
  278. private void UpdateTablePanel(TableLayoutPanel tlp, IList<WindturbineStatus> lstWs)
  279. {
  280. int col = 4;
  281. int row = (int)Math.Ceiling((decimal)lstWs.Count / col);
  282. int arrIndex = 0;
  283. var arr = lstWs.ToArray();
  284. tlp.Height = row * 60;
  285. tlp.RowCount = row;
  286. for (int i = 0; i < row; i++)
  287. {
  288. tlp.RowStyles.Add(new RowStyle(SizeType.Absolute, 60));
  289. for (int j = 0; j < col; j++)
  290. {
  291. if (arrIndex >= lstWs.Count)
  292. return;
  293. PopupDevice pd = new PopupDevice();
  294. WindturbineStatus ws = arr[arrIndex];
  295. pd.DeviceId = ws.WindturbineId;
  296. pd.WindSpeed = ws["AI022"].doubleValue == null ? 0 : ws["AI022"].doubleValue.Value;
  297. pd.Status = ws.GetStatus();
  298. pd.Power = ws["AI130"].doubleValue == null ? 0 : ws["AI130"].doubleValue.Value;
  299. pd.Rank = RandomRank();
  300. tlp.Controls.Add(pd);
  301. tlp.SetRow(pd, i);
  302. tlp.SetColumn(pd, j);
  303. arrIndex++;
  304. }
  305. }
  306. }
  307. private string RandomRank()
  308. {
  309. Random random = new Random();
  310. int rank = random.Next(0, 100);
  311. if (rank >= 90)
  312. return "AA";
  313. else if (rank > 80)
  314. return "A";
  315. else if (rank > 60)
  316. return "BBB";
  317. else if (rank > 40)
  318. return "BB";
  319. else if (rank > 20)
  320. return "B";
  321. else if (rank > 10)
  322. return "C";
  323. else
  324. return "C-";
  325. }
  326. #endregion
  327. }
  328. }