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.WindturbineInfo; using log4net; using log4net.Util; using WisdomClient; using WisdomClient.data; namespace IntelligentControlForsx.MyControls.windturbine { /// /// 输入输出 /// public partial class OutInInfo : BaseControl { private static ILog logger = LogManager.GetLogger("AppInfoLog"); private string partNow = ""; Dictionary> infoDic = new Dictionary>(); private string stationIdNow = ""; private string windturbineIdNow = ""; private string modelIdNow = ""; public OutInInfo() { InitializeComponent(); LeftBind(STATIONID, WINDTURBINEID, MODELID); } public override void Active(string stationId, string windturbineId, string modelId) { STATIONID = stationId; WINDTURBINEID = windturbineId; stationIdNow = stationId; windturbineIdNow = windturbineId; modelIdNow = modelId; partNow = "part1"; timer1.Enabled = true; Refresh(); } public override void DeActive() { timer1.Enabled = false; } private void timer1_Tick(object sender, EventArgs e) { if (isRefreshOver) { isRefreshOver = false; //刷新数据线程 Thread refreshThread = new Thread(RefreshData); refreshThread.Start(); isRefreshOver = true; } //绑定数据线程 Thread bindDataThread = new Thread(RefreshFormData); bindDataThread.Start(); } private void RefreshData() { WindturbineInfoSvc infoSvc = WindturbineInfoSvc.Instance; if (infoDic.ContainsKey(partNow)) infoSvc.RefreshPointValue(infoDic[partNow], windturbineIdNow); } private delegate void BindFormInfoDelegate(); private void RefreshFormData() { BindFormInfoDelegate del = new BindFormInfoDelegate(BindFormData); if (this.InvokeRequired) { this.BeginInvoke(del, new object[] { }); } else { BindFormData(); } } private void BindFormData() { IList list = WindturbineInfoSvc.Instance.GetPointData(); for (int i = 0; i < plInfo.Controls.Count; i++) { if (plInfo.Controls[i] is OutInLine) { OutInLine ol = (OutInLine)plInfo.Controls[i]; UniformCodeInfo info = list.Where(s => s.PlcName == ol.Name).FirstOrDefault(); if (info != null) { ol.PointValue = info.PointValue; } } } } public void LeftBind(string stationId, string windturbineId, string model) { windturbineIdNow = windturbineId; modelIdNow = model; stationIdNow = stationId; plType.Controls.Clear(); IList list = UniformCodeInfoSvc.GetUniformCode(stationId, model, "OutIn"); Dictionary> dic = new Dictionary>(); for (int i = 0; i < list.Count; i++) { IList dicList = new List(); if (!dic.ContainsKey(list[i].PartIndex)) { dicList.Add(list[i]); dic.Add(list[i].PartIndex, dicList); } else { dicList = dic[list[i].PartIndex]; dicList.Add(list[i]); } } foreach (var item in dic) { LabelName ln = new LabelName(); if (item.Value.Count > 0) ln.LblName = item.Value[0].PartName; ln.Name = item.Key; ln.Dock = DockStyle.Top; ln.MyClick += Type_Clikc; plType.Controls.Add(ln); } infoDic = dic; } private void Type_Clikc(object sender, EventArgs e) { partNow = sender.ToString(); plInfo.Controls.Clear(); string typeName = sender.ToString(); IList list = infoDic[typeName]; for (int i = 0; i < list.Count; i++) { OutInLine ln = new OutInLine(); ln.Name = list[i].PlcName; ln.PointName = list[i].Name; ln.PLCName = list[i].PlcName; ln.Dock = DockStyle.Top; plInfo.Controls.Add(ln); } } } }