login.aspx.cs
来自「图书馆的书目查询」· CS 代码 · 共 107 行
CS
107 行
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;
using System.Data.SqlClient;
namespace Library_BS
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class Login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.TextBox TextBox1;
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.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(connStr);
string checkStr = "select count(*) from 读者信息 where (注册名='"+ TextBox1.Text+"')";
SqlCommand myCommand = new SqlCommand(checkStr, myConnection);
string checkPwd = "select 密码 from 读者信息 where(注册名='"+ TextBox1.Text+"')";
SqlCommand myCommand1 = new SqlCommand(checkPwd, myConnection);
myConnection.Open();
int flag = (int)myCommand.ExecuteScalar();
if(flag == 0)
{
Response.Write("该注册名不存在");
}
else
{
if(TextBox3.Text != (myCommand1.ExecuteScalar()).ToString())
{
Response.Write("密码错误");
}
else
{
Response.Redirect("LoginOK.aspx?Register="+TextBox1.Text);
}
}
myConnection.Close();
}
private void Button2_Click(object sender, System.EventArgs e)
{
UserDB userDb = new UserDB();
int errorCode=0;
errorCode = userDb.UserRegister(TextBox2.Text);
if(2 == errorCode) Response.Write("该证号不存在");
if(1 == errorCode) Response.Write("已注册用户");
if(0 == errorCode)
{
Response.Redirect("Register.aspx?UserID="+this.TextBox2.Text);
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?