using System;
using System.Collections.Generic;
using BLL;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.WeldingProcess.WeldingReport
{
public partial class WelderRepairLog : PageBase
{
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
BLL.Project_InstallationService.InitInstallationDropDownList(this.drpInstallationId, true, this.CurrUser.LoginProjectId, Resources.Lan.PleaseSelect);//装置
BLL.Base_PipingClassService.InitPipingClassDropDownList(this.drpPipingClassId, true, Resources.Lan.PleaseSelect);//管道等级
}
}
///
/// 绑定数据
///
private void BindGrid()
{
List listStr = new List();
listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
if (this.drpInstallationId.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@installationId", this.drpInstallationId.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@installationId", null));
}
if (this.drpPipingClassId.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@pipingClassId", this.drpPipingClassId.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@pipingClassId", null));
}
if (!string.IsNullOrEmpty(this.txtStarTime.Text))
{
listStr.Add(new SqlParameter("@date1", this.txtStarTime.Text.Trim()));
}
else
{
listStr.Add(new SqlParameter("@date1", null));
}
if (!string.IsNullOrEmpty(this.txtEndTime.Text))
{
listStr.Add(new SqlParameter("@date2", this.txtEndTime.Text.Trim()));
}
else
{
listStr.Add(new SqlParameter("@date2", null));
}
if (!string.IsNullOrEmpty(this.txtWelderCode.Text.Trim()))
{
listStr.Add(new SqlParameter("@welderCode", this.txtWelderCode.Text.Trim()));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunProc("sp_rpt_WelderRepairLog", parameter);
this.Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
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.WelderRepairLog + 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("{0} | ", 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;
}
if (column.ColumnID == "CheckDefects")
{
html = (row.FindControl("lbCheckDefects") as AspNet.Label).Text;
}
sb.AppendFormat("{0} | ", html);
}
sb.Append("
");
}
sb.Append("
");
return sb.ToString();
}
#endregion
#region 格式化字符串
///
/// 是否热处理
///
///
///
protected string ConvertCheckDefects(object checkDefects)
{
string defectList = string.Empty;
if (checkDefects != null)
{
defectList = BLL.Base_DefectService.GetDefectNameStrByDefectIdStr(checkDefects.ToString());
}
return defectList;
}
#endregion
}
}