using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using EntityDataSet; using log4net; using IntelligentControlForsx.Service; using IntelligentControlForsx.Model; using WisdomClient.data; using WisdomClient; using System.Threading; using IntelligentControlForsx.Common; namespace IntelligentControlForsx.MyControls { public partial class MatrixStation : UserControl { private ILog logger = LogManager.GetLogger("AppInfoLog"); private string[] deviceArray; private Dictionary dictMatrixDevice; private ContextMenuStrip contextMenuStrip; public MatrixStation() { this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);//开启双缓冲 InitializeComponent(); } string stationName; string stationId; double zfdl; double nfdl; double yfdl; double rfdl; double power; double windSpeed; double fhl; int cntAll; int cntBW; int cntSD; int cntTJ; int cntDJ; int cntGZ; int cntWH; int cntLX; int cntQD; #region 基本属性 [Browsable(true), Category("Data")] public string StationName { get { return stationName; } set { stationName = value; lblStationName.Text = value; } } [Browsable(true), Category("Data")] public string StationId { get { return stationId; } set { stationId = value; } } public ContextMenuStrip ContextMenuStrip1 { get { return contextMenuStrip; } set { contextMenuStrip = value; } } #endregion #region 指标属性 [Browsable(true), Category("Data")] public double WindSpeed { get { return windSpeed; } set { windSpeed = value; lblWindSpeed.Text = Convert.ToDouble(value).ToString("0.00"); } } [Browsable(true), Category("Data")] public double Power { get { return power; } set { power = value; lblPower.Text = Convert.ToDouble(value).ToString("0.00"); } } [Browsable(true), Category("Data")] public double ZFDL { get { return zfdl; } set { zfdl = value; //lblZFDL.Text = Convert.ToDouble(value).ToString("0.00"); } } [Browsable(true), Category("Data")] public double NFDL { get { return nfdl; } set { nfdl = value; lblNFDL.Text = Convert.ToDouble(value).ToString("0.00"); } } [Browsable(true), Category("Data")] public double YFDL { get { return yfdl; } set { yfdl = value; lblYFDL.Text = Convert.ToDouble(value).ToString("0.00"); } } [Browsable(true), Category("Data")] public double RFDL { get { return rfdl; } set { rfdl = value; lblRFDL.Text = Convert.ToDouble(value).ToString("0.00"); } } [Browsable(true), Category("Data")] public double FHL { get { return fhl; } set { fhl = value; lblFHL.Text = Convert.ToDouble(value).ToString("0.00"); } } #endregion #region 状态台数 [Browsable(true), Category("Data")] public int CntAll { get { return cntAll; } set { cntAll = value; lblCntAll.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntBW { get { return cntBW; } set { cntBW = value; lblCntAll.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntSD { get { return cntSD; } set { cntSD = value; lblCntSD.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntTJ { get { return cntTJ; } set { cntTJ = value; lblCntTJ.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntDJ { get { return cntDJ; } set { cntDJ = value; lblCntDJ.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntGZ { get { return cntGZ; } set { cntGZ = value; lblCntGZ.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntWH { get { return cntWH; } set { cntWH = value; lblCntWH.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntLX { get { return cntLX; } set { cntLX = value; lblCntLX.Text = value.ToString(); } } [Browsable(true), Category("Data")] public int CntQD { get { return cntQD; } set { cntQD = value; lblCntQD.Text = value.ToString(); } } #endregion public void InitTablePanel() { if (String.IsNullOrWhiteSpace(stationId)) return; deviceArray = MatrixFormService.GetDeviceIdArrayByStationId(stationId); var wtArray = CacheService.Instance.GetWindturbineListByStationId(stationId).ToArray(); if (wtArray == null || wtArray.Length < 1) return; dictMatrixDevice = new Dictionary(); int col = 22; int row = (int)Math.Ceiling((decimal)wtArray.Length / 22); int arrIndex = 0; pnlTable.Height = row * 42; this.Height = pnlTable.Height + 24; pnlTable.RowCount = row; this.SuspendLayout(); for (int i = 0; i < row; i++) { pnlTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 42)); for (int j = 0; j < col; j++) { if (arrIndex >= wtArray.Length) return; MatrixBlock device = new MatrixBlock(); device.ContextMenuStrip = contextMenuStrip; device.DeviceId = CommonMethod.GetShortWindturbineId(wtArray[arrIndex].ID); device.DeviceModel = wtArray[arrIndex].MODELID; device.StationId = wtArray[arrIndex].WINDPOWERSTATIONID; device.Status = 3; pnlTable.Controls.Add(device); if (!dictMatrixDevice.ContainsKey(device.DeviceId)) dictMatrixDevice.Add(device.DeviceId, device); pnlTable.SetRow(device, i); pnlTable.SetColumn(device, j); arrIndex++; } } this.Refresh(); this.ResumeLayout(); timer1.Enabled = true; } public void DeActive() { this.Hide(); timer1.Stop(); } public void Active() { this.Show(); Thread ayscThread = new Thread(LoadData); ayscThread.IsBackground = true; ayscThread.Start(); timer1.Start(); } #region 异步加载数据 private void timer1_Tick(object sender, EventArgs e) { if (isLoadding) return; LoadData(); } private bool isLoadding = true; private object loadDataLocker = new object(); private async void LoadData() { isLoadding = true; try { foreach (var kv in await SearchStationData()) { if (CacheService.Instance.MatrixPointMap.ContainsKey(kv.Key)) { CacheService.Instance.MatrixPointMap[kv.Key].Value = kv.Value.doubleValue.Value; switch (CacheService.Instance.MatrixPointMap[kv.Key].UniformCode) { #region Switch //"YXTS", //运行台数 //"TXZD", //通讯中断 //"DJTS", //待机台数 //"WHTJ", //维护台数 //"GZTJ", //故障台数 //"XDTS", //限电台数 //"SSFS", //实时平均风速 //"SSZGL", //实时总功率 //"RFDL", //日发电量 //"YFDL", //月发电量 //"NFDL", //年发电量 //"ZFDL" //总发电量 case "BWTS8": lblCntBW.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "LXTS8": lblCntLX.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "DJTS8": lblCntDJ.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "WHTS8": lblCntWH.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "GZTS8": lblCntGZ.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "QDTS8": lblCntQD.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "TJTS8": lblCntTJ.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "SDTS8": lblCntSD.Text = kv.Value.doubleValue.Value.ToString("f0"); break; case "RFDL": lblRFDL.Text = kv.Value.doubleValue.Value.ToString("f2"); break; case "YFDL": lblYFDL.Text = kv.Value.doubleValue.Value.ToString("f2"); break; case "NFDL": lblNFDL.Text = kv.Value.doubleValue.Value.ToString("f2"); break; case "ZFDL": // lblZFDL.Text = value.ToString("f2"); break; case "SSFS": lblWindSpeed.Text = kv.Value.doubleValue.Value.ToString("f2"); break; case "SSZGL": lblPower.Text = kv.Value.doubleValue.Value.ToString("f2"); double fh = 0.0; double fhl = 0.0; if (stationId == "SBQ_FDC") { fh = kv.Value.doubleValue.Value / 198.5; fhl = fh * 100; } if (stationId == "MHS_FDC") { fh = kv.Value.doubleValue.Value / 69.5; fhl = fh * 100; } if (stationId == "XS_FDC") { fh = kv.Value.doubleValue.Value / 99; fhl = fh * 100; } if (stationId == "QS_FDC") { fh = kv.Value.doubleValue.Value / 99; fhl = fh * 100; } if (stationId == "NSS_FDC") { fh = kv.Value.doubleValue.Value / 148.5; fhl = fh * 100; } lblFHL.Text = fhl.ToString("f2"); break; #endregion } } } foreach (var kv in await SearchWindturbineData()) { if (CacheService.Instance.MatrixPointMap.ContainsKey(kv.Key)) { CacheService.Instance.MatrixPointMap[kv.Key].Value = kv.Value.doubleValue.Value; MatrixBlock wBlock = dictMatrixDevice[CacheService.Instance.MatrixPointMap[kv.Key].ThingId]; switch (CacheService.Instance.MatrixPointMap[kv.Key].UniformCode) { #region Switch //"AI021", //3秒平均风速 //"AI130", //功率 //"AI010", //风向角度 //"FJZT" //风机状态 case "AI022": wBlock.WindSpeed = kv.Value.doubleValue.Value; break; case "AI130": wBlock.Power = kv.Value.doubleValue.Value; break; //case "AI010": // wBlock.WindAngle = values[i].ToString("f2") + " 度"; // break; case "FJZT8": wBlock.Status = kv.Value.doubleValue.Value; wBlock.Ts = kv.Value.ts; break; case "XDSL": if (kv.Value.doubleValue.Value != 0) wBlock.IsLock = true; else wBlock.IsLock = false; wBlock.LockValue = kv.Value.doubleValue.Value; break; #endregion } } } } catch (Exception ex) { logger.Info("读取实时数据失败!ex=" + ex.Message); } finally { isLoadding = false; } } private Task> SearchStationData() { return Task.Run( () => { var dict = CacheService.Instance.MatrixPointMap; if (dict == null) return new Dictionary(); var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == stationId).ToArray(); var points = pmms.Select(q => q.PointId).ToArray(); return RestfulClient.findLatestByTagNames(points); }); } private Task> SearchWindturbineData() { return Task.Run( () => { if (deviceArray == null || deviceArray.Length < 1) return new Dictionary(); var dict = CacheService.Instance.MatrixPointMap; if (dict == null) return new Dictionary(); var pmms = dict.Values.Where(q => q.ThingType == PointType.Windturbine && deviceArray.Contains(q.ThingId)).ToArray(); var points = pmms.Select(q => q.PointId).ToArray(); return RestfulClient.findLatestByTagNames(points); }); } #endregion } }