2025-03-26 09:53:22 +08:00
using BLL ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
namespace FineUIPro.Web.DataShow
{
public partial class JD : PageBase
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
Funs . DropDownPageSize ( this . ddlPageSize ) ;
2025-03-27 15:22:48 +08:00
Funs . DropDownPageSize ( this . ddlPageSize2 ) ;
2025-03-27 17:14:51 +08:00
Funs . DropDownPageSize ( this . ddlPageSize3 ) ;
2025-03-26 09:53:22 +08:00
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
2025-03-27 15:22:48 +08:00
ddlPageSize2 . SelectedValue = Grid2 . PageSize . ToString ( ) ;
2025-03-27 17:14:51 +08:00
ddlPageSize3 . SelectedValue = Grid3 . PageSize . ToString ( ) ;
2025-03-26 09:53:22 +08:00
BLL . ProjectService . InitProjectDropDownList ( this . drpProject , true ) ;
2025-03-27 15:22:48 +08:00
BLL . ProjectService . InitProjectDropDownList ( this . drpProject2 , true ) ;
2025-04-01 11:14:25 +08:00
BLL . UserService . InitSGBUser ( this . drpDutyPerson2 , true ) ;
2025-03-27 17:14:51 +08:00
BLL . ProjectService . InitProjectDropDownList ( this . drpProject3 , true ) ;
2025-04-01 11:14:25 +08:00
BLL . UserService . InitSGBUser ( this . drpDutyPerson3 , true ) ;
2025-03-26 09:53:22 +08:00
BindGrid1 ( ) ;
}
}
private void BindGrid1 ( )
{
2025-03-27 15:22:48 +08:00
string strSql = @ "select p.ProjectId,ProjectCode, ProjectName,(select sum(isnull(RealNum,0)) from JDGL_ProgressCompletion a where a.ProjectId=p.ProjectId) as RealNum,
cast ( ( case when isnull ( MonthPlan . MonthPlanNum , 0 ) = 0 then 0 else isnull ( MonthPlanOK . MonthPlanOKNum , 0 ) / ( 1.0 * isnull ( MonthPlan . MonthPlanNum , 0 ) ) * 100 end ) as DECIMAL ( 19 , 2 ) ) as MonthPlanRate ,
cast ( ( case when isnull ( WeekPlan . WeekPlanNum , 0 ) = 0 then 0 else isnull ( WeekPlanOK . WeekPlanOKNum , 0 ) / ( 1.0 * isnull ( WeekPlan . WeekPlanNum , 0 ) ) * 100 end ) as DECIMAL ( 19 , 2 ) ) as WeekPlanRate
from Base_Project p
left join (
SELECT COUNT ( w . WeekPlanId ) AS WeekPlanNum , w . ProjectId FROM JDGL_WeekPlan w
GROUP BY w . ProjectId
) AS WeekPlan ON WeekPlan . ProjectId = p . ProjectId
left join (
SELECT COUNT ( w . WeekPlanId ) AS WeekPlanOKNum , w . ProjectId FROM JDGL_WeekPlan w
where w . IsOK = 1
GROUP BY w . ProjectId
) AS WeekPlanOK ON WeekPlanOK . ProjectId = p . ProjectId
left join (
SELECT COUNT ( w . MonthPlanId ) AS MonthPlanNum , w . ProjectId FROM JDGL_MonthPlan w
GROUP BY w . ProjectId
) AS MonthPlan ON MonthPlan . ProjectId = p . ProjectId
left join (
SELECT COUNT ( w . MonthPlanId ) AS MonthPlanOKNum , w . ProjectId FROM JDGL_MonthPlan w
where w . RealDate is not null and w . RealDate < = w . PlanDate
GROUP BY w . ProjectId
) AS MonthPlanOK ON MonthPlanOK . ProjectId = p . ProjectId
where ProjectState = 1 ";
2025-03-26 09:53:22 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
string cpara = string . Empty ;
if ( this . drpProject . SelectedValue ! = Const . _Null )
{
2025-03-27 17:14:51 +08:00
strSql + = " AND p.ProjectId = @projectId" ;
2025-03-26 09:53:22 +08:00
listStr . Add ( new SqlParameter ( "@projectId" , this . drpProject . SelectedValue ) ) ;
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
}
2025-03-27 15:22:48 +08:00
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid2 ( )
{
2025-03-27 17:14:51 +08:00
DataTable tb = new DataTable ( ) ;
tb . Columns . Add ( new DataColumn ( "ProjectId" , typeof ( String ) ) ) ;
tb . Columns . Add ( new DataColumn ( "ProjectCode" , typeof ( String ) ) ) ;
tb . Columns . Add ( new DataColumn ( "ProjectName" , typeof ( String ) ) ) ;
tb . Columns . Add ( new DataColumn ( "PlanNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "CompletedNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "Rate" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "TotalPlanNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "TotalCompletedNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "TotalRate" , typeof ( decimal ) ) ) ;
Model . SGGLDB db = Funs . DB ;
var projects = from x in db . Base_Project where x . ProjectState = = "1" orderby x . ProjectName select x ;
if ( this . drpProject2 . SelectedValue ! = BLL . Const . _Null )
{
projects = projects . Where ( x = > x . ProjectId = = this . drpProject2 . SelectedValue ) . OrderBy ( x = > x . ProjectName ) ;
}
//统计月份信息
DateTime months = Convert . ToDateTime ( DateTime . Now . Year . ToString ( ) + "-" + DateTime . Now . Month . ToString ( ) + "-01" ) ;
if ( DateTime . Now . Day < 26 )
{
months = Convert . ToDateTime ( DateTime . Now . Year . ToString ( ) + "-" + DateTime . Now . AddMonths ( - 1 ) . Month . ToString ( ) + "-01" ) ;
}
//2、获取当前项目指定月所有计划
var allMonthPlans = from x in db . JDGL_MonthPlan
where x . Months = = months
select x ;
//3、获取当前项目所有月计划
var allPlans = from x in db . JDGL_MonthPlan
where x . Months < = months
select x ;
foreach ( var item in projects )
{
double planNum = allMonthPlans . Where ( x = > x . ProjectId = = item . ProjectId ) . Count ( ) ;
double completedNum = allMonthPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . RealDate ! = null ) . Count ( ) ;
2025-04-01 11:14:25 +08:00
if ( this . drpDutyPerson2 . SelectedValue ! = BLL . Const . _Null )
{
planNum = allMonthPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson2 . SelectedValue ) ) . Count ( ) ;
completedNum = allMonthPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson2 . SelectedValue ) & & x . RealDate ! = null ) . Count ( ) ;
}
2025-03-27 17:14:51 +08:00
double rate = planNum > 0 ? Math . Round ( ( completedNum / planNum ) * 100 , 2 ) : 0 ;
double totalPlanNum = allPlans . Where ( x = > x . ProjectId = = item . ProjectId ) . Count ( ) ;
double totalCompletedNum = allPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . RealDate ! = null ) . Count ( ) ;
2025-04-01 11:14:25 +08:00
if ( this . drpDutyPerson2 . SelectedValue ! = BLL . Const . _Null )
{
totalPlanNum = allPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson2 . SelectedValue ) ) . Count ( ) ;
totalCompletedNum = allPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson2 . SelectedValue ) & & x . RealDate ! = null ) . Count ( ) ;
}
2025-03-27 17:14:51 +08:00
double totalRate = totalPlanNum > 0 ? Math . Round ( ( totalCompletedNum / totalPlanNum ) * 100 , 2 ) : 0 ;
DataRow row ;
row = tb . NewRow ( ) ;
row [ 0 ] = item . ProjectId ;
row [ 1 ] = item . ProjectCode ;
row [ 2 ] = item . ProjectName ;
row [ 3 ] = planNum ;
row [ 4 ] = completedNum ;
row [ 5 ] = rate ;
row [ 6 ] = totalPlanNum ;
row [ 7 ] = totalCompletedNum ;
row [ 8 ] = totalRate ;
tb . Rows . Add ( row ) ;
}
Grid2 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid2 , tb ) ;
Grid2 . DataSource = table ;
Grid2 . DataBind ( ) ;
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid3 ( )
{
DataTable tb = new DataTable ( ) ;
tb . Columns . Add ( new DataColumn ( "ProjectId" , typeof ( String ) ) ) ;
tb . Columns . Add ( new DataColumn ( "ProjectCode" , typeof ( String ) ) ) ;
tb . Columns . Add ( new DataColumn ( "ProjectName" , typeof ( String ) ) ) ;
tb . Columns . Add ( new DataColumn ( "PlanNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "CompletedNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "Rate" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "TotalPlanNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "TotalCompletedNum" , typeof ( decimal ) ) ) ;
tb . Columns . Add ( new DataColumn ( "TotalRate" , typeof ( decimal ) ) ) ;
Model . SGGLDB db = Funs . DB ;
var projects = from x in db . Base_Project where x . ProjectState = = "1" orderby x . ProjectName select x ;
if ( this . drpProject3 . SelectedValue ! = BLL . Const . _Null )
{
projects = projects . Where ( x = > x . ProjectId = = this . drpProject3 . SelectedValue ) . OrderBy ( x = > x . ProjectName ) ;
}
//统计月份信息
DateTime months = Convert . ToDateTime ( DateTime . Now . Year . ToString ( ) + "-" + DateTime . Now . Month . ToString ( ) + "-01" ) ;
if ( DateTime . Now . Day < 26 )
{
months = Convert . ToDateTime ( DateTime . Now . Year . ToString ( ) + "-" + DateTime . Now . AddMonths ( - 1 ) . Month . ToString ( ) + "-01" ) ;
}
//2、获取当前项目指定月所有计划
var allWeekPlans = from x in db . JDGL_WeekPlan
select x ;
foreach ( var item in projects )
{
var lastWeek = ( from x in db . JDGL_WeekPlan where x . ProjectId = = item . ProjectId & & DateTime . Now > ( ( DateTime ) x . EndDate ) . AddDays ( 1 ) orderby x . EndDate select x ) . FirstOrDefault ( ) ;
double planNum = 0 , completedNum = 0 , rate = 0 ;
if ( lastWeek ! = null )
{
planNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . WeekNo = = lastWeek . WeekNo ) . Count ( ) ;
completedNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . WeekNo = = lastWeek . WeekNo & & x . IsOK = = true ) . Count ( ) ;
2025-04-01 11:14:25 +08:00
if ( this . drpDutyPerson3 . SelectedValue ! = BLL . Const . _Null )
{
planNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson3 . SelectedValue ) & & x . WeekNo = = lastWeek . WeekNo ) . Count ( ) ;
completedNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson3 . SelectedValue ) & & x . WeekNo = = lastWeek . WeekNo & & x . IsOK = = true ) . Count ( ) ;
}
2025-03-27 17:14:51 +08:00
rate = planNum > 0 ? Math . Round ( ( completedNum / planNum ) * 100 , 2 ) : 0 ;
}
double totalPlanNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId ) . Count ( ) ;
double totalCompletedNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . IsOK = = true ) . Count ( ) ;
2025-04-01 11:14:25 +08:00
if ( this . drpDutyPerson3 . SelectedValue ! = BLL . Const . _Null )
{
totalPlanNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson3 . SelectedValue ) ) . Count ( ) ;
totalCompletedNum = allWeekPlans . Where ( x = > x . ProjectId = = item . ProjectId & & x . DutyPerson . Contains ( this . drpDutyPerson3 . SelectedValue ) & & x . IsOK = = true ) . Count ( ) ;
}
2025-03-27 17:14:51 +08:00
double totalRate = totalPlanNum > 0 ? Math . Round ( ( totalCompletedNum / totalPlanNum ) * 100 , 2 ) : 0 ;
DataRow row ;
row = tb . NewRow ( ) ;
row [ 0 ] = item . ProjectId ;
row [ 1 ] = item . ProjectCode ;
row [ 2 ] = item . ProjectName ;
row [ 3 ] = planNum ;
row [ 4 ] = completedNum ;
row [ 5 ] = rate ;
row [ 6 ] = totalPlanNum ;
row [ 7 ] = totalCompletedNum ;
row [ 8 ] = totalRate ;
tb . Rows . Add ( row ) ;
}
Grid3 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid3 , tb ) ;
Grid3 . DataSource = table ;
Grid3 . DataBind ( ) ;
2025-03-27 15:22:48 +08:00
}
2025-03-26 09:53:22 +08:00
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged ( object sender , EventArgs e )
{
this . BindGrid1 ( ) ;
}
#endregion
#region 表 排 序 、 分 页 、 关 闭 窗 口
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid1 ( ) ;
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
BindGrid1 ( ) ;
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid1 . PageSize = Convert . ToInt32 ( ddlPageSize . SelectedValue ) ;
BindGrid1 ( ) ;
}
2025-03-27 17:14:51 +08:00
#endregion
2025-03-27 15:22:48 +08:00
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox2_TextChanged ( object sender , EventArgs e )
{
this . BindGrid2 ( ) ;
}
#region 表 排 序 、 分 页 、 关 闭 窗 口
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid2_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid2 ( ) ;
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid2_Sort ( object sender , GridSortEventArgs e )
{
BindGrid2 ( ) ;
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize2_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid2 . PageSize = Convert . ToInt32 ( ddlPageSize2 . SelectedValue ) ;
BindGrid2 ( ) ;
}
#endregion
2025-03-27 17:14:51 +08:00
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox3_TextChanged ( object sender , EventArgs e )
{
this . BindGrid3 ( ) ;
}
#region 表 排 序 、 分 页 、 关 闭 窗 口
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid3_PageIndexChange ( object sender , GridPageEventArgs e )
{
BindGrid3 ( ) ;
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid3_Sort ( object sender , GridSortEventArgs e )
{
BindGrid3 ( ) ;
}
/// <summary>
/// 分页显示条数下拉框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize3_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid3 . PageSize = Convert . ToInt32 ( ddlPageSize3 . SelectedValue ) ;
BindGrid3 ( ) ;
}
#endregion
2025-03-27 15:22:48 +08:00
protected void TabStrip1_TabIndexChanged ( object sender , EventArgs e )
{
if ( TabStrip1 . ActiveTabIndex = = 1 )
{
2025-03-27 17:14:51 +08:00
if ( this . Grid2 . Rows . Count = = 0 )
{
BindGrid2 ( ) ;
}
}
else if ( TabStrip1 . ActiveTabIndex = = 2 )
{
if ( this . Grid3 . Rows . Count = = 0 )
{
BindGrid3 ( ) ;
}
2025-03-27 15:22:48 +08:00
}
}
2025-04-10 19:04:56 +08:00
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid3_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
this . ViewWeekDetail ( ) ;
}
/// <summary>
/// 查看
/// </summary>
private void ViewWeekDetail ( )
{
if ( Grid3 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
else if ( Grid3 . SelectedRowIndexArray . Length > 1 )
{
Alert . ShowInTop ( "请选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
string projectId = Grid3 . SelectedRowID ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "JDWeekDetail.aspx?projectId={0}" , projectId , "查看明细 - " ) ) ) ;
}
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid2_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
this . ViewMonthDetail ( ) ;
}
/// <summary>
/// 查看
/// </summary>
private void ViewMonthDetail ( )
{
if ( Grid2 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
else if ( Grid2 . SelectedRowIndexArray . Length > 1 )
{
Alert . ShowInTop ( "请选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
//统计月份信息
DateTime months = Convert . ToDateTime ( DateTime . Now . Year . ToString ( ) + "-" + DateTime . Now . Month . ToString ( ) + "-01" ) ;
if ( DateTime . Now . Day < 26 )
{
months = Convert . ToDateTime ( DateTime . Now . Year . ToString ( ) + "-" + DateTime . Now . AddMonths ( - 1 ) . Month . ToString ( ) + "-01" ) ;
}
string projectId = Grid2 . SelectedRowID ;
string month = months . ToString ( "yyyy-MM-dd" ) ;
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "JDMonthDetail.aspx?projectId={0}&month={1}" , projectId , month , "查看明细 - " ) ) ) ;
}
2025-03-26 09:53:22 +08:00
}
}