namespace SK.MemberWeb.Templates.Default
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using SK.MemberBLL;

	/// <summary>
	///		cu_NeedValidEmail 的摘要说明。
	/// </summary>
	public class cu_NeedValidEmail : BaseControl
	{
		protected System.Web.UI.WebControls.TextBox txtMemberName;
		protected System.Web.UI.WebControls.Button btnSend;
		protected SK.MemberWeb.Controls.ControlHolder ControlHolder2;
		protected SK.MemberWeb.Controls.ControlHolder ControlHolder1;
		MemberSystem member = new MemberSystem();

		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.btnSend.Click += new System.EventHandler(this.btnSend_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSend_Click(object sender, System.EventArgs e)
		{
			DataRow drMember = member.Info_Name(txtMemberName.Text);
			if(drMember!=null)
			{
				BasePape des = new BasePape();
				des.DecryptKey = "sorkednc";
				des.InputString = drMember["Password"].ToString();
				des.DesDecrypt();
				string DecryptString = des.OutString;

				string body = Main.GetValue("ActiveEmailBody").ToString();
				body = body.Replace("[[MemberID]]",drMember["MemberID"].ToString());
				body = body.Replace("[[MemberName]]",drMember["MemberName"].ToString());
				body = body.Replace("[[Password]]",DecryptString);
				body = body.Replace("[[Email]]",drMember["Email"].ToString());
				body = body.Replace("[[EmailValidCode]]",drMember["EmailValidCode"].ToString());

				string subject = Main.GetValue("ActiveEmailSubject").ToString();
				subject = subject.Replace("[[MemberID]]",drMember["MemberID"].ToString());
				subject = subject.Replace("[[MemberName]]",drMember["MemberName"].ToString());
				subject = subject.Replace("[[Password]]",DecryptString);
				subject = subject.Replace("[[Email]]",drMember["Email"].ToString());
				subject = subject.Replace("[[EmailValidCode]]",drMember["EmailValidCode"].ToString());

				bool inhtml = Convert.ToBoolean(Convert.ToInt16(Main.GetValue("ActiveEmailInHtml")));
				Utils.SendMail(drMember["Email"].ToString(),txtMemberName.Text,subject,body,inhtml?PatNorSoft.Mail.Message.Build.BodyPartFormat.HTML:PatNorSoft.Mail.Message.Build.BodyPartFormat.Plain);
				Response.Redirect("msg.aspx?msg="+Server.UrlEncode("激活邮件已发送至"+drMember["Email"].ToString()));
			}
			else
			{
				this.DisplayAlert("此用户名不存在");
			}
		}
	}
}
