using BLL; using FineUIPro.Web.Controls; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.WeldingReport { public partial class OneDayTrustReport : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); List units = new List(); dpDate.SelectedDate = new DateTime( DateTime.Now.Year, DateTime.Now.Month,1); var pUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); if (pUnit == null || pUnit.UnitType == Const.ProjectUnitType_1) { units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2); //this.drpUnit.Enabled = false; this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = units; this.drpUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpUnit); units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_5); //this.drpUnit.Enabled = false; this.drpCheckUnit.DataTextField = "UnitName"; this.drpCheckUnit.DataValueField = "UnitId"; this.drpCheckUnit.DataSource = units; this.drpCheckUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpCheckUnit); } else { units = BLL.UnitService.GetSubUnitsListBySupervisorUnitId(this.CurrUser.ProjectId, this.CurrUser.UnitId); this.drpUnit.Enabled = false; this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = units; this.drpUnit.DataBind(); this.drpUnit.SelectedValue = CurrUser.UnitId; units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_5); //this.drpUnit.Enabled = false; this.drpCheckUnit.DataTextField = "UnitName"; this.drpCheckUnit.DataValueField = "UnitId"; this.drpCheckUnit.DataSource = units; this.drpCheckUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpCheckUnit); } //显示列 //Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, Const.UnitAreaQualityMenuId); //if (c != null) //{ // this.GetShowColumn(c.Columns); //} //BindGrid(); } } #endregion #region 绑定BindGrid /// /// /// private DataTable tb = null; /// /// 绑定数据 /// private void BindGrid() { string strSql = @"select 1 id,a.WorkAreaCode,a.WorkAreaId,c.UnitName TrustName ,b.UnitId TrustUnitId ,e.UnitName CheckName ,h.DetectionTypeName,d.UnitId CheckUnitId ,f.CH_NDTMethod,f.trustTotalNum,g.CheckTotalNum,f.trustTotalNum-g.CheckTotalNum NotCheck,100*g.CheckTotalNum/f.trustTotalNum HasPer from ProjectData_WorkArea a left join Project_ProjectUnit b on b.ProjectId = a.ProjectId and b.UnitType='2' and a.UnitId =b.UnitId left join Base_Unit c on c.UnitId=b.UnitId left join Project_ProjectUnit d on d.ProjectId = a.ProjectId and d.UnitType='6' left join Base_Unit e on e.UnitId=d.UnitId left join ( select a.CH_TrustUnit,a.CH_CheckUnit,a.CH_NDTMethod,WorkAreaId,count(distinct b.JOT_ID)TrustTotalNum from CH_Trust a left join CH_TrustItem b on a.CH_TrustID=b.CH_TrustID LEFT JOIN pw_jointinfo c on c.JOT_ID=b.JOT_ID LEFT JOIN pw_isoinfo ON c.ISO_ID = pw_isoinfo.ISO_ID where a.ProjectId=@ProjectId and a.CH_AuditDate is not null and (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') group by a.CH_TrustUnit,a.CH_CheckUnit,a.CH_NDTMethod,WorkAreaId ) f on f.CH_CheckUnit = d.UnitId and f.CH_TrustUnit=b.UnitId and a.WorkAreaId =f.WorkAreaId left join ( select a.CH_TrustUnit,a.CH_CheckUnit,a.CH_NDTMethod,WorkAreaId,count(distinct c.JOT_ID)CheckTotalNum from CH_Trust a left join CH_Check b on a.CH_TrustID=b.CH_TrustID left join CH_CheckItem c on b.CHT_CheckID=c.CHT_CheckID LEFT JOIN pw_jointinfo d on d.JOT_ID=c.JOT_ID LEFT JOIN pw_isoinfo ON d.ISO_ID = pw_isoinfo.ISO_ID where a.ProjectId=@ProjectId and a.CH_AuditDate is not null and (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') group by a.CH_TrustUnit,a.CH_CheckUnit ,a.CH_NDTMethod ,WorkAreaId ) g on g.CH_CheckUnit = d.UnitId and g.CH_TrustUnit=b.UnitId and f.CH_NDTMethod=g.CH_NDTMethod and g.WorkAreaId = a.WorkAreaId left join Base_DetectionType h on h.DetectionTypeId = f.CH_NDTMethod where h.DetectionTypeName is not null and a.ProjectId=@ProjectId "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); if (this.drpUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.UnitId = @UnitId"; listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue)); } if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { strSql += " and d.UnitId = @UnitId"; listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue)); } if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length == 1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", "")); } strSql += " order by a.WorkAreaCode,c.UnitName,e.UnitName "; SqlParameter[] parameter = listStr.ToArray(); DataTable tb1 = SQLHelper.GetDataTableRunText(strSql, parameter); strSql = @" select a.CH_TrustUnit,a.CH_CheckUnit,a.CH_NDTMethod,WorkAreaId,DAY(CH_AuditDate) Day ,MONTH(CH_AuditDate) Month,count(distinct b.JOT_ID)TrustTotalNum from CH_Trust a left join CH_TrustItem b on a.CH_TrustID=b.CH_TrustID LEFT JOIN pw_jointinfo c on c.JOT_ID=b.JOT_ID LEFT JOIN pw_isoinfo ON c.ISO_ID = pw_isoinfo.ISO_ID where (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') and a.CH_AuditDate is not null and a.ProjectId = '" + this.CurrUser.LoginProjectId + "' "; if (this.drpUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.CH_TrustUnit ='" + this.drpUnit.SelectedValue + "' "; } if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.CH_CheckUnit ='" + this.drpCheckUnit.SelectedValue + "' "; } strSql += " and a.CH_AuditDate >='" + dpDate.SelectedDate.Value.ToString("yyyy-MM-01") + "' and a.CH_AuditDate <'" + dpDate.SelectedDate.Value.AddMonths(1).ToString("yyyy-MM-01") + "'"; strSql += @" group by a.CH_TrustUnit,a.CH_CheckUnit,WorkAreaId,a.CH_NDTMethod,DAY(CH_AuditDate) ,MONTH(CH_AuditDate) "; listStr = new List(); if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length == 1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", "")); } parameter = listStr.ToArray(); DataTable tb2 = SQLHelper.GetDataTableRunText(strSql, parameter); strSql = @" select a.CH_TrustUnit,a.CH_CheckUnit,a.CH_NDTMethod,WorkAreaId,DAY(b.CHT_AuditDate) Day ,MONTH(b.CHT_AuditDate) Month,count(distinct c.JOT_ID)TrustTotalNum from CH_Trust a left join CH_Check b on a.CH_TrustID=b.CH_TrustID left join CH_CheckItem c on b.CHT_CheckID=c.CHT_CheckID LEFT JOIN pw_jointinfo e on e.JOT_ID=c.JOT_ID LEFT JOIN pw_isoinfo ON e.ISO_ID = pw_isoinfo.ISO_ID where (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') and a.CH_AuditDate is not null and a.ProjectId = '" + this.CurrUser.LoginProjectId + "' "; if (this.drpUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.CH_TrustUnit ='" + this.drpUnit.SelectedValue + "' "; } if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.CH_CheckUnit ='" + this.drpCheckUnit.SelectedValue + "' "; } strSql += " and b.CHT_AuditDate >='" + dpDate.SelectedDate.Value.ToString("yyyy-MM-01") + "' and b.CHT_AuditDate <'" + dpDate.SelectedDate.Value.AddMonths(1).ToString("yyyy-MM-01") + "'"; strSql += @" group by a.CH_TrustUnit,a.CH_CheckUnit,WorkAreaId,a.CH_NDTMethod,DAY(b.CHT_AuditDate) ,MONTH(b.CHT_AuditDate) "; listStr = new List(); if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length == 1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", "")); } parameter = listStr.ToArray(); DataTable tb3 = SQLHelper.GetDataTableRunText(strSql, parameter); strSql = @"select a.UnitId,b.UnitName,c.CH_NDTMethod,c.TrustTotalNum,e.DetectionTypeName,d.CheckTotalNum,c.trustTotalNum-d.CheckTotalNum NotCheck,100*d.CheckTotalNum/c.trustTotalNum HasPer from Project_ProjectUnit a left join Base_Unit b on a.UnitId=b.UnitId left join ( select a.CH_CheckUnit,a.CH_NDTMethod,count(distinct b.JOT_ID)TrustTotalNum from CH_Trust a left join CH_TrustItem b on a.CH_TrustID=b.CH_TrustID LEFT JOIN pw_jointinfo c on c.JOT_ID=b.JOT_ID LEFT JOIN pw_isoinfo ON c.ISO_ID = pw_isoinfo.ISO_ID where a.ProjectId=@ProjectId and a.CH_AuditDate is not null and (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') group by a.CH_CheckUnit,a.CH_NDTMethod) c on a.UnitId = c.CH_CheckUnit left join ( select a.CH_CheckUnit,a.CH_NDTMethod,count(distinct c.JOT_ID)CheckTotalNum from CH_Trust a left join CH_Check b on a.CH_TrustID=b.CH_TrustID left join CH_CheckItem c on b.CHT_CheckID=c.CHT_CheckID LEFT JOIN pw_jointinfo d on d.JOT_ID=c.JOT_ID LEFT JOIN pw_isoinfo ON d.ISO_ID = pw_isoinfo.ISO_ID where a.ProjectId=@ProjectId and c.CHT_FilmDate is not null and (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') group by a.CH_CheckUnit ,a.CH_NDTMethod )d on a.UnitId = d.CH_CheckUnit and d.CH_NDTMethod = c.CH_NDTMethod left join Base_DetectionType e on e.DetectionTypeId = c.CH_NDTMethod where a.UnitType = '6' and a.ProjectId=@ProjectId "; listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); if (this.drpUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.UnitId = @UnitId"; listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue)); } if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { strSql += " and d.UnitId = @UnitId"; listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue)); } if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length == 1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", "")); } parameter = listStr.ToArray(); DataTable tb4 = SQLHelper.GetDataTableRunText(strSql, parameter); strSql = @" select a.CH_CheckUnit,a.CH_NDTMethod,DAY(CH_AuditDate) Day ,MONTH(CH_AuditDate) Month,count(distinct b.JOT_ID)TrustTotalNum from CH_Trust a left join CH_TrustItem b on a.CH_TrustID=b.CH_TrustID LEFT JOIN pw_jointinfo c on c.JOT_ID=b.JOT_ID LEFT JOIN pw_isoinfo ON c.ISO_ID = pw_isoinfo.ISO_ID where (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') and a.CH_AuditDate is not null and a.ProjectId = '" + this.CurrUser.LoginProjectId + "' "; if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.CH_CheckUnit ='" + this.drpCheckUnit.SelectedValue + "' "; } strSql += " and a.CH_AuditDate >='" + dpDate.SelectedDate.Value.ToString("yyyy-MM-01") + "' and a.CH_AuditDate <'" + dpDate.SelectedDate.Value.AddMonths(1).ToString("yyyy-MM-01") + "'"; strSql += @" group by a.CH_CheckUnit,a.CH_NDTMethod,DAY(CH_AuditDate) ,MONTH(CH_AuditDate) "; listStr = new List(); if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length == 1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", "")); } parameter = listStr.ToArray(); DataTable tb5 = SQLHelper.GetDataTableRunText(strSql, parameter); strSql = @" select a.CH_CheckUnit,a.CH_NDTMethod,DAY(b.CHT_AuditDate) Day ,MONTH(b.CHT_AuditDate) Month,count(distinct c.JOT_ID)TrustTotalNum from CH_Trust a left join CH_Check b on a.CH_TrustID=b.CH_TrustID left join CH_CheckItem c on b.CHT_CheckID=c.CHT_CheckID LEFT JOIN pw_jointinfo e on e.JOT_ID=c.JOT_ID LEFT JOIN pw_isoinfo ON e.ISO_ID = pw_isoinfo.ISO_ID where (pw_isoinfo.Is_Standard=@IsStandard OR @IsStandard ='') and c.CHT_FilmDate is not null and a.ProjectId = '" + this.CurrUser.LoginProjectId + "' "; if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { strSql += " and a.CH_CheckUnit ='" + this.drpCheckUnit.SelectedValue + "' "; } strSql += " and b.CHT_AuditDate >='" + dpDate.SelectedDate.Value.ToString("yyyy-MM-01") + "' and b.CHT_AuditDate <'" + dpDate.SelectedDate.Value.AddMonths(1).ToString("yyyy-MM-01") + "'"; strSql += @" group by a.CH_CheckUnit,a.CH_NDTMethod,DAY(b.CHT_AuditDate) ,MONTH(b.CHT_AuditDate) "; listStr = new List(); if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length == 1) { listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0])); } else { listStr.Add(new SqlParameter("@IsStandard", "")); } parameter = listStr.ToArray(); DataTable tb6 = SQLHelper.GetDataTableRunText(strSql, parameter); int day = DateTime.DaysInMonth(dpDate.SelectedDate.Value.Year, dpDate.SelectedDate.Value.Month); if (tb1 != null) { tb1.Columns.Add("has_month_din"); tb1.Columns.Add("Type"); for (int i = 1; i <= day; i++) { tb1.Columns.Add("Day" + i); } } int numCount = tb1.Rows.Count; for (int j = numCount - 1; j >= 0; j--) { var row1 = tb1.NewRow(); row1[0] = tb1.Rows[j][0]; row1[1] = tb1.Rows[j][1]; row1[2] = tb1.Rows[j][2]; row1[3] = tb1.Rows[j][3]; row1[4] = tb1.Rows[j][4]; row1[5] = tb1.Rows[j][5]; row1[6] = tb1.Rows[j][6]; row1[7] = tb1.Rows[j][7]; row1[8] = tb1.Rows[j][8]; row1[9] = tb1.Rows[j][9]; row1[10] = tb1.Rows[j][10]; row1[11] = tb1.Rows[j][11]; row1[12] = tb1.Rows[j][12]; row1[13] = tb1.Rows[j][13]; tb1.Rows.InsertAt(row1, j + 1); } for (int j = 0; j < numCount; j++) { var row1 = tb1.Rows[j * 2]; row1["id"] = j * 2; row1["Type"] = "委托焊口数(道)"; for (int i = 0; i < tb2.Rows.Count; i++) { var row2 = tb2.Rows[i]; if (row2["WorkAreaId"].ToString() == row1["WorkAreaId"].ToString() && row2["CH_TrustUnit"].ToString() == row1["TrustUnitId"].ToString() && row2["CH_CheckUnit"].ToString() == row1["CheckUnitId"].ToString() && row2["CH_NDTMethod"].ToString() == row1["CH_NDTMethod"].ToString()) { if (tb1.Columns.Contains("Day" + row2["day"])) { row1["Day" + row2["day"]] = row2["TrustTotalNum"]; } } } double has = 0; var row4 = tb1.Rows[j * 2]; for (int i = 1; i <= day; i++) { if (row4["Day" + i] != DBNull.Value) try { has += double.Parse(row4["Day" + i].ToString()); } catch (Exception e) { } } tb1.Rows[j * 2]["has_month_din"] = has; row1 = tb1.Rows[j * 2 + 1]; row1["id"] = j * 2 + 1; row1["Type"] = "检测焊口数(道)"; for (int i = 0; i < tb3.Rows.Count; i++) { var row3 = tb3.Rows[i]; if (row3["WorkAreaId"].ToString() == row1["WorkAreaId"].ToString() && row3["CH_TrustUnit"].ToString() == row1["TrustUnitId"].ToString() && row3["CH_CheckUnit"].ToString() == row1["CheckUnitId"].ToString() && row3["CH_NDTMethod"].ToString() == row1["CH_NDTMethod"].ToString()) { if (tb1.Columns.Contains("Day" + row3["day"])) { row1["Day" + row3["day"]] = row3["TrustTotalNum"]; } } } has = 0; row4 = tb1.Rows[j * 2 + 1]; for (int i = 1; i <= day; i++) { if (row4["Day" + i] != DBNull.Value) try { has += double.Parse(row4["Day" + i].ToString()); } catch (Exception e) { } } tb1.Rows[j * 2+1]["has_month_din"] = has; } int indes = tb1.Rows.Count; for (int j = 0; j < tb4.Rows.Count; j++) { { var row1 = tb1.NewRow(); row1["id"] = indes++; row1["TrustName"] = "每日累计汇总"; row1["CheckUnitId"] = tb4.Rows[j]["UnitId"]; row1["CheckName"] = tb4.Rows[j]["UnitName"]; row1["DetectionTypeName"] = tb4.Rows[j]["DetectionTypeName"]; row1["CH_NDTMethod"] = tb4.Rows[j]["CH_NDTMethod"]; row1["TrustTotalNum"] = tb4.Rows[j]["TrustTotalNum"]; row1["CheckTotalNum"] = tb4.Rows[j]["CheckTotalNum"]; row1["NotCheck"] = tb4.Rows[j]["NotCheck"]; row1["HasPer"] = tb4.Rows[j]["HasPer"]; row1["Type"] = "委托焊口数(道)"; for (int i = 0; i < tb5.Rows.Count; i++) { var row2 = tb5.Rows[i]; if ( row2["CH_CheckUnit"].ToString() == row1["CheckUnitId"].ToString() && row2["CH_NDTMethod"].ToString() == row1["CH_NDTMethod"].ToString()) { if (tb1.Columns.Contains("Day" + row2["day"])) { row1["Day" + row2["day"]] = row2["TrustTotalNum"]; } } } tb1.Rows.Add(row1); } { var row1 = tb1.NewRow(); row1["id"] = indes++; row1["TrustName"] = "每日累计汇总"; row1["CheckUnitId"] = tb4.Rows[j]["UnitId"]; row1["CheckName"] = tb4.Rows[j]["UnitName"]; row1["DetectionTypeName"] = tb4.Rows[j]["DetectionTypeName"]; row1["CH_NDTMethod"] = tb4.Rows[j]["CH_NDTMethod"]; row1["TrustTotalNum"] = tb4.Rows[j]["TrustTotalNum"]; row1["CheckTotalNum"] = tb4.Rows[j]["CheckTotalNum"]; row1["NotCheck"] = tb4.Rows[j]["NotCheck"]; row1["HasPer"] = tb4.Rows[j]["HasPer"]; row1["Type"] = "检测焊口数(道)"; for (int i = 0; i < tb6.Rows.Count; i++) { var row2 = tb6.Rows[i]; if ( row2["CH_CheckUnit"].ToString() == row1["CheckUnitId"].ToString() && row2["CH_NDTMethod"].ToString() == row1["CH_NDTMethod"].ToString()) { if (tb1.Columns.Contains("Day" + row2["day"])) { row1["Day" + row2["day"]] = row2["TrustTotalNum"]; } } } tb1.Rows.Add(row1); } } Grid1.RecordCount = tb1.Rows.Count; Grid1.DataSource = tb1; Grid1.DataBind(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #endregion /// /// /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); // 显示列 //var c = UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, Const.UnitAreaQualityMenuId); //if (c != null) //{ // this.GetShowColumn(c.Columns); //} } /// /// 显示的列 /// /// private void GetShowColumn(string column) { if (!string.IsNullOrEmpty(column)) { for (int i = 0; i < Grid1.Columns.Count; i++) { this.Grid1.Columns[i].Hidden = true; } List columns = column.Split(',').ToList(); foreach (var item in columns) { this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false; } } } #region 统计按钮事件 /// /// 统计 /// /// /// protected void BtnAnalyse_Click(object sender, EventArgs e) { if (dpDate.SelectedDate.HasValue) { CollumMonth.HeaderText = dpDate.SelectedDate.Value.ToString("yyyy年MM月"); int day = DateTime.DaysInMonth(dpDate.SelectedDate.Value.Year, dpDate.SelectedDate.Value.Month); if (day == 30) { Day31.Hidden = true; } else if (day == 29) { Day30.Hidden = true; Day31.Hidden = true; } else if (day == 28) { Day29.Hidden = true; Day30.Hidden = true; Day31.Hidden = true; } } else { Alert.ShowInTop("请选择日期!", MessageBoxIcon.Warning); return; } BindGrid(); //OutputSummaryData(); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("储罐/管道每日焊接量统计表" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); MultiHeaderTable mht = new MultiHeaderTable(); mht.ResolveMultiHeaderTable(Grid1.Columns); sb.Append(""); sb.Append(""); 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) { sb.AppendFormat("{3}", rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "", colspan != 1 ? " colspan=\"" + colspan + "\"" : "", colspan != 1 ? " style=\"text-align:center;\"" : "", column.HeaderText); } } sb.Append(""); } int j = 0; foreach (GridRow row in grid.Rows) { sb.Append(""); int i = 0; foreach (GridColumn column in mht.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("spanNumber") as System.Web.UI.HtmlControls.HtmlGenericControl).InnerText; } else if (column.ColumnID == "tfGender") { html = (row.FindControl("labGender") as AspNet.Label).Text; } if (i <= 6 && j % 2 == 0) { if (!column.Hidden) { sb.AppendFormat("", html); } } else if (i > 6) { if (!column.Hidden) { sb.AppendFormat("", html); } } i++; } j++; sb.Append(""); } sb.Append("
{0}{0}
"); return sb.ToString(); } #endregion #region 下拉选择事件 /// /// 单位下拉选择事件 /// /// /// < param name="e"> protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) { } #endregion protected void cb_IsStandard_SelectedIndexChanged(object sender, EventArgs e) { } } }