123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- 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.Common;
- using IntelligentControlForsx.Service;
- using IntelligentControlForsx.Model;
- using WisdomClient.data;
- using WisdomClient;
- using log4net;
- using IntelligentControlForsx.ChildForms;
- using EntityDataSet;
- namespace IntelligentControlForsx.MyControls.zm
- {
- public partial class ZM_QS : ZMControl
- {
- private ILog logger = LogManager.GetLogger("AppInfoLog");
- private NavService navSvc;
- //key: 风机ID
- private Dictionary<string, WindturbineIcon> dictWindturbintIcon;
- public ZM_QS()
- {
- InitializeComponent();
- navSvc = NavService.Instance;
- }
- private string stationId = "QS_FDC";
- public string StationId
- {
- get
- {
- return stationId;
- }
- }
- private void SbqZM_Load(object sender, EventArgs e)
- {
- dictWindturbintIcon = new Dictionary<string, WindturbineIcon>();
- foreach (var p in this.pnlLine.Controls)
- {
- WindturbineIcon pd = p as WindturbineIcon;
- if (pd != null &&
- String.IsNullOrWhiteSpace(pd.WindturbineId) == false &&
- dictWindturbintIcon.ContainsKey(pd.WindturbineId) == false)
- {
- dictWindturbintIcon.Add(pd.WindturbineId, pd);
- }
- }
- Thread ayscThread = new Thread(LoadInitData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- }
- private void btnSYZ_Click(object sender, EventArgs e)
- {
- navSvc.NavForElectrical("pictureBoxSYZ", "QS_FDC");
- }
- private void btnMap_Click(object sender, EventArgs e)
- {
- navSvc.NavForMap("MapForm", "QS_FDC");
- }
- #region 加载数据
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isLoadding == true)
- return;
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- }
- public override void DeActive()
- {
- timer1.Stop();
- this.stationPowerLine1.DeActive();
- }
- public override void Active()
- {
- Thread ayscThread = new Thread(LoadData);
- ayscThread.IsBackground = true;
- ayscThread.Start();
- timer1.Start();
- this.stationPowerLine1.Active();
- }
- private bool isLoadding = false;
- private void LoadData()
- {
- if (isLoadding == true)
- return;
- isLoadding = true;
- try
- {
- UpdateStationStates();
- UpdatePnlLine();
- }
- catch (Exception ex)
- {
- logger.Info("读取实时数据失败!ex=" + ex.Message);
- }
- finally
- {
- isLoadding = false;
- }
- }
- private void UpdatePnlLine()
- {
- if (dictWindturbintIcon == null || dictWindturbintIcon.Count < 1)
- return;
- var dict = CacheService.Instance.MatrixPointMap;
- if (dict == null)
- return;
- var pmms = dict.Values
- .Where(q => q.ThingType == PointType.Windturbine &&
- "FJZT8".Equals(q.UniformCode) )
- .ToArray();
- var points = pmms.Select(q => q.PointId).ToArray();
- Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
- lock (this.pnlLine)
- {
- 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;
- String wtId = pmms[i].ThingId;
- string controlName = CommonMethod.GetLongWindturbineId(wtId);
- if (dictResult.ContainsKey(pmms[i].PointId) && dictWindturbintIcon.ContainsKey(controlName))
- {
- TsData tsData = dictResult[pmms[i].PointId];
-
- WindturbineIcon ctrl = dictWindturbintIcon[controlName];
- if (tsData.doubleValue.HasValue)
- ctrl.Status = (int)tsData.doubleValue.Value;
- }
- }
- });
- }
- }
- private void UpdateStationStates()
- {
- var dict = CacheService.Instance.MatrixPointMap;
- 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<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
- lock (this.pnlStat)
- {
- //this.BeginInvoke(
- this.Invoke(
- (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
- case "BWTS8":
- lblCntBW.LableText = value.ToString("f0");
- break;
- case "LXTS8":
- lblCntLX.LableText = value.ToString("f0");
- break;
- case "DJTS8":
- lblCntDJ.LableText = value.ToString("f0");
- break;
- case "WHTS8":
- lblCntWH.LableText = value.ToString("f0");
- break;
- case "GZTS8":
- lblCntGZ.LableText = value.ToString("f0");
- break;
- case "TJTS8":
- lblCntTJ.LableText = value.ToString("f0");
- break;
- case "QDTS8":
- lblCntQD.LableText = value.ToString("f0");
- break;
- case "SDTS8":
- lblCntSD.LableText = value.ToString("f0");
- break;
- case "SSFS":
- lblWindspeed.LableText = value.ToString("f2");
- break;
- case "SSZGL":
- lblPower.LableText = value.ToString("f2");
- break;
- #endregion
- }
- }
- });
- }
- }
- private void LoadInitData()
- {
- try
- {
- var stInfo = CacheService.Instance.getStationInfo(stationId);
- if (stInfo != null)
- {
- lock (this.pnlStat)
- {
- this.BeginInvoke(
- (Action)delegate
- {
- this.lblCapacity.LableText = stInfo.CAPACITY.ToString();
- this.lblCntAll.LableText = stInfo.QUANTITY.ToString();
- });
- }
- }
- }
- catch (Exception ex)
- {
- logger.Error(ex);
- }
- }
- #endregion
- #region 窗体样式事件
- private void pnlStat_Paint(object sender, PaintEventArgs e)
- {
- ControlPaint.DrawBorder(e.Graphics,
- this.pnlStat.ClientRectangle,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid);
- }
- private void pnlCurve_Paint(object sender, PaintEventArgs e)
- {
- ControlPaint.DrawBorder(e.Graphics,
- this.pnlCurve.ClientRectangle,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid);
- }
- private void pnlLink_Paint(object sender, PaintEventArgs e)
- {
- ControlPaint.DrawBorder(e.Graphics,
- this.pnlLink.ClientRectangle,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid,
- Color.FromArgb(49, 185, 251),
- 1,
- ButtonBorderStyle.Solid);
- }
- private void btnSYZ_MouseHover(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.Image = global::IntelligentControlForsx.Properties.Resources.B01;
- //btn.FlatAppearance.BorderSize = 0;
- }
- private void btnMap_MouseHover(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.Image = global::IntelligentControlForsx.Properties.Resources.B01;
- }
- private void btnSYZ_MouseLeave(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.Image = global::IntelligentControlForsx.Properties.Resources.B02;
- }
- private void btnMap_MouseLeave(object sender, EventArgs e)
- {
- Button btn = sender as Button;
- btn.Image = global::IntelligentControlForsx.Properties.Resources.B02;
- }
- #endregion
- private void windturbineIcon4_MyClick(object sender, EventArgs e)
- {
- MessageBox.Show("Click");
- }
- private void Windturbine_MyClick(object sender, EventArgs e)
- {
- try
- {
- WindturbineIcon icon = (WindturbineIcon)sender;
- if (icon != null)
- {
- navSvc.NavForWindturbine("pictureBoxParamters", icon.WindturbineId, "QS_FDC");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- DateTime time = DateTime.Now;
- lblDate.Text = time.ToString("yyyy-MM-dd");
- lblTime.LableText = time.ToString("HH:mm:ss");
- }
- }
- }
|