using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using log4net; namespace IntelligentControlForsx.Service.WindturbineInfo { public class FaultGridViewSvc { private static ILog logger = LogManager.GetLogger("AppInfoLog"); #region 单例 private FaultGridViewSvc() { } public static FaultGridViewSvc Instance { get { return SingletonCreator.instance; } } class SingletonCreator { internal static readonly FaultGridViewSvc instance = new FaultGridViewSvc(); } #endregion public DataTable GetDataTableHeaders() { DataTable dataTable = new DataTable(); dataTable.Columns.Add("报警编号"); dataTable.Columns.Add("PLC变量名称"); dataTable.Columns.Add("报警信息"); dataTable.Columns.Add("故障状态"); return dataTable; } public DataTable GetFaultDataTable(IList list) { DataTable resultTable = GetDataTableHeaders(); for (int i = 0; i < list.Count; i++) { #region 生成GridView信息 DataRow row = resultTable.NewRow(); row["报警编号"] = list[i].WarningNum; row["PLC变量名称"] = list[i].PlcName; row["报警信息"] = list[i].Name; try { double warningStatus = Convert.ToDouble(list[i].PointValue); if (warningStatus == 1) { row["故障状态"] ="故障"; } else { row["故障状态"] = "正常"; } } catch (Exception ex) { row["故障状态"] = "-"; logger.Info("数据转换异常:"+ex.Message); } resultTable.Rows.Add(row); #endregion } return resultTable; } } }