using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using System.Text; using BLL; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.YLRQ.WeldingReport { public partial class StatisticsSampleTable : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BridProjectGrid(); this.drpWelded.DataTextField = "Text"; this.drpWelded.DataValueField = "Value"; this.drpWelded.DataSource = BLL.DropListService.WeldedStatesList(); this.drpWelded.DataBind(); Funs.FineUIPleaseSelect(this.drpWelded); this.drpWelded.SelectedValue = "1"; this.drpNdtType.DataTextField = "NDT_Code"; this.drpNdtType.DataValueField = "NDT_Code"; this.drpNdtType.DataSource = BLL.HJGL_TestingService.GetNDTTypeNameList(); this.drpNdtType.DataBind(); Funs.FineUIPleaseSelect(this.drpNdtType); Funs.FineUIPleaseSelect(this.drpState); } } #endregion #region 绑定数据 /// /// 绑定项目 /// public void BridProjectGrid() { GridProject.DataSource = BLL.Base_ProjectService.GetYlrqProjectListByUserId(this.CurrUser.UserId, "2"); GridProject.DataBind(); drpProject.Value = this.CurrUser.LoginProjectId; } /// /// 绑定数据 /// private void BindGrid() { List listStr = new List(); if (!string.IsNullOrEmpty(drpProject.Value)) { listStr.Add(new SqlParameter("@projectId", this.drpProject.Value)); } else { listStr.Add(new SqlParameter("@projectId", null)); } if (!string.IsNullOrEmpty(this.txtWeldingCode.Text.Trim())) { listStr.Add(new SqlParameter("@weldingCode", this.txtWeldingCode.Text.Trim())); } else { listStr.Add(new SqlParameter("@weldingCode", null)); } if (this.ckbHotPress.Checked) { listStr.Add(new SqlParameter("@isHotPress", true)); } else { listStr.Add(new SqlParameter("@isHotPress", null)); } if (this.drpWelded.SelectedValue != BLL.Const._Null && this.drpWelded.SelectedValue != null) { listStr.Add(new SqlParameter("@Welded", this.drpWelded.SelectedValue)); } else { listStr.Add(new SqlParameter("@Welded", null)); } if (this.drpNdtType.SelectedValue != BLL.Const._Null && this.drpNdtType.SelectedValue != null) { listStr.Add(new SqlParameter("@ndtType", this.drpNdtType.SelectedText)); } else { listStr.Add(new SqlParameter("@ndtType", null)); } if (this.drpState.SelectedValue != BLL.Const._Null && this.drpState.SelectedValue != null) { listStr.Add(new SqlParameter("@ndtResult", this.drpState.SelectedText)); } else { listStr.Add(new SqlParameter("@ndtResult", null)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunProc("PV_sp_StatisticsSampleTable", parameter); this.Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion protected void drpNdtType_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpNdtType.SelectedValue != BLL.Const._Null) { this.drpState.DataTextField = "Text"; this.drpState.DataValueField = "Value"; this.drpState.DataSource = BLL.DropListService.CheckStatesList(); this.drpState.DataBind(); Funs.FineUIPleaseSelect(this.drpState); this.drpState.SelectedValue = BLL.Const._Null; } } #region 分页 /// /// 分页 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { this.BindGrid(); } /// /// 分页显示条数下拉框 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue); this.BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #endregion #region 统计按钮事件 /// /// 统计 /// /// /// protected void BtnAnalyse_Click(object sender, EventArgs e) { BindGrid(); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { BindGrid(); 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(); sb.Append(""); sb.Append(""); sb.Append(""); this.Grid1.PageSize = 10000; BindGrid(); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("", column.HeaderText); } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("labNumber") as AspNet.Label).Text; } sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion } }