using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Mail;
public partial class WebMain_Member_FindPassword : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Panel1.Visible = true;
            this.Panel2.Visible = false;
            this.Panel3.Visible = false;
            Panel4.Visible = false;
            this.cancel.Attributes.Add("onclick","window.close()");
            this.close2.Attributes.Add("onclick", "window.close()");
            this.close3.Attributes.Add("onclick", "window.close()");
            this.close4.Attributes.Add("onclick", "window.close()");
        }
    }
    protected void next_Click(object sender, EventArgs e)
    {
        this.Panel1.Visible = false;
        this.Panel2.Visible = true;
        this.Panel3.Visible = false;
        Panel4.Visible = false;
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select * from MemberVIP where vipusername='" + this.user.Text.Trim() + "' and vipemail='"+this.email.Text.Trim()+"'", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        if (sdr.HasRows)
        {
            sdr.Read();

            this.aw.Text = sdr.GetString(5);
            Session["da"] = sdr.GetString(6).Trim();
            Session["wtouserer"] = sdr.GetString(3);
            Session["wtousereepwd"] = sdr.GetString(4);
        }
        else
        {
            this.Panel3.Visible = false;
            this.Panel2.Visible = false;
            this.Panel1.Visible = false;
            Panel4.Visible = true;
        }
        sdr.Close();
        conn.Close();
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        if (Session["da"].ToString() == this.da.Text.Trim())
        {
            this.Panel3.Visible = true;
            this.Panel2.Visible = false;
            this.Panel1.Visible = false;
            Panel4.Visible = false;
            this.finduser.Text = Session["wtouserer"].ToString();
            this.findpwd.Text = Session["wtousereepwd"].ToString();
            //邮件发送
          
            SqlConnection Mconn = CDatabase.wtoconn();
            Mconn.Open();
            SqlCommand Msmd = new SqlCommand("select * from SystemBasicInformation", Mconn);
            SqlDataReader Msdr = Msmd.ExecuteReader();
            Msdr.Read();
            string Mform, Muid, Mpwd, Mstmp, Misopen, Mcont, MCompanyName, MWEBName, MTel, MFax, MEmail, MQQ, MAddress, MMSN, TBWW, MLOGOpic,Memailto;
            Mform = Msdr.GetString(7);
            Muid = Mform;
            Mpwd = Msdr.GetString(26);
            Mstmp = Msdr.GetString(25);
            Misopen = Msdr.GetString(1).ToString().Trim();
            MCompanyName = Msdr.GetString(2);
            MWEBName = Msdr.GetString(3);
            MTel = Msdr.GetString(5);
            MFax = Msdr.GetString(6);
            MEmail = Msdr.GetString(7);
            MQQ = Msdr.GetString(8);
            MAddress = Msdr.GetString(10);
            MMSN = Msdr.GetString(13);
            TBWW = Msdr.GetString(14);
            Memailto = Msdr.GetString(21).Trim();
            MLOGOpic = "<a href=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "><img src=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "/images/" + Msdr.GetString(15) + " border=0></a>";
            Msdr.Close();
            if (Memailto == "y")
            {
                SqlCommand Msmd2 = new SqlCommand("select content from email where lx='2'", Mconn);
                Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar()));
                SqlCommand Msmd3 = new SqlCommand("select title from email where lx='2'", Mconn);
                string Mti = Convert.ToString(Msmd3.ExecuteScalar());
                MailMessage msg = new MailMessage();
                msg.From = Mform;  //发送方地址(如test@163.com)
                msg.To = this.email.Text; //接收方地址(如test@163.com) 
                msg.BodyFormat = MailFormat.Html;   //正文内容类型 
                msg.BodyEncoding = System.Text.Encoding.Default;    //正文内容编码 
                //msg.Attachments.Add(new MailAttachment("d:\\d.txt"));
                //主题 
                msg.Subject = Mti;
                //内容 
                //编码定义
                Mcont = ((Mcont.Replace("$UID$", Session["wtouserer"].ToString())).Replace("$PWD$", Session["wtousereepwd"].ToString()));
                Mcont = Mcont.Replace("$CMY$", MCompanyName);
                Mcont = Mcont.Replace("$WEBN$", MWEBName);
                Mcont = Mcont.Replace("$TEL$", MTel);
                Mcont = Mcont.Replace("$FAX$", MFax);
                Mcont = Mcont.Replace("$EMA$", MEmail);
                Mcont = Mcont.Replace("$QQ$", MQQ);
                Mcont = Mcont.Replace("$ADD$", MAddress);
                Mcont = Mcont.Replace("$MSN$", MMSN);
                Mcont = Mcont.Replace("$TBW$", TBWW);
                Mcont = Mcont.Replace("$LOGO$", MLOGOpic);
                msg.Body = Mcont;
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置为需要用户验证 
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Muid); //设置验证用户名 
                msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Mpwd); //设置验证密码 
                SmtpMail.SmtpServer = Mstmp;  //邮件服务器地址(如smtp.163.com) 
                SmtpMail.Send(msg);  //发送 

            }
            Mconn.Close();



        }
        else

        {
            this.Panel3.Visible = false;
            this.Panel2.Visible = false;
            this.Panel1.Visible = false;
            Panel4.Visible = true;
        }
    }
}
