SGGL_JT/SUBQHSE/FineUIPro.Web/HSSE/Check/PunishNoticeStatistics.aspx.cs

254 lines
8.8 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.Check
{
public partial class PunishNoticeStatistics : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region
public string UnitId
{
get
{
return (string)ViewState["UnitId"];
}
set
{
ViewState["UnitId"] = value;
}
}
#endregion
#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);
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
this.InitDropDownList();
this.ucTree.UnitId = this.CurrUser.UnitId;
this.ucTree.ProjectId = this.ProjectId;
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
this.panelLeftRegion.Hidden = true;
// this.Grid1.Columns[0].Hidden = true;
}
if (this.CurrUser != null && this.CurrUser.PageSize.HasValue)
{
Grid1.PageSize = this.CurrUser.PageSize.Value;
}
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
this.BindGrid();
}
}
private void InitDropDownList()
{
BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true);
if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId))
{
this.drpUnitId.SelectedValue = this.CurrUser.UnitId;
this.drpUnitId.Enabled = false;
}
}
protected void changeTree(object sender, EventArgs e)
{
this.ProjectId = this.ucTree.ProjectId;
this.InitDropDownList();
//新增UnitId
//this.UnitId = this.ucTree.UnitId;
//判断 当有projectId的时候单位id为空
if (!string.IsNullOrEmpty(this.ProjectId))
{
this.UnitId = "";
}
this.BindGrid();
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
if (string.IsNullOrEmpty(this.ProjectId))
{
return;
}
if (!string.IsNullOrEmpty(this.ProjectId))
{
string strSql = @"SELECT SUM(PunishMoney) AS PunishMoney, P.UnitId,Unit.UnitName,Unit.UnitCode"
+ @" FROM Check_PunishNotice AS P "
+ @" LEFT JOIN Base_Unit AS Unit ON P.UnitId=Unit.UnitId"
+ @" WHERE 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(ProjectId))
{
strSql += " AND P.ProjectId = @ProjectId";
listStr.Add(new SqlParameter("@ProjectId", ProjectId));
}
//if (!string.IsNullOrEmpty(UnitId))
//{
// strSql += " AND P.UnitId = @UnitId1";
// listStr.Add(new SqlParameter("@UnitId1", UnitId));
//}
/// 施工分包 只看到自己已完成的处罚单
if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId))
{
strSql += " AND P.UnitId = @UnitId"; ///处罚单位
listStr.Add(new SqlParameter("@UnitId", this.CurrUser.UnitId));
}
if (this.drpUnitId.SelectedValue != null && this.drpUnitId.SelectedValue != BLL.Const._Null)
{
strSql += " AND P.UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue.Trim()));
}
if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()))
{
strSql += " AND P.PunishNoticeDate >= @StartDate";
listStr.Add(new SqlParameter("@StartDate", this.txtStartDate.Text.Trim()));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
{
strSql += " AND P.PunishNoticeDate <= @EndDate";
listStr.Add(new SqlParameter("@EndDate", this.txtEndDate.Text.Trim()));
}
if (this.rbState.SelectedValue == "1")
{
strSql += " AND P.PunishStates =" + BLL.Const.State_3;
}
else if (this.rbState.SelectedValue == "2")
{
strSql += " AND P.PunishStates =" + BLL.Const.State_4;
}
strSql += " GROUP BY P.UnitId,Unit.UnitName,Unit.UnitCode";
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();
}
}
#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 ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtStartDate.Text.Trim()) && !string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
{
if (Convert.ToDateTime(this.txtStartDate.Text.Trim()) > Convert.ToDateTime(this.txtEndDate.Text.Trim()))
{
Alert.ShowInTop("开始时间不能大于结束时间", MessageBoxIcon.Warning);
return;
}
}
this.BindGrid();
}
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("处罚通知单" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = this.Grid1.RecordCount;
this.BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#endregion
protected void rbState_SelectedIndexChanged(object sender, EventArgs e)
{
this.BindGrid();
}
}
}