using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.ReportManage.SafeEnvBudget { public partial class SafetyManagementDataTotal : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ///单位 BLL.UnitService.InitAllUnitDropDownList(this.drpUnitId, true); Funs.DropDownPageSize(this.ddlPageSize); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } private DataTable GetSourceDataTable() { string strSql = @" select s.UnitId, s.ReportDate, MAX(u.UnitName) AS UnitName, -- 项目运行 SUM(s.ConAndEPCCount) AS ConAndEPCCount, SUM(s.SurveyAndDesignCount) AS SurveyAndDesignCount, SUM(s.WorkingHours) AS WorkingHours, SUM(s.SafeDrivingMileage) AS SafeDrivingMileage, -- 分公司监督中心监督检查 SUM(s.SubSupervise_InspectionItems) AS SubSupervise_InspectionItems, SUM(s.SubSupervise_Inspections) AS SubSupervise_Inspections, SUM(s.SubSupervise_HSE_Total) AS SubSupervise_HSE_Total, SUM(s.SubSupervise_HSE_Larger) AS SubSupervise_HSE_Larger, SUM(s.SubSupervise_HSE_Generally) AS SubSupervise_HSE_Generally, SUM(s.SubSupervise_HSE_Slight) AS SubSupervise_HSE_Slight, SUM(s.SubSupervise_Quality_Total) AS SubSupervise_Quality_Total, SUM(s.SubSupervise_Quality_Larger) AS SubSupervise_Quality_Larger, SUM(s.SubSupervise_Quality_Generally) AS SubSupervise_Quality_Generally, SUM(s.SubSupervise_Quality_Slight) AS SubSupervise_Quality_Slight, -- 分公司视频监督检查 SUM(s.SubVideo_InspectionItems) AS SubVideo_InspectionItems, SUM(s.SubVideo_InspectionsMin) AS SubVideo_InspectionsMin, SUM(s.SubVideo_HSE_Total) AS SubVideo_HSE_Total, SUM(s.SubVideo_HSE_Larger) AS SubVideo_HSE_Larger, SUM(s.SubVideo_HSE_Generally) AS SubVideo_HSE_Generally, SUM(s.SubVideo_HSE_Slight) AS SubVideo_HSE_Slight, SUM(s.SubVideo_Quality_Total) AS SubVideo_Quality_Total, SUM(s.SubVideo_Quality_Larger) AS SubVideo_Quality_Larger, SUM(s.SubVideo_Quality_Generally) AS SubVideo_Quality_Generally, SUM(s.SubVideo_Quality_Slight) AS SubVideo_Quality_Slight, -- 总部监督中心监督检查 SUM(s.HQ_InspectionItems) AS HQ_InspectionItems, SUM(s.HQ_Inspections) AS HQ_Inspections, SUM(s.HQ_HSE_Total) AS HQ_HSE_Total, SUM(s.HQ_HSE_Larger) AS HQ_HSE_Larger, SUM(s.HQ_HSE_Generally) AS HQ_HSE_Generally, SUM(s.HQ_HSE_Slight) AS HQ_HSE_Slight, SUM(s.HQ_Quality_Total) AS HQ_Quality_Total, SUM(s.HQ_Quality_Larger) AS HQ_Quality_Larger, SUM(s.HQ_Quality_Generally) AS HQ_Quality_Generally, SUM(s.HQ_Quality_Slight) AS HQ_Quality_Slight, -- 质量记分及问责考核 SUM(s.Quality_Employee_Count) AS Quality_Employee_Count, SUM(s.Quality_Employee_Score) AS Quality_Employee_Score, SUM(s.Quality_Contractor_Count) AS Quality_Contractor_Count, SUM(s.Quality_Contractor_Score) AS Quality_Contractor_Score, SUM(s.Quality_Employee_Fine) AS Quality_Employee_Fine, SUM(s.Quality_Employee_FineAmount) AS Quality_Employee_FineAmount, SUM(s.Quality_Contractor_Fine) AS Quality_Contractor_Fine, SUM(s.Quality_Contractor_FineAmount) AS Quality_Contractor_FineAmount, SUM(s.Quality_Contractor_Deduction) AS Quality_Contractor_Deduction, SUM(s.Quality_Contractor_DeductionAmount) AS Quality_Contractor_DeductionAmount, SUM(s.Quality_ProjectDepartment_Fine) AS Quality_ProjectDepartment_Fine, SUM(s.Quality_ProjectDepartment_FineAmount) AS Quality_ProjectDepartment_FineAmount, -- 安全记分及问责考核 SUM(s.HSE_Employee_Count) AS HSE_Employee_Count, SUM(s.HSE_Employee_Score) AS HSE_Employee_Score, SUM(s.HSE_Contractor_Count) AS HSE_Contractor_Count, SUM(s.HSE_Contractor_Score) AS HSE_Contractor_Score, SUM(s.HSE_Employee_Fine) AS HSE_Employee_Fine, SUM(s.HSE_Employee_FineAmount) AS HSE_Employee_FineAmount, SUM(s.HSE_Contractor_Fine) AS HSE_Contractor_Fine, SUM(s.HSE_Contractor_FineAmount) AS HSE_Contractor_FineAmount, SUM(s.HSE_Contractor_Deduction) AS HSE_Contractor_Deduction, SUM(s.HSE_Contractor_DeductionAmount) AS HSE_Contractor_DeductionAmount, SUM(s.HSE_ProjectDepartment_Fine) AS HSE_ProjectDepartment_Fine, SUM(s.HSE_ProjectDepartment_FineAmount) AS HSE_ProjectDepartment_FineAmount, -- 领导干部HSE片区监管活动 SUM(s.LeaderSupervision_HSECheck_Leaders) AS LeaderSupervision_HSECheck_Leaders, SUM(s.LeaderSupervision_HSECheck_Count) AS LeaderSupervision_HSECheck_Count, SUM(s.LeaderSupervision_HSECheck_Hazards) AS LeaderSupervision_HSECheck_Hazards, SUM(s.LeaderSupervision_SafetyLectures_Leaders) AS LeaderSupervision_SafetyLectures_Leaders, SUM(s.LeaderSupervision_SafetyLectures_Count) AS LeaderSupervision_SafetyLectures_Count, SUM(s.LeaderSupervision_SafetyLectures_Attendees)AS LeaderSupervision_SafetyLectures_Attendees, SUM(s.LeaderSupervision_Activities_Leaders) AS LeaderSupervision_Activities_Leaders, SUM(s.LeaderSupervision_Activities_Count) AS LeaderSupervision_Activities_Count, -- 落实安全管理新举措 SUM(s.HSEMeasures_OfficesCount) AS HSEMeasures_OfficesCount, SUM(s.HSEMeasures_TrainingBooths) AS HSEMeasures_TrainingBooths, SUM(s.HSEMeasures_Toolboxs) AS HSEMeasures_Toolboxs, SUM(s.HSEMeasures_Consultant_Projects) AS HSEMeasures_Consultant_Projects, SUM(s.HSEMeasures_Consultant_Count) AS HSEMeasures_Consultant_Count, SUM(s.HSEMeasures_FiveStar_Star2) AS HSEMeasures_FiveStar_Star2, SUM(s.HSEMeasures_FiveStar_Star3) AS HSEMeasures_FiveStar_Star3, SUM(s.HSEMeasures_FiveStar_Star4) AS HSEMeasures_FiveStar_Star4, SUM(s.HSEMeasures_FiveStar_Star5) AS HSEMeasures_FiveStar_Star5, SUM(s.HSEMeasures_Contractor_Interviewees) AS HSEMeasures_Contractor_Interviewees, SUM(s.HSEMeasures_PilotProject_Headquarters) AS HSEMeasures_PilotProject_Headquarters, SUM(s.HSEMeasures_PilotProject_Branch) AS HSEMeasures_PilotProject_Branch, -- 基层站队HSE标准化建设 SUM(s.Construction_Teams_Totals) AS Construction_Teams_Totals, SUM(s.Construction_Teams_Compliant) AS Construction_Teams_Compliant, SUM(s.Construction_ModelTeams_Headquarters) AS Construction_ModelTeams_Headquarters, SUM(s.Construction_ModelTeams_CPECC) AS Construction_ModelTeams_CPECC, SUM(s.Construction_ModelTeams_Group) AS Construction_ModelTeams_Group, -- HSE培训 SUM(s.HSETraining_ThreeCategory) AS HSETraining_ThreeCategory, SUM(s.HSETraining_TrainingPersons) AS HSETraining_TrainingPersons, SUM(s.HSETraining_ContractorTraining) AS HSETraining_ContractorTraining from SafetyManagementData as s left join Base_Unit as u on u.UnitId = s.UnitId where 1=1 "; List listStr = new List(); if (this.drpUnitId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnitId.SelectedValue)) { strSql += " AND s.UnitId =@unitId "; listStr.Add(new SqlParameter("@unitId", this.drpUnitId.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtStartTime.Text.Trim())) { strSql += " AND s.ReportDate >= @StartTime"; listStr.Add(new SqlParameter("@StartTime", Funs.GetNewDateTime(this.txtStartTime.Text.Trim()))); } if (!string.IsNullOrEmpty(this.txtEndTime.Text.Trim())) { strSql += " AND s.ReportDate <= @EndTime"; listStr.Add(new SqlParameter("@EndTime", Funs.GetNewDateTime(this.txtEndTime.Text.Trim()))); } strSql += " group by s.UnitId,s.ReportDate order by s.UnitId,s.ReportDate desc"; SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); return tb; } /// /// 绑定数据 /// private void BindGrid() { DataTable tb = GetSourceDataTable(); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 表排序、分页、关闭窗口 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { DateTime? startTime = Funs.GetNewDateTime(this.txtStartTime.Text.Trim()); DateTime? endTime = Funs.GetNewDateTime(this.txtEndTime.Text.Trim()); if (startTime > endTime) { Alert.ShowInTop("开始日期不能大于结束日期!", MessageBoxIcon.Warning); return; } this.BindGrid(); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string fileName = System.Web.HttpUtility.UrlEncode($"安全管理数据" + Funs.GetNewFileName(), System.Text.Encoding.UTF8); Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; DataTable dtAll = GetSourceDataTable(); string html = GetGridMultiHeaderTableHtml(Grid1, dtAll); Response.Write(html); Response.End(); } /// /// 多表头导出 /// public string GetGridMultiHeaderTableHtml(Grid grid, DataTable dtSource) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); MultiHeaderTable mht = new MultiHeaderTable(); mht.ResolveMultiHeaderTable(grid.Columns); foreach (List rows in mht.MultiTable) { sb.Append(""); foreach (object[] cell in rows) { int rowspan = Convert.ToInt32(cell[0]); int colspan = Convert.ToInt32(cell[1]); GridColumn column = cell[2] as GridColumn; if (column.Hidden == false) { sb.AppendFormat("{3}", rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "", colspan != 1 ? " colspan=\"" + colspan + "\"" : "", colspan != 1 ? " style=\"text-align:center;\"" : "", column.HeaderText); } } sb.Append(""); } int rowIndex = 0; foreach (DataRow dr in dtSource.Rows) { sb.Append(""); foreach (GridColumn column in mht.Columns) { if (column.ColumnID == "ckbIsSelected" || column.ColumnID == "Punish" || column.ColumnID == "Del") continue; string cellValue = ""; if (column.ColumnID == "tfNumber") { //导出序号:全部数据的序号 cellValue = (rowIndex + 1).ToString(); } else if (column.ColumnID == "ReportDate") { cellValue = string.Format("{0:yyyy-MM}", dr[column.ColumnID]); } else { if (!string.IsNullOrEmpty(column.ColumnID) && dtSource.Columns.Contains(column.ColumnID)) { cellValue = dr[column.ColumnID] == DBNull.Value ? "" : dr[column.ColumnID].ToString(); } } sb.AppendFormat("", System.Web.HttpUtility.HtmlEncode(cellValue)); //sb.AppendFormat("", System.Web.HttpUtility.HtmlEncode(cellValue)); } sb.Append(""); rowIndex++; } sb.Append("
{0}{0}
"); return sb.ToString(); } #endregion } }