Пример #1
0
        /// <summary>
        /// Save Button Click
        /// </summary>
        protected void SaveBtn_Click(object sender, DirectEventArgs e)
        {
            try {
                var cacheKey = WebUtility.GetCacheKeyName(UserData, "his-alarms");
                var alarms   = HttpRuntime.Cache[cacheKey] as List <AlarmInfo>;
                if (alarms == null)
                {
                    alarms = AddDataToCache();
                }
                if (alarms == null)
                {
                    WebUtility.ShowMessage(EnmErrType.Warning, "获取数据时发生错误,导出失败!");
                    return;
                }

                var datas = new DataTable();
                datas.Columns.Add(new DataColumn("Lsc名称", typeof(String)));
                datas.Columns.Add(new DataColumn("地区名称", typeof(String)));
                datas.Columns.Add(new DataColumn("县市名称", typeof(String)));
                datas.Columns.Add(new DataColumn("局站名称", typeof(String)));
                datas.Columns.Add(new DataColumn("设备名称", typeof(String)));
                datas.Columns.Add(new DataColumn("设备描述", typeof(String)));
                datas.Columns.Add(new DataColumn("测点名称", typeof(String)));
                datas.Columns.Add(new DataColumn("告警描述", typeof(String)));
                datas.Columns.Add(new DataColumn("告警设备类型", typeof(String)));
                datas.Columns.Add(new DataColumn("告警逻辑分类", typeof(String)));
                datas.Columns.Add(new DataColumn("告警标准名称", typeof(String)));
                datas.Columns.Add(new DataColumn("告警类别", typeof(String)));
                datas.Columns.Add(new DataColumn("告警级别", typeof(String)));
                datas.Columns.Add(new DataColumn("告警时间", typeof(DateTime)));
                datas.Columns.Add(new DataColumn("结束时间", typeof(DateTime)));
                datas.Columns.Add(new DataColumn("处理标识", typeof(String)));
                datas.Columns.Add(new DataColumn("处理时间", typeof(DateTime)));
                datas.Columns.Add(new DataColumn("处理人员", typeof(String)));
                datas.Columns.Add(new DataColumn("告警历时", typeof(String)));
                datas.Columns.Add(new DataColumn("动环监控告警ID", typeof(String)));
                datas.Columns.Add(new DataColumn("工程预约", typeof(String)));
                datas.Columns.Add(new DataColumn("主告警", typeof(String)));
                datas.Columns.Add(new DataColumn("关联告警", typeof(String)));
                datas.Columns.Add(new DataColumn("翻转次数", typeof(Int32)));
                datas.Columns.Add(new DataColumn("ColorColumn", typeof(Excel.Color)));

                alarms = WebUtility.AlarmSAlmFilter(alarms);
                DataRow row;
                for (int i = 0; i < alarms.Count; i++)
                {
                    row                = datas.NewRow();
                    row["Lsc名称"]       = alarms[i].LscName;
                    row["地区名称"]        = alarms[i].Area2Name;
                    row["县市名称"]        = alarms[i].Area3Name;
                    row["局站名称"]        = alarms[i].StaName;
                    row["设备名称"]        = alarms[i].DevName;
                    row["设备描述"]        = alarms[i].DevDesc;
                    row["测点名称"]        = alarms[i].NodeName;
                    row["告警描述"]        = alarms[i].AlarmDesc;
                    row["告警设备类型"]      = alarms[i].AlarmDeviceType;
                    row["告警逻辑分类"]      = alarms[i].AlarmLogType;
                    row["告警标准名称"]      = alarms[i].AlarmName;
                    row["告警类别"]        = alarms[i].AlarmClass;
                    row["告警级别"]        = WebUtility.GetAlarmLevelName(alarms[i].AlarmLevel);
                    row["告警时间"]        = WebUtility.DBNullDateTimeChecker(alarms[i].StartTime);
                    row["结束时间"]        = WebUtility.DBNullDateTimeChecker(alarms[i].EndTime);
                    row["处理标识"]        = WebUtility.GetConfirmMarkingName(alarms[i].ConfirmMarking);
                    row["处理时间"]        = WebUtility.DBNullDateTimeChecker(alarms[i].ConfirmTime);
                    row["处理人员"]        = alarms[i].ConfirmName;
                    row["告警历时"]        = WebUtility.GetDateTimeInterval(alarms[i].StartTime, alarms[i].EndTime);
                    row["动环监控告警ID"]    = alarms[i].NMAlarmID;
                    row["工程预约"]        = WebUtility.GetBooleanName(!String.IsNullOrEmpty(alarms[i].ProjName));
                    row["主告警"]         = WebUtility.GetBooleanName(alarms[i].AuxAlarmDesc.Equals("MAlm"));
                    row["关联告警"]        = WebUtility.GetBooleanName(alarms[i].AuxAlarmDesc.Equals("Conn"));
                    row["翻转次数"]        = alarms[i].TurnCount;
                    row["ColorColumn"] = WebUtility.GetExcelAlarmColor(alarms[i].AlarmLevel);
                    datas.Rows.Add(row);
                }

                var fileName  = "HisAlarms.xls";
                var sheetName = "历史告警";
                var title     = "动力环境监控中心系统 历史告警报表";
                var subTitle  = String.Format("值班员:{0}  日期:{1}", Page.User.Identity.Name, WebUtility.GetDateString(DateTime.Now));
                var xls       = WebUtility.ExportDataToExcel(fileName, sheetName, title, subTitle, datas);
                if (xls != null)
                {
                    xls.Send();
                }
            } catch (Exception err) {
                WebUtility.WriteLog(EnmSysLogLevel.Error, EnmSysLogType.Exception, err.ToString(), Page.User.Identity.Name);
                WebUtility.ShowMessage(EnmErrType.Error, err.Message);
            }
        }