FaultGridViewSvc.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using log4net;
  8. namespace IntelligentControlForsx.Service.WindturbineInfo
  9. {
  10. public class FaultGridViewSvc
  11. {
  12. private static ILog logger = LogManager.GetLogger("AppInfoLog");
  13. #region 单例
  14. private FaultGridViewSvc()
  15. {
  16. }
  17. public static FaultGridViewSvc Instance
  18. {
  19. get { return SingletonCreator.instance; }
  20. }
  21. class SingletonCreator
  22. {
  23. internal static readonly FaultGridViewSvc instance = new FaultGridViewSvc();
  24. }
  25. #endregion
  26. public DataTable GetDataTableHeaders()
  27. {
  28. DataTable dataTable = new DataTable();
  29. dataTable.Columns.Add("报警编号");
  30. dataTable.Columns.Add("PLC变量名称");
  31. dataTable.Columns.Add("报警信息");
  32. dataTable.Columns.Add("故障状态");
  33. return dataTable;
  34. }
  35. public DataTable GetFaultDataTable(IList<UniformCodeInfo> list)
  36. {
  37. DataTable resultTable = GetDataTableHeaders();
  38. for (int i = 0; i < list.Count; i++)
  39. {
  40. #region 生成GridView信息
  41. DataRow row = resultTable.NewRow();
  42. row["报警编号"] = list[i].WarningNum;
  43. row["PLC变量名称"] = list[i].PlcName;
  44. row["报警信息"] = list[i].Name;
  45. try
  46. {
  47. double warningStatus = Convert.ToDouble(list[i].PointValue);
  48. if (warningStatus == 1)
  49. {
  50. row["故障状态"] ="故障";
  51. }
  52. else
  53. {
  54. row["故障状态"] = "正常";
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. row["故障状态"] = "-";
  60. logger.Info("数据转换异常:"+ex.Message);
  61. }
  62. resultTable.Rows.Add(row);
  63. #endregion
  64. }
  65. return resultTable;
  66. }
  67. }
  68. }