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_pw : System.Web.UI.Page
{
    user u = new user();
    sqlServer sql = new sqlServer();
    email mail = new email();
    javasrcipt js = new javasrcipt();
    public string webTitle = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        u.check("", url.before);
        webTitle = xml.read("xabara.config", "webName", 180);
        Page.Title = "修改密码　" + webTitle + xml.read("xabara.config", "titleMeta", 180);

        regExpression reg = new regExpression();
        oldPWRegularExpressionValidator.ValidationExpression = reg.passWord(6, 20);
        oldPWRegularExpressionValidator.ErrorMessage = reg.passWordError(6, 20);
        PWRegularExpressionValidator.ValidationExpression = reg.passWord(6, 20);
        PWRegularExpressionValidator.ErrorMessage = reg.passWordError(6, 20);
    }

    protected void postImgButton_Click(object sender, ImageClickEventArgs e)
    {
        DataTable dt = sql.getDataTable("select * from xabaraUser where userCardID='" + u.userCardID + "' and userPW='" + xabara.md5(oldPw.Text) + "'");
        if (dt.Rows.Count > 0)
        {
            string[] strValue = new string[1];
            strValue[0] = xabara.md5(uPW.Text);
            string str = sql.update("xabaraUser", "@userPW", strValue, "userCardID='" + u.userCardID + "'");
            if (str.Equals("更新成功"))
            {
                string nameStr = HttpUtility.UrlDecode(Request.Cookies["XabaraUser"]["userName"].ToString().Trim());
                if (string.IsNullOrEmpty(nameStr as string))
                {
                    nameStr = u.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>" + nameStr + @"</strong>，您好！<br /><br />　　您的密码已被修改！请妥善保存您的新密码，并可在&nbsp;[&nbsp;<a href='http://" + url.domain + @"/member/' target='_blank'>会员中心</a>&nbsp;]&nbsp;中修改您的密码。</td></tr></table>";

                mail.add(u.userCardID, "user", 0, dt.Rows[0]["userEmail"].ToString().Trim(), "密码修改", "会员密码修改通知信", bodyHtml, true);

                sql.log(u.userCardID, "user", "修改密码");
            }
            js.div(false, "", "text", "密码" + str + "！", 400, 0, "my.aspx", "goto");
        }
        else
        {
            js.div(false, "", "text", "您的原密码不正确！", 400, 0, "", "");
        }
        dt.Dispose();
    }
}