123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616 |
- 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<string, MatrixBlock> 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<string, MatrixBlock>();
- 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<Dictionary<string, TsData>> SearchStationData()
- {
- return Task.Run(
- () =>
- {
- var dict = CacheService.Instance.MatrixPointMap;
- if (dict == null)
- return new Dictionary<string, TsData>();
- 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<Dictionary<string, TsData>> SearchWindturbineData()
- {
- return Task.Run(
- () =>
- {
- if (deviceArray == null || deviceArray.Length < 1)
- return new Dictionary<string, TsData>();
- var dict = CacheService.Instance.MatrixPointMap;
- if (dict == null)
- return new Dictionary<string, TsData>();
- 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
- }
- }
|