📄 login.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace tang
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.ImageButton ImageButton2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.Button Button3;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand sqlCommand1;
protected System.Data.SqlClient.SqlCommand sqlCommand2;
protected System.Data.SqlClient.SqlCommand sqlCommand3;
protected System.Data.SqlClient.SqlCommand sqlCommand4;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand2 = new System.Data.SqlClient.SqlCommand();
this.sqlCommand4 = new System.Data.SqlClient.SqlCommand();
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"SUNLIGHT-17F324\";packet size=4096;integrated security=SSPI;data s" +
"ource=\"SUNLIGHT-17F324\";persist security info=False;initial catalog=大型数据库";
//
// sqlCommand1
//
this.sqlCommand1.CommandText = "SELECT 学生编号, 学生密码 FROM 学生信息";
this.sqlCommand1.Connection = this.sqlConnection1;
//
// sqlCommand2
//
this.sqlCommand2.CommandText = "SELECT 管理人员编号, 管理人员密码 FROM 实验室管理人员";
this.sqlCommand2.Connection = this.sqlConnection1;
//
// sqlCommand4
//
this.sqlCommand4.CommandText = "SELECT 授课教师编号, 授课教师密码 FROM 授课教师信息";
this.sqlCommand4.Connection = this.sqlConnection1;
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
System.Data.SqlClient.SqlDataReader sdr;
sqlConnection1.Open();
if(RadioButtonList1.SelectedIndex==0)
sdr=sqlCommand1.ExecuteReader();
else
if(RadioButtonList1.SelectedIndex==1)
sdr=sqlCommand2.ExecuteReader();
else
sdr=sqlCommand4.ExecuteReader();
while(sdr.Read())
{
if(TextBox1.Text==sdr.GetValue(0).ToString()&&TextBox2.Text==sdr.GetValue(1).ToString())
{
Session["username"]=sdr.GetValue(0).ToString();
Session["password"]=sdr.GetValue(1).ToString();
if(RadioButtonList1.SelectedIndex==0)
Response.Redirect("admin1.aspx");
else
if(RadioButtonList1.SelectedIndex==1)
{
if(Session["username"].ToString()=="admin1")
Response.Redirect("guanliyuan.aspx");
else
Response.Redirect("admin2.aspx");
}
else
Response.Redirect("admin3.aspx");
}
}
if(!sdr.Read())
Label2.Text="不能验证,请确认帐号密码正确!";
sdr.Close();
sqlConnection1.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm1.aspx");
}
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("jiaoshizhuce.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -