📄 login.aspx.cs
字号:
using System;
using System.Data;
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 Login : System.Web.UI.Page
{
//定义变量TypeValues来保存代表用户身份的值(0代表管理员,1代表工程师,2代表普通用户,3表示用户没有选择身份登录,该用户将无法登录)
public int TypeValues;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlType.Items.Add(new ListItem("请选择身份"));//通过代码给DropDownList添加项
this.ddlType.Items.Add(new ListItem("管理员"));
this.ddlType.Items.Add(new ListItem("工程师"));
this.ddlType.Items.Add(new ListItem("普通员工"));
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string UserName=this.txtUserName.Text.Trim();
string Password=this.txtPassord.Text.Trim();
if (this.ddlType.SelectedValue == "管理员")
{
TypeValues = 0;
}
if (this.ddlType.SelectedValue == "工程师")
{
TypeValues = 1;
}
if (this.ddlType.SelectedValue == "普通员工")
{
TypeValues = 2;
}
if (this.ddlType.SelectedValue == "请选择身份")
{
TypeValues = 3;
}
if (Operation.FindPeople(UserName, Password, TypeValues))//通过调用FindPeople方法判断用户是否通过身份验证
{
Session["flag"] = true;//用来标识用户登录成功
Session["UserName"] = this.txtUserName.Text.Trim();//使用Session["UserName"]来保存用户名
Session["TypeValues"] = TypeValues;//使用Session["UserName"]来保存登录身份
Session["UserID"] = Operation.UserID;//使用 Session["UserID"]来保存用户ID
Response.Redirect("Pages/Index.aspx");//跳转到主页
}
else
{
Response.Write("<script>alert('登录失败!请返回查找原因');location='Login.aspx'</script>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -