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 TopWinCMS.Model;
using TopWinCMS.BLL;
using TopWinCMS.Common;

public partial class Member_GetPassword : TopWinCMS.BLL.PageFactory.Pages.ClientPublicPage
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            this.Wizard1.ActiveStepIndex = 0;
        }
    }

    protected void BT_OK_Click1(object sender, EventArgs e)
    {

    }
    protected void BT_OK_Click(object sender, EventArgs e)
    {
        //MemberInfo model = new MemberInfo();
        //model.Name = TB_Name.Text.Trim();
        //model.Question = HttpContext.Current.Session["Member_Question"].ToString();
        //model.Answer = TB_Answer.Text.Trim();
        //model.PassCode = TB_PassCode.Text.Trim();

        //new MemberManage().TryGetPassword2(model);

    }

    protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {

        if (e.NextStepIndex == 1)
        {
            string Err = null;
            if (new MemberManage().CheckUserName(TB_UserName.Text.Trim(), ref Err) == false)
            {
                MsgBox.Alert(Err, this.UpdatePanel1);
                e.Cancel = true;

                return;
            }

            if (RadioButtonList1.SelectedIndex == 0)
            {
                Panel1.Visible = true;
                Panel2.Visible = false;
            }
            else if (RadioButtonList1.SelectedIndex == 1)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;

                string str = new MemberManage().LoadQuestion(TB_UserName.Text.Trim()).ToString();

                if (string.IsNullOrEmpty(str))
                {
                    MsgBox.Alert("未设置密码问题", this.UpdatePanel1);
                    e.Cancel = true;
                    return;
                }
                else
                {
                    LB_Question.Text = str;
                }
            }
        }

        if (e.NextStepIndex == 2)
        {
            if (Panel1.Visible == true)
            {
                if (new MemberManage().TestEmail(TB_UserName.Text.Trim(), TB_eMail.Text.Trim()) == false)
                {
                    MsgBox.Alert("电邮地址错误.", this.UpdatePanel1);
                    e.Cancel = true;
                    return;
                }
                else
                {
                    Panel3.Visible = true;
                    Panel4.Visible = false;
                }
            }
            else
            {
                if (new MemberManage().TestQA(TB_UserName.Text.Trim(), LB_Question.Text, TB_Answer.Text.Trim()) == false)
                {
                    MsgBox.Alert("密码答案错误.", this.UpdatePanel1);
                    e.Cancel = true;
                    return;
                }
                else
                {
                    Panel3.Visible = false;
                    Panel4.Visible = true;
                }
            }
        }
    }

    protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (Panel3.Visible == true)
        {
            if (eMailConfig.MailSend)
            {
                string NewPSW = Guid.NewGuid().ToString();
                eMail mail = new eMail();
                mail.Send("恭喜您，您在《" + Config.SiteName + "》进行取回密码操纵成功！", "恭喜您，您在《" + Config.SiteName + "》进行取回密码操纵成功<br>您的密码为：" + NewPSW, TB_eMail.Text, eMailConfig.MailFrom, eMailConfig.MailFromName, eMailConfig.MailDomain, eMailConfig.MailServerUserName, eMailConfig.MailServerPassWord);
      
                new MemberManage().PasswordModify(TB_UserName.Text, NewPSW, NewPSW);

                MsgBox.Alert("密码修改完成。", UpdatePanel1);

                System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "close", "window.close();", true);
            }
            else
            {
                MsgBox.Alert("管理员关闭邮件发送功能。", UpdatePanel1);
            }
        }
        else
        {
        
            bool b = new MemberManage().PasswordModify(TB_UserName.Text, TB_PSW1.Text, TB_PSW2.Text);

            if (b)
            {
                MsgBox.Alert("密码修改成功。", UpdatePanel1);
                System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "close", "window.close();", true);
            }
            else
            {
                MsgBox.Alert("两次输入的密码不一致。", UpdatePanel1);
            }
        }

    }
}