📄 individual.aspx.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.CheckLeave
{
/// <summary>
/// Individual 的摘要说明。
/// </summary>
public class Individual : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblDenyReason;
protected System.Web.UI.WebControls.Label lblDeny;
protected System.Web.UI.WebControls.Label lblReason;
protected System.Web.UI.WebControls.Label lblApproverName;
protected System.Web.UI.WebControls.Panel pnlDetail;
protected System.Web.UI.WebControls.Label lblViewDept;
protected System.Web.UI.WebControls.DropDownList cmbDeptList;
protected System.Web.UI.WebControls.Label lblViewEmp;
protected System.Web.UI.WebControls.DropDownList cmbEmpList;
protected System.Web.UI.WebControls.TextBox txtStartTime;
protected System.Web.UI.WebControls.TextBox txtEndTime;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.DataGrid grdResult;
protected System.Web.UI.WebControls.Panel pnlSearch;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
protected System.Web.UI.WebControls.CompareValidator CompareValidator2;
protected System.Web.UI.WebControls.Label lblMessage;
private void Page_Load(object sender, System.EventArgs e)
{
#region// 在此处放置用户代码以初始化页面
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.lblMessage .Text = "对不起,该网页属经理专用,请退出!";
this.lblMessage.Visible = true;
}
else
{
//当前员工是部门经理或总经理
this.pnlSearch.Visible = true;
#region//初使化开始时间
if(Request.QueryString["StartTime"] != null)
{
//从Summary.aspx页面中的"进入"转向时,默认为已选中的时间
this.txtStartTime.Text = Request.QueryString["StartTime"].ToString();
}
else
{
//直接从导航"员工记录查询"进入时,默认为一个月前的时间
this.txtStartTime.Text = System.DateTime.Now.AddMonths(-1).ToShortDateString();
}
#endregion
#region//初使化结束时间
if(Request.QueryString["EndTime"] != null)
{
//从Summary.aspx页面中的"进入"转向时,默认为已选中的时间
this.txtEndTime.Text = Request.QueryString["EndTime"].ToString();
}
else
{
//直接从导航"员工记录查询"进入时,默认为当前时间的第二天
this.txtEndTime.Text = System.DateTime.Now.AddDays(1).ToShortDateString();
}
#endregion
//判断当前员工是否为总经理
int iCEOID = 0;
iSuccess = Employee.GetCEOInfo(ref iCEOID);
if(iSuccess ==(int)DBResult.Success)
{
//查询是否为总经理操作成功
if(employee.EmployeeID == iCEOID)
{
//当前登录的员工是总经理,要显示"要查询的部门"
this.lblViewDept.Visible = true;
this.cmbDeptList.Visible = true;
//绑定部门列表和相应的员工列表
this.BindToDeptList();
}
else
{
//当前登录的员工是部门经理,不能显示"要查询的部门"
this.lblViewDept.Visible = false;
this.cmbDeptList.Visible = false;
//获取该经理所在的部门编号
int iDeptID = employee.DeptID;
//绑定该部门的员工列表
this.BindToEmpList(iDeptID);
}
//判断是否为 Summary.aspx 页面转向过来的,如果是,则应显示出历史数据
if(Request.QueryString["DeptID"] != null)
{
//说明是从 Summary.aspx 页面转向过来的,应显示出历史数据
this.QueryIndividHistory();
}
}
else
{
//查询员工信息操作失败
this.lblMessage.Text = "查询员工信息操作失败,请重试";
this.lblMessage.Visible = true;
}
}
}
else
{
//查询员工信息操作失败
this.lblMessage.Text = "查询员工信息操作失败,请重试";
this.lblMessage.Visible = true;
}
}
#endregion
}
/// <summary>
/// 从数据库中获取所有部门的列表,并绑定相应部门的员工列表
/// </summary>
private void BindToDeptList()
{
#region//调用 CheckLvReq.GetDeptList(dsDept) 函数,从数据库中获取所有部门的列表
//设置数据库操作是否正确的标志
int iSuccess;
//创建 DataSet 对象,用来保存部门列表
DataSet dsDept = new DataSet();
//调用 CheckLvReq.GetDeptList(dsDept) 函数,从数据库中获取所有部门的列表,返回操作是否成功标志
iSuccess = DBUtils.CheckLvReq.GetDeptList(ref dsDept);
if(iSuccess == (int)DBResult.Success)
{
//查询部门列表成功
//判断是否有部门信息记录
if(dsDept.Tables[0].Rows.Count >0 )
{
//有部门列表记录
//绑定部门列表到下拉列表框
this.cmbDeptList.DataSource = dsDept.Tables[0].DefaultView;
this.cmbDeptList.DataTextField = "DeptName";
this.cmbDeptList.DataValueField = "DeptID";
this.cmbDeptList.DataBind();
//设置默认选中项
if(Request.QueryString["DeptID"] != null)
{
//从 Summary.aspx 页面中的"进入"时,默认为Summary.aspx 页面已选中的项
this.cmbDeptList.SelectedValue = Request.QueryString["DeptID"].ToString();
}
else
{
//直接导航中"员工记录查询"时,默认选中第一项
this.cmbDeptList.SelectedIndex = 0;
}
//从数据库中获取选中部门的员工列表,并绑定到员工列表下拉框中
//获取选中部门编号
int iDeptID = Convert.ToInt32(this.cmbDeptList.SelectedValue);
//获取选中部门的员工列表
this.BindToEmpList(iDeptID);
}
else
{
//数据库中没有找到部门列表记录
this.lblMessage.Text = "数据库中没有找到部门列表记录,请重试";
this.lblMessage.Visible = true;
//清楚原有的元素
this.cmbDeptList.Items.Clear();
}
}
else
{
//查询部门列表失败
//查询部门列表操作失败
this.lblMessage.Text = "数据库操作失败,请重试";
this.lblMessage.Visible = true;
}
#endregion
}
/// <summary>
/// 从数据库中获取选中部门的员工列表
/// </summary>
private void BindToEmpList(int iDeptID)
{
#region//从数据库中获取选中部门的员工列表
//设置数据库操作是否正确的标志
int iSuccess;
//创建一个 DataSet 对象,保存查询的员工列表
DataSet dsEmployee = new DataSet();
//从数据库中获取选中部门的员工列表,返回操作是否成功标志
iSuccess = DBUtils.CheckLvReq.GetDeptMember(iDeptID,ref dsEmployee);
if(iSuccess == (int)DBResult.Success)
{
//从数据库中查询选中部门的员工列表成功
//判断是否有员工记录
if(dsEmployee.Tables[0].Rows.Count > 0)
{
//数据库中有员工记录
//绑定员工列表到下拉框
this.cmbEmpList.DataSource = dsEmployee.Tables[0].DefaultView;
this.cmbEmpList.DataTextField = "Name";
this.cmbEmpList.DataValueField = "EmployeeID";
this.cmbEmpList.DataBind();
//设置默认选中项
if(Request.QueryString["EmpID"] != null )
{
if(this.cmbEmpList.Items.FindByValue(Request.QueryString["EmpID"].ToString())!=null)
{
//从Summary.aspx页面中的"进入"转向时,默认为已选中项
this.cmbEmpList.SelectedValue = Request.QueryString["EmpID"].ToString();
}
else
{
//部门列表选中项修改时,默认为第一项
this.cmbEmpList.SelectedIndex = 0;
}
}
else
{
//直接从导航"员工记录查询"进入时,默认为第一项
this.cmbEmpList.SelectedIndex = 0;
}
}
else
{
//数据库中没有相应的员工记录
this.lblMessage.Text = "没有任何员工记录,请重试";
this.lblMessage.Visible = true;
//清楚原有元素
this.cmbEmpList.Items.Clear();
}
}
else
{
//从数据库中获取选中部门的员工列表失败
this.lblMessage.Text = "从数据库中获取选中部门的员工列表失败";
this.lblMessage.Visible = true;
}
#endregion
}
/// <summary>
/// 检索数据库中员工请假的历史记录并以 DataGrid 的形式显示返回结果
/// </summary>
private void QueryIndividHistory()
{
//设置时间格式是否正确的标志,默认为真,将字符串转化为时间类型时出错则为 false
bool isTime = true;
//设置一个时间类型变量用于判断时间格式是否正确
DateTime dt = System.DateTime.Now;
//获取员工编号
int iEmpID = Convert.ToInt32(this.cmbEmpList.SelectedValue.Trim());
//获取开始时间
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)
{
//用户输入的时间类型正确
//创建一个 DataSet 对象,保存查询到的结果
DataSet dsResult = new DataSet();
//调用查询员工请假的历史记录的方法,返回数据库操作是否成功的标志,将数据库保存在 DataSet 对象中
int iSuccess = DBUtils.CheckLvReq.QueryIndividHistory(iEmpID,strStartTime,strEndTime,dsResult);
if(iSuccess == (int)DBResult.Success)
{
//数据库操作成功
//判断是否有记录
if(dsResult.Tables[0].Rows.Count > 0)
{
//数据库中有相应的记录
//绑定记录到 DataGrid 对象
this.grdResult.DataSource = dsResult.Tables[0].DefaultView;
this.grdResult.DataBind();
this.grdResult.Visible = true;
this.lblMessage.Visible = false;
}
else
{
//数据库中没有任何记录
this.grdResult.Visible = false;
this.lblMessage.Text = "数据库中没有任何请假记录";
this.lblMessage.Visible = true;
}
}
else
{
//数据库操作失败
this.lblMessage.Text = "数据库操作失败";
this.lblMessage.Visible = true;
}
}
else
{
//用户输入的时间类型错误
this.lblMessage.Text = "请输入正确的时间格式";
this.lblMessage.Visible = true;
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.cmbDeptList.SelectedIndexChanged += new System.EventHandler(this.cmbDeptList_SelectedIndexChanged);
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 cmbDeptList_SelectedIndexChanged(object sender, System.EventArgs e)
{
//部门列表选择项修改时,修改相应的员工列表
//获取部门编号
int iDeptID = Convert.ToInt32(this.cmbDeptList.SelectedValue);
//重新绑定相应部门的员工列表
this.BindToEmpList(iDeptID);
}
/// <summary>
/// 检索数据库中员工请假的历史记录并以 DataGrid 的形式显示返回结果
/// </summary>
/// <param name="sender">发送该事件的对象</param>
/// <param name="e">网页事件的基本参数</param>
private void btnSearch_Click(object sender, System.EventArgs e)
{
this.QueryIndividHistory();
}
private void grdResult_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if(e.CommandName == "Select")
{
//用户单击"详细情况"
//显示请假信息的详细情况
this.pnlDetail.Visible = true;
//审批者姓名
this.lblApproverName.Text = e.Item.Cells[1].Text.ToString();
this.lblApproverName.Visible = true;
//请假事由
this.lblReason.Text = e.Item.Cells[2].Text.ToString();
this.lblReason.Visible = true;
//否决理由
if(e.Item.Cells[7].Text == "已否决")
{
this.lblDeny.Visible = true;
this.lblDenyReason.Visible = true;
this.lblDenyReason.Text = e.Item.Cells[3].Text;
}
else
{
this.lblDeny.Visible = false;
this.lblDenyReason.Visible = false;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -