using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using xabaraCOM;

public partial class member_user_forget : System.Web.UI.Page
{
    user u = new user();
    javasrcipt js = new javasrcipt();
    xabara x = new xabara();
    email mail = new email();
    public string webTitle = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        webTitle = xml.read("xabara.config", "webName", 180);
        Page.Title = "取回密码　" + webTitle + xml.read("xabara.config", "titleMeta", 180);

        if (!IsPostBack)
        {
            advertisement ad = new advertisement();
            ad950.Text = ad.read("", 950, 90, 1, false, true, "");

            regExpression reg = new regExpression();
            uIDRegularExpressionValidator.ValidationExpression = reg.useridCN(2, 20);
            uIDRegularExpressionValidator.ErrorMessage = reg.useridCNError(2, 20);
            emailRegularExpressionValidator.ValidationExpression = reg.email;
            emailRegularExpressionValidator.ErrorMessage = reg.emailError;
            rndNumRegularExpressionValidator.ValidationExpression = reg.rndNums(6, 20);
            rndNumRegularExpressionValidator.ErrorMessage = reg.rndNumsError(6, 20);
        }
    }

    protected void loginEnter_Click(object sender, ImageClickEventArgs e)
    {
        if (x.checkValidateCode(true, RndNum.Text.ToString()))
        {
            sqlServer sql = new sqlServer();
            DataTable dt = sql.getDataTable("select userName,userCardID from XabaraUser where userID='" + uID.Text.Trim() + "' and userEmail='" + email.Text.Trim() + "'");
            if (dt.Rows.Count > 0)
            {
                string userCardID = dt.Rows[0]["userCardID"].ToString().Trim();
                string txtName = dt.Rows[0]["userName"].ToString().Trim();
                if (string.IsNullOrEmpty(txtName as string))
                {
                    txtName = uID.Text.Trim();
                }
                string[] strValue = new string[1];      //更新验证数据
                string newPw = xabara.rnd("abc", 3) + xabara.rnd("abc123", 5);
                strValue[0] = xabara.md5(newPw);
                sql.update("XabaraUser", "@userPW", strValue, "userCardID='" + userCardID + "'");

                string bodyHtml = @"
<table width='100%' border='0' cellpadding='3' cellspacing='3'>  
  <tr>
    <td style='text-align:left; vertical-align:top; line-height:180%;'>尊敬的&nbsp;<strong>" + txtName + @"</strong>，您好！<br /><br />　　您的密码已重置，具体如下:<br /><br />　　用户名：<span class='redFont'>" + uID.Text.Trim() + @"</span><br />　　新密码：<span class='redFont'>" + newPw + @"</span><br /><br />　　请妥善保存您的新密码（注意密码大小写），并可在&nbsp;[&nbsp;<a href='http://" + url.domain + @"/member/' target='_blank'>会员中心</a>&nbsp;]&nbsp;中修改您的密码。</td>
  </tr>   
</table>";
                mail.add(userCardID, "user", 0, email.Text, "获取新密码", "新密码发送成功!", bodyHtml, true);

                Response.Redirect("/member/?errorTitle=" + Server.UrlEncode("新密码已发送至您的邮箱，请注意查收！"), true);
            }
            else
            {
                js.div(false, "", "text", "对不起，您所填写的信箱与该会员的联系信箱不符！", 400, 0, "", "");
            }
            dt.Dispose();
        }
    }
}