CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/HSSE/SitePerson/PersonInfo.aspx.cs

441 lines
16 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.SitePerson
{
public partial class PersonInfo : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string CheckingId
{
get
{
return (string)ViewState["CheckingId"];
}
set
{
ViewState["CheckingId"] = value;
}
}
public int RowCount
{
get
{
return (int)ViewState["RowCount"];
}
set
{
ViewState["RowCount"] = 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.GetButtonPower();
btnNew.OnClientClick = Window1.GetShowReference("PersonInfoEdit.aspx") + "return false;";
this.btnMenuDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!");
this.btnMenuDelete.ConfirmText = String.Format("你确定要删除选中的&nbsp;<b><script>{0}</script></b>&nbsp;行数据吗?", Grid1.GetSelectedCountReference());
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
UnitService.InitUnitDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, true);
if (ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId))
{
this.drpUnit.SelectedValue = this.CurrUser.UnitId;
this.drpUnit.Enabled = false;
}
this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(-1));
this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddMinutes(1));
// 绑定表格
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT CheckingId,CardNo,ProjectId,IdentityCard,WorkAreaId,IntoOutTime,IntoOut,Address,WorkAreaName,PersonName,UnitId,UnitName,States
FROM dbo.View_SitePerson_Checking where 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
strSql += " AND ProjectId = @ProjectId";
if (!string.IsNullOrEmpty(Request.Params["projectId"])) ///是否文件柜查看页面传项目值
{
listStr.Add(new SqlParameter("@ProjectId", Request.Params["projectId"]));
strSql += " AND States = @States"; ///状态为已完成
listStr.Add(new SqlParameter("@States", BLL.Const.State_2));
}
else
{
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
}
if (this.drpUnit.SelectedValue != Const._Null)
{
strSql += " AND UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.drpUnit.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtPersonName.Text))
{
strSql += " AND PersonName LIKE @PersonName";
listStr.Add(new SqlParameter("@PersonName", "%" + this.txtPersonName.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtStartDate.Text))
{
strSql += " AND IntoOutTime >= @StartDate";
listStr.Add(new SqlParameter("@StartDate", this.txtStartDate.Text.Trim()));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text))
{
strSql += " AND IntoOutTime < @EndDate";
listStr.Add(new SqlParameter("@EndDate", this.txtEndDate.Text.Trim()));
}
strSql += " order by PersonName";
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
this.RowCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <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();
}
#endregion
#region
/// <summary>
/// 关闭弹出框事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string CheckingId = Grid1.SelectedRowID;
var checking = BLL.SitePerson_CheckingService.GetPersonInfoByCheckingId(CheckingId);
if (checking != null)
{
if (this.btnMenuEdit.Hidden) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonInfoEdit.aspx?CheckingId={0}&type=view", CheckingId, "查看 - ")));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonInfoEdit.aspx?CheckingId={0}", CheckingId, "编辑 - ")));
}
}
else
{
Alert.ShowInTop("门禁系统自动考勤,不允许再次编辑!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
bool isShow = false;
if (Grid1.SelectedRowIndexArray.Length == 1)
{
isShow = true;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (this.judgementDelete(rowID, isShow))
{
var getV = BLL.SitePerson_CheckingService.GetPersonInfoByCheckingId(rowID);
if (getV != null)
{
BLL.LogService.AddSys_Log(this.CurrUser, getV.CardNo, getV.CheckingId, BLL.Const.PersonalInfoMenuId, BLL.Const.BtnDelete);
BLL.SitePerson_CheckingService.DeletePersonInfoByCheckingId(rowID);
}
else
{
BLL.LogService.AddSys_Log(this.CurrUser, getV.CardNo, getV.CheckingId, BLL.Const.PersonalInfoMenuId, BLL.Const.BtnDelete);
BLL.SitePerson_CheckingService.DeletePersonInfoByCheckingId(rowID);
}
BindGrid();
ShowNotify("删除数据成功!(表格数据已重新绑定)", MessageBoxIcon.Success);
}
}
}
}
/// <summary>
/// 判断是否可删除
/// </summary>
/// <param name="rowID"></param>
/// <param name="isShow"></param>
/// <returns></returns>
private bool judgementDelete(string rowID, bool isShow)
{
string content = string.Empty;
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content);
}
return false;
}
}
#endregion
#region
/// <summary>
/// 把进出转换为字符串类型
/// </summary>
/// <param name="sex"></param>
/// <returns></returns>
protected string ConvertIntoOut(object intoOut)
{
if (intoOut != null)
{
if (intoOut.ToString() == "1")
{
return "进场";
}
else
{
return "出场";
}
}
return "";
}
#endregion
#region
/// <summary>
/// 判断按钮权限
/// </summary>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PersonInfoMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
this.btnImport.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
}
}
#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.RowCount;
BindGrid();
Response.Write(GetGridTableHtml1(Grid1));
Response.End();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml1(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
if (column.ColumnID == "tfIdentityCard")
{
html = (row.FindControl("lblIdentityCard") as AspNet.Label).Text;
}
if (column.ColumnID == "tfWorkAreaName")
{
html = (row.FindControl("lblWorkAreaName") as AspNet.Label).Text;
}
if (column.ColumnID == "tfIntoOut")
{
html = (row.FindControl("lblIntoOut") as AspNet.Label).Text;
}
if (column.ColumnID == "tfAddress")
{
html = (row.FindControl("lblAddress") as AspNet.Label).Text;
}
//sb.AppendFormat("<td>{0}</td>", html);
sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;width:140px;'>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
protected void btSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PersonInfoIn.aspx", "导入 - ")));
}
}
}