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

456 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Data;
using BLL;
using System.Text;
using Newtonsoft.Json.Linq;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HJGL.WeldingReport
{
public partial class UnitWorkareaAnalyze : 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();
List<Model.Base_Unit> units = new List<Model.Base_Unit>();
var pUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
if (pUnit == null || pUnit.UnitType == Const.ProjectUnitType_1)
{
units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2);
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = units;
this.drpUnit.DataBind();
this.drpUnit.SelectedValue = CurrUser.UnitId;
Funs.FineUIPleaseSelect(this.drpUnit);
Funs.FineUIPleaseSelect(this.drpInstallation);
}
else
{
units = BLL.UnitService.GetSubUnitsListBySupervisorUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
this.drpUnit.Enabled = false;
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = units;
this.drpUnit.DataBind();
this.drpUnit.SelectedValue = CurrUser.UnitId;
Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, this.CurrUser.LoginProjectId, true);
this.drpInstallation.SelectedValue = BLL.Const._Null;
}
///单位
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);
//显示列
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, Const.UnitAreaAnalyzeMenuId);
if (c != null)
{
this.GetShowColumn(c.Columns);
}
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)
{
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 (!string.IsNullOrEmpty(this.txtStarTime.Text))
{
listStr.Add(new SqlParameter("@startTime", this.txtStarTime.Text.Trim()));
}
else
{
listStr.Add(new SqlParameter("@startTime", null));
}
if (!string.IsNullOrEmpty(this.txtEndTime.Text))
{
listStr.Add(new SqlParameter("@endTime", this.txtEndTime.Text.Trim()));
}
else
{
listStr.Add(new SqlParameter("@endTime", 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));
}
if (this.drpSteType.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpSteType.SelectedValue))
{
listStr.Add(new SqlParameter("@ste_steeltype", this.drpSteType.SelectedValue));
}
else
{
listStr.Add(new SqlParameter("@ste_steeltype", null));
}
if (this.cb_IsStandard.SelectedIndexArray != null && this.cb_IsStandard.SelectedIndexArray.Length==1)
{
listStr.Add(new SqlParameter("@IsStandard", this.cb_IsStandard.SelectedValueArray[0]));
}
else
{
listStr.Add(new SqlParameter("@IsStandard", null));
}
SqlParameter[] parameter = listStr.ToArray();
tb = SQLHelper.GetDataTableRunProc("sp_rpt_UnitWorkareaAnalyze", parameter);
this.Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
OutputSummaryData();
}
/// <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
/// <summary>
/// 全部行合计
/// </summary>
private void OutputSummaryData()
{
if (tb != null)
{
int total_jot = 0;
int total_sjot = 0;
int total_fjot = 0;
int cut_total_jot = 0;
double total_din = 0.0f;
double total_Sdin = 0.0f;
double total_Fdin = 0.0f;
int finished_total_jot_bq = 0;
int finished_total_sjot_bq = 0;
int finished_total_fjot_bq = 0;
double finished_total_din_bq = 0.0f;
double finished_total_Sdin_bq = 0.0f;
double finished_total_Fdin_bq = 0.0f;
int finished_total_jot = 0;
int finished_total_sjot = 0;
int finished_total_fjot = 0;
double finished_total_din = 0.0f;
double finished_total_sdin = 0.0f;
double finished_total_Fdin = 0.0f;
//string filmPassRate = "";
//string jointPassRate = "";
foreach (DataRow row in tb.Rows)
{
total_jot += Convert.ToInt32(row["total_jot"]);
total_sjot += Convert.ToInt32(row["total_sjot"]);
total_fjot += Convert.ToInt32(row["total_fjot"]);
cut_total_jot += Convert.ToInt32(row["cut_total_jot"]);
total_din += Convert.ToDouble(row["total_din"]);
total_Sdin += Convert.ToDouble(row["total_Sdin"]);
total_Fdin += Convert.ToDouble(row["total_Fdin"]);
finished_total_jot_bq += Convert.ToInt32(row["finished_total_jot_bq"]);
finished_total_sjot_bq += Convert.ToInt32(row["finished_total_sjot_bq"]);
finished_total_fjot_bq += Convert.ToInt32(row["finished_total_fjot_bq"]);
finished_total_din_bq += Convert.ToDouble(row["finished_total_din_bq"]);
finished_total_Sdin_bq += Convert.ToDouble(row["finished_total_Sdin_bq"]);
finished_total_Fdin_bq += Convert.ToDouble(row["finished_total_Fdin_bq"]);
finished_total_jot += Convert.ToInt32(row["finished_total_jot"]);
finished_total_sjot += Convert.ToInt32(row["finished_total_sjot"]);
finished_total_fjot += Convert.ToInt32(row["finished_total_fjot"]);
finished_total_din += Convert.ToDouble(row["finished_total_din"]);
finished_total_sdin += Convert.ToDouble(row["finished_total_sdin"]);
finished_total_Fdin += Convert.ToDouble(row["finished_total_Fdin"]);
}
//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
{
{ "tfNumber", "合计" },
{ "total_jot", total_jot.ToString() },
{ "total_sjot", total_sjot.ToString() },
{ "total_fjot", total_fjot.ToString() },
{ "cut_total_jot", cut_total_jot.ToString() },
{ "total_din", total_din.ToString("F2") },
{ "total_Sdin", total_Sdin.ToString("F2") },
{ "total_Fdin", total_Fdin.ToString("F2") },
{ "finished_total_jot_bq", finished_total_jot_bq.ToString() },
{ "finished_total_sjot_bq", finished_total_sjot_bq.ToString() },
{ "finished_total_fjot_bq", finished_total_fjot_bq.ToString() },
{ "finished_total_din_bq", finished_total_din_bq.ToString("F2") },
{ "finished_total_Sdin_bq", finished_total_Sdin_bq.ToString("F2") },
{ "finished_total_Fdin_bq", finished_total_Fdin_bq.ToString("F2") },
{ "finished_total_jot", finished_total_jot.ToString() },
{ "finished_total_sjot", finished_total_sjot.ToString() },
{ "finished_total_fjot", finished_total_fjot.ToString() },
{ "finished_total_din", finished_total_din.ToString("F2") },
{ "finished_total_sdin", finished_total_sdin.ToString("F2") },
{ "finished_total_Fdin", finished_total_Fdin.ToString("F2") }
};
Grid1.SummaryData = summary;
}
}
#region
/// <summary>
/// 选择显示列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelectColumn_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ShowColumn.aspx?menuId={0}", BLL.Const.UnitAreaAnalyzeMenuId, "显示列 - ")));
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
// 显示列
Model.Sys_UserShowColumns c = BLL.UserShowColumnsService.GetColumnsByUserId(this.CurrUser.UserId, BLL.Const.UnitAreaAnalyzeMenuId);
if (c != null)
{
this.GetShowColumn(c.Columns);
}
}
/// <summary>
/// 显示的列
/// </summary>
/// <param name="column"></param>
private void GetShowColumn(string column)
{
if (!string.IsNullOrEmpty(column))
{
for (int i = 0; i < Grid1.Columns.Count; i++)
{
this.Grid1.Columns[i].Hidden = true;
}
List<string> columns = column.Split(',').ToList();
foreach (var item in columns)
{
this.Grid1.Columns[Convert.ToInt32(item)].Hidden = false;
}
}
}
#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();
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
/// <summary>
/// 单位下拉选择事件
/// </summary>
/// <param name = "sender" ></ param >
/// < param name="e"></param>
protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpInstallation.Items.Clear(); ///装置
this.drpWorkArea.Items.Clear(); ///区域
Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, this.CurrUser.LoginProjectId, true);
this.drpInstallation.SelectedValue = BLL.Const._Null;
Funs.FineUIPleaseSelect(this.drpWorkArea);
this.drpWorkArea.SelectedValue = BLL.Const._Null;
BindGrid();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpInstallation_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpWorkArea.Items.Clear();
WorkAreaService.InitWorkAreaProjectInstallUnitDropDownList(this.drpWorkArea, this.CurrUser.LoginProjectId, this.drpInstallation.SelectedValue, this.drpUnit.SelectedValue, true);
this.drpWorkArea.SelectedValue = BLL.Const._Null;
BindGrid();
}
#endregion
}
}