123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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 QS_Project2 : MapControl
- {
- private static ILog logger = LogManager.GetLogger("AppInfoLog");
- /// <summary>
- /// 数据访问是否结束
- /// </summary>
- private bool IsRefreshDataOver = true;
- /// <summary>
- /// 绑定页面是否结束
- /// </summary>
- private bool IsBindFormOver = true;
- private NavService navSvc;
- public QS_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<string, WindturbineInfoControl> dicWindturbineInfoControl;
- private string projectId = "QS02_GC";
- private string stationId = "QS_FDC";//QS_FDC QS02_GC
- private void Init()
- {
- dicWindturbineInfoControl = new Dictionary<string, WindturbineInfoControl>();
- 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<ZmWindturbineInfo> 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
- }
- }
|