using BLL;
using Newtonsoft.Json.Linq;
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
{
private int AllCount1 = 0;
private int AllCount2 = 0;
private int AllCount3 = 0;
#region 加载页面
///
/// 加载页面
///
///
///
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();
//合计
// OutputSummaryData();
this.Panel1.Title = "隐患排查治理数据(" + BLL.UnitService.GetUnitNameByUnitId(BLL.CommonService.GetThisUnitId()) + ")";
}
}
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"select ProjectId,ProjectCode, ProjectName from Base_Project where ProjectState =1 and (ProjectState2 is null or ProjectState2 !=9) ";
List listStr = new List();
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);
Grid1.DataSource = tb;
Grid1.DataBind();
OutputSummaryData();
}
#endregion
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
AllCount1 = 0;
AllCount2 = 0;
AllCount3= 0;
this.BindGrid();
}
#endregion
#region 表排序、分页、关闭窗口
///
/// 分页
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
///
/// 分页显示条数下拉框
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
/// 关闭弹出窗
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region Grid双击事件 编辑
///
/// Grid行双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
EditData();
}
///
///
///
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();
}
///
/// 数量
///
///
///
protected int Count1(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 != "4" && 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);
}
if (this.rbType.SelectedValue == "0")
{
getT = getT.Where(x => x.Risk_Level == "重大");
}
else
{
getT = getT.Where(x => x.Risk_Level == "一般");
}
cout1 = getT.Count();
}
AllCount1 += cout1;
return cout1;
}
protected int CountALL(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 != "4" && 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);
}
if (this.rbType.SelectedValue == "0")
{
getT = getT.Where(x => x.Risk_Level == "重大");
}
else
{
getT = getT.Where(x => x.Risk_Level == "一般");
}
cout1 = getT.Count();
}
return cout1;
}
protected int Count2(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.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);
}
if (this.rbType.SelectedValue == "0")
{
getT = getT.Where(x => x.Risk_Level == "重大");
}
else
{
getT = getT.Where(x => x.Risk_Level == "一般");
}
cout1 = getT.Count();
}
AllCount2 += cout1;
return cout1;
}
protected int CountOk(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.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);
}
if (this.rbType.SelectedValue == "0")
{
getT = getT.Where(x => x.Risk_Level == "重大");
}
else
{
getT = getT.Where(x => x.Risk_Level == "一般");
}
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");
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();
}
AllCount3 += cout1;
return cout1;
}
protected string Count4(object projectId)
{
string rate = string.Empty;
if (projectId != null)
{
int coutall = CountALL(projectId);
int cout0 = CountOk(projectId);
if (coutall > 0)
{
rate = Math.Round(cout0 * 1.0 / coutall * 100, 2).ToString();
}
}
return rate;
}
#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 listStr = new List();
//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
}
}