谁能帮我看看下面的哪里错了!注册发信
源程序如下!是一个注册程序!但是要求 注册完后可以发信给注册人红色部分 为我加的发信代码
xxxxxxx 为我个人隐藏!
using System;
using System.Collections;
using
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
using
namespace onlineHotel.user
{
/// <summary>
/// Register 的摘要说明。
/// </summary>
public class Register : BasePage
{
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.TextBox txtRePassword;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.TextBox txtTel;
protected System.Web.UI.WebControls.Button btnAffirm;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(! IsPostBack)
{
btnAffirm.Attributes.Add("onClick","javascript:return post_go();");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnAffirm.Click += new System.EventHandler(this.btnAffirm_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnAffirm_Click(object sender, System.EventArgs e)
{
if(txtUserName.Text.Trim() == "")
{
ToolHelper.Alert("请输入登录名",this.Page);
return;
}
if(txtPassword.Text.Trim() == "")
{
ToolHelper.Alert("请输入密码",this.Page);
return;
}
Config cg = new Config();
DataTable dt = cg.GetTable("select [ID] from t_member_member where [UserName]='"+txtUserName.Text.Trim()+"'");
if(dt.Rows.Count > 0)
{
ToolHelper.Alert("此登录名已存在!请选择其它的名字.",this.Page);
return;
}
SqlParameter[] sp = new SqlParameter[]
{
new SqlParameter("@UserName",SqlDbType.NVarChar),
new SqlParameter("@Password",SqlDbType.NVarChar),
new SqlParameter("@Email",SqlDbType.NVarChar),
new SqlParameter("@Tel",SqlDbType.NVarChar),
new SqlParameter("@RegistDate",SqlDbType.DateTime)
};
sp[0].Value = ToolHelper.StringReplace(txtUserName.Text.Trim(),1);
sp[1].Value = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(ToolHelper.StringReplace(txtPassword.Text.Trim(),1),"MD5");
sp[2].Value = ToolHelper.StringReplace(txtEmail.Text.Trim());
sp[3].Value = ToolHelper.StringReplace(txtTel.Text.Trim(),1);
sp[4].Value = System.DateTime.Now;
string strSql = "insert into t_member_member([UserName],[PassWord],[Email],[Tel],[RegistDate]) values(@UserName,@Password,@Email,@Tel,@RegistDate)";
Config.ExecuteNonQuery(Config.CONN_STRING,CommandType.Text,strSql,sp);
Session["id"]= cg.GetMaxId("ID","t_member_member") - 1;
Session["name"] = txtUserName.Text.Trim();
bool bTF = false;
if (dal.ExecuteSql(sb.ToString()))
{
bTF = true;
}
return bTF;
}
public bool SendEmail(string UserName, string Password, string Email)
{
string form = "xxxxxxxxxxx";
string FromName = "xxxxxxxxxxxxx";
string to = Email;
MailMessage mail = new MailMessage(form, to);
mail.IsBodyHtml = true;
mail.Subject = "xxxxxxx!";
StringBuilder sb = new StringBuilder();
sb.Append("xxxxx:<br>");
sb.Append(" xx:<br>");
sb.Append(" xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <br>");
sb.Append(" » 会员号: " + UserName + " <br>");
sb.Append(" » 密 码: " + Password + " <br>");
sb.Append(" xxxxxxxxxxxxxxxx <br>");
sb.Append(" xxxxxxx <br><br>");
sb.Append(" xxxxxx <br>");
sb.Append(" xxxxxxxxx <br><br><br><br>");
sb.Append(" xxxxxx <br>");
sb.Append(" xxxxxx <br>");
mail.Body = sb.ToString();
SmtpClient smtp = new SmtpClient();
bool bTF = true;
try
{
smtp.Send(mail);
}
catch
{
bTF = false;
}
return bTF;
}
}
}