400 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			400 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using System;
 | |
| 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 string ProjectId
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 return (string)ViewState["ProjectId"];
 | |
|             }
 | |
|             set
 | |
|             {
 | |
|                 ViewState["ProjectId"] = 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;
 | |
|                 ////权限按钮方法
 | |
|                 this.GetButtonPower();
 | |
|                 btnNew.OnClientClick = Window1.GetShowReference("PersonInfoEdit.aspx") + "return false;";
 | |
|                 this.btnMenuDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!");
 | |
|                 this.btnMenuDelete.ConfirmText = String.Format("你确定要删除选中的 <b><script>{0}</script></b> 行数据吗?", Grid1.GetSelectedCountReference());
 | |
|                 ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
 | |
|                 UnitService.InitUnitDropDownList(this.drpUnit, this.ProjectId , true);
 | |
|                 if (ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId , this.CurrUser.UnitId))
 | |
|                 {
 | |
|                     this.drpUnit.SelectedValue = this.CurrUser.UnitId;
 | |
|                     this.drpUnit.Enabled = false;
 | |
|                 }
 | |
|                 this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
 | |
|                 this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now.AddDays(1));
 | |
|                 // 绑定表格
 | |
|                 BindGrid();
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 绑定数据
 | |
|         /// </summary>
 | |
|         private void BindGrid()
 | |
|         {
 | |
|             var getData = SitePerson_CheckingService.getListData(this.ProjectId , this.drpUnit.SelectedValue, this.txtPersonName.Text.Trim(),
 | |
|                this.txtStartDate.Text, this.txtEndDate.Text, Grid1);
 | |
|             Grid1.RecordCount = SitePerson_CheckingService.count;
 | |
|             Grid1.DataSource = getData;
 | |
|             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.ProjectId , 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.Grid1.RecordCount;
 | |
|             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", "导入 - ")));
 | |
|         }
 | |
|     }
 | |
| } |