📄 login.aspx.cs
字号:
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 WebApplication8
{
/// <summary>
/// login 的摘要说明。
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ImageButton log;
protected System.Web.UI.WebControls.ImageButton reg;
protected System.Web.UI.HtmlControls.HtmlInputText userName;
protected System.Web.UI.HtmlControls.HtmlInputText password;
protected System.Data.SqlClient.SqlConnection logConnection;
protected System.Data.SqlClient.SqlCommand logCommand;
protected System.Web.UI.WebControls.Label mistake;
protected System.Web.UI.WebControls.RadioButtonList type;
SqlDataReader reader;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Session.Clear();
logConnection.Open();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.logConnection = new System.Data.SqlClient.SqlConnection();
this.logCommand = new System.Data.SqlClient.SqlCommand();
this.log.Click += new System.Web.UI.ImageClickEventHandler(this.log_Click);
this.reg.Click += new System.Web.UI.ImageClickEventHandler(this.reg_Click);
//
// logcommand
//
this.logConnection.ConnectionString = Application["market"].ToString();
this.logCommand.Connection = this.logConnection;
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void log_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(type.SelectedValue == "个人")
{
logCommand.CommandText = "select * from Single where userName='"+userName.Value+"' and password='"+password.Value+"' and type='个人'";
reader = logCommand.ExecuteReader();
if(reader.Read())
{
Session["type"] = "个人";
Session["studentNO"] = reader["studentNO"];
Session["userName"] = reader["userName"];
logConnection.Close();
Response.Redirect("firstPage/index.aspx");
}
else
{
reader.Close();
logConnection.Close();
Response.Write("<script language=javascript>alert('输入的用户名或者密码错误!');this.location.href='login.aspx';</script>");
}
}
if(type.SelectedValue == "企业")
{
logCommand.CommandText = "select * from Company where userName='"+userName.Value+"' and password='"+password.Value+"'";
reader = logCommand.ExecuteReader();
if(reader.Read())
{
Session["type"] = "企业";
Session["studentNO"] = reader["studentNO"];
Session["userName"] = reader["userName"];
Session["comName"] = reader["comName"];
logConnection.Close();
Response.Redirect("firstPage/index.aspx");
}
else
{
reader.Close();
logConnection.Close();
Response.Write("<script language=javascript>alert('输入的用户名或者密码错误!');this.location.href='login.aspx';</script>");
}
}
if(type.SelectedValue == "管理员")
{
logCommand.CommandText = "select * from Administrator where userName='"+userName.Value+"' and password='"+password.Value+"' and type='网站管理员'";
reader = logCommand.ExecuteReader();
if(reader.Read())
{
Session["type"] = "管理员";
Session["userName"] = reader["userName"];
logConnection.Close();
Response.Redirect("admin/classManage.aspx");//此处中转到管理员的页面
}
else
{
logConnection.Close();
reader.Close();
Response.Write("<script language=javascript>alert('输入的用户名或者密码错误!');this.location.href='login.aspx';</script>");
}
}
}
private void reg_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(type.SelectedValue == "个人")
{
Response.Redirect("firstPage/applySingle.aspx");
}
if(type.SelectedValue == "企业")
{
Response.Redirect("firstPage/applyEnterprise.aspx");
}
logConnection.Close();
mistake.Text = "管理员的不受理申请请求!";
mistake.Visible = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -