⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 summary.aspx.cs

📁 该管理系统的主要功能是管理员工资料、管理员工考勤、计算员工薪资和业绩评定等。大部分涉及对敏感数据修改的工作都仅由人事部完成
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using DBUtils;

namespace BlueHill.Attendance
{
	/// <summary>
	/// Summary 的摘要说明。
	/// </summary>
	public class Summary : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtStartTime;
		protected System.Web.UI.WebControls.TextBox txtEndTime;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.DataGrid grdResult;
		protected System.Web.UI.WebControls.RadioButtonList rdoTypeList;
		protected System.Web.UI.WebControls.RadioButtonList rdoAscendList;
		protected System.Web.UI.WebControls.DropDownList cmbDeptList;
		protected System.Web.UI.WebControls.Button btnSearch;
		protected System.Web.UI.WebControls.Label lblChooseDept;
		protected System.Web.UI.WebControls.Panel pnlSearch;
		protected System.Web.UI.WebControls.Panel pnlError;
		protected System.Web.UI.WebControls.Label lblError;
		protected System.Web.UI.WebControls.Label lblDeptID;
		protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
		protected System.Web.UI.WebControls.CompareValidator CompareValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!this.Page.IsPostBack)
			{
				//判断用户权限

				//获取员工编号信息和员工其他信息
				int iEmpID = Convert.ToInt32(Session["EmployeeID"]);
				Employee employee = new Employee();
				//查询员工信息,并返回查询是否成功
				int iSuccess = Employee.GetEmployeeInfo(iEmpID,ref employee);

				if(iSuccess == (int)DBResult.Success)
				{
					//查询员工信息操作成功
					//判断当前登录员工的权限
					if(!employee.IsManager)
					{
						//普通员工,没有权限查看此页
						this.pnlError.Visible = true;
						this.lblError.Visible = true;
						this.pnlSearch.Visible = false;
					}
					else
					{
						//当前员工是经理或者总经理
						//显示出初使化页面
						this.pnlError.Visible = false;
						this.pnlSearch.Visible = true;
						this.txtStartTime.Visible = true;
						this.txtEndTime.Visible = true;
						this.rdoAscendList.Visible = true;
						this.rdoTypeList.Visible = true;
						this.btnSearch.Visible = true;
						this.lblDeptID.Visible = false;


						//设置开始时间为当前时间的一个月前
						this.txtStartTime.Text = System.DateTime.Now.AddMonths(-1).ToShortDateString();

						//设置结果时间为当日的第二天
						this.txtEndTime.Text = System.DateTime.Now.AddDays(1).ToShortDateString();

						//判断当前员工是否为总经理
						int iCEOID = 0;
						iSuccess = Employee.GetCEOInfo(ref iCEOID);
						if(iSuccess ==(int)DBResult.Success)
						{
							//查询是否为总经理操作成功
							if(employee.EmployeeID == iCEOID)
							{
								//当前登录的员工是总经理,要显示"选择要查询的部门"
								this.lblChooseDept.Visible = true;
								this.cmbDeptList.Visible = true;

								//绑定部门列表
								
								//创建 DataSet 对象,保存部门列表
								DataSet dsDept = new DataSet();

								//调用 CheckLvReq.GetDeptList(dsDept) 函数,返回数据库操作是否成功
								iSuccess = DBUtils.CheckLvReq.GetDeptList(ref dsDept);
								
								if(iSuccess == (int)DBResult.Success)
								{
									//查询部门列表操作成功
									//绑定部门列表到下拉列表框
									this.cmbDeptList.DataSource = dsDept.Tables[0].DefaultView;
									this.cmbDeptList.DataTextField = "DeptName";
									this.cmbDeptList.DataValueField = "DeptID";
									this.cmbDeptList.DataBind();

									//默认选中第一项
									this.cmbDeptList.SelectedIndex = 0;
								}							
								else
								{
									//数据库操作失败
									this.pnlError.Visible = true;
									this.lblError.Visible = true;
									this.lblError.Text = "数据库操作失败,请重试";
									this.pnlSearch.Visible = false;
								}

							}
							else
							{
								//当前员工是部门经理,隐藏“选择要查询的部门”
								this.lblChooseDept.Visible = false;
								this.cmbDeptList.Visible = false;
						
								//获取部门经理的部门编号
								this.lblDeptID.Text  = employee.DeptID.ToString();							
							}
						
						}
				
					}
				}
				else
				{
					//查询员工信息操作失败
					this.pnlError.Visible = true;
					this.lblError.Visible = true;
					this.lblError.Text = "数据库操作失败,请重试";
					this.pnlSearch.Visible = false;

				}

			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			this.grdResult.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grdResult_ItemCommand);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion


		//检索指定部门在指定时间段内的考勤汇总信息
		private void btnSearch_Click(object sender, System.EventArgs e)
		{			
			//设置时间格式是否正确的标志,默认为真,将字符串转化为时间类型时出错则为 false
			bool isTime = true;

			//设置一个时间类型变量用于判断时间格式是否正确
			DateTime dt = System.DateTime.Now;

			//获取开始时间
			string strStartTime = this.txtStartTime.Text.Trim();
			try
			{
				//判断时间格式是否正确
				dt = Convert.ToDateTime(strStartTime);
			}
			catch(Exception ex)
			{
				isTime = false;
			}

			//获取结束时间
			string strEndTime = this.txtEndTime.Text.Trim();
			try
			{
				dt = Convert.ToDateTime(strEndTime);
			}
			catch(Exception ex)
			{
				isTime = false;
			}

			if(isTime)
			{
				//时间格式正确,继续执行

				//获取部门编号
				int iDeptID = 0;
				if(this.lblDeptID.Text == "")
				{
					//当前登录者为总经理,部门编号为下拉框的选中项
					iDeptID = Convert.ToInt32(this.cmbDeptList.SelectedValue);
				}
				else
				{
					//当前登录者为部门经理
					iDeptID = Convert.ToInt32(this.lblDeptID.Text);
				}

				//创建 DataSet 对象,保存查询结果
				DataSet dsResult = new DataSet();

				//执行考勤查询,返回数据操作是否成功标志
				int iSuccess = DBUtils.Attendance.DeptSummary(iDeptID,strStartTime,strEndTime,ref dsResult);

				if(iSuccess == (int)DBResult.Success )
				{
					//数据库操作成功
					//判断是否有记录
					if(dsResult.Tables[0].Rows.Count >0 )
					{
						//数据库中有相应的数据,绑定到 DataGrid 控件上
						#region//获取排序方式
						//排序类型
						string strType = "LateCount";
						if(this.rdoTypeList.SelectedValue =="0")
						{
							//按迟到次数排序
							strType = "LateCount";
						}
						else
						{
							if(this.rdoTypeList.SelectedValue == "1")
							{
								//按早退次数排序
								strType = "EarlyCount";
							}
							else
							{
								//按勤次数排序
								strType = "AbsenceCount";
							}
						}

						//降/升序
						string strAscend = "DESC";
						if(this.rdoAscendList.SelectedValue == "0")
						{
							//降序
							strAscend = "DESC";
						}
						else
						{
							//升序
							strAscend = "ASC";
						}
						#endregion

						dsResult.Tables[0].DefaultView.Sort = strType + " " + strAscend;
						this.grdResult.DataSource = dsResult.Tables[0].DefaultView;
						this.grdResult.DataBind();
						this.grdResult.Visible = true;
						this.lblMessage.Visible = false;
					}
					else
					{
						//数据库中没有记录,给出提示信息
						this.lblMessage.Text = "没有任何记录";
						this.lblMessage.Visible = true;
						this.grdResult.Visible = false;
					}
				}
				else
				{
					//数据库操作失败
					this.lblMessage.Text = "数据库操作失败,请重试";
					this.lblMessage.Visible = true;
					this.grdResult.Visible = false;
				}
			}
			else
			{
				//时间格式不正确
				this.lblMessage.Text = "时间格式不正确,请重新输入";
				this.lblMessage.Visible = true;
				this.grdResult.Visible = false;
			}
		}

		private void grdResult_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if(e.CommandName == "Select")
			{
				//单击"详细情况",转向查看详细信息页面
				//获取请假者编号
				string strEmpID = e.Item.Cells[1].Text.Trim();

				//获取请假者姓名
				string strName = e.Item.Cells[2].Text.Trim();

				//获取开始时间
				string strStartTime = this.txtStartTime.Text.Trim();

				//获取结束时间
				string strEndTime = this.txtEndTime.Text.Trim();

				//设置转向页面的地址
				string url = "ShowAttendDetail.aspx?EmpID=" + strEmpID + "&Name=" + strName + "&StartTime=" + strStartTime + "&EndTime=" + strEndTime;
				Response.Redirect(url);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -