ChengDa_English/SGGL/FineUIPro.Web/HJGL/WeldingReport/MediaComprehensive.aspx.cs

354 lines
14 KiB
C#
Raw Normal View History

2022-03-15 17:36:38 +08:00
using BLL;
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 MediaComprehensive : 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();
//单位
// var unit = BLL.UnitService.GetUnitByUnitId(this.CurrUser.UnitId);
// if (unit != null && unit.UnitTypeId == BLL.Const.ProjectUnitType_2)
if (this.CurrUser.UnitId != Const.UnitId_CD && this.CurrUser.UnitId != Const.hfnbdId)
{
BLL.UnitService.InitSubUnitNameDownList(this.drpUnit, this.CurrUser.LoginProjectId, this.CurrUser.UnitId, true);
this.drpUnit.SelectedValue = this.CurrUser.UnitId;
this.drpUnit.Enabled = false;
BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.CurrUser.UnitId, true);
}
else
{
//var supervisonUnit = BLL.WorkAreaService.IsSupervisor(this.CurrUser.UnitId, this.CurrUser.LoginProjectId);
//if (supervisonUnit)
//{
// BLL.UnitService.InitSubUnitNameDownList(this.drpUnit, this.CurrUser.LoginProjectId, this.CurrUser.UnitId, true);
//}
//else
{
BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);
}
Funs.FineUIPleaseSelect(this.drpWorkArea);
}
BLL.Base_TestMediumService.InitMediumDropDownList(this.ddlService, true);//介质
2023-08-29 18:56:49 +08:00
BindGrid();
}
2022-03-15 17:36:38 +08:00
}
#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.drpUnit.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnit.SelectedValue))
{
listStr.Add(new SqlParameter("@unitcode", this.drpUnit.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@unitcode", null));
}
if (this.drpWorkArea.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpWorkArea.SelectedValue))
{
listStr.Add(new SqlParameter("@workareacode", this.drpWorkArea.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@workareacode", null));
}
if (this.ddlService.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.ddlService.SelectedValue))
{
listStr.Add(new SqlParameter("@sername", this.ddlService.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@sername", null));
}
if (BLL.WorkAreaService.IsSupervisor(this.CurrUser.UnitId, this.CurrUser.LoginProjectId))
{
listStr.Add(new SqlParameter("@supervisorUnitId", this.CurrUser.UnitId));
}
else
{
listStr.Add(new SqlParameter("@supervisorUnitId", null));
}
SqlParameter[] parameter = listStr.ToArray();
tb = SQLHelper.GetDataTableRunProc("sp_rpt_service", parameter);
this.Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
2023-08-29 18:56:49 +08:00
Grid1.DataBind();
OutputSummaryData();
}
2022-03-15 17:36:38 +08:00
/// <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;
int total_sjot = 0;
int total_fjot = 0;
int finished_jot = 0;
int finished_sjot = 0;
int finished_fjot = 0;
int cut_jot = 0;
decimal? total_din = 0;
decimal? total_sdin = 0;
decimal? total_fdin = 0;
decimal? finished_din = 0;
decimal? finished_sdin = 0;
decimal? finished_fdin = 0;
int total_film = 0;
int pass_film = 0;
int ext_totalfilm = 0;
int ext_passfilm = 0;
int point_totalfilm = 0;
int point_passfilm = 0;
int cut_totalfilm = 0;
int cut_passfilm = 0;
int trust_total_jot = 0;
int trust_ext_total_jot = 0;
int trust_point_total_jot = 0;
int check_point_total_jot = 0;
int repair_jot = 0;
foreach (DataRow row in tb.Rows)
{
total_jot += Funs.GetNewIntOrZero(row["total_jot"].ToString());
total_sjot += Funs.GetNewIntOrZero(row["total_sjot"].ToString());
total_fjot += Funs.GetNewIntOrZero(row["total_fjot"].ToString());
finished_jot += Funs.GetNewIntOrZero(row["finished_jot"].ToString());
finished_sjot += Funs.GetNewIntOrZero(row["finished_sjot"].ToString());
finished_fjot += Funs.GetNewIntOrZero(row["finished_fjot"].ToString());
cut_jot += Funs.GetNewIntOrZero(row["cut_jot"].ToString());
total_din += Funs.GetNewDecimalOrZero(row["total_din"].ToString());
total_sdin += Funs.GetNewDecimalOrZero(row["total_sdin"].ToString());
total_fdin += Funs.GetNewDecimalOrZero(row["total_fdin"].ToString());
finished_din += Funs.GetNewDecimalOrZero(row["finished_din"].ToString());
finished_sdin += Funs.GetNewDecimalOrZero(row["finished_sdin"].ToString());
finished_fdin += Funs.GetNewDecimalOrZero(row["finished_fdin"].ToString());
total_film += Funs.GetNewIntOrZero(row["total_film"].ToString());
pass_film += Funs.GetNewIntOrZero(row["pass_film"].ToString());
ext_totalfilm += Funs.GetNewIntOrZero(row["ext_totalfilm"].ToString());
ext_passfilm += Funs.GetNewIntOrZero(row["ext_passfilm"].ToString());
point_totalfilm += Funs.GetNewIntOrZero(row["point_totalfilm"].ToString());
point_passfilm += Funs.GetNewIntOrZero(row["point_passfilm"].ToString());
cut_totalfilm += Funs.GetNewIntOrZero(row["cut_totalfilm"].ToString());
cut_passfilm += Funs.GetNewIntOrZero(row["cut_passfilm"].ToString());
trust_total_jot += Funs.GetNewIntOrZero(row["trust_total_jot"].ToString());
trust_ext_total_jot += Funs.GetNewIntOrZero(row["trust_ext_total_jot"].ToString());
trust_point_total_jot += Funs.GetNewIntOrZero(row["trust_point_total_jot"].ToString());
check_point_total_jot += Funs.GetNewIntOrZero(row["check_point_total_jot"].ToString());
repair_jot += Funs.GetNewIntOrZero(row["repair_jot"].ToString());
}
JObject summary = new JObject
{
{ "tfNumber", "合计" },
{ "total_jot", total_jot },
{ "total_sjot", total_sjot },
{ "total_fjot", total_fjot },
{ "finished_jot", finished_jot },
{ "finished_sjot", finished_sjot },
{ "finished_fjot", finished_fjot },
{ "cut_jot", cut_jot },
{ "total_din",total_din},
{ "total_sdin",total_sdin},
{ "total_fdin",total_fdin},
{ "finished_din",finished_din},
{ "finished_sdin",finished_sdin},
{ "finished_fdin",finished_fdin},
{ "total_film",total_film},
{ "pass_film",pass_film},
{ "ext_totalfilm",ext_totalfilm},
{ "ext_passfilm",ext_passfilm},
{ "point_totalfilm",point_totalfilm},
{ "point_passfilm",point_passfilm},
{ "cut_totalfilm",cut_totalfilm},
{ "cut_passfilm",cut_passfilm},
{ "trust_total_jot",trust_total_jot},
{ "trust_ext_total_jot",trust_ext_total_jot},
{ "trust_point_total_jot",trust_point_total_jot},
{ "check_point_total_jot",check_point_total_jot},
{ "repair_jot",repair_jot}
};
Grid1.SummaryData = summary;
}
}
#endregion
#region
/// <summary>
/// 统计
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
BindGrid();
2023-08-29 18:56:49 +08:00
2022-03-15 17:36:38 +08:00
}
#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();
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)
{
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)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", html);
}
sb.Append("</tr>");
}
var sumary = grid.SummaryData;
if (sumary != null)
{
foreach (GridColumn column in grid.Columns)
{
try
{
if (sumary.ContainsKey(column.ColumnID))
{
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", sumary.GetValue(column.ColumnID).ToString());
}
else
{
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
catch (Exception e)
{
sb.AppendFormat("<td style=\"vnd.ms-excel.numberformat:@\" >{0}</td>", "");
}
}
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region DropDownList下拉选择事件
/// <summary>
/// 单位下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpWorkArea.Items.Clear();
if (this.drpUnit.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpUnit.SelectedValue))
{
BLL.WorkAreaService.InitWorkAreaProjectUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue, true);
this.drpWorkArea.SelectedIndex = 0;
2023-08-29 18:56:49 +08:00
}
BindGrid();
}
2022-03-15 17:36:38 +08:00
#endregion
}
}