123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- 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 IntelligentControlForsx.Service.WindturbineInfo.Domain;
- using log4net;
- using log4net.Util;
- using WisdomClient;
- using WisdomClient.data;
- namespace IntelligentControlForsx.MyControls.windturbine
- {
- /// <summary>
- /// 输入输出
- /// </summary>
- public partial class FaultInfo2 : BaseControl
- {
- private static ILog logger = LogManager.GetLogger("AppInfoLog");
- private BindingSource formBindingSource = new BindingSource();
- private string partNow = "part1";
- Dictionary<string, IList<UniformCodeInfo>> infoDic = new Dictionary<string, IList<UniformCodeInfo>>();
- private static BindingList<FaultDataInfo> formDataList = new BindingList<FaultDataInfo>();
- private string stationIdNow = "";
- private string windturbineIdNow = "";
- private string modelIdNow = "";
- //数据是否绑定完毕
- private bool isUpdateOverGv = true;
- public FaultInfo2()
- {
- 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();
- }
- //绑定数据线程
- if (isUpdateOverGv)
- {
- isUpdateOverGv = false;
- Thread bindDataThread = new Thread(RefreshFormData);
- bindDataThread.IsBackground = true;
- bindDataThread.Start();
- }
- }
- private void RefreshData()
- {
- WindturbineInfoSvc infoSvc = WindturbineInfoSvc.Instance;
- IList<UniformCodeInfo> codeInfoList = new List<UniformCodeInfo>();
- IList<string> keyList = infoDic.Keys.ToList();
- foreach (string key in keyList)
- {
- codeInfoList = codeInfoList.Union(infoDic[key]).ToList();
- }
- infoSvc.RefreshPointValue(codeInfoList, WINDTURBINEID);
- isRefreshOver = true;
- }
- 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()
- {
- DateTime st = DateTime.Now;
- IList<UniformCodeInfo> list = WindturbineInfoSvc.Instance.GetPointData();
- try
- {
- #region 控制上层菜单样式(若其中有一个为报警,则上层菜单样式颜色改变)
- IList<string> partList = list.Select(s => s.PartIndex).Distinct().ToList();
- for (int i = 0; i < partList.Count; i++)
- {
- int count = list.Where(s => s.PartIndex == partList[i] && s.PointValue != null && s.PointValue.Contains("1")).ToList().Count;
- for (int j = 0; j < this.plType.Controls.Count; j++)
- {
- if (this.plType.Controls[j] is LabelName)
- {
- LabelName ln = (LabelName)this.plType.Controls[j];
- if (ln.Name == partList[i])
- {
- if (count > 0)
- ln.WarningValue = true;
- else
- ln.WarningValue = false;
- }
- }
- }
- }
- #endregion
- BindingList<FaultDataInfo> formDataList = this.formBindingSource.DataSource as BindingList<FaultDataInfo>;
- IList<UniformCodeInfo> showList = list.Where(s => s.PartIndex == partNow).ToList();
- for (int i = 0; i < showList.Count; i++)
- {
- var data = formDataList.Where(s => s.WarningNum == showList[i].WarningNum).FirstOrDefault();
- if (data != null)
- {
- data.Name = showList[i].Name;
- data.PlcName = showList[i].PlcName;
- try
- {
- double pointValue = Convert.ToDouble(showList[i].PointValue);
- if (pointValue == 0)
- data.PointValue = "正常";
- else
- data.PointValue = "故障";
- }
- catch (Exception ex)
- {
- logger.Info("数据转换错误:" + ex.Message);
- }
- }
- #region 修改故障显示样式
- for (int j = 0; j < gv.RowCount; j++)
- {
- DataGridViewRow row = gv.Rows[i];
- string faultString = "";
- if (gv.Rows[i].Cells[3].Value != null)
- faultString = gv.Rows[i].Cells[3].Value.ToString().Trim();
- if (faultString.Trim() == "故障")
- {
- row.Cells[0].Style.ForeColor = Color.FromArgb(255, 128, 0);
- row.Cells[1].Style.ForeColor = Color.FromArgb(255, 128, 0);
- row.Cells[2].Style.ForeColor = Color.FromArgb(255, 128, 0);
- row.Cells[3].Style.ForeColor = Color.FromArgb(255, 128, 0);
- }
- else
- {
- row.Cells[0].Style.ForeColor = Color.FromArgb(255, 255, 255);
- row.Cells[1].Style.ForeColor = Color.FromArgb(255, 255, 255);
- row.Cells[2].Style.ForeColor = Color.FromArgb(255, 255, 255);
- row.Cells[3].Style.ForeColor = Color.FromArgb(255, 255, 255);
- }
- }
- #endregion
- }
- }
- catch (Exception ex)
- {
- logger.Info("风机参数-故障页面异常"+ex.Message);
- }
- finally
- {
- isUpdateOverGv = true;
- DateTime et = DateTime.Now;
- TimeSpan sp = et - st;
- Console.WriteLine("绑定页面时间:" + sp.TotalMilliseconds);
- }
-
- }
- 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, "Fault");
- 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]);
- }
- }
- IList<string> partList = dic.Keys.ToList().OrderByDescending(s => Convert.ToInt32(s.Replace("part", ""))).ToList();
- for (int i = 0; i < partList.Count; i++)
- {
- LabelName ln = new LabelName();
- if (dic[partList[i]].Count > 0)
- ln.LblName = dic[partList[i]][0].PartName;
- ln.Name = partList[i];
- ln.Dock = DockStyle.Top;
- ln.MyClick += Type_Clikc;
- plType.Controls.Add(ln);
- }
- //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;
- if (infoDic.ContainsKey("part1"))
- partNow = "part1";
- GvInit();
- }
- private void Type_Clikc(object sender, EventArgs e)
- {
- partNow = sender.ToString();
- GvInit();
- //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);
- //}
- }
- /// <summary>
- /// gridview初始化工作
- /// </summary>
- private void GvInit()
- {
- gv.DataSource = null;
- formDataList = new BindingList<FaultDataInfo>();
- IList<UniformCodeInfo> codeInfoList = infoDic[partNow];
- for (int i = 0; i < codeInfoList.Count; i++)
- {
- FaultDataInfo data = new FaultDataInfo(
- codeInfoList[i].WarningNum,
- codeInfoList[i].Name,
- codeInfoList[i].PlcName,
- "正常"
- );
- formDataList.Add(data);
- }
- formBindingSource.DataSource = formDataList;
- this.gv.DataSource = formBindingSource;
- gv.Columns[0].HeaderText = "报警编号";
- gv.Columns[1].HeaderText = "PLC变量名";
- gv.Columns[2].HeaderText = "报警信息";
- gv.Columns[3].HeaderText = "报警状态";
- }
- }
- }
|