searchemp.aspx.cs
来自「该管理系统的主要功能是管理员工资料、管理员工考勤、计算员工薪资和业绩评定等。大部」· CS 代码 · 共 148 行
CS
148 行
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.EmployeeInfo
{
/// <summary>
/// SearchEmp 的摘要说明。
/// </summary>
public class SearchEmp : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtKey;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.Label lblNoResult;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Panel pnlResult;
protected System.Web.UI.WebControls.DataGrid grdResult;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//网页初始化时执行该方法。根据网页 URL 中的部门编号信息,显示该部门的所有员工
//该过程调用 EmployeeInfo.SearchEmpByDept(iDeptID, dsResult) 函数
if(!this.Page.IsPostBack)
{
//按 部门编号 查询员工信息
if(Request.QueryString["DeptID"] != null)
{
int iDeptID = Convert.ToInt32(Request.QueryString["DeptID"]);
//定义一个 DataSet 对象,用来存储查询到的数据集
DataSet dsResult = new DataSet();
//执行 按部门编号 查询员工操作,并返回操作是否成功
int iRetValue = DBUtils.EmployeeInfo.SearchEmpByDept(iDeptID,ref dsResult);
if(iRetValue == (int )DBResult.Success )
{
//数据库查询操作成功
this.pnlResult.Visible = true;
this.grdResult.Visible = true;
//绑定数据到页面上
this.grdResult.DataSource = dsResult.Tables["EmployeeInfo"].DefaultView;
this.grdResult.DataBind();
}
else
{
//数据库查询操作失败
this.lblNoResult.Visible = true;
}
}
}
}
#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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSearch_Click(object sender, System.EventArgs e)
{
//该方法将按用户输入查找数据库中符合条件的记录并显示
//该过程调用 EmployeeInfo.SearchEmpByKey(txtKey.Text.Trim(), dsResult) 函数
//在加载信息前,先清除以前的数据
this.grdResult.DataSource = null;
//创建关键字字符串
string strKey = this.txtKey.Text.Trim();
//定义一个 DataSet 对象用来存放查询到的数据集
DataSet dsResult = new DataSet();
//设置查询操作成功与否的标志,1表示成功,0表示失败
int iRetValue = (int)DBResult.Success;
//执行查询操作,并返回操作成功与否
iRetValue = DBUtils.EmployeeInfo.SearchEmpByKey(strKey,ref dsResult);
if(iRetValue == 1)
{
//数据库查询成功
if(dsResult.Tables["EmployeeInfo"].Rows.Count == 0 )
{
//没有查询到任何记录
this.lblNoResult.Visible = true;
}
else
{
if(dsResult.Tables["EmployeeInfo"].Rows.Count == 1)
{
//只有一条记录,则直接跳转到员工资料页
//记录员工编号
string strEmpID = dsResult.Tables["EmployeeInfo"].Rows[0]["EmployeeID"].ToString();
//跳转到员工资料页
Response.Redirect("ShowEmpInfo.aspx?EmpID=" + strEmpID );
}
else
{
//有多条数据,在 grdResult 列举出来
this.grdResult.DataSource = dsResult.Tables["EmployeeInfo"].DefaultView;
this.grdResult.DataBind();
this.pnlResult.Visible = true;
this.grdResult.Visible = true;
}
}
}
else
{
//数据库查询失败
this.lblNoResult.Visible = true;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?