📄 default.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;
using System.Data.SqlClient;
public partial class Default : System.Web.UI.Page
{
Datacon dataconn = new Datacon();
protected void Page_Load(object sender, EventArgs e)
{
Session["StuName"] = this.txtUserName.Text;
if (!IsPostBack)
{
Random rnd = new Random();
//生成验证码
this.labValidate.Text = rnd.Next(1000,9999).ToString();
}
}
//==============================找回密码=========================
protected void Button3_Click(object sender, EventArgs e)
{
Page.Response.Redirect("InfoPwd.aspx");
}
//==============================新学生注册=========================
protected void Button2_Click(object sender, EventArgs e)
{
Page.Response.Redirect("zhuce.aspx");
}
//==============================登录按钮=========================
protected void Button1_Click(object sender, EventArgs e)
{
if (txtValidate.Text != labValidate.Text)
{
Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
}
else
{
if (cblAdminLog.Items[0].Selected == true)
{
this.getcom(1);
}
else
{
this.getcom(2);
}
}
}
//==============================登录控制============================
private void getcom(int i)
{
SqlConnection con = dataconn.getcon();
con.Open();
SqlCommand com=con.CreateCommand();
switch (i)
{
case 1:
com.CommandText = "select count(*) from tb_Administrator where Name='" + txtUserName.Text + "' and PWD='" + txtPwd.Text + "'";
int count1 = Convert.ToInt32(com.ExecuteScalar());//获取SQL语句的值 强制转换成数值类型
if (count1 > 0)
{
Application["Name"] = txtUserName.Text;//成功
Application["PWD"] = txtPwd.Text;//成功
Page.Response.Redirect("HouAdmin/admin.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>");
return;
}
break;
case 2:
com.CommandText = "select count(*) from tb_Student where ID='" + txtUserName.Text + "' and PWD='" + txtPwd.Text + "'";
int count2 = Convert.ToInt32(com.ExecuteScalar());
if (count2 > 0)
{
Application["ID"] = txtUserName.Text;
Application["PWD"] = txtPwd.Text;
Page.Response.Redirect("QianUser/zaixian_kaoshi.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>");
return;
}
break;
}
con.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -