123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 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
- {
- /// <summary>
- /// 输入输出
- /// </summary>
- public partial class OutInInfo : BaseControl
- {
- private static ILog logger = LogManager.GetLogger("AppInfoLog");
- private string partNow = "";
- Dictionary<string, IList<UniformCodeInfo>> infoDic = new Dictionary<string, IList<UniformCodeInfo>>();
- 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<UniformCodeInfo> 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<UniformCodeInfo> list = UniformCodeInfoSvc.GetUniformCode(stationId, model, "OutIn");
- Dictionary<string, IList<UniformCodeInfo>> dic = new Dictionary<string, IList<UniformCodeInfo>>();
- for (int i = 0; i < list.Count; i++)
- {
- IList<UniformCodeInfo> dicList = new List<UniformCodeInfo>();
- 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<UniformCodeInfo> 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);
- }
- }
- }
- }
|