FaultInfo2.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using IntelligentControlForsx.Service.WindturbineInfo;
  12. using IntelligentControlForsx.Service.WindturbineInfo.Domain;
  13. using log4net;
  14. using log4net.Util;
  15. using WisdomClient;
  16. using WisdomClient.data;
  17. namespace IntelligentControlForsx.MyControls.windturbine
  18. {
  19. /// <summary>
  20. /// 输入输出
  21. /// </summary>
  22. public partial class FaultInfo2 : BaseControl
  23. {
  24. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  25. private BindingSource formBindingSource = new BindingSource();
  26. private string partNow = "part1";
  27. Dictionary<string, IList<UniformCodeInfo>> infoDic = new Dictionary<string, IList<UniformCodeInfo>>();
  28. private static BindingList<FaultDataInfo> formDataList = new BindingList<FaultDataInfo>();
  29. private string stationIdNow = "";
  30. private string windturbineIdNow = "";
  31. private string modelIdNow = "";
  32. //数据是否绑定完毕
  33. private bool isUpdateOverGv = true;
  34. public FaultInfo2()
  35. {
  36. InitializeComponent();
  37. LeftBind(STATIONID, WINDTURBINEID, MODELID);
  38. }
  39. public override void Active(string stationId, string windturbineId, string modelId)
  40. {
  41. STATIONID = stationId;
  42. WINDTURBINEID = windturbineId;
  43. stationIdNow = stationId;
  44. windturbineIdNow = windturbineId;
  45. modelIdNow = modelId;
  46. //partNow = "part1";
  47. timer1.Enabled = true;
  48. Refresh();
  49. }
  50. public override void DeActive()
  51. {
  52. timer1.Enabled = false;
  53. }
  54. private void timer1_Tick(object sender, EventArgs e)
  55. {
  56. if (isRefreshOver)
  57. {
  58. isRefreshOver = false;
  59. //刷新数据线程
  60. Thread refreshThread = new Thread(RefreshData);
  61. refreshThread.Start();
  62. }
  63. //绑定数据线程
  64. if (isUpdateOverGv)
  65. {
  66. isUpdateOverGv = false;
  67. Thread bindDataThread = new Thread(RefreshFormData);
  68. bindDataThread.IsBackground = true;
  69. bindDataThread.Start();
  70. }
  71. }
  72. private void RefreshData()
  73. {
  74. WindturbineInfoSvc infoSvc = WindturbineInfoSvc.Instance;
  75. IList<UniformCodeInfo> codeInfoList = new List<UniformCodeInfo>();
  76. IList<string> keyList = infoDic.Keys.ToList();
  77. foreach (string key in keyList)
  78. {
  79. codeInfoList = codeInfoList.Union(infoDic[key]).ToList();
  80. }
  81. infoSvc.RefreshPointValue(codeInfoList, WINDTURBINEID);
  82. isRefreshOver = true;
  83. }
  84. private delegate void BindFormInfoDelegate();
  85. private void RefreshFormData()
  86. {
  87. BindFormInfoDelegate del = new BindFormInfoDelegate(BindFormData);
  88. if (this.InvokeRequired)
  89. {
  90. this.BeginInvoke(del, new object[] { });
  91. }
  92. else
  93. {
  94. BindFormData();
  95. }
  96. }
  97. private void BindFormData()
  98. {
  99. DateTime st = DateTime.Now;
  100. IList<UniformCodeInfo> list = WindturbineInfoSvc.Instance.GetPointData();
  101. try
  102. {
  103. #region 控制上层菜单样式(若其中有一个为报警,则上层菜单样式颜色改变)
  104. IList<string> partList = list.Select(s => s.PartIndex).Distinct().ToList();
  105. for (int i = 0; i < partList.Count; i++)
  106. {
  107. int count = list.Where(s => s.PartIndex == partList[i] && s.PointValue != null && s.PointValue.Contains("1")).ToList().Count;
  108. for (int j = 0; j < this.plType.Controls.Count; j++)
  109. {
  110. if (this.plType.Controls[j] is LabelName)
  111. {
  112. LabelName ln = (LabelName)this.plType.Controls[j];
  113. if (ln.Name == partList[i])
  114. {
  115. if (count > 0)
  116. ln.WarningValue = true;
  117. else
  118. ln.WarningValue = false;
  119. }
  120. }
  121. }
  122. }
  123. #endregion
  124. BindingList<FaultDataInfo> formDataList = this.formBindingSource.DataSource as BindingList<FaultDataInfo>;
  125. IList<UniformCodeInfo> showList = list.Where(s => s.PartIndex == partNow).ToList();
  126. for (int i = 0; i < showList.Count; i++)
  127. {
  128. var data = formDataList.Where(s => s.WarningNum == showList[i].WarningNum).FirstOrDefault();
  129. if (data != null)
  130. {
  131. data.Name = showList[i].Name;
  132. data.PlcName = showList[i].PlcName;
  133. try
  134. {
  135. double pointValue = Convert.ToDouble(showList[i].PointValue);
  136. if (pointValue == 0)
  137. data.PointValue = "正常";
  138. else
  139. data.PointValue = "故障";
  140. }
  141. catch (Exception ex)
  142. {
  143. logger.Info("数据转换错误:" + ex.Message);
  144. }
  145. }
  146. #region 修改故障显示样式
  147. for (int j = 0; j < gv.RowCount; j++)
  148. {
  149. DataGridViewRow row = gv.Rows[i];
  150. string faultString = "";
  151. if (gv.Rows[i].Cells[3].Value != null)
  152. faultString = gv.Rows[i].Cells[3].Value.ToString().Trim();
  153. if (faultString.Trim() == "故障")
  154. {
  155. row.Cells[0].Style.ForeColor = Color.FromArgb(255, 128, 0);
  156. row.Cells[1].Style.ForeColor = Color.FromArgb(255, 128, 0);
  157. row.Cells[2].Style.ForeColor = Color.FromArgb(255, 128, 0);
  158. row.Cells[3].Style.ForeColor = Color.FromArgb(255, 128, 0);
  159. }
  160. else
  161. {
  162. row.Cells[0].Style.ForeColor = Color.FromArgb(255, 255, 255);
  163. row.Cells[1].Style.ForeColor = Color.FromArgb(255, 255, 255);
  164. row.Cells[2].Style.ForeColor = Color.FromArgb(255, 255, 255);
  165. row.Cells[3].Style.ForeColor = Color.FromArgb(255, 255, 255);
  166. }
  167. }
  168. #endregion
  169. }
  170. }
  171. catch (Exception ex)
  172. {
  173. logger.Info("风机参数-故障页面异常"+ex.Message);
  174. }
  175. finally
  176. {
  177. isUpdateOverGv = true;
  178. DateTime et = DateTime.Now;
  179. TimeSpan sp = et - st;
  180. Console.WriteLine("绑定页面时间:" + sp.TotalMilliseconds);
  181. }
  182. }
  183. public void LeftBind(string stationId, string windturbineId, string model)
  184. {
  185. windturbineIdNow = windturbineId;
  186. modelIdNow = model;
  187. stationIdNow = stationId;
  188. plType.Controls.Clear();
  189. IList<UniformCodeInfo> list = UniformCodeInfoSvc.GetUniformCode(stationId, model, "Fault");
  190. Dictionary<string, IList<UniformCodeInfo>> dic = new Dictionary<string, IList<UniformCodeInfo>>();
  191. for (int i = 0; i < list.Count; i++)
  192. {
  193. IList<UniformCodeInfo> dicList = new List<UniformCodeInfo>();
  194. if (!dic.ContainsKey(list[i].PartIndex))
  195. {
  196. dicList.Add(list[i]);
  197. dic.Add(list[i].PartIndex, dicList);
  198. }
  199. else
  200. {
  201. dicList = dic[list[i].PartIndex];
  202. dicList.Add(list[i]);
  203. }
  204. }
  205. IList<string> partList = dic.Keys.ToList().OrderByDescending(s => Convert.ToInt32(s.Replace("part", ""))).ToList();
  206. for (int i = 0; i < partList.Count; i++)
  207. {
  208. LabelName ln = new LabelName();
  209. if (dic[partList[i]].Count > 0)
  210. ln.LblName = dic[partList[i]][0].PartName;
  211. ln.Name = partList[i];
  212. ln.Dock = DockStyle.Top;
  213. ln.MyClick += Type_Clikc;
  214. plType.Controls.Add(ln);
  215. }
  216. //foreach (var item in dic)
  217. //{
  218. // LabelName ln = new LabelName();
  219. // if (item.Value.Count > 0)
  220. // ln.LblName = item.Value[0].PartName;
  221. // ln.Name = item.Key;
  222. // ln.Dock = DockStyle.Top;
  223. // ln.MyClick += Type_Clikc;
  224. // plType.Controls.Add(ln);
  225. //}
  226. infoDic = dic;
  227. if (infoDic.ContainsKey("part1"))
  228. partNow = "part1";
  229. GvInit();
  230. }
  231. private void Type_Clikc(object sender, EventArgs e)
  232. {
  233. partNow = sender.ToString();
  234. GvInit();
  235. //plInfo.Controls.Clear();
  236. //string typeName = sender.ToString();
  237. //IList<UniformCodeInfo> list = infoDic[typeName];
  238. //for (int i = 0; i < list.Count; i++)
  239. //{
  240. // OutInLine ln = new OutInLine();
  241. // ln.Name = list[i].PlcName;
  242. // ln.PointName = list[i].Name;
  243. // ln.PLCName = list[i].PlcName;
  244. // ln.Dock = DockStyle.Top;
  245. // plInfo.Controls.Add(ln);
  246. //}
  247. }
  248. /// <summary>
  249. /// gridview初始化工作
  250. /// </summary>
  251. private void GvInit()
  252. {
  253. gv.DataSource = null;
  254. formDataList = new BindingList<FaultDataInfo>();
  255. IList<UniformCodeInfo> codeInfoList = infoDic[partNow];
  256. for (int i = 0; i < codeInfoList.Count; i++)
  257. {
  258. FaultDataInfo data = new FaultDataInfo(
  259. codeInfoList[i].WarningNum,
  260. codeInfoList[i].Name,
  261. codeInfoList[i].PlcName,
  262. "正常"
  263. );
  264. formDataList.Add(data);
  265. }
  266. formBindingSource.DataSource = formDataList;
  267. this.gv.DataSource = formBindingSource;
  268. gv.Columns[0].HeaderText = "报警编号";
  269. gv.Columns[1].HeaderText = "PLC变量名";
  270. gv.Columns[2].HeaderText = "报警信息";
  271. gv.Columns[3].HeaderText = "报警状态";
  272. }
  273. }
  274. }