123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 |
- 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.Threading;
- using log4net;
- using IntelligentControlForsx.Service;
- using IntelligentControlForsx.Model;
- using WisdomClient.data;
- using WisdomClient;
- namespace IntelligentControlForsx.MyControls
- {
- public partial class MatrixTop : UserControl
- {
- private ILog logger = LogManager.GetLogger("AppInfoLog");
- public MatrixTop()
- {
- InitializeComponent();
- }
- 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 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 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;
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- LoadData();
- Thread statusCountThread = new Thread(BindFormThread);
- statusCountThread.IsBackground = true;
- statusCountThread.Start();
- }
- 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.MatrixPointMap;
- if (dict == null)
- return;
- var pmms = dict.Values.Where(q => q.ThingType == PointType.Station && q.ThingId == "-1").ToArray();
- var points = pmms.Select(q => q.PointId).ToArray();
- Dictionary<string, TsData> 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.Value;
- pmms[i].Value = value;
- switch (pmms[i].UniformCode)
- {
- #region Switch
- //"YXTS", //运行台数
- //"TXZD", //通讯中断
- //"DJTS", //待机台数
- //"WHTJ", //维护台数
- //"GZTJ", //故障台数
- //"XDTS", //限电台数
- //"SSFS", //实时平均风速
- //"SSZGL", //实时总功率
- //"RFDL", //日发电量
- //"YFDL", //月发电量
- //"NFDL", //年发电量
- //"ZFDL" //总发电量
- case "BWTS8":
- lblCntBW.Text = value.ToString("f0");
- break;
- case "LXTS8":
- lblCntLX.Text = value.ToString("f0");
- break;
- case "DJTS8":
- lblCntDJ.Text = value.ToString("f0");
- break;
- case "WHTS8":
- lblCntWH.Text = value.ToString("f0");
- break;
- case "GZTS8":
- lblCntGZ.Text = value.ToString("f0");
- break;
- case "QDTS8":
- lblCntQD.Text = value.ToString("f0");
- break;
- case "SDTS8":
- lblCntSD.Text = value.ToString("f0");
- break;
- case "TJTS8":
- lblCntTJ.Text = value.ToString("f0");
- break;
- case "RFDL":
- lblRFDL.Text = value.ToString("f2");
- break;
- case "YFDL":
- lblYFDL.Text = value.ToString("f2");
- break;
- case "NFDL":
- lblNFDL.Text = value.ToString("f2");
- break;
- case "SFDL":
- // lblZFDL.Text = value.ToString("f2");
- break;
- case "SSFS":
- lblWindSpeed.Text = value.ToString("f2");
- break;
- case "SSZGL":
- lblPower.Text = value.ToString("f2");
- double fh = value / 684.5;
- double fhl = fh*100;
- lblFHL.Text = fhl.ToString("f2");
- break;
- #endregion
- }
- }
- });
- }
- }
- #endregion
- #region 异步加载初始化数据
- private void MatrixTop_Load(object sender, EventArgs e)
- {
- Thread ayscThread = new Thread(LoadInitData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- }
- private void LoadInitData()
- {
- try
- {
- UpdateLblCntAll();
- }
- catch (Exception ex)
- {
- logger.Info("读取实时数据失败!ex=" + ex.Message);
- }
- }
- private void UpdateLblCntAll()
- {
- int count = CacheService.Instance.WindturbineList.Count();
- lock (this.lblCntAll)
- {
- this.lblCntAll.BeginInvoke(
- (Action)delegate
- {
- lblCntAll.Text = count.ToString();
- });
- }
- }
- #endregion
- private delegate void UpdateGridViewDelegate();
- public void BindFormThread()
- {
- UpdateGridViewDelegate del = new UpdateGridViewDelegate(UpdateWindturbineStatusCount);
- if (this.InvokeRequired)
- {
- this.BeginInvoke(del, new object[] { });
- }
- else
- {
- UpdateWindturbineStatusCount();
- }
- }
- private void UpdateWindturbineStatusCount()
- {
- string[] uniformCode = new string[] { "TJTS8", "SDTS8", "DJTS8", "QDTS8", "BWTS8", "GZTS8", "WHTS8", "LXTS8" };
- Dictionary<string, TsData> dictResult_SBQ = RestfulClient.findLatestByThingCodes("station", "SBQ_FDC",
- uniformCode);
- Dictionary<string, TsData> dictResult_MHS = RestfulClient.findLatestByThingCodes("station", "MHS_FDC",
- uniformCode);
- Dictionary<string, TsData> dictResult_NSS = RestfulClient.findLatestByThingCodes("station", "NSS_FDC",
- uniformCode);
- Dictionary<string, TsData> dictResult_QS = RestfulClient.findLatestByThingCodes("station", "QS_FDC",
- uniformCode);
- Dictionary<string, TsData> dictResult_XS = RestfulClient.findLatestByThingCodes("station", "XS_FDC",
- uniformCode);
- int stopCount = 0;
- int onPowerCount = 0;
- int standByCount = 0;
- int startCount = 0;
- int onlineCount = 0;
- int faultCount = 0;
- int maintainCount = 0;
- int offlineCount = 0;
- stopCount = GetCount("TJTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- onPowerCount = GetCount("SDTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- standByCount = GetCount("DJTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- startCount = GetCount("QDTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- onlineCount = GetCount("BWTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- faultCount = GetCount("GZTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- maintainCount = GetCount("WHTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- offlineCount = GetCount("LXTS8", dictResult_SBQ, dictResult_MHS, dictResult_NSS, dictResult_QS, dictResult_XS);
- lblCntBW.Text = onlineCount.ToString();
- lblCntDJ.Text = standByCount.ToString();
- lblCntSD.Text = onPowerCount.ToString();
- lblCntQD.Text = startCount.ToString();
- lblCntGZ.Text = faultCount.ToString();
- lblCntWH.Text = maintainCount.ToString();
- lblCntLX.Text = offlineCount.ToString();
- lblCntTJ.Text = stopCount.ToString();
- }
- private int GetCount(string unifromCode, Dictionary<string, TsData> dic_SBQ, Dictionary<string, TsData> dic_MHS, Dictionary<string, TsData> dic_XS, Dictionary<string, TsData> dic_QS, Dictionary<string, TsData> dic_NSS)
- {
- int resultCount = 0;
- try
- {
- if (dic_SBQ.ContainsKey(unifromCode))
- {
- int count = Convert.ToInt32(dic_SBQ[unifromCode].getValue());
- resultCount = resultCount + count;
- }
- if (dic_MHS.ContainsKey(unifromCode))
- {
- int count = Convert.ToInt32(dic_MHS[unifromCode].getValue());
- resultCount = resultCount + count;
- }
- if (dic_XS.ContainsKey(unifromCode))
- {
- int count = Convert.ToInt32(dic_XS[unifromCode].getValue());
- resultCount = resultCount + count;
- }
- if (dic_QS.ContainsKey(unifromCode))
- {
- int count = Convert.ToInt32(dic_QS[unifromCode].getValue());
- resultCount = resultCount + count;
- }
- if (dic_NSS.ContainsKey(unifromCode))
- {
- int count = Convert.ToInt32(dic_NSS[unifromCode].getValue());
- resultCount = resultCount + count;
- }
- return resultCount;
- }
- catch (Exception ex)
- {
- logger.Info("MatrixTop中全区风机状态数量统计转换错误" + ex);
- return 0;
- }
- }
- }
- }
|