2023-03-29 14:32:57 +08:00
using BLL ;
2023-11-11 16:02:42 +08:00
using Newtonsoft.Json.Linq ;
2023-03-29 14:32:57 +08:00
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
namespace FineUIPro.Web.DataShow
{
public partial class HiddenRectification : PageBase
{
2023-11-11 16:02:42 +08:00
private int AllCount1 = 0 ;
private int AllCount2 = 0 ;
private int AllCount3 = 0 ;
2023-03-29 14:32:57 +08:00
#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 ) ;
ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
BLL . ProjectService . InitProjectDropDownList ( this . drpProject , true ) ;
// 绑定表格t
BindGrid ( ) ;
2023-11-11 16:02:42 +08:00
//合计
// OutputSummaryData();
2023-06-10 10:55:18 +08:00
this . Panel1 . Title = "隐患排查治理数据(" + BLL . UnitService . GetUnitNameByUnitId ( BLL . CommonService . GetThisUnitId ( ) ) + ") " ;
2023-03-29 14:32:57 +08:00
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
2023-11-02 15:40:43 +08:00
string strSql = @"select ProjectId,ProjectCode, ProjectName from Base_Project where ProjectState =1 and (ProjectState2 is null or ProjectState2 !=9) " ;
2023-03-29 14:32:57 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
string cpara = string . Empty ;
if ( this . drpProject . SelectedValue ! = Const . _Null )
{
strSql + = " AND projectId = @projectId" ; ///状态为已完成
listStr . Add ( new SqlParameter ( "@projectId" , this . drpProject . SelectedValue ) ) ;
}
//if (!string.IsNullOrEmpty(this.txtStartTime.Text))
//{
// strSql += " AND h.RegisterDate >=@StartTime";
// listStr.Add(new SqlParameter("@StartTime", this.txtStartTime.Text));
// cpara += " AND c.RegisterDate >=" + this.txtStartTime.Text;
//}
//if (!string.IsNullOrEmpty(this.txtEndTime.Text))
//{
// strSql += " AND h.RegisterDate <=@EndTime";
// listStr.Add(new SqlParameter("@EndTime", this.txtEndTime.Text));
// cpara += " AND c.RegisterDate <=" + this.txtEndTime.Text;
//}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
2023-11-11 16:02:42 +08:00
Grid1 . DataSource = tb ;
2023-03-29 14:32:57 +08:00
Grid1 . DataBind ( ) ;
2023-11-11 16:02:42 +08:00
OutputSummaryData ( ) ;
2023-03-29 14:32:57 +08:00
}
#endregion
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged ( object sender , EventArgs e )
{
2023-11-11 16:02:42 +08:00
AllCount1 = 0 ;
AllCount2 = 0 ;
AllCount3 = 0 ;
2023-03-29 14:32:57 +08:00
this . BindGrid ( ) ;
}
#endregion
#region 表 排 序 、 分 页 、 关 闭 窗 口
/// <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 Grid1_Sort ( object sender , GridSortEventArgs 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 Window1_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region Grid双击事件 编 辑
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
EditData ( ) ;
}
/// <summary>
///
/// </summary>
private void EditData ( )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "HiddenRectificationItem.aspx?projectId={0}" , Grid1 . SelectedRowID , "查看 - " ) ) ) ;
}
#endregion
protected void btnView_Click ( object sender , EventArgs e )
{
EditData ( ) ;
}
2023-11-11 16:02:42 +08:00
2023-03-29 14:32:57 +08:00
/// <summary>
/// 数量
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
protected int Count1 ( object projectId )
{
int cout1 = 0 ;
if ( projectId ! = null )
{
var datetime1 = Funs . GetNewDateTime ( this . txtStartTime . Text ) ;
2023-11-11 16:02:42 +08:00
var datetime2 = Funs . GetNewDateTime ( this . txtEndTime . Text ) ;
var getT = Funs . DB . HSSE_Hazard_HazardRegister . Where ( x = > x . ProjectId = = projectId . ToString ( ) & & x . States ! = "4" & & x . RegisterDate > Funs . minSysDate & & x . ProblemTypes = = "1" ) ;
2023-03-29 14:32:57 +08:00
if ( datetime1 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate > = datetime1 ) ;
}
if ( datetime2 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate < = datetime2 ) ;
}
if ( this . rbType . SelectedValue = = "0" )
{
getT = getT . Where ( x = > x . Risk_Level = = "重大" ) ;
}
else
{
getT = getT . Where ( x = > x . Risk_Level = = "一般" ) ;
}
cout1 = getT . Count ( ) ;
}
2023-11-11 16:02:42 +08:00
AllCount1 + = cout1 ;
2023-03-29 14:32:57 +08:00
return cout1 ;
}
2023-11-11 16:02:42 +08:00
protected int CountALL ( object projectId )
2023-03-29 14:32:57 +08:00
{
int cout1 = 0 ;
if ( projectId ! = null )
{
var datetime1 = Funs . GetNewDateTime ( this . txtStartTime . Text ) ;
2023-11-11 16:02:42 +08:00
var datetime2 = Funs . GetNewDateTime ( this . txtEndTime . Text ) ;
var getT = Funs . DB . HSSE_Hazard_HazardRegister . Where ( x = > x . ProjectId = = projectId . ToString ( ) & & x . States ! = "4" & & x . RegisterDate > Funs . minSysDate & & x . ProblemTypes = = "1" ) ;
2023-03-29 14:32:57 +08:00
if ( datetime1 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate > = datetime1 ) ;
}
if ( datetime2 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate < = datetime2 ) ;
}
if ( this . rbType . SelectedValue = = "0" )
{
getT = getT . Where ( x = > x . Risk_Level = = "重大" ) ;
}
else
{
getT = getT . Where ( x = > x . Risk_Level = = "一般" ) ;
}
cout1 = getT . Count ( ) ;
2023-11-11 16:02:42 +08:00
}
2023-03-29 14:32:57 +08:00
return cout1 ;
}
2023-11-11 16:02:42 +08:00
protected int Count2 ( object projectId )
2023-03-29 14:32:57 +08:00
{
int cout1 = 0 ;
if ( projectId ! = null )
{
var datetime1 = Funs . GetNewDateTime ( this . txtStartTime . Text ) ;
2023-11-11 16:02:42 +08:00
var datetime2 = Funs . GetNewDateTime ( this . txtEndTime . Text ) ;
var getT = Funs . DB . HSSE_Hazard_HazardRegister . Where ( x = > x . ProjectId = = projectId . ToString ( ) & & x . States = = "3" & & x . RegisterDate > Funs . minSysDate & & x . ProblemTypes = = "1" ) ;
2023-03-29 14:32:57 +08:00
if ( datetime1 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate > = datetime1 ) ;
}
if ( datetime2 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate < = datetime2 ) ;
}
if ( this . rbType . SelectedValue = = "0" )
{
getT = getT . Where ( x = > x . Risk_Level = = "重大" ) ;
}
else
{
getT = getT . Where ( x = > x . Risk_Level = = "一般" ) ;
}
cout1 = getT . Count ( ) ;
}
2023-11-11 16:02:42 +08:00
AllCount2 + = cout1 ;
2023-03-29 14:32:57 +08:00
return cout1 ;
}
2023-11-11 16:02:42 +08:00
protected int CountOk ( object projectId )
2023-03-29 14:32:57 +08:00
{
2023-11-11 16:02:42 +08:00
int cout1 = 0 ;
2023-03-29 14:32:57 +08:00
if ( projectId ! = null )
{
var datetime1 = Funs . GetNewDateTime ( this . txtStartTime . Text ) ;
2023-11-11 16:02:42 +08:00
var datetime2 = Funs . GetNewDateTime ( this . txtEndTime . Text ) ;
var getT = Funs . DB . HSSE_Hazard_HazardRegister . Where ( x = > x . ProjectId = = projectId . ToString ( ) & & x . States = = "3" & & x . RegisterDate > Funs . minSysDate & & x . ProblemTypes = = "1" ) ;
if ( datetime1 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate > = datetime1 ) ;
}
if ( datetime2 . HasValue )
{
getT = getT . Where ( x = > x . RegisterDate < = datetime2 ) ;
}
2023-03-29 14:32:57 +08:00
if ( this . rbType . SelectedValue = = "0" )
{
2023-11-11 16:02:42 +08:00
getT = getT . Where ( x = > x . Risk_Level = = "重大" ) ;
2023-03-29 14:32:57 +08:00
}
else
{
2023-11-11 16:02:42 +08:00
getT = getT . Where ( x = > x . Risk_Level = = "一般" ) ;
2023-03-29 14:32:57 +08:00
}
2023-11-11 16:02:42 +08:00
cout1 = getT . Count ( ) ;
}
return cout1 ;
}
protected int Count3 ( object projectId )
{
int cout1 = 0 ;
if ( projectId ! = null )
{
var datetime1 = Funs . GetNewDateTime ( this . txtStartTime . Text ) ;
var datetime2 = Funs . GetNewDateTime ( this . txtEndTime . Text ) ;
var getT = Funs . DB . HSSE_Hazard_HazardRegister . Where ( x = > x . ProjectId = = projectId . ToString ( ) & & x . States ! = "3" & & x . States ! = "4" & & x . RegisterDate > Funs . minSysDate & & x . ProblemTypes = = "1" ) ;
2023-03-29 14:32:57 +08:00
if ( datetime1 . HasValue )
{
2023-11-11 16:02:42 +08:00
getT = getT . Where ( x = > x . RegisterDate > = datetime1 ) ;
2023-03-29 14:32:57 +08:00
}
if ( datetime2 . HasValue )
{
2023-11-11 16:02:42 +08:00
getT = getT . Where ( x = > x . RegisterDate < = datetime2 ) ;
}
if ( this . rbType . SelectedValue = = "0" )
{
getT = getT . Where ( x = > x . Risk_Level = = "重大" ) ;
2023-03-29 14:32:57 +08:00
}
2023-11-11 16:02:42 +08:00
else
{
getT = getT . Where ( x = > x . Risk_Level = = "一般" ) ;
}
cout1 = getT . Count ( ) ;
}
AllCount3 + = cout1 ;
return cout1 ;
}
protected string Count4 ( object projectId )
{
string rate = string . Empty ;
if ( projectId ! = null )
{
int coutall = CountALL ( projectId ) ;
int cout0 = CountOk ( projectId ) ;
2023-03-29 14:32:57 +08:00
if ( coutall > 0 )
{
rate = Math . Round ( cout0 * 1.0 / coutall * 100 , 2 ) . ToString ( ) ;
}
}
return rate ;
}
2023-11-11 16:02:42 +08:00
#region 合 计 数 据 ( 不 根 据 条 件 改 变 )
public void OutputSummaryData ( )
{
//string strSql = @"select ProjectId,ProjectCode, ProjectName,isnull(count1,0) as count1,isnull(count2,0) as count2,isnull(count3,0) as count3 from Base_Project f
//left join(select count(*) as count1,ProjectId as ProjectIda from HSSE_Hazard_HazardRegister
//where states <> 4 and Risk_Level= '" + this.rbType.SelectedItem.Text + @"' and RegisterDate > '2023-01-01'
//group by ProjectId) a
//on f.ProjectId = a.ProjectIda
//left join(select count(*) as count2,ProjectId as ProjectIdb from HSSE_Hazard_HazardRegister
//where states = 3 and Risk_Level= '" + this.rbType.SelectedItem.Text + @"' and RegisterDate > '2023-01-01'
//group by ProjectId) b
//on f.ProjectId = b.ProjectIdb
//left join(select count(*) as count3,ProjectId as ProjectIdc from HSSE_Hazard_HazardRegister
//where states <> 3 and states<>4 and Risk_Level= '" + this.rbType.SelectedItem.Text + @"' and RegisterDate > '2023-01-01'
//group by ProjectId) c
//on f.ProjectId = c.ProjectIdc
//where ProjectState = 1 and(isDelete IS NULL OR isDelete = 0)";
//List<SqlParameter> listStr = new List<SqlParameter>();
//SqlParameter[] parameter = listStr.ToArray();
//DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
JObject summary = new JObject ( ) ;
summary . Add ( "ProjectName" , "合计:" ) ;
summary . Add ( "Count1" , AllCount1 . ToString ( ) ) ;
summary . Add ( "Count2" , AllCount2 . ToString ( ) ) ;
summary . Add ( "Count3" , AllCount3 . ToString ( ) ) ;
summary . Add ( "Count4" , ( float . Parse ( AllCount2 . ToString ( ) ) / float . Parse ( AllCount1 . ToString ( ) ) * 100 ) . ToString ( "F2" ) ) ;
Grid1 . SummaryData = summary ;
}
#endregion
2023-03-29 14:32:57 +08:00
}
}