下面是全源码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
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.Web.Security;
namespace mybook
{
/// <summary>
/// user 的摘要说明。
/// </summary>
public class usereg : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox email;
protected System.Web.UI.WebControls.TextBox age;
protected System.Web.UI.WebControls.DropDownList sex;
protected System.Web.UI.WebControls.TextBox oicq;
protected System.Web.UI.WebControls.TextBox hostpage;
protected System.Web.UI.WebControls.Button Button;
protected System.Web.UI.HtmlControls.HtmlForm reg1;
protected System.Web.UI.WebControls.TextBox email1;
protected System.Web.UI.HtmlControls.HtmlGenericControl pageerr;
protected System.Web.UI.HtmlControls.HtmlGenericControl userreg;
protected System.Web.UI.WebControls.TextBox mypwd;
protected System.Web.UI.WebControls.TextBox mypwda;
config obj = new config();
OleDbCommand mycommand;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_userid02;
protected System.Web.UI.WebControls.TextBox userid;
protected System.Web.UI.WebControls.RequiredFieldValidator chk_userid01;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_userid03;
protected System.Web.UI.WebControls.RequiredFieldValidator chk_mypwd01;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_mypwd02;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_mypwd03;
protected System.Web.UI.WebControls.RequiredFieldValidator chk_mypwda01;
protected System.Web.UI.WebControls.CompareValidator chk_mypwda02;
protected System.Web.UI.WebControls.RequiredFieldValidator chk_email01;
protected System.Web.UI.WebControls.RegularExpressionValidator chk_email02;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.CompareValidator Comparevalidator2;
protected System.Web.UI.WebControls.ValidationSummary chkall;
OleDbDataReader rs;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面reg1
userreg.Visible=true;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button.Click += new System.EventHandler(this.Button_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
obj.dataopen();
//检查用户是否已经被注册
mycommand=new OleDbCommand("select uid from [user] where uid='"+ userid.Text +"'",obj.mdbconn);
rs=mycommand.ExecuteReader();
if(rs.Read())
{
obj.mdbconn.Close();
userreg.Visible=false;
pageerr.InnerHtml="<br><br><br><br><br><br><br><pre><font color=red><b>注册出错!!</b></font> 你所注册的用户帐号已经存在,请换名重试!</pre><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
return;
}
rs.Close();
//检查用户EMAIL是否已经被注册
mycommand=new OleDbCommand("select uid from [user] where email='"+ email.Text+"'",obj.mdbconn);
rs=mycommand.ExecuteReader();
if(rs.Read())
{
obj.mdbconn.Close();
userreg.Visible=false;
pageerr.InnerHtml="<br><br><br><br><br><br><br><pre><font color=red><b>注册出错!!</b></font> 该Email地址已经被注册,请换一个重试!</pre><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
return;
}
rs.Close();
//提交用户,对用户密码和提示答案加密
string a_password=FormsAuthentication.HashPasswordForStoringInConfigFile(mypwd.Text,"md5");
//开始将用户注册资料添加入库
string sql="insert into [user](uid,pass,email,sex,age,oicq,hostpage,sendtime)"+
"values('"+userid.Text+"','"+a_password+"','"+email.Text+"','"+sex.SelectedItem.Text+"','"+age.Text+"','"+oicq.Text+"','"+hostpage.Text+"','"+DateTime.Now+"')";
mycommand=new OleDbCommand(sql,obj.mdbconn);
mycommand.ExecuteNonQuery();
//obj.mdbconn.Close();
//注册成功,出现提示页面。
pageerr.InnerHtml="<br><br><br><br><br><br><br><pre><font color=red><b>恭喜你!!</b></font>你已经在本站注册成功,你现在就可以在线定购我们的服务了<br><br>你可以看看服务定购流程,以便给你更好的服务!!</pre><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
userreg.Visible=false;
}
mycommand.Dispose();
obj.mdbconn.Close();
obj.mdbconn.Dispose();
}
}
}