制作SQLHelper类完成登陆注册

login登陆页:

login.aspx页代码:

<head runat="server">
<title></title>
<style type="text/css">
.red
{
color:Red;
}
</style>
</head>

<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>用户名:</td>
<td>
<asp:TextBox ID="txtUserName"

runat="server"></asp:TextBox>
</td>
<td>
<span class="red">*</span>
</td>
</tr>
<tr>
<td>密&nbsp;码</td>
<td>
<asp:TextBox ID="txtPassword"

runat="server"></asp:TextBox></td>
<td><span class="red">*</span></td></tr>

<tr><td>
<asp:Button ID="btnLogin" runat="server" Text="登陆"

Xοnclick="btnLogin_Click" /></td>
<td>&nbsp<asp:Button ID="btnRegister" runat="server"

Text="注册"
Xοnclick="btnRegister_Click" /></td>
<td>
</td>

</tr>


</table>
<asp:Label ID="lblErrorMessage" runat="server" Text=""

></asp:Label>

</div>
</form>
</body>
</html>

login.aspx.cs页代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace Web1017.lianxi
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnLogin_Click(object sender, EventArgs e)
{
string username = txtUserName.Text;
string password = txtPassword.Text;
string connStr = "data source=PPT-

20120822JRP;database=Net;integrated security=true";

//string connStr = "Data Source=PPT-

20120822JRP;Initial Catalog=Net;Persist Security Info=Ture;User

ID=sa;Password=admin";
using (SqlConnection conn = new SqlConnection

(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from T_User where

UserName=@name";
cmd.Parameters.Add(new SqlParameter("@name",

username));
SqlDataReader reader = cmd.ExecuteReader();


//cmd.ExecuteScalar();
if (reader.Read() == true)
{
string pwd = reader.GetString

(reader.GetOrdinal("Password"));
if (pwd == password)
{
this.lblErrorMessage.Visible = false;
Response.Redirect

("~/lianxi/Welcom.aspx");
}

else
{
this.lblErrorMessage.Visible = true;
this.lblErrorMessage.Text = "密码错

误";
}


}
else
{
this.lblErrorMessage.Visible = true;
this.lblErrorMessage.Text = "用户名不存在

!";
}
}
}
//SqlConnection conn = new SqlConnection(connStr);
//conn.Open();
//SqlCommand cmd = conn.CreateCommand();

}

protected void btnRegister_Click(object sender, EventArgs

e)
{
Response.Redirect("注册页面.aspx");

}
}
}


registor注册页

注册页面.aspx代码


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 186px; width: 649px">

<asp:Label ID="Label1" runat="server" Text="用户

名:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"

runat="server"
ControlToValidate="TextBox1" ErrorMessage="用户名不能

为空" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
密&nbsp;&nbsp;码:&nbsp;&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"

runat="server"
ControlToValidate="TextBox1" ErrorMessage="密码不能为

空" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />
&nbsp;Email :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"

runat="server"
ControlToValidate="TextBox3" ErrorMessage="email不能为

空" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;
<asp:Button ID="Button1" runat="server"

Xοnclick="Button1_Click" Text="注册"
Height="29px" Width="66px" />
<br />

</div>
</form>

</body>
</html>


注册页面.aspx.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace Web1017.lianxi
{
public partial class 注册页面 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
string username = TextBox1.Text;
string password = TextBox2.Text;
string emaile = TextBox3.Text;
string connStr = "data source=PPT-

20120822JRP;database=Net;integrated security=true";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into T_User (UserName,Password,Email)

values (@name,@pwd,@email)";
cmd.Parameters.Add(new SqlParameter("@name", username));
cmd.Parameters.Add(new SqlParameter("@pwd", password));
cmd.Parameters.Add(new SqlParameter("@email", emaile));
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("注册成功");

}
}
}

welcome 欢迎页

welcome.aspx的代码

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
欢迎来到此地!

</div>
</form>
</body>
</html>

welcome.aspx.cs的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _10_17.数据库建立
{
public partial class welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

}
}
protected void Page_UnLoad(object sender, EventArgs e)
{

}

}

showMsg页代码
showMsg.aspx代码


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
setTimeout(function () {
location.href = '<%=Request["RedirectURL"]%>';

},3000);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbl" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>


showMsg.aspx.cs代码


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _1017
public partial class 成功 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbl.Text = Request["Msg"];
}
}
}


Global.asax.cs的设计
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace _1017
{
public class Global : System.Web.HttpApplication
{

protected void Application_Start(object sender, EventArgs e)
{

}

protected void Session_Start(object sender, EventArgs e)
{
Session["login"] = false;
Session.Timeout = 1;
}

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{

}

protected void Application_Error(object sender, EventArgs e)
{

}

protected void Session_End(object sender, EventArgs e)
{
Session.Clear();
}

protected void Application_End(object sender, EventArgs e)
{

}
}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值