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_id : System.Web.UI.Page
{
    user u = new user();
    sqlServer sql = new sqlServer();
    javasrcipt js = new javasrcipt();

    protected void Page_Load(object sender, EventArgs e)
    {
        u.check("", url.before);

        if (!IsPostBack)
        {
            regExpression reg = new regExpression();
            uIDRegularExpressionValidator.ValidationExpression = reg.useridCN(3, 20);
            uIDRegularExpressionValidator.ErrorMessage = reg.useridCNError(3, 20);
            PWRegularExpressionValidator.ValidationExpression = reg.passWord(6, 20);
            PWRegularExpressionValidator.ErrorMessage = reg.passWordError(6, 20);

            DataTable dt = sql.getDataTable("select * from XabaraUser where userCardID='" + u.userCardID + "'");
            if (dt.Rows.Count > 0)
            {
                string userID = dt.Rows[0]["userID"].ToString().Trim();
                if (!string.IsNullOrEmpty(userID as string))
                {
                    Response.Redirect("/member/user/my.aspx", true);
                }
            }
            dt.Dispose();
        }

        Page.Title = "主帐号捆绑　" + xml.read("xabara.config", "webName", 180) + xml.read("xabara.config", "titleMeta", 180);
    }

    protected void postButton_Click(object sender, ImageClickEventArgs e)
    {
        string uidText = uID.Text.Trim().ToLower();
        string webTitle = xml.read("xabara.config", "webName", 180);

        string strSql = "select * from XabaraUser where userID='" + uidText + "'";
        if (sql.getDataTable(strSql).Rows.Count > 0)
        {
            js.div(false, "", "text", "很遗憾，该帐号已经被使用，请您另选一个！", 350, 0, "", "");
        }
        else
        {
            string strDim = "@userID,@userPW";
            string[] strValue = new string[2];
            strValue[0] = uidText;
            strValue[1] = xabara.md5(uPW.Text.Trim());

            if (sql.update("XabaraUser", strDim, strValue, "userCardID='" + u.userCardID + "'").Equals("更新成功"))
            {
                u.login("", uidText, uPW.Text.Trim(), "/member/", true, false);
            }
            else
            {
                js.div(false, "", "text", "绑定失败！", 350, 0, "id.aspx", "top");
            }
        }
    }
}