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 kyxz.Users
{
/// <summary>
/// Regist 的摘要说明。
/// </summary>
public class Regist : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator6;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator3;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator4;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator5;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Button Button4;
//判断用户号码是否合法的标志量
private bool flag=false;
//------------------------------------------------------------------------------------------
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.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//-------------------------------重置,初始化各项------------------------------------------
private void Button2_Click(object sender, System.EventArgs e)
{
//用户号码
TextBox1.Text ="";
//用户昵称
TextBox2.Text ="";
//用户密码
TextBox3.Text ="";
//确认密码
TextBox4.Text ="";
//问题答案
TextBox5.Text ="";
//email地址
TextBox6.Text ="";
//验证问题
DropDownList1.SelectedValue="我最喜欢的电影?";
}
//-------------------------------------注册按钮-----------------------------------------
private void Button1_Click(object sender, System.EventArgs e)
{
string id,name,password,question,answer,email;
string sqlstr;
bool flag;
//用户号码
id=TextBox1.Text ;
//用户昵称
name=TextBox2.Text ;
//用户密码
password=TextBox3.Text ;
//问题答案
answer=TextBox5.Text ;
//email地址
email=TextBox6.Text ;
//验证问题
question=DropDownList1.SelectedValue;
//执行插入记录,并返回是否执行成功,true为成功,false为失败
sqlstr="insert into users(u_id,u_name,u_password,u_money,u_ch_q,u_ch_a,u_date,u_email) values ('";
sqlstr=sqlstr+id+"','"+name+"','"+password+"',0,'"+question+"','"+answer+"','"+DateTime.Now+"','"+email+"')";
Db conn=new Db ();
flag=conn.SqlExecution(sqlstr);
//注册成功
if(flag)
{
Response.Write ("<script>alert('注册成功!')</script>");
}
//注册失败
else
Response.Write ("<script>alert('注册失败!')</script>");
}
//------------------------------检测用户号码是否已被使用---------------------------------------
private void Button3_Click(object sender, System.EventArgs e)
{
//查询用户记录
Db conn=new Db ();
string id=TextBox1.Text;
if(id.Length >5 && id.Length <11)
{
if(!flag)
{
Response.Write ("<script>alert('该用户号码无效,请检查您是否输入正确!')</script>");
}
else
{
string sqlstr;
sqlstr="select u_id from users where u_id='"+id+"'";
DataSet users=conn.Select(sqlstr,"used");
//若记录不为空,则已有相同的用户号码注册过
if(users.Tables ["used"].Rows .Count!=0)
Response.Write ("<script>alert('该用户号码已被使用!')</script>");
//若为空,则该用户号码尚未被注册
else
Response.Write ("<script>alert('该用户号码未被使用!')</script>");
}
}
else
Response.Write ("<script>alert('该用户号码无效,请检查您是否输入正确!')</script>");
}
//----------------------------输入的用户号码是否是字母或数字---------------------------------
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(char.IsLetter(e.KeyChar)||char.IsNumber(e.KeyChar))
{
flag=true;
}
}
//------------------------------------用户登录界面-------------------------------------------
private void Button4_Click(object sender, System.EventArgs e)
{
Response.Redirect ("Login.aspx");
}
//-------------------------------------------------------------------------------------------
}
}
这是我写的,你可以参考一下,功能不是很全,但其他的也类似,你自己可以再加