using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using IntelligentControlForsx.Service; using IntelligentControlForsx.Service.ZM; using IntelligentControlForsx.Service.ZM.Domain; using log4net; namespace IntelligentControlForsx.MyControls.zm.map { public partial class SBQ_Project4 : MapControl { private static ILog logger = LogManager.GetLogger("AppInfoLog"); /// /// 数据访问是否结束 /// private bool IsRefreshDataOver = true; /// /// 绑定页面是否结束 /// private bool IsBindFormOver = true; private NavService navSvc; public SBQ_Project4() { InitializeComponent(); navSvc = NavService.Instance; } public override void Active() { timer1.Enabled = true; } public override void DeActive() { timer1.Enabled = false; } private void timer1_Tick(object sender, EventArgs e) { if (IsRefreshDataOver) { IsRefreshDataOver = false; Thread t = new Thread(RefreshData); t.IsBackground = true; t.Start(); } if (IsBindFormOver) { IsBindFormOver = false; Thread t = new Thread(BindFormInvoke); t.IsBackground = true; t.Start(); } } private void RefreshData() { ZmWindturbineInfoSvc.GetInfo("SBQ_FDC", "SBQ04_GC"); IsRefreshDataOver = true; } public delegate void UpdateFormInfoDelegate(); public void BindFormInvoke() { SBQ_Project2.UpdateFormInfoDelegate del = new SBQ_Project2.UpdateFormInfoDelegate(FormDataBind); if (this.InvokeRequired) { this.BeginInvoke(del, new object[] { }); } else { FormDataBind(); } IsBindFormOver = true; } private void FormDataBind() { try { if (!timer1.Enabled) { return; } ZmWindturbineInfo[] tmplist = new ZmWindturbineInfo[ZmWindturbineInfoSvc.infoList.Count]; ZmWindturbineInfoSvc.infoList.CopyTo(tmplist, 0); IList list = tmplist.Where(s => s.ProjectId == "SBQ04_GC" && s.StationId == "SBQ_FDC").ToList(); for (int i = 0; i < list.Count; i++) { string controlName = "wf" + list[i].WindturbineId.Replace("SG01_", ""); Control ct = this.Controls.Find(controlName, true).FirstOrDefault(); if (ct != null) { try { if (ct is WindturbineInfoControl) { WindturbineInfoControl wc = (WindturbineInfoControl)ct; wc.BindData(list[i].Power, list[i].WindSpeed, Convert.ToInt32(list[i].Status)); } } catch (Exception ex) { logger.Info("寻找控件或控件转换失败" + ex.Message); } } } } catch { } } private void Windturbine_MyClick(object sender, EventArgs e) { try { WindturbineInfoControl icon = (WindturbineInfoControl)sender; if (icon != null) { string windturbineId = "SG01_" + icon.WindturbineName.Replace("号", "").Trim(); navSvc.NavForWindturbine("pictureBoxParamters", windturbineId,"SBQ_FDC"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }