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 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(); 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 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 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"); } } }