Basf_TCC7/HJGL/FineUIPro.Web/WeldingProcess/PMI/PMIDelegationReport.aspx.cs

210 lines
8.3 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNet = System.Web.UI.WebControls;
using System.Drawing;
namespace FineUIPro.Web.WeldingProcess.PMI
{
public partial class PMIDelegationReport : 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();
BLL.Base_UnitService.InitProjectUnitDropDownList(this.drpUnitId, true, this.CurrUser.LoginProjectId, BLL.Const.UnitType_5, Resources.Lan.PleaseSelect);//单位
BLL.Project_WorkAreaService.InitWorkAreaDropDownList(this.drpWorkAreaId, true, this.CurrUser.LoginProjectId, string.Empty, this.drpUnitId.SelectedValue, string.Empty, Resources.Lan.PleaseSelect);//区域
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string sql = @"select *from (
select
projectId,
InstallationId,
WorkAreaId,
UnitId,
PipelineId,
InstallationCode,
WorkAreaCode,
PipelineCode,
PMINum,
(convert(float,PMIBySNum)/NULLIF(convert(float,PMINum),0)*100) as RateBys,
PMIBySNum,
(convert(float,PMIByFNum)/NULLIF(convert(float,PMINum),0)*100) as RateByf,
PMIByFNum
from (
select
a.projectId,
a.InstallationId,
a.WorkAreaId,
a.UnitId,
a.PipelineId,
b.InstallationCode,
c.WorkAreaCode,
a.PipelineCode,
(select count(1) from Pipeline_WeldJoint as d where isPMI=1 and d.PipelineId=a.PipelineId) as PMINum,
(
select count(1) from PMI_Delegation as pd inner join PMI_DelegationDetails as pdd on pd.Id=pdd.PMIId
inner join Pipeline_WeldJoint as pwj on pdd.JointId=pwj.WeldJointId
where pd.InstallationId=a.InstallationId and pd.UnitId=a.UnitId and pdd.WorkAreaId=a.WorkAreaId
and pwj.PipelineId=a.PipelineId and pwj.JointAttribute='活动S' and pwj.isPMI=1
) as PMIBySNum,
(
select count(1) from PMI_Delegation as pd inner join PMI_DelegationDetails as pdd on pd.Id=pdd.PMIId
inner join Pipeline_WeldJoint as pwj on pdd.JointId=pwj.WeldJointId
where pd.InstallationId=a.InstallationId and pd.UnitId=a.UnitId and pdd.WorkAreaId=a.WorkAreaId
and pwj.PipelineId=a.PipelineId and pwj.JointAttribute='固定F' and pwj.isPMI=1
) as PMIByFNum
from Pipeline_Pipeline as a
left join Project_Installation as b on a.InstallationId=b.InstallationId
left join Project_WorkArea as c on a.WorkAreaId=c.WorkAreaId
) as t
) as H where projectId=@projectId and RateBys>0 ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
sql += " and UnitId=@unitId";
listStr.Add(new SqlParameter("@unitId", this.drpUnitId.SelectedValue));
}
if (this.drpWorkAreaId.SelectedValue != BLL.Const._Null)
{
sql += " and WorkAreaId=@workAreaId";
listStr.Add(new SqlParameter("@workAreaId", this.drpWorkAreaId.SelectedValue));
}
if (this.drpIsALl.SelectedValue!="全部")
{
sql += " and RateBys<=2";
}
if (!string.IsNullOrEmpty(this.txtPipelineCode.Text))
{
sql += " and PipelineCode like '%'+@PipelineCode+'%'";
listStr.Add(new SqlParameter("@PipelineCode", this.txtPipelineCode.Text.Trim()));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(sql, parameter);
this.Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
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();
}
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
DataRowView row = e.DataItem as DataRowView;
decimal rates =Math.Round(Convert.ToDecimal(row["RateBys"]),2);
decimal ratef = Math.Round(Convert.ToDecimal(row["RateByf"]), 2);
AspNet.Label itemLable = e.Row.FindControl("labRateBys") as AspNet.Label;
if (itemLable !=null && !string.IsNullOrEmpty(itemLable.Text))
{
itemLable.Text = rates.ToString() + "%";
if (rates <= 2)
{
itemLable.ForeColor = Color.Red;
}
}
AspNet.Label labRateByf = e.Row.FindControl("labRateByf") as AspNet.Label;
if(labRateByf!=null && !string.IsNullOrEmpty(labRateByf.Text))
{
labRateByf.Text= ratef.ToString() + "%";
if (ratef <= 2)
{
labRateByf.ForeColor = Color.Red;
}
}
}
/// <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>
/// 单位下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpUnitId_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpWorkAreaId.Items.Clear();
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
BLL.Project_WorkAreaService.InitWorkAreaDropDownList(this.drpWorkAreaId, true, this.CurrUser.LoginProjectId, string.Empty, this.drpUnitId.SelectedValue, string.Empty, Resources.Lan.PleaseSelect);
}
else
{
Funs.FineUIPleaseSelect(this.drpWorkAreaId, Resources.Lan.PleaseSelect);
}
this.drpWorkAreaId.SelectedValue = BLL.Const._Null;
}
protected void drpIsALl_SelectedIndexChanged(object obj, EventArgs e)
{
this.BindGrid();
}
#endregion
}
}