📄 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 BackDesk_Login_Login : System.Web.UI.Page
{
DataCon myCon = new DataCon();
ValidateCode code = new ValidateCode();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
labValidateCode.Text = code.validateCode().ToString();
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
Session["UserID"] = txtUserID.Text;//给DeliverCard.aspx页传值
Session["Name"] = txtUserName.Text;//给Index.aspx页传值
if(txtValidateCode.Text.Trim()!=labValidateCode.Text.Trim())
{
Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
}
else
{
SqlConnection sqlconn = myCon.getCon();
sqlconn.Open();
SqlCommand sqlcom = sqlconn.CreateCommand();
if (cbAdminLogin.Checked == true)
{
sqlcom.CommandText = "select count(*) from tb_Admin where AdminID='" + txtUserID.Text
+ "' and AdminName='" + txtUserName.Text + "' and AdminPwd='" + txtPassword.Text + "'";
int countAdmin = Convert.ToInt32(sqlcom.ExecuteScalar());//获取SQL语句的值 强制转换成数值类型
if (countAdmin > 0)
{
Page.Response.Redirect("AdminLogined.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>");
return;
}
}
else
{
sqlcom.CommandText = "select count(*) from tb_User where UserID='" + txtUserID.Text
+ "'and UserLoginName='" + txtUserName.Text + "'and UserPwd='" + txtPassword.Text + "'";
int countUser = Convert.ToInt32(sqlcom.ExecuteScalar());
if (countUser > 0)
{
Page.Response.Redirect("UserLogined.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>");
return;
}
}
sqlconn.Close();
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
txtUserID.Text = "";
txtUserName.Text = "";
txtPassword.Text = "";
txtValidateCode.Text = "";
txtUserID.Focus();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -