📄 summary.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>
/// Summary 的摘要说明。
/// </summary>
public class Summary : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel pnlSearch;
protected System.Web.UI.WebControls.DataGrid grdResult;
protected System.Web.UI.WebControls.TextBox txtStartTime;
protected System.Web.UI.WebControls.TextBox txtEndTime;
protected System.Web.UI.WebControls.DropDownList cmbDeptList;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.Label lblDeptView;
protected System.Web.UI.WebControls.Label lblDeptID;
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;
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.lblDeptView.Visible = true;
this.cmbDeptList.Visible = true;
//绑定部门列表,以供查询选择的部门
//创建 DataSet 对象,用来保存部门列表
DataSet dsDept = new DataSet();
//查询部门列表,并判断是否查询成功
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.lblMessage.Text = "数据库操作失败,请重试";
this.lblMessage.Visible = true;
}
}
else
{
//当前员工是部门经理,没有权限查看其他部门的信息
this.lblDeptView.Visible = false;
this.cmbDeptList.Visible = false;
//获取部门经理所在的部门编号
this.lblDeptID.Text = employee.DeptID.ToString();
this.lblDeptID.Visible = false;
}
}
else
{
//查询是否为总经理操作失败
this.lblMessage.Text = "数据库操作失败,请重试";
this.lblMessage.Visible = true;
}
}
}
else
{
//查询员工信息操作失败
this.lblMessage.Text = "数据库操作失败,请重试";
this.lblMessage.Visible = true;
}
}
#endregion
}
#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)
{
#region//检索数据库中的部门汇总请假信息并以 DataGrid 的形式显示返回结果
//设置时间格式是否正确的标志,默认为真,将字符串转化为时间类型时出错则为 false
bool isTime = true;
//设置一个时间类型变量用于判断时间格式是否正确
DateTime dt = System.DateTime.Now;
//获取部门编号
int iDeptID = 0;
if(this.lblDeptID.Text != "")
{
//当前员工是部门经理,只能查询其部门的员工信息
iDeptID = Convert.ToInt32(this.lblDeptID.Text.Trim());
}
else
{
//当前员工是总经理,可查询其选择的部门中的员工信息
iDeptID = Convert.ToInt32(this.cmbDeptList.SelectedValue);
}
//获取查询的开始时间
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();
//查询部门汇总请假信息,返回数据库操作是否成功
int iSuccess = DBUtils.CheckLvReq.DeptSummary(iDeptID,strStartTime,strEndTime,ref dsResult);
if(iSuccess == (int)DBResult.Success)
{
//查询部门汇总请假信息操作成功
//判断是否有查询记录
if(dsResult.Tables[0].Rows.Count > 0)
{
//有查询记录,绑定到 DataGrid 控件
this.grdResult.DataSource = dsResult.Tables[0].DefaultView;
this.grdResult.DataBind();
//显示 DataGrid 控件
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;
}
#endregion
}
private void grdResult_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//当用户单击 DataGrid 中的“进入”链接时,该方法将网页跳转到“员工查询网页”来显示该员工请假明细。
if(e.CommandName == "Select")
{
//设置时间格式是否正确的标志,默认为真,将字符串转化为时间类型时出错则为 false
bool isTime = true;
//设置一个时间类型变量用于判断时间格式是否正确
DateTime dt = System.DateTime.Now;
//获取部门编号
string strDeptID = e.Item.Cells[0].Text.Trim();
//获取员工编号
string strEmpID = e.Item.Cells[1].Text.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)
{
//用户输入的时间格式正确
//根据获得的参数转向 "员工记录查询" 页面
string url = "Individual.aspx?DeptID=" + strDeptID + "&EmpID=" + strEmpID + "&StartTime=" + strStartTime + "&EndTime=" + strEndTime;
Response.Redirect(url);
}
else
{
//用户输入的时间格式不正确,给出提示信息
this.lblMessage.Text = "时间格式不正确,请重新输入";
this.lblMessage.Visible = true;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -