using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Drawing.Drawing2D; using System.Threading; using IntelligentControlForsx.Service; using IntelligentControlForsx.Model; using WisdomClient.data; using WisdomClient; using log4net; using IntelligentControlForsx.ChildForms; using EntityDataSet; namespace IntelligentControlForsx.MyControls { public partial class MatrixPopup : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); public MatrixPopup() { InitializeComponent(); } private void btnClose_Click(object sender, EventArgs e) { ExitPopup(); } private void btnCancel_Click(object sender, EventArgs e) { ExitPopup(); } private void ExitPopup() { this.SendToBack(); MatrixForm frm = this.Parent as MatrixForm; if (frm != null) { frm.FormMode = "matrix"; frm.Active(); } this.Visible = false; } private void btnClose_MouseHover(object sender, EventArgs e) { Button btn = sender as Button; btn.FlatAppearance.BorderSize = 1; } private void btnClose_MouseLeave(object sender, EventArgs e) { Button btn = sender as Button; btn.FlatAppearance.BorderSize = 0; } private void btnCancel_MouseHover(object sender, EventArgs e) { Button btn = sender as Button; btn.FlatAppearance.BorderSize = 1; } private void btnCancel_MouseLeave(object sender, EventArgs e) { Button btn = sender as Button; btn.FlatAppearance.BorderSize = 0; } private void btnConfirm_Click(object sender, EventArgs e) { user u = null; FingerCheck fc = new FingerCheck(); fc.ShowDialog(); u = FingerCheck.checkSuccessUser; if (u != null) { MessageBox.Show("命令发送成功"); ExitPopup(); } } private void btnConfirm_MouseHover(object sender, EventArgs e) { Button btn = sender as Button; btn.FlatAppearance.BorderSize = 1; } private void btnConfirm_MouseLeave(object sender, EventArgs e) { Button btn = sender as Button; btn.FlatAppearance.BorderSize = 0; } public string StationId { get { return this.stationRadio1.StationId; } set { this.stationRadio1.StationId = value; this.matrixPopupLine1.StationId = value; } } private void stationRadio1_StationIdChanged(object sender, EventArgs e) { //MessageBox.Show(StationId); this.matrixPopupLine1.StationId = StationId; Thread ayscThread2 = new Thread(LoadData2); ayscThread2.IsBackground = true; ayscThread2.Start(); } public void DeActive() { timer1.Stop(); timer2.Stop(); this.matrixPopupLine1.DeActive(); } public void Active() { Thread ayscThread = new Thread(LoadData); ayscThread.IsBackground = true; ayscThread.Start(); timer1.Start(); Thread ayscThread2 = new Thread(LoadData2); ayscThread2.IsBackground = true; ayscThread2.Start(); timer2.Start(); matrixPopupLine1.Active(); } #region 异步加载AGC数据 private void timer1_Tick(object sender, EventArgs e) { if (isLoadding) return; Thread ayscThread = new Thread(LoadData); ayscThread.IsBackground = true; ayscThread.Start(); //LoadData(); } private bool isLoadding = false; private void LoadData() { isLoadding = true; try { UpdateStationStates(); } catch (Exception ex) { logger.Info("读取实时数据失败!ex=" + ex.Message); } finally { isLoadding = false; } } private void UpdateStationStates() { var dict = CacheService.Instance.MatrixPopupPointMap; if (dict == null) return; var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == StationId).ToArray(); var points = pmms.Select(q => q.PointId).ToArray(); Dictionary dictResult = RestfulClient.findLatestByTagNames(points); //foreach (var tmp in dictResult) //{ // logger.Info(tmp.Key); // logger.Info(tmp.Value.ts); // logger.Info(tmp.Value.doubleValue); //} lock (this) { this.BeginInvoke( (Action)delegate { for (int i = 0; i < points.Length; i++) { if (dictResult.ContainsKey(points[i]) == false) continue; double value = dictResult[points[i]].doubleValue == null ? 0 : dictResult[points[i]].doubleValue.Value; pmms[i].Value = value; switch (pmms[i].UniformCode) { #region Switch //"YGSDZ", //有功设定值 //"SSZGL", //实时总功率 //"ZLLGL", //总理论功率 //"ZZSGL", //矫正后功率 //"SSZGL", //15分钟预测功率 //"SSZGL", //30分钟预测功率 //"SSZGL", //1h预测功率 //"SSZGL", //4h预测功率 case "YGSDZ": lblAGCSetting.Text = value.ToString("f0"); break; case "SSZGL": lblFactPower.Text = value.ToString("f0"); break; case "ZLLGL": lblTheoryPower.Text = value.ToString("f0"); break; case "ZZSGL": lblAdjustPower.Text = value.ToString("f0"); break; case "FCFGCDQ0001": lblForecast15.Text = value.ToString("f2"); break; case "FCFGCDQ0002": lblForecast30.Text = value.ToString("f2"); break; case "FCFGCDQ0004": lblForecast1h.Text = value.ToString("f2"); break; case "FCFGCDQ0016": lblForecast4h.Text = value.ToString("f2"); break; #endregion } } }); } } #endregion #region 异步加载启停推荐数据 private void timer2_Tick(object sender, EventArgs e) { if (isLoadding2) return; Thread ayscThread = new Thread(LoadData2); ayscThread.IsBackground = true; ayscThread.Start(); //LoadData(); } private bool isLoadding2 = false; private void LoadData2() { isLoadding2 = true; try { UpdatePredictPanel(); } catch (Exception ex) { logger.Info("读取实时数据失败!ex=" + ex.Message); } finally { isLoadding2 = false; } } private void UpdatePredictPanel() { var sp = PredictService.GetStationPredict(StationId); lock (this) { this.BeginInvoke( (Action)delegate { this.tlpCancelMaintain.Controls.Clear(); this.tlpMaintain.Controls.Clear(); this.tlpReset.Controls.Clear(); this.tlpStartUp.Controls.Clear(); if (sp.StartupList.Count > 0) { UpdateTablePanel(this.tlpStartUp, sp.StartupList); } if (sp.ResetList.Count > 0) { UpdateTablePanel(this.tlpReset, sp.ResetList); } if (sp.MaintainList.Count > 0) { UpdateTablePanel(this.tlpMaintain, sp.MaintainList); } if (sp.CancelMaintainList.Count > 0) { UpdateTablePanel(this.tlpCancelMaintain, sp.CancelMaintainList); } }); } } private void UpdateTablePanel(TableLayoutPanel tlp, IList lstWs) { int col = 4; int row = (int)Math.Ceiling((decimal)lstWs.Count / col); int arrIndex = 0; var arr = lstWs.ToArray(); tlp.Height = row * 60; tlp.RowCount = row; for (int i = 0; i < row; i++) { tlp.RowStyles.Add(new RowStyle(SizeType.Absolute, 60)); for (int j = 0; j < col; j++) { if (arrIndex >= lstWs.Count) return; PopupDevice pd = new PopupDevice(); WindturbineStatus ws = arr[arrIndex]; pd.DeviceId = ws.WindturbineId; pd.WindSpeed = ws["AI022"].doubleValue == null ? 0 : ws["AI022"].doubleValue.Value; pd.Status = ws.GetStatus(); pd.Power = ws["AI130"].doubleValue == null ? 0 : ws["AI130"].doubleValue.Value; pd.Rank = RandomRank(); tlp.Controls.Add(pd); tlp.SetRow(pd, i); tlp.SetColumn(pd, j); arrIndex++; } } } private string RandomRank() { Random random = new Random(); int rank = random.Next(0, 100); if (rank >= 90) return "AA"; else if (rank > 80) return "A"; else if (rank > 60) return "BBB"; else if (rank > 40) return "BB"; else if (rank > 20) return "B"; else if (rank > 10) return "C"; else return "C-"; } #endregion } }