📄 regist.aspx.cs
字号:
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;
using da;
using System.Web.Mail;
namespace bbs
{
/// <summary>
/// reg 的摘要说明。
/// </summary>
public class regist : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button_reg;
protected System.Web.UI.WebControls.TextBox TextBox_username;
protected System.Web.UI.WebControls.TextBox TextBox_pwd;
protected System.Web.UI.WebControls.TextBox TextBox_Rpwd;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.TextBox TextBox_introduce;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList_sex;
protected System.Web.UI.WebControls.Literal Literal_pwd;
protected System.Web.UI.WebControls.Literal Literal_name;
protected System.Web.UI.WebControls.TextBox TextBox_question;
protected System.Web.UI.WebControls.TextBox TextBox_answer;
protected System.Web.UI.WebControls.TextBox TextBox_email;
private void Page_Load(object sender, System.EventArgs e)
{
this.Panel1.Visible=false;
string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
if(!Page.IsPostBack)
{
this.MyDataBind();
}
}
private void MyDataBind()
{
string sqlstr = "select * from users where UserName="+this.TextBox_username.Text;
da.da d = new da.da();
DataSet ds = d.Select(sqlstr,"users");
if(ds !=null)
{
Response.Write("用户名已存在");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.Button_reg.Click += new System.EventHandler(this.Button_reg_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void LinkButton1_Click(object sender, System.EventArgs e)
{
this.Panel1.Visible=true;
}
private void Button_reg_Click(object sender, System.EventArgs e)
{
string ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
string sqlstr="select count(*) from users where username='"+this.TextBox_username.Text+"'";
SqlConnection Myconn = new SqlConnection(ConnectionString);
SqlCommand Mycmd=new SqlCommand(sqlstr,Myconn);
try
{
if(Myconn.State!=ConnectionState.Open)
{
Myconn.Open();
}
int count=Convert.ToInt32(Mycmd.ExecuteScalar());
if(count>0)
{
this.Literal_name.Text="该用户已经存在,请重试!";
}
else if (this.TextBox_pwd.Text!=this.TextBox_Rpwd.Text)
{
this.Literal_pwd.Text="两次输入密码不一致,请重新输入!";
return ;
}
else
{
string sql="insert into users(username,pwd,semail,sSex,sBbSquestion,sBbsAnswer,face,zhucetime,sintroduce) values('"+this.TextBox_username.Text+"','"+this.TextBox_pwd.Text+"','"+this.TextBox_email.Text+"','"+this.RadioButtonList_sex.SelectedItem.Value.ToString()+"','"+this.TextBox_question.Text+"','"+this.TextBox_answer.Text+"','face/01s.jpg','"+DateTime.Now+"','"+this.TextBox_introduce.Text+"')";
// string sql="insert into users(username,pwd,email,sSex) values('"+this.TextBox_username.Text+"','"+this.TextBox_pwd.Text+"','"+this.TextBox_email.Text+"','"+this.RadioButtonList_sex.SelectedItem+"')";
Session["username"]=this.TextBox_username.Text;
da.da d=new da.da();
d.command(sql);
MailMessage mail=new MailMessage();
mail.To=this.TextBox_email.Text;
mail.From="123@163.com";
mail.Subject="会员注册成功";
mail.Body=" 请您记住您的资料:用户名:"+this.TextBox_username.Text+",密码:"+this.TextBox_pwd.Text+".请忙删除此消息,无需回复!";
SmtpMail.Send(mail);
string sql1="select iUserID from users where username='"+this.TextBox_username.Text+"'";
string sql2="select iPowerLevels from users where username='"+this.TextBox_username.Text+"'";
da.da p=new da.da();
DataSet ds=p.Select(sql1,"users");
DataSet myds=p.Select(sql2,"users");
Session["userid"]=ds.Tables["users"].Rows[0][0].ToString();
Session["iPowerLevels"]=myds.Tables["users"].Rows[0]["iPowerLevels"].ToString();
Response.Redirect("index.aspx");
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
Myconn.Close();
}
finally
{
Myconn.Close();
Myconn.Dispose();
Myconn=null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -