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 NSS_Project2 : MapControl { private static ILog logger = LogManager.GetLogger("AppInfoLog"); /// /// 数据访问是否结束 /// private bool IsRefreshDataOver = true; /// /// 绑定页面是否结束 /// private bool IsBindFormOver = true; private NavService navSvc; public NSS_Project2() { InitializeComponent(); Init(); 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(this.stationId, this.projectId); IsRefreshDataOver = true; } public delegate void UpdateFormInfoDelegate(); public void BindFormInvoke() { UpdateFormInfoDelegate del = new UpdateFormInfoDelegate(FormDataBind); if (this.InvokeRequired) { this.BeginInvoke(del, new object[] { }); } else { FormDataBind(); } IsBindFormOver = true; } #region //key: 风机ID private Dictionary dicWindturbineInfoControl; private string projectId = "NSS02_GC"; private string stationId = "NSS_FDC"; private void Init() { dicWindturbineInfoControl = new Dictionary(); foreach (var p in this.Controls) { if (p is WindturbineInfoControl) { WindturbineInfoControl wifo = p as WindturbineInfoControl; if (wifo != null && !String.IsNullOrWhiteSpace(wifo.WindturbineId) && !dicWindturbineInfoControl.ContainsKey(wifo.WindturbineId)) { dicWindturbineInfoControl.Add(wifo.WindturbineId, wifo); } } } } 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 == projectId && s.StationId == stationId).ToList(); if (this.IsHandleCreated) { this.BeginInvoke((Action)delegate { for (int i = 0; i < list.Count; i++) { if (dicWindturbineInfoControl.ContainsKey(list[i].WindturbineId)) { dicWindturbineInfoControl[list[i].WindturbineId].BindData(list[i].Power, list[i].WindSpeed, Convert.ToInt32(list[i].Status)); } } } ); } } catch { } } private void Windturbine_MyClick(object sender, EventArgs e) { try { WindturbineInfoControl icon = (WindturbineInfoControl)sender; if (icon != null) { navSvc.NavForWindturbine("pictureBoxParamters", icon.WindturbineId, stationId); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion } }