📄 findemployee.aspx.cs
字号:
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class FindEmployee : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridViewAllEmployee.Visible = false;
NoRecord.Visible = false;
}
protected void SearchAllEmployee(string name)
{
String strconn = System.Configuration.ConfigurationManager.AppSettings["SQLCONNECTION"];
SqlConnection myconn = new SqlConnection(strconn);
String strsql = "SELECT EmployeeID,Name,LoginName,Email,tblEmployee.DeptID,DeptName FROM tblEmployee," +
"tblDepartment WHERE tblEmployee.DeptID = tblDepartment.DeptID AND Name LIKE '" + "%" + name + "%'";
SqlCommand dbCommand = new SqlCommand(strsql, myconn);
myconn.Open();
SqlDataReader dsEmployee = dbCommand.ExecuteReader();
GridViewAllEmployee.DataSource = dsEmployee;
GridViewAllEmployee.Visible = true;
GridViewAllEmployee.DataBind();
if (GridViewAllEmployee.Rows.Count == 0)
{
GridViewAllEmployee.Visible = false;
NoRecord.Visible = true;
}
myconn.Close();
}
protected void SearchOneDeptEmployee(string deptid)
{
String strconn = System.Configuration.ConfigurationManager.AppSettings["SQLCONNECTION"];
SqlConnection myconn = new SqlConnection(strconn);
String strsql = "SELECT EmployeeID,Name,LoginName,Email,tblEmployee.DeptID,DeptName FROM tblEmployee," +
"tblDepartment WHERE tblEmployee.DeptID = tblDepartment.DeptID AND tblEmployee.DeptID = '" + deptid.ToString() + "'";
SqlCommand dbCommand = new SqlCommand(strsql, myconn);
myconn.Open();
SqlDataReader dsEmployee = dbCommand.ExecuteReader();
GridViewAllEmployee.DataSource = dsEmployee;
GridViewAllEmployee.Visible = true;
GridViewAllEmployee.DataBind();
myconn.Close();
}
protected void AllEmployee_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ShowOneDept")
{
SearchOneDeptEmployee(e.CommandArgument.ToString());
}
else if (e.CommandName == "ShowOneInfo")
{
string url;
url = "ShowEmployeeInfo.aspx?id=" + e.CommandArgument.ToString();
Response.Redirect(url);
}
}
protected void ButtonSearch_Click(object sender, EventArgs e)
{
if(TextBoxName.Text!="")
SearchAllEmployee(TextBoxName.Text);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -