数据大屏优化
This commit is contained in:
@@ -0,0 +1,234 @@
|
||||
using BLL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text;
|
||||
|
||||
namespace FineUIPro.Web.DataShow
|
||||
{
|
||||
public partial class HazardFactor : PageBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 单位id
|
||||
/// </summary>
|
||||
public string UnitId
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)ViewState["UnitId"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["UnitId"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region 加载页面
|
||||
/// <summary>
|
||||
/// 加载页面
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
BLL.ConstValue.InitConstValueDropDownList(this.drpYear, ConstValue.Group_0008, true);
|
||||
BLL.ConstValue.InitConstValueDropDownList(this.drpMonth, ConstValue.Group_0009, true);
|
||||
BLL.UnitService.InitBranchUnitDropDownList(this.drpUnit, true, true);
|
||||
BLL.RiskLevelService.InitRiskLevelDropDownListByRiskLevelName(this.drpBaseRiskLevel, true);
|
||||
BLL.RiskLevelService.InitRiskLevelDropDownListByRiskLevelName(this.drpNetRiskLevel, true);
|
||||
this.UnitId = this.CurrUser.UnitId;
|
||||
if (CommonService.IsSuperAdminManage(this.CurrUser.UserId) || (!string.IsNullOrWhiteSpace(this.UnitId) && this.UnitId == Const.UnitId_XJYJ))
|
||||
{
|
||||
this.drpUnit.Hidden = false;
|
||||
this.UnitId = this.CurrUser.LastUnitId;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(this.UnitId))
|
||||
{
|
||||
this.drpUnit.SelectedValue = this.UnitId;
|
||||
}
|
||||
var dateYearMon = DateTime.Now.ToString("yyyy-M");
|
||||
this.drpYear.SelectedValue = dateYearMon.Split('-')[0];
|
||||
this.drpMonth.SelectedValue = dateYearMon.Split('-')[1];
|
||||
|
||||
Funs.DropDownPageSize(this.ddlPageSize);
|
||||
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||||
// 绑定表格
|
||||
BindGrid();
|
||||
this.Panel1.Title = "安全危害因素";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 绑定数据
|
||||
/// </summary>
|
||||
private void BindGrid()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
|
||||
string dedupe = rbDedupe.SelectedValue;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dedupe))
|
||||
{
|
||||
sb.Append("WITH CTE AS ( ");
|
||||
if (dedupe == "0")
|
||||
{//按月
|
||||
sb.Append("SELECT ROW_NUMBER() OVER (PARTITION BY tba.Year,tba.Month,tba.WorkPlace,tba.JobStep,tba.Hazard,tba.Consequence,tba.AccidentType,tba.Illegality,tba.BaseRiskSeverity,tba.BaseRiskProbability,tba.BaseRiskScore,tba.BaseRiskLevel,tba.BaseRiskAcceptabity,tba.NetRiskControlMeasures,tba.NetRiskSeverity,tba.NetRiskProbability,tba.NetRiskScore,tba.NetRiskLevel,tba.NetRiskAcceptabity,tba.AdditionalControlMeasures ORDER BY CompileDate desc) as rn,tba.* ");
|
||||
}
|
||||
else
|
||||
{//按年
|
||||
sb.Append("SELECT ROW_NUMBER() OVER (PARTITION BY tba.Year,tba.WorkPlace,tba.JobStep,tba.Hazard,tba.Consequence,tba.AccidentType,tba.Illegality,tba.BaseRiskSeverity,tba.BaseRiskProbability,tba.BaseRiskScore,tba.BaseRiskLevel,tba.BaseRiskAcceptabity,tba.NetRiskControlMeasures,tba.NetRiskSeverity,tba.NetRiskProbability,tba.NetRiskScore,tba.NetRiskLevel,tba.NetRiskAcceptabity,tba.AdditionalControlMeasures ORDER BY CompileDate desc) as rn,tba.* ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("SELECT tba.* ");
|
||||
}
|
||||
sb.Append("FROM HazardFactor_Safety AS tba WITH(NOLOCK) ");
|
||||
//sb.Append("LEFT JOIN Base_Project AS tbb WITH(NOLOCK) ON tbb.ProjectId = tba.ProjectId ");
|
||||
sb.Append("WHERE 1=1 AND tba.State = 1 ");//取已提交数据
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.CurrUser.UnitId) && this.CurrUser.UnitId != Const.UnitId_XJYJ)
|
||||
{//分公司只能查看本单位的数据
|
||||
sb.Append("AND tba.UnitId = @UnitId ");
|
||||
listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != Const._Null && this.drpUnit.SelectedValue != Const.UnitId_XJYJ)
|
||||
{
|
||||
sb.Append("AND tba.UnitId = @UnitId ");
|
||||
listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue));
|
||||
}
|
||||
}
|
||||
//if (!string.IsNullOrWhiteSpace(this.drpProject.SelectedValue) && this.drpProject.SelectedValue != Const._Null)
|
||||
//{
|
||||
// sb.Append("AND tba.ProjectId = @ProjectId ");
|
||||
// listStr.Add(new SqlParameter("@ProjectId", this.drpProject.SelectedValue));
|
||||
//}
|
||||
if (!string.IsNullOrWhiteSpace(this.drpYear.SelectedValue) && this.drpYear.SelectedValue != Const._Null)
|
||||
{
|
||||
sb.Append("AND tba.Year = @Year ");
|
||||
listStr.Add(new SqlParameter("@Year", this.drpYear.SelectedValue));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(this.drpMonth.SelectedValue) && this.drpMonth.SelectedValue != Const._Null)
|
||||
{
|
||||
string month = this.drpMonth.SelectedValue;
|
||||
sb.Append("AND tba.Month = @Month ");
|
||||
listStr.Add(new SqlParameter("@Month", month.Length == 1 ? $"0{month}" : month));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(this.drpBaseRiskLevel.SelectedValue) && this.drpBaseRiskLevel.SelectedValue != Const._Null)
|
||||
{
|
||||
sb.Append("AND tba.BaseRiskLevel = @BaseRiskLevel ");
|
||||
listStr.Add(new SqlParameter("@BaseRiskLevel", this.drpBaseRiskLevel.SelectedValue));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(this.drpNetRiskLevel.SelectedValue) && this.drpNetRiskLevel.SelectedValue != Const._Null)
|
||||
{
|
||||
sb.Append("AND tba.NetRiskLevel = @NetRiskLevel ");
|
||||
listStr.Add(new SqlParameter("@NetRiskLevel", this.drpNetRiskLevel.SelectedValue));
|
||||
}
|
||||
//if (!string.IsNullOrEmpty(this.rbState.SelectedValue))
|
||||
//{
|
||||
// sb.Append("AND tba.State = @State ");
|
||||
// listStr.Add(new SqlParameter("@State", this.rbState.SelectedValue));
|
||||
//}
|
||||
if (!string.IsNullOrEmpty(this.rbIllegality.SelectedValue))
|
||||
{
|
||||
sb.Append("AND tba.Illegality = @Illegality ");
|
||||
listStr.Add(new SqlParameter("@Illegality", this.rbIllegality.SelectedValue == "1" ? true : false));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(dedupe))
|
||||
{
|
||||
sb.Append(") ");
|
||||
sb.Append("SELECT * FROM CTE WHERE rn = 1; ");
|
||||
}
|
||||
|
||||
string sqlStr = sb.ToString();
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
DataTable tb = SQLHelper.GetDataTableRunText(sqlStr, parameter);
|
||||
|
||||
Grid1.RecordCount = tb.Rows.Count;
|
||||
var table = this.GetPagedDataTable(Grid1, tb);
|
||||
|
||||
Grid1.DataSource = table;
|
||||
Grid1.DataBind();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 格式化数据
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
protected string ConvertDataState(object data)
|
||||
{
|
||||
string result = string.Empty;
|
||||
string dataStr = data.ToString();
|
||||
if (data != null)
|
||||
{
|
||||
result = dataStr == "1" ? "已提交" : "未提交";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 查询
|
||||
/// <summary>
|
||||
/// 查询
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void TextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user