CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/Door/InOutList.aspx.cs

184 lines
7.3 KiB
C#
Raw Normal View History

2021-04-30 10:28:37 +08:00
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.Door
{
public partial class InOutList : PageBase
{
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
Funs.DropDownPageSize(this.ddlPageSize);
UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId, true);
this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
if (this.CurrUser != null && this.CurrUser.PageSize.HasValue)
{
Grid1.PageSize = this.CurrUser.PageSize.Value;
}
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// GetPersonStatistic();
}
}
/// <summary>
/// 获取数据,合并相同行
/// </summary>
private void GetPersonStatistic()
{
if (!string.IsNullOrEmpty(this.ProjectId))
{
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
if (this.rbCheckType.SelectedValue == "1")
{
strSql = @"SELECT NEWID,ValidEventID AS ID,V.ProjectId,EmployName,DepartmentID,DepartmentName AS DepartName,AreaID,AreaName,EmployNO,V.CardNO AS CardID
,RecordDateTime AS DateTimeRecord,RecordAll AS RecordDes,(CASE WHEN InOrOut=2 THEN '' ELSE '' END) AS InOrOut
,P.UnitId,P.TeamGroupId
FROM t_d_validcardevent V
LEFT JOIN SitePerson_Person AS P ON V.IDCardNo=P.IdentityCard AND V.ProjectId=P.ProjectId
where V.ProjectId = @ProjectId";
if (!string.IsNullOrEmpty(this.txtStartDate.Text))
{
strSql += " AND RecordDateTime >= @StartDate";
listStr.Add(new SqlParameter("@StartDate", this.txtStartDate.Text));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text))
{
strSql += " AND RecordDateTime < @EndDate";
listStr.Add(new SqlParameter("@EndDate", Funs.GetNewDateTime(this.txtEndDate.Text).Value.AddDays(1)));
}
}
else
{
strSql = @"SELECT NewID,ID,V.ProjectId,EmployName,DepartmentID,DepartName,AreaID,AreaName,EmployNO,CardID,RoleID
,DateTimeRecord,RecordDes, InOrOut ,P.UnitId,P.TeamGroupId
FROM dbo.t_d_facerecord V
LEFT JOIN SitePerson_Person AS P ON V.EmployNO=P.IdentityCard AND V.ProjectId=P.ProjectId
where V.ProjectId = @ProjectId";
if (this.rbCheckType.SelectedValue == "2")
{
strSql += " AND RoleID = '微信端'";
}
else
{
strSql += " AND RoleID != '微信端'";
}
if (!string.IsNullOrEmpty(this.txtStartDate.Text))
{
strSql += " AND DateTimeRecord >= @StartDate";
listStr.Add(new SqlParameter("@StartDate", this.txtStartDate.Text));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text))
{
strSql += " AND DateTimeRecord < @EndDate";
listStr.Add(new SqlParameter("@EndDate", Funs.GetNewDateTime(this.txtEndDate.Text).Value.AddDays(1)));
}
}
listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
strSql += " AND UnitId = @UnitId ";
listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
{
strSql += " AND EmployName LIKE @EmployName";
listStr.Add(new SqlParameter("@EmployName", "%" + this.txtName.Text.Trim() + "%"));
}
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();
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
GetPersonStatistic();
}
#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;
GetPersonStatistic();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#endregion
#region
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
GetPersonStatistic();
}
/// <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);
GetPersonStatistic();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
GetPersonStatistic();
}
#endregion
}
}