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

368 lines
14 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 WelderPerformance : 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();
var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.drpProject.SelectedValue, BLL.Const.UnitType_4);
///单位
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = pUnit;
this.drpUnit.DataBind();
Funs.FineUIPleaseSelect(this.drpUnit);
///项目
this.drpProject.DataTextField = "ProjectCode";
this.drpProject.DataValueField = "ProjectId";
this.drpProject.DataSource = BLL.Base_ProjectService.GetProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProject.DataBind();
Funs.FineUIPleaseSelect(this.drpProject);
Funs.FineUIPleaseSelect(this.drpWloName);
////材质
this.drpSteel.DataTextField = "STE_Code";
this.drpSteel.DataValueField = "STE_ID";
this.drpSteel.DataSource = BLL.HJGL_MaterialService.GetSteelList();
this.drpSteel.DataBind();
Funs.FineUIPleaseSelect(this.drpSteel);
}
}
#endregion
/// <summary>
/// 全部行合计
/// </summary>
private void OutputSummaryData()
{
if (tb != null)
{
double totalSize = 0.0f;
int totalJoint = 0;
int JointNum1 = 0;
int totalfilm = 0;
int JointPassNum1 = 0;
int totalPassfilm = 0;
int RepairJoint1 = 0;
int repairFilm1 = 0;
int RepairJoint2 = 0;
int repairFilm2 = 0;
int RepairJoint3 = 0;
int repairFilm3 = 0;
string filmPassRate = "";
string jointPassRate = "";
foreach (DataRow row in tb.Rows)
{
totalSize += Convert.ToDouble(row["totalSize"]);
totalJoint += Convert.ToInt32(row["totalJoint"]);
JointNum1 += Convert.ToInt32(row["JointNum1"]);
totalfilm += Convert.ToInt32(row["totalfilm"]);
JointPassNum1 += Convert.ToInt32(row["JointPassNum1"]);
totalPassfilm += Convert.ToInt32(row["totalPassfilm"]);
RepairJoint1 += Convert.ToInt32(row["RepairJoint1"]);
repairFilm1 += Convert.ToInt32(row["repairFilm1"]);
RepairJoint2 += Convert.ToInt32(row["RepairJoint2"]);
repairFilm2 += Convert.ToInt32(row["repairFilm2"]);
RepairJoint3 += Convert.ToInt32(row["RepairJoint3"]);
repairFilm3 += Convert.ToInt32(row["repairFilm3"]);
}
if (totalfilm != 0)
{
filmPassRate = (totalPassfilm * 100.0 / totalfilm * 1.0).ToString("0.00") + "%";
}
if (JointNum1 != 0)
{
jointPassRate = (JointPassNum1 * 100.0 / JointNum1 * 1.0).ToString("0.00") + "%";
}
JObject summary = new JObject();
summary.Add("tfNumber", "合计");
summary.Add("totalJoint", totalJoint.ToString());
summary.Add("totalSize", totalSize.ToString("F2"));
summary.Add("JointNum1", JointNum1.ToString());
summary.Add("totalfilm", totalfilm.ToString());
summary.Add("JointPassNum1", JointPassNum1.ToString());
summary.Add("totalPassfilm", totalPassfilm.ToString());
summary.Add("RepairJoint1", RepairJoint1.ToString());
summary.Add("repairFilm1", repairFilm1.ToString());
summary.Add("RepairJoint2", RepairJoint2.ToString());
summary.Add("repairFilm2", repairFilm2.ToString());
summary.Add("RepairJoint3", RepairJoint3.ToString());
summary.Add("repairFilm3", repairFilm3.ToString());
summary.Add("JointPassRate", jointPassRate.ToString());
summary.Add("JointFilmPassRate", filmPassRate.ToString());
Grid1.SummaryData = summary;
}
}
/// <summary>
/// 数据表
/// </summary>
private DataTable tb = null;
#region
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string projectIds = String.Join(",", drpProject.SelectedValueArray);
List<SqlParameter> listStr = new List<SqlParameter>();
if (this.drpIns.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@installationId", this.drpIns.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@installationId", null));
}
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@unitcode", this.drpUnit.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@unitcode", null));
}
if (this.drpSteel.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@steel", this.drpSteel.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@steel", null));
}
if (this.drpWloName.SelectedValue != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@WED_ID", this.drpWloName.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@WED_ID", null));
}
if (!string.IsNullOrEmpty(this.txtStarTime.Text))
{
listStr.Add(new SqlParameter("@date1", Convert.ToDateTime(this.txtStarTime.Text)));
}
else
{
listStr.Add(new SqlParameter("@date1", null));
}
if (!string.IsNullOrEmpty(this.txtEndTime.Text))
{
listStr.Add(new SqlParameter("@date2", Convert.ToDateTime(this.txtEndTime.Text)));
}
else
{
listStr.Add(new SqlParameter("@date2", null));
}
if (this.drpProject.SelectedValueArray.Length > 0 && this.drpProject.SelectedValueArray[0] != BLL.Const._Null)
{
listStr.Add(new SqlParameter("@projectId", projectIds));
}
else
{
listStr.Add(new SqlParameter("@projectId", null));
}
SqlParameter[] parameter = listStr.ToArray();
tb = SQLHelper.GetDataTableRunProc("HJGL_sp_rpt_welderPerformance", parameter);
this.Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#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();
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();
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 drpProject_OnSelectedIndexChanged(object sender, EventArgs e)
{
drpIns.Items.Clear();
this.drpUnit.Items.Clear(); ///单位
this.drpWloName.Items.Clear(); ///焊工
if (drpProject.SelectedValueArray.Length > 1)
{
drpProject.Items[0].Selected = false;
}
if (drpProject.SelectedValueArray.Length == 0)
{
drpProject.Items[0].Selected = true;
}
if (drpProject.SelectedValueArray.Length==1 && this.drpProject.SelectedValueArray[0] != BLL.Const._Null)
{
var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(drpProject.SelectedValueArray[0], BLL.Const.UnitType_4);
this.drpUnit.DataSource = pUnit;
this.drpUnit.DataBind();
this.drpIns.Items.Clear();
this.drpIns.DataTextField = "Text";
this.drpIns.DataValueField = "Value";
this.drpIns.DataSource = BLL.Project_InstallationService.GetInstallationList(drpProject.SelectedValueArray[0]);
this.drpIns.DataBind();
}
Funs.FineUIPleaseSelect(this.drpIns);
this.drpIns.SelectedValue = BLL.Const._Null;
Funs.FineUIPleaseSelect(this.drpUnit);
this.drpUnit.SelectedValue = BLL.Const._Null;
Funs.FineUIPleaseSelect(this.drpWloName);
this.drpWloName.SelectedValue = BLL.Const._Null;
}
/// <summary>
/// 单位下拉框变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpUnit_OnSelectedIndexChanged(object sender, EventArgs e)
{
this.drpWloName.Items.Clear(); ///焊工
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
this.drpWloName.DataTextField = "Text";
this.drpWloName.DataValueField = "Value";
this.drpWloName.DataSource = BLL.HJGL_PersonManageService.GetProjectWelderCodeListByUnitId(this.drpProject.SelectedValue, this.drpUnit.SelectedValue);
this.drpWloName.DataBind();
}
Funs.FineUIPleaseSelect(this.drpWloName);
this.drpWloName.SelectedValue = BLL.Const._Null;
}
#endregion
}
}