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 Base;
using UserInfo;

public partial class login_Retrieve_Password : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnEmail_Click(object sender, EventArgs e)
    {
        if (txtUserName.Text.Trim() == "")
        {
            lblMessage.Text = "请填写您的用户名!";
            return;
        }
        if (txtEmail.Text.Trim() == "" || txtEmail1.Text.Trim() == "")
        {
            lblMessage.Text = "请填写您的邮箱名!";
            return;
        }
        bool flag = Base.Common.isUserName(txtUserName.Text.Trim());
        if (!flag)
        {
            lblMessage.Text = "用户名是由英文字母、数字、下划线组成的6-20个字符";
            return;
        }
        string UserEmail = txtEmail.Text.Trim() + "@" + txtEmail1.Text.Trim();
        bool isEmail = Base.Common.isMail(UserEmail);
        if (!isEmail)
        {
            lblMessage.Text = "邮箱格式不正确!";
            return;
        }
        string where = "where LoginName='" + txtUserName.Text.Trim() + "'";
        IUserInfo user = new RUserInfo();
        DataTable dt = user.GetDataTable(where);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Text = "所查询的用户不存在！";
            return;
        }
        else
        {
            int id = int.Parse(dt.Rows[0]["UserID"].ToString());
            string email = dt.Rows[0]["Email"].ToString();

            if (email != "")
            {
                if (Base.Common.isMail(email))
                {

                    if (email == UserEmail)
                    {
                        string strFlag = Base.XMLProcess.Read("xml/EmailFlag.xml", "/Item/flag/mode[@type='userFindPwd']", "value");
                        if (strFlag == "")
                            strFlag = "us_FindPwd";
                        nspBase.Core.clsEmail.SendMail(strFlag, id);
                        lblMessage.Text = "您的激活信息已经发送致您的邮箱，请查看邮箱后再次登录";
                    }
                    else
                    {
                        lblMessage.Text = "您填写的邮箱地址与注册时填写的邮箱地址不一致，请在下框中重新输入您的邮箱地址。";
                    }
                }
                else
                {
                    lblMessage.Text = "您的邮箱格式不正确！";
                }
            }
            else
            {
                lblMessage.Text = "对不起，您尚未注册邮箱！";
                return;
            }
        }
    }
    protected void btnQuestion_Click(object sender, EventArgs e)
    {
        string where = "where LoginName='" + txtUserName.Text.Trim() + "'";
        IUserInfo user = new RUserInfo();
        DataTable dt = user.GetDataTable(where);
        if (dt.Rows.Count == 0)
        {
            lblMessage.Text = "所查询的用户不存在！";
            return;
        }
        else
        {
            int userid = int.Parse(dt.Rows[0]["UserID"].ToString());
            string Answer = dt.Rows[0]["Answer"].ToString();
            string Question = dt.Rows[0]["Question"].ToString();
            if (Answer == "" || Question == "")
            {
                lblMessage.Text = "您没有设置密码保护问题及答案，无法通过密码保护问题来取回密码！";
            }
            else
            {
                Response.Redirect("HelpKey.aspx?UserID=" + userid);
            }
        }
    }
    //protected void btnMobileTel_Click(object sender, EventArgs e)
    //{
    //    if (txtMobileTel.Text.Trim() == "")
    //    {
    //        lblMessage.Text = "手机号码不能为空！";
    //        return;
    //    }
    //    string where = "where LoginName='" + txtUserName.Text.Trim() + "'";
    //    IUserInfo user = new RUserInfo();
    //    DataTable dt = user.GetDataTable(where);
    //    if (dt.Rows.Count == 0)
    //    {
    //        lblMessage.Text = "所查询的用户不存在！";
    //        return;
    //    }
    //    else
    //    {
    //        if (Base.Common.isCellphone(txtMobileTel.Text.Trim()))
    //        {
    //            int userid = int.Parse(dt.Rows[0]["UserID"].ToString());
    //            string tel = dt.Rows[0]["MobilePhone"].ToString();

    //            if (tel !=txtMobileTel.Text.Trim())
    //            {
    //                lblMessage.Text = "您输入的手机号码与您注册时填写的手机号码不匹配。";
    //                return;
    //            }
    //            else
    //            {
    //               //发送密码到手机上
    //            }
    //        }
    //        else
    //        {
    //            lblMessage.Text = "手机号码格式不正确！";
    //            return;
    //        }
    //    }
    //}
}
