380 lines
15 KiB
C#
380 lines
15 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 FilmJointStatistics : 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);
|
||
Funs.FineUIPleaseSelect(this.drpWorkArea);
|
||
}
|
||
}
|
||
#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));
|
||
}
|
||
if (this.drpWorkArea.SelectedValue != BLL.Const._Null)
|
||
{
|
||
listStr.Add(new SqlParameter("@workAreaId", this.drpWorkArea.SelectedValue));
|
||
}
|
||
else
|
||
{
|
||
listStr.Add(new SqlParameter("@workAreaId", null));
|
||
}
|
||
|
||
SqlParameter[] parameter = listStr.ToArray();
|
||
tb = SQLHelper.GetDataTableRunProc("sp_rpt_FilmJointStatistics", parameter);
|
||
this.Grid1.RecordCount = tb.Rows.Count;
|
||
var table = this.GetPagedDataTable(Grid1, tb);
|
||
table.Columns.Add("pt_jot");
|
||
foreach(DataRow row in table.Rows)
|
||
{
|
||
int pt_jot = 0;
|
||
try
|
||
{
|
||
pt_jot += int.Parse(row["five_pt_jot"].ToString());
|
||
}
|
||
catch (Exception e) { }
|
||
try
|
||
{
|
||
pt_jot += int.Parse(row["ten_pt_jot"].ToString());
|
||
}
|
||
catch (Exception e) { }
|
||
try
|
||
{
|
||
pt_jot += int.Parse(row["twenty_pt_jot"].ToString());
|
||
}
|
||
catch (Exception e) { }
|
||
try
|
||
{
|
||
pt_jot += int.Parse(row["onHundred_pt_jot"].ToString());
|
||
}
|
||
catch (Exception e) { }
|
||
row["pt_jot"] = pt_jot;
|
||
}
|
||
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_jot = 0;//焊口数
|
||
decimal total_size = 0;//吋
|
||
int five_bw_jot = 0;//5% 对接焊口(道)
|
||
int five_extract_jot = 0;//5% 抽拍数(道)
|
||
int five_fw_jot = 0;//5% 角焊缝焊口数
|
||
int five_pt_jot = 0;//5% PT(道)
|
||
int ten_bw_jot = 0;//10% 对接焊口(道)
|
||
int ten_extract_jot = 0;//10% 抽拍数(道)
|
||
int ten_fw_jot = 0;//10% 角焊缝焊口数
|
||
int ten_pt_jot = 0;//10% PT(道)
|
||
int twenty_bw_jot = 0; //20% 对接焊口(道)
|
||
int twenty_extract_jot = 0; //20% 抽拍数(道)
|
||
int twenty_fw_jot = 0; //20% 角焊缝焊口数
|
||
int twenty_pt_jot = 0;//20% PT(道)
|
||
int onHundred_bw_jot = 0; //100% 对接焊口(道)
|
||
int onHundred_extract_jot = 0;//100% 抽拍数(道)
|
||
int onHundred_fw_jot = 0;//100% 角焊缝焊口数
|
||
int onHundred_pt_jot = 0;//100% PT(道)
|
||
int estimate_check_film = 0;//估计检测拍片数量(6张)
|
||
|
||
foreach (DataRow row in tb.Rows)
|
||
{
|
||
total_jot += Funs.GetNewIntOrZero(row["total_jot"].ToString());
|
||
total_size += Funs.GetNewDecimalOrZero(row["total_size"].ToString());
|
||
five_bw_jot += Funs.GetNewIntOrZero(row["five_bw_jot"].ToString());
|
||
five_extract_jot += Funs.GetNewIntOrZero(row["five_extract_jot"].ToString());
|
||
five_fw_jot += Funs.GetNewIntOrZero(row["five_fw_jot"].ToString());
|
||
five_pt_jot += Funs.GetNewIntOrZero(row["five_pt_jot"].ToString());
|
||
ten_bw_jot += Funs.GetNewIntOrZero(row["ten_bw_jot"].ToString());
|
||
ten_extract_jot += Funs.GetNewIntOrZero(row["ten_extract_jot"].ToString());
|
||
ten_fw_jot += Funs.GetNewIntOrZero(row["ten_fw_jot"].ToString());
|
||
ten_pt_jot += Funs.GetNewIntOrZero(row["ten_pt_jot"].ToString());
|
||
twenty_bw_jot += Funs.GetNewIntOrZero(row["twenty_bw_jot"].ToString());
|
||
twenty_extract_jot += Funs.GetNewIntOrZero(row["twenty_extract_jot"].ToString());
|
||
twenty_fw_jot += Funs.GetNewIntOrZero(row["twenty_fw_jot"].ToString());
|
||
twenty_pt_jot += Funs.GetNewIntOrZero(row["twenty_pt_jot"].ToString());
|
||
onHundred_bw_jot += Funs.GetNewIntOrZero(row["onHundred_bw_jot"].ToString());
|
||
onHundred_extract_jot += Funs.GetNewIntOrZero(row["onHundred_extract_jot"].ToString());
|
||
onHundred_fw_jot += Funs.GetNewIntOrZero(row["onHundred_fw_jot"].ToString());
|
||
onHundred_pt_jot += Funs.GetNewIntOrZero(row["onHundred_pt_jot"].ToString());
|
||
estimate_check_film += Funs.GetNewIntOrZero(row["estimate_check_film"].ToString());
|
||
}
|
||
|
||
JObject summary = new JObject
|
||
{
|
||
{ "WorkAreaCode", "合计:" },
|
||
{ "total_jot", total_jot },
|
||
{"total_size",total_size },
|
||
{"five_bw_jot",five_bw_jot },
|
||
{"five_extract_jot",five_extract_jot },
|
||
{"five_fw_jot",five_fw_jot },
|
||
{"five_pt_jot",five_pt_jot },
|
||
{"ten_bw_jot",ten_bw_jot },
|
||
{"ten_extract_jot",ten_extract_jot },
|
||
{"ten_fw_jot",ten_fw_jot },
|
||
{"ten_pt_jot",ten_pt_jot },
|
||
{"twenty_bw_jot",twenty_bw_jot },
|
||
{"twenty_extract_jot",twenty_extract_jot },
|
||
{"twenty_fw_jot",twenty_fw_jot },
|
||
{"twenty_pt_jot",twenty_pt_jot },
|
||
{"onHundred_bw_jot",onHundred_bw_jot },
|
||
{"onHundred_extract_jot",onHundred_extract_jot },
|
||
{"onHundred_fw_jot",onHundred_fw_jot },
|
||
{"onHundred_pt_jot",onHundred_pt_jot },
|
||
{"estimate_check_film",estimate_check_film }
|
||
};
|
||
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
|
||
|
||
#region 下拉选择事件
|
||
/// <summary>
|
||
/// 单位下拉选择事件
|
||
/// </summary>
|
||
/// <param name = "sender" ></ param >
|
||
/// < param name="e"></param>
|
||
protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
this.drpWorkArea.Items.Clear(); ///区域
|
||
if (this.drpUnitId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnitId.SelectedValue))
|
||
{
|
||
BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.drpUnitId.SelectedValue, true);
|
||
}
|
||
else
|
||
{
|
||
Funs.FineUIPleaseSelect(this.drpWorkArea);
|
||
}
|
||
this.drpWorkArea.SelectedIndex = 0;
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |