116 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			116 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | 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; | |||
|  | using AspNet = System.Web.UI.WebControls; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.CQMS.Foreign | |||
|  | { | |||
|  |     public partial class ForeignWBSOut : PageBase | |||
|  |     { | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 BindGrid(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 绑定数据 | |||
|  |         /// <summary> | |||
|  |         /// 绑定数据 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid() | |||
|  |         { | |||
|  |             string strSql = @"SELECT breakdown.BreakdownProjectId,
 | |||
|  |                                     breakdown.ProjectId, | |||
|  |                                     breakdown.UnitWorkId, | |||
|  |                                     breakdown.CNProfessionalId, | |||
|  |                                     breakdown.BreakdownCode, | |||
|  |                                     breakdown.BreakdownName, | |||
|  |                                     breakdown.BreakdownDef, | |||
|  |                                     breakdown.Remark, | |||
|  |                                     cn.ProfessionalName, | |||
|  |                                     unitWork.UnitWorkName"
 | |||
|  |                         + @" FROM WBS_ForeignBreakdownProject AS breakdown" | |||
|  |                         + @" LEFT JOIN WBS_UnitWork unitWork on unitWork.UnitWorkId = breakdown.UnitWorkId" | |||
|  |                         + @" LEFT JOIN WBS_ForeignCNProfessional cn on cn.CNProfessionalId = breakdown.CNProfessionalId" | |||
|  |                         + @" WHERE breakdown.ProjectId=@projectId AND breakdown.IsSelected='TRUE' "; | |||
|  |             List<SqlParameter> listStr = new List<SqlParameter>(); | |||
|  |             listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId)); | |||
|  |             SqlParameter[] parameter = listStr.ToArray(); | |||
|  |             DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); | |||
|  |             Grid1.DataSource = tb; | |||
|  |             Grid1.DataBind(); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 导出 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         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; | |||
|  |             //this.Grid1.PageSize = this.; | |||
|  |             //this.Grid1.PageSize = 10000; | |||
|  |             BindGrid(); | |||
|  |             Response.Write(GetGridTableHtml(Grid1)); | |||
|  |             Response.End(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 导出方法 | |||
|  |         /// </summary> | |||
|  |         /// <param name="grid"></param> | |||
|  |         /// <returns></returns> | |||
|  |         private string GetGridTableHtml(Grid grid) | |||
|  |         { | |||
|  |             StringBuilder sb = new StringBuilder(); | |||
|  |             sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>"); | |||
|  |             sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">"); | |||
|  |             sb.Append("<tr>"); | |||
|  |             foreach (GridColumn column in grid.Columns) | |||
|  |             { | |||
|  |                 //if (column.ColumnID != "AttachUrl" && column.ColumnID != "ITPListId") | |||
|  |                 //{ | |||
|  |                     sb.AppendFormat("<td>{0}</td>", column.HeaderText); | |||
|  |                 //} | |||
|  |             } | |||
|  |             sb.Append("</tr>"); | |||
|  |             foreach (GridRow row in grid.Rows) | |||
|  |             { | |||
|  |                 sb.Append("<tr>"); | |||
|  |                 foreach (GridColumn column in grid.Columns) | |||
|  |                 { | |||
|  |                     //if (column.ColumnID != "AttachUrl" && column.ColumnID != "ITPListId") | |||
|  |                     //{ | |||
|  |                         string html = row.Values[column.ColumnIndex].ToString(); | |||
|  |                         if (column.ColumnID == "tfPageIndex") | |||
|  |                         { | |||
|  |                             html = (row.FindControl("lblPageIndex") as AspNet.Label).Text; | |||
|  |                         } | |||
|  |                         sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;width:140px;'>{0}</td>", html); | |||
|  |                     //} | |||
|  |                 } | |||
|  | 
 | |||
|  |                 sb.Append("</tr>"); | |||
|  |             } | |||
|  | 
 | |||
|  |             sb.Append("</table>"); | |||
|  | 
 | |||
|  |             return sb.ToString(); | |||
|  |         } | |||
|  |     } | |||
|  | } |