adduser.aspx.cs
资源名称:论坛源码.rar [点击查看]
上传用户:scene123
上传日期:2010-02-19
资源大小:3311k
文件大小:6k
源码类别:
.net编程
开发平台:
C#
- 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.OleDb;
- using System.Text;
- using System.Configuration;
- using System.Web.Security;
- using System.Security.Cryptography;
- using System.Web.Mail;
- namespace kuangren
- {
- /// <summary>
- /// adduser 的摘要说明。
- /// </summary>
- public class adduser : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.Button Button2;
- protected System.Web.UI.WebControls.TextBox u_user;
- protected System.Web.UI.WebControls.TextBox u_pass;
- protected System.Web.UI.WebControls.TextBox u_pass1;
- protected System.Web.UI.WebControls.TextBox u_question;
- protected System.Web.UI.WebControls.TextBox u_result;
- protected System.Web.UI.WebControls.TextBox u_Email;
- protected System.Web.UI.WebControls.TextBox u_Address;
- protected System.Web.UI.WebControls.TextBox u_Oicq;
- protected System.Web.UI.WebControls.TextBox u_icq;
- protected System.Web.UI.WebControls.TextBox u_Occupation;
- protected System.Web.UI.WebControls.TextBox u_Signature;
- protected System.Web.UI.WebControls.TextBox u_Homepage;
- protected System.Web.UI.WebControls.TextBox u_user1;
- protected System.Web.UI.WebControls.Button Button1;
- protected System.Web.UI.WebControls.Button Button3;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
- protected System.Web.UI.WebControls.TextBox u_pass2;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
- protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
- protected System.Web.UI.WebControls.RadioButton u_msn;
- protected System.Web.UI.WebControls.RadioButton u_msn1;
- protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
- protected System.Web.UI.WebControls.TextBox TextBox1;
- protected System.Data.OleDb.OleDbCommand cmd1;
- protected System.Data.OleDb.OleDbConnection conn;
- protected int intRunTime;
- protected System.Web.UI.WebControls.Label lblMessage;
- protected DateTime dtStartTime = DateTime.Now;
- public string s2;
- public string s1;
- 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.u_pass2.TextChanged += new System.EventHandler(this.u_pass2_TextChanged);
- this.u_Oicq.TextChanged += new System.EventHandler(this.u_Oicq_TextChanged);
- this.Button1.Click += new System.EventHandler(this.Button1_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void Button1_Click(object sender, System.EventArgs e)
- {
- conn = new OleDbConnection(ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
- cmd1=new OleDbCommand("select u_User from userinfo where u_User='"+u_user1.Text+"'",conn);
- OleDbDataReader objDataReader ;
- cmd1.Connection.Open();
- objDataReader = cmd1.ExecuteReader();
- if (objDataReader.Read() == true)
- {
- Response.Redirect("checkout.aspx");
- lblMessage.Text = "对不起,该用户名已经被注册!";
- return;
- }
- OleDbConnection con;
- string OleDbsql;
- OleDbCommand cmd;
- StringBuilder sb=new StringBuilder();
- ArrayList values=new ArrayList();
- sb.Append("INSERT INTO [userinfo](u_User,u_pass,u_question,u_result,u_Email,u_Address,u_Oicq,u_icq,u_Occupation,u_Homepage,u_Signature,u_msn) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')");
- s1=(FormsAuthentication.HashPasswordForStoringInConfigFile(u_pass1.Text.ToString().Trim(),"MD5"));
- s2=s1.Substring(8,s1.Length-16);
- values.Add(u_user1.Text);
- values.Add(s2);
- values.Add(u_question.Text);
- values.Add(u_result.Text);
- values.Add(u_Email.Text);
- values.Add(u_Address.Text);
- values.Add(u_Oicq.Text);
- values.Add(u_icq.Text);
- values.Add(u_Occupation.Text);
- values.Add(u_Homepage.Text);
- values.Add(u_Signature.Text);
- if (u_msn.Checked)
- values.Add(u_msn.Text);
- else
- values.Add(u_msn1.Text);
- if(u_user1.Text!=string.Empty)
- values.Add("'"+u_user1.Text+"'");
- else
- values.Add("Null");
- if(u_pass1.Text==u_pass2.Text)
- values.Add("'"+u_pass1.Text+"'");
- else
- values.Add("Null");
- OleDbsql=String.Format(sb.ToString(),values.ToArray());
- con=new OleDbConnection(ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
- cmd=new OleDbCommand(OleDbsql,con);
- con.Open();
- bool doredirect=true;
- try
- {
- cmd.ExecuteNonQuery();
- }
- catch
- {
- doredirect=false;
- this.lblMessage.Visible=true;
- this.lblMessage.Text="Insert couldn't be performed.username may be already taken.";
- }
- finally
- {
- con.Close();
- }
- //定义自动登陆
- Response.Cookies["jusername"].Value=""+u_user1.Text+"";
- Response.Cookies["jpassword"].Value=""+s2+"";
- Response.Cookies["jpower"].Value="42";
- Response.Cookies["jhidden"].Value="0";
- //结束
- if(doredirect)
- {
- Response.Redirect("adduser_havier.aspx");
- }
- else
- {
- lblMessage.Text="Fix the Following errors and retry:";
- }
- }
- private void u_msn_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- }
- private void u_Oicq_TextChanged(object sender, System.EventArgs e)
- {
- }
- private void u_pass2_TextChanged(object sender, System.EventArgs e)
- {
- }
- }
- }