using System; using System.Collections.Generic; using System.Linq; using AspNet = System.Web.UI.WebControls; using BLL; using System.Text; namespace FineUIPro.Web.WeldingProcess.WeldingReport { public partial class NDTBacklogList : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); BLL.Base_UnitService.InitProjectUnitDropDownList(this.drpUnitId, true, this.CurrUser.LoginProjectId, BLL.Const.UnitType_5, Resources.Lan.PleaseSelect);//单位 BLL.Project_InstallationService.InitInstallationDropDownList(this.drpInstallationId, true, this.CurrUser.LoginProjectId, Resources.Lan.PleaseSelect);//装置 BLL.Base_DetectionTypeService.InitDetectionTypeDropDownList(this.drpNDEType, Resources.Lan.PleaseSelect, true, string.Empty);//探伤类型 } } /// /// 绑定数据 /// private void BindGrid() { //this.Grid1.Hidden = true; this.Grid1.DataSource = null; this.Grid1.DataBind(); List itemLists = new List(); var q = from x in Funs.DB.View_NDTBacklogList where x.ProjectId == this.CurrUser.LoginProjectId select x; if (this.drpInstallationId.SelectedValue!=BLL.Const._Null) { q = from x in q where x.InstallationId ==this.drpInstallationId.SelectedValue select x; } if (this.drpUnitId.SelectedValue!=BLL.Const._Null) { q = from x in q where x.UnitId == this.drpUnitId.SelectedValue.Trim() select x; } q = from x in q orderby x.PipelineCode, x.WeldJointCode select x; if (this.drpNDEType.SelectedValue!=BLL.Const._Null) { var items = from x in q where x.DetectionTypeId == this.drpNDEType.SelectedValue orderby x.TrustBatchCode select x; if (items.Count() > 0) { Model.View_NDTBacklogList n = new Model.View_NDTBacklogList(); n.TrustBatchCode = Resources.Lan.RequestMethod + ":" + drpNDEType.SelectedItem.Text; n.TrustBatchItemId = "0"; itemLists.Add(n); itemLists.AddRange(items); } //this.Grid1.Hidden = false; this.Grid1.DataSource = itemLists; this.Grid1.DataBind(); } else { var ndtTypes = from x in Funs.DB.Base_DetectionType select x; if (q.Count() > 0 && ndtTypes.Count() > 0) { foreach (var ndtTypeItem in ndtTypes) //循环委托方法 按委托方法 添加明细项 { var items = from x in q where x.DetectionTypeId == ndtTypeItem.DetectionTypeId select x; if (items.Count() > 0) { Model.View_NDTBacklogList n = new Model.View_NDTBacklogList(); n.TrustBatchCode = Resources.Lan.RequestMethod + ":" + ndtTypeItem.DetectionTypeName; n.TrustBatchItemId = "0"; itemLists.Add(n); itemLists.AddRange(items); } } //this.Grid1.Hidden = false; this.Grid1.DataSource = itemLists; this.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 #region 统计按钮事件 /// /// 统计 /// /// /// protected void BtnAnalyse_Click(object sender, EventArgs e) { BindGrid(); } #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(Resources.Lan.NDTBacklogList + 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(); grid.PageSize = 10000; BindGrid(); sb.Append(""); sb.Append(""); sb.Append(""); 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(); string jot = row.Values[column.ColumnIndex].ToString(); string html = string.Empty; if (column.ColumnID == "WeldJointCode" && jot.Split('-').Length > 1) { html = "'" + row.Values[column.ColumnIndex].ToString(); } else { 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 } }