xinjiang/SGGL/FineUIPro.Web/HJGL/WeldingReport/WelderDynamicStatistics.asp...

304 lines
12 KiB
C#

using BLL;
using FineUIPro.Web.Controls;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.WeldingReport
{
public partial class WelderDynamicStatistics : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);
}
}
#endregion
#region BindGrid
/// <summary>
///
/// </summary>
private DataTable tb = null;
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@projectId", this.CurrUser.LoginProjectId)
};
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@unitId", this.drpUnitId.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@unitId", null));
}
SqlParameter[] parameter = listStr.ToArray();
tb = SQLHelper.GetDataTableRunProc("sp_rpt_WelderDynamicStatistics", parameter);
this.Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 计算合计
/// </summary>
protected void OutputSummaryData()
{
if (tb != null)
{
int total_count = 0;//报考总人数
int PD_wait_exam_count = 0;//管道(人数)待考试
int PD_qualified_duty_count = 0;////管道(人数)合格在岗
int PD_qualified_leave_count = 0;////管道(人数)合格离岗
int FE_wait_exam_count = 0;//设备(人数)待考试
int FE_qualified_duty_count = 0;////设备(人数)合格在岗
int FE_qualified_leave_count = 0;////设备(人数)合格离岗
int JG_wait_exam_count = 0;//钢结构(人数)待考试
int JG_qualified_duty_count = 0;////钢结构(人数)合格在岗
int JG_qualified_leave_count = 0;////钢结构(人数)合格离岗
int TJ_wait_exam_count = 0;//土建(人数)待考试
int TJ_qualified_duty_count = 0;////土建(人数)合格在岗
int TJ_qualified_leave_count = 0;////土建(人数)合格离岗
foreach (DataRow row in tb.Rows)
{
total_count += Funs.GetNewIntOrZero(row["total_count"].ToString());
PD_wait_exam_count += Funs.GetNewIntOrZero(row["PD_wait_exam_count"].ToString());
PD_qualified_duty_count += Funs.GetNewIntOrZero(row["PD_qualified_duty_count"].ToString());
PD_qualified_leave_count += Funs.GetNewIntOrZero(row["PD_qualified_leave_count"].ToString());
FE_wait_exam_count += Funs.GetNewIntOrZero(row["FE_wait_exam_count"].ToString());
FE_qualified_duty_count += Funs.GetNewIntOrZero(row["FE_qualified_duty_count"].ToString());
FE_qualified_leave_count += Funs.GetNewIntOrZero(row["FE_qualified_leave_count"].ToString());
JG_wait_exam_count += Funs.GetNewIntOrZero(row["JG_wait_exam_count"].ToString());
JG_qualified_duty_count += Funs.GetNewIntOrZero(row["JG_qualified_duty_count"].ToString());
JG_qualified_leave_count += Funs.GetNewIntOrZero(row["JG_qualified_leave_count"].ToString());
TJ_wait_exam_count += Funs.GetNewIntOrZero(row["TJ_wait_exam_count"].ToString());
TJ_qualified_duty_count += Funs.GetNewIntOrZero(row["TJ_qualified_duty_count"].ToString());
TJ_qualified_leave_count += Funs.GetNewIntOrZero(row["TJ_qualified_leave_count"].ToString());
}
JObject summary = new JObject
{
{ "UnitName", "合计:" },
{ "total_count", total_count },
{"PD_wait_exam_count",PD_wait_exam_count },
{"PD_qualified_duty_count",PD_qualified_duty_count },
{"PD_qualified_leave_count",PD_qualified_leave_count },
{"FE_wait_exam_count",FE_wait_exam_count },
{"FE_qualified_duty_count",FE_qualified_duty_count },
{"FE_qualified_leave_count",FE_qualified_leave_count },
{"JG_wait_exam_count",JG_wait_exam_count },
{"JG_qualified_duty_count",JG_qualified_duty_count },
{"JG_qualified_leave_count",JG_qualified_leave_count },
{"TJ_wait_exam_count",TJ_wait_exam_count },
{"TJ_qualified_duty_count",TJ_qualified_duty_count },
{"TJ_qualified_leave_count",TJ_qualified_leave_count },
};
Grid1.SummaryData = summary;
}
}
#endregion
#region
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
BindGrid();
OutputSummaryData();
}
#endregion
#region
/// 导出按钮
/// </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;
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
grid.PageSize = this.Grid1.RecordCount;
BindGrid();
MultiHeaderTable mht = new MultiHeaderTable();
mht.ResolveMultiHeaderTable(Grid1.Columns);
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;\">");
foreach (List<object[]> rows in mht.MultiTable)
{
sb.Append("<tr>");
foreach (object[] cell in rows)
{
int rowspan = Convert.ToInt32(cell[0]);
int colspan = Convert.ToInt32(cell[1]);
GridColumn column = cell[2] as GridColumn;
if (!column.Hidden)
{
sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
colspan != 1 ? " style=\"text-align:center;\"" : "",
column.HeaderText);
}
}
sb.Append("</tr>");
}
int j = 0;
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
int i = 0;
foreach (GridColumn column in mht.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
sb.AppendFormat("<td style=\"text-align:center;\">{0}</td>", html);
i++;
}
j++;
sb.Append("</tr>");
}
var sumary = grid.SummaryData;
if (sumary != null)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
try
{
if (column is GroupField)
{
if (((GroupField)column).Columns != null)
{
foreach (var item in ((GroupField)column).Columns)
{
if (sumary.ContainsKey(item.ColumnID))
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", sumary.GetValue(item.ColumnID).ToString());
}
else
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
}
}
else if (column is RenderField)
{
if (sumary.ContainsKey(column.ColumnID))
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", sumary.GetValue(column.ColumnID).ToString());
}
else
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
else
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
catch (Exception e)
{
sb.AppendFormat("<td style=\"text-align:center;vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
}
}