namespace FineUIPro.Web.SysManage { using BLL; using System; using System.Data; using System.Text; using System.Web.UI.WebControls; using AspNet = System.Web.UI.WebControls; public partial class CustomQuery : PageBase { /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 绑定表格 this.BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { this.lbCount.Text = "0 行"; gvHazard.DataSource = null; gvHazard.DataBind(); string strSql = this.txtCustomQuery.Text.Trim(); if (!string.IsNullOrEmpty(strSql)) { DataTable table = SQLHelper.GetDataTableRunText(strSql, null); if (table.Rows.Count > 0) { this.lbCount.Text = table.Rows.Count.ToString()+" 行"; gvHazard.DataSource = table; gvHazard.DataBind(); } else { ShowNotify("没有满足条件的数据,请检查查询语句!", MessageBoxIcon.Warning); } } } protected void btnQuery_Click(object sender, EventArgs e) { BindGrid(); } /// /// 导出 /// /// /// protected void btnMenuOut_Click(object sender, EventArgs e) { string strSql = this.txtCustomQuery.Text.Trim(); if (!string.IsNullOrEmpty(strSql)) { DataTable table = SQLHelper.GetDataTableRunText(strSql, null); 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(GetTableHtml(table)); Response.End(); } } } }