📄 login.aspx.cs
字号:
using System;
using System.Data;
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 Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public int IS_Login(string loginName,string passWord)
{
string strConn = System.Configuration.ConfigurationManager.AppSettings["SQLCONNECTION"];
string strSql = "Select * from tblEmployee where LoginName = '" + loginName + "'";
SqlConnection myConn = new SqlConnection(strConn);
SqlCommand myCmd = new SqlCommand(strSql, myConn);
myConn.Open();
SqlDataReader myDrd = myCmd.ExecuteReader();
while (myDrd.Read())
{
if (myDrd["LoginName"].ToString() == loginName)
{//将必要信息记录在Session对象里,之后的操作要用到
if (myDrd["PassWord"].ToString() == passWord)
{
Session["LoginName"] = myDrd["LoginName"].ToString();
Session["Name"] = myDrd["Name"].ToString();
Session["EmployeeID"] = myDrd["EmployeeID"].ToString();
Session["EmployeeLevel"] = myDrd["EmployeeLevel"].ToString();
Session["DeptID"] = myDrd["DeptID"].ToString();
return 1;
}
else
{
return 2;
}
}
}
return 3;
}
protected void LoginOK_Click(object sender, EventArgs e)
{
int flag = IS_Login(LoginName.Text, PassWd.Text);
if (1 == flag)
Response.Redirect("Main.aspx");//如果登陆路成功,跳转页面
else if (2 == flag)
LabelFail.Text = "该用户存在,但密码错误";
else
LabelFail.Text = "该用户不存在";
//Response.Redirect("LoginFail.aspx");
}
protected void Clear_Click(object sender, EventArgs e)
{
LoginName.Text = "";
PassWd.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -