ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/HJGL/WeldingReport/UnitWorkAreaQuality.aspx.cs

348 lines
15 KiB
C#

namespace FineUIPro.Web.HJGL.WeldingReport
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using BLL;
using Newtonsoft.Json.Linq;
using AspNet = System.Web.UI.WebControls;
public partial class UnitWorkAreaQuality : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
List<Model.Base_Unit> units = new List<Model.Base_Unit>();
var pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
if (pUnit == null || pUnit.UnitType == Const.UnitType_5 || pUnit.UnitType == Const.UnitType_2)
{
units = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.CurrUser.LoginProjectId, BLL.Const.UnitType_3);
}
else
{
units = BLL.Base_UnitService.GetUnitListByUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
}
///单位
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = units;
this.drpUnit.DataBind();
Funs.FineUIPleaseSelect(this.drpUnit);
Funs.FineUIPleaseSelect(this.drpInstallation);
Funs.FineUIPleaseSelect(this.drpWorkArea);
////钢材类型
this.drpSteType.DataTextField = "Text";
this.drpSteType.DataValueField = "Value";
this.drpSteType.DataSource = BLL.DropListService.HJGL_GetSteTypeList();
this.drpSteType.DataBind();
Funs.FineUIPleaseSelect(this.drpSteType);
}
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
List<SqlParameter> listStr = new List<SqlParameter>();
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@UnitNo", this.drpUnit.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@UnitNo", null));
}
if (this.drpInstallation.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@installationId", this.drpInstallation.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@installationId", null));
}
if (this.drpWorkArea.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@AreaNo", this.drpWorkArea.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@AreaNo", null));
}
if (this.drpSteType.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@ste_steeltype", this.drpSteType.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@ste_steeltype", 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));
}
listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunProc("HJGL_sp_rpt_baw_zlfx", parameter);
this.Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
this.OutputSummaryData(tb); ///取合计值
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
/// 计算合计
/// </summary>
private void OutputSummaryData(DataTable tb)
{
int total_jotSum = 0;//总焊口数
int total_sjotSum = 0;
int total_fjotSum = 0;
int finished_total_jotSum = 0;
int finished_total_sjotSum = 0;
int finished_total_fjotSum = 0;
int current_total_filmSum = 0;
int current_pass_filmSum = 0;
int current_point_total_filmSum = 0;
int current_point_pass_filmSum = 0;
int current_ext_total_filmSum = 0;
int current_ext_pass_filmSum = 0;
int current_trust_count_totalSum = 0;
int current_check_count_totalSum = 0;
int total_filmSum = 0;
int pass_filmSum = 0;
int point_total_filmSum = 0;
int point_pass_filmSum = 0;
int ext_total_filmSum = 0;
int ext_pass_filmSum = 0;
int trust_count_totalSum = 0;
int point_count_totalSum = 0;
int extend_count_totalSum = 0;
int repair_count_totalSum = 0;
int trust_check_totalSum = 0;
for (int i = 0; i < tb.Rows.Count; i++)
{
total_jotSum += Funs.GetNewIntOrZero(tb.Rows[i]["total_jot"].ToString());
total_sjotSum += Funs.GetNewIntOrZero(tb.Rows[i]["total_sjot"].ToString());
total_fjotSum += Funs.GetNewIntOrZero(tb.Rows[i]["total_fjot"].ToString());
finished_total_jotSum += Funs.GetNewIntOrZero(tb.Rows[i]["finished_total_jot"].ToString());
finished_total_sjotSum += Funs.GetNewIntOrZero(tb.Rows[i]["finished_total_sjot"].ToString());
finished_total_fjotSum += Funs.GetNewIntOrZero(tb.Rows[i]["finished_total_fjot"].ToString());
current_total_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_total_film"].ToString());
current_pass_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_pass_film"].ToString());
current_point_total_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_point_total_film"].ToString());
current_point_pass_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_point_pass_film"].ToString());
current_ext_total_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_ext_total_film"].ToString());
current_ext_pass_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_ext_pass_film"].ToString());
current_trust_count_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_trust_count_total"].ToString());
current_check_count_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["current_check_count_total"].ToString());
total_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["total_film"].ToString());
pass_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["pass_film"].ToString());
point_total_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["point_total_film"].ToString());
point_pass_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["point_pass_film"].ToString());
ext_total_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["ext_total_film"].ToString());
ext_pass_filmSum += Funs.GetNewIntOrZero(tb.Rows[i]["ext_pass_film"].ToString());
trust_count_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["trust_count_total"].ToString());
point_count_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["point_count_total"].ToString());
extend_count_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["extend_count_total"].ToString());
repair_count_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["repair_count_total"].ToString());
trust_check_totalSum += Funs.GetNewIntOrZero(tb.Rows[i]["trust_check_total"].ToString());
}
JObject summary = new JObject();
summary.Add("bsu_unitname", "合计:");
summary.Add("total_jot", total_jotSum);
summary.Add("total_sjot", total_sjotSum);
summary.Add("total_fjot", total_fjotSum);
summary.Add("finished_total_jot", finished_total_jotSum);
summary.Add("finished_total_sjot", finished_total_sjotSum);
summary.Add("finished_total_fjot", finished_total_fjotSum);
summary.Add("current_total_film", current_total_filmSum);
summary.Add("current_pass_film", current_pass_filmSum);
summary.Add("current_point_total_film", current_point_total_filmSum);
summary.Add("current_ext_total_film", current_ext_total_filmSum);
summary.Add("current_ext_pass_film", current_ext_pass_filmSum);
summary.Add("current_trust_count_total", current_trust_count_totalSum);
summary.Add("current_check_count_total", current_check_count_totalSum);
summary.Add("total_film", total_filmSum);
summary.Add("pass_film", pass_filmSum);
summary.Add("point_total_film", point_total_filmSum);
summary.Add("point_pass_film", point_pass_filmSum);
summary.Add("ext_total_film", ext_total_filmSum);
summary.Add("ext_pass_film", ext_pass_filmSum);
summary.Add("trust_count_total", trust_count_totalSum);
summary.Add("point_count_total", point_count_totalSum);
summary.Add("extend_count_total", extend_count_totalSum);
summary.Add("repair_count_total", repair_count_totalSum);
summary.Add("trust_check_total", trust_check_totalSum);
Grid1.SummaryData = summary;
}
#endregion
#region
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
this.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>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnAnalyse_Click(object sender, EventArgs e)
{
BindGrid();
}
#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();
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>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region
/// <summary>
/// 单位下拉框变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpUnit_OnSelectedIndexChanged(object sender, EventArgs e)
{
this.drpInstallation.Items.Clear();
this.drpWorkArea.Items.Clear(); ///区域
///装置
this.drpInstallation.DataTextField = "Text";
this.drpInstallation.DataValueField = "Value";
this.drpInstallation.DataSource = BLL.Project_InstallationService.GetInstallationList(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
this.drpInstallation.DataBind();
Funs.FineUIPleaseSelect(this.drpInstallation);
this.drpInstallation.SelectedValue = BLL.Const._Null;
Funs.FineUIPleaseSelect(this.drpWorkArea);
this.drpWorkArea.SelectedValue = BLL.Const._Null;
}
/// <summary>
/// 单位、装置下拉框变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpInstallation_OnSelectedIndexChanged(object sender, EventArgs e)
{
this.drpWorkArea.Items.Clear(); ///区域
this.drpWorkArea.DataTextField = "WorkAreaCode";
this.drpWorkArea.DataValueField = "WorkAreaId";
this.drpWorkArea.DataSource = BLL.Project_WorkAreaService.GetWorkAreaListByInstallationIdUnitId(this.drpInstallation.SelectedValue, this.drpUnit.SelectedValue);
this.drpWorkArea.DataBind();
Funs.FineUIPleaseSelect(this.drpWorkArea);
this.drpWorkArea.SelectedValue = BLL.Const._Null;
}
#endregion
}
}