📄 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)
{
this.Title = "登录系统";
txtUserName.Focus();
}
//==============================找回密码=========================
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 (Request.Cookies["CheckCode"] == null)
{
Response.Write("<script lanuage=javascript>alert('您的浏览器设置已被禁用 Cookies,您必须设置浏览器允许使用 Cookies 选项后才能使用本系统。');location='javascript:history.go(-1)'</script>");
}
else
{
if (String.Compare(Request.Cookies["checkcode"].Value, txtValidate.Text, true) != 0)
{
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 users where User_id='" + txtUserName.Text + "' and User_Password='" + txtPwd.Text + "'";
int count1 = Convert.ToInt32(com.ExecuteScalar());//获取SQL语句的值 强制转换成数值类型
if (count1 > 0)
{
Session.Add("UserID", txtUserName.Text);
Session.Add("Power", "1");
Page.Response.Redirect("teacher/admin.aspx");
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>");
return;
}
break;
case 2:
com.CommandText = "select count(*) from stu where stu_name='" + txtUserName.Text + "' and stu_Password='" + txtPwd.Text + "'";
int count2 = Convert.ToInt32(com.ExecuteScalar());
if (count2 > 0)
{
Session.Add("UserID", txtUserName.Text);
Session.Add("Power", "0");
Page.Response.Redirect("stu/stu.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 + -