protected void SubmitButtom_Click(object sender, EventArgs e)
    {
        string userName     = this.UserName.Text.Trim();
        string userPassword = this.UserPassword.Text.Trim();

        if (userName == "")
        {
            Utility.Alert(this, "用户名未填写!");
            return;
        }

        if (userPassword == "")
        {
            Utility.Alert(this, "密码未填写!");
            return;
        }

        //保留用户名Cookie
        Response.Cookies["UserCookie"].Value   = userName;
        Response.Cookies["UserCookie"].Expires = DateTime.MaxValue;

        int  userId  = 0;
        bool success = UserAccess.CheckUserLogin(userName, userPassword, out userId);

        if (success)
        {
            Session["TodayDate"] = DateTime.Now.ToString("yyyy-MM-dd");

            UserEntity user = UserAccess.GetUserById(userId);
            Session["UserID"]       = user.UserID;
            Session["UserName"]     = user.UserName;
            Session["UserNickName"] = user.UserNickName;
            Session["UserTheme"]    = user.UserTheme;
            Session["UserLevel"]    = user.UserLevel.ToString();
            Session["UserFrom"]     = user.UserFrom;
            Session["UserWorkDay"]  = user.UserWorkDay;
            Session["UserFunction"] = user.UserFunction;
            Session["CategoryRate"] = user.CategoryRate;

            Response.Cookies["ThemeCookie"].Value   = user.UserTheme;
            Response.Cookies["ThemeCookie"].Expires = DateTime.MaxValue;

            string url = Request.QueryString["url"];
            if (url == "" || url == null)
            {
                url = "Default.aspx";
            }

            Response.Redirect(url);
        }
        else
        {
            Utility.Alert(this, "登录失败!");
        }
    }
    //绑定已有帐号
    protected void BoundButton_Click(object sender, EventArgs e)
    {
        string userName = this.UserNameBound.Text.Trim();

        if (!ValidHelper.CheckLength(userName, 2))
        {
            Utility.Alert(this, "用户名填写错误!");
            return;
        }

        string userPassword = this.UserPasswordBound.Text.Trim();

        if (!ValidHelper.CheckLength(userPassword, 2))
        {
            Utility.Alert(this, "密码填写错误!");
            return;
        }

        int  newUserId = 0;
        bool success   = UserAccess.CheckUserLogin(userName, userPassword, out newUserId);

        if (success)
        {
            UserEntity user = UserAccess.GetUserById(newUserId);
            success = OAuthAccess.OAuthBoundUser(userId, user.UserID);
            if (success)
            {
                Session["UserID"]       = userId = user.UserID;
                Session["UserName"]     = user.UserName;
                Session["UserNickName"] = user.UserNickName;
                Session["UserTheme"]    = user.UserTheme;
                Session["UserLevel"]    = user.UserLevel.ToString();
                Session["UserFrom"]     = user.UserFrom;
                Session["UserWorkDay"]  = user.UserWorkDay;
                Session["UserFunction"] = user.UserFunction;
                Session["CategoryRate"] = user.CategoryRate;

                Response.Cookies["ThemeCookie"].Value   = user.UserTheme;
                Response.Cookies["ThemeCookie"].Expires = DateTime.MaxValue;

                PopulateControls();
                Utility.Alert(this, "绑定成功。", "UserBoundAdmin.aspx");
            }
            else
            {
                Utility.Alert(this, "绑定失败!");
            }
        }
        else
        {
            Utility.Alert(this, "登录失败!");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string userName     = Request.Form["username"].ToString();
        string userPassword = Request.Form["userpass"].ToString();
        int    type         = Int32.Parse(Request.Form["type"].ToString());

        string result = "{";

        int  userId  = 0;
        bool success = UserAccess.CheckUserLogin(userName, userPassword, out userId);

        if (success)
        {
            UserEntity user = UserAccess.GetUserById(userId);

            result += "\"userid\":\"" + userId + "\",";
            result += "\"username\":\"" + user.UserName + "\",";
            result += "\"userpass\":\"" + user.UserPassword + "\",";
            result += "\"usernickname\":\"" + user.UserNickName + "\",";
            result += "\"useremail\":\"" + user.UserEmail + "\",";
            result += "\"userphone\":\"" + user.UserPhone + "\",";
            result += "\"userimage\":\"" + user.UserImage + "\",";
            result += "\"userworkday\":\"" + user.UserWorkDay + "\",";
            result += "\"usermoney\":\"" + user.UserMoney + "\",";
            result += "\"categoryrate\":\"" + user.CategoryRate + "\",";

            DataTable dt = null;
            if (type == 1)
            {
                dt = SyncHelper.SyncGetItemListWebFirst(userId);
            }
            else
            {
                dt = SyncHelper.SyncGetItemListWeb(userId);
            }
            if (dt.Rows.Count > 0)
            {
                result += "\"hassync\":\"1\",";
            }
            else
            {
                result += "\"hassync\":\"0\",";
            }

            bool isBound = SyncHelper.CheckOAuthBound(userId);
            if (!isBound)
            {
                result += "\"userbound\":\"0\"";
            }
            else
            {
                result += "\"userbound\":\"1\"";
            }
        }
        else
        {
            result += "\"userid\":\"0\",";
            result += "\"username\":\"\",";
            result += "\"userpass\":\"\",";
            result += "\"usernickname\":\"\",";
            result += "\"useremail\":\"\",";
            result += "\"userphone\":\"\",";
            result += "\"userimage\":\"\",";
            result += "\"userworkday\":\"\",";
            result += "\"usermoney\":\"0\",";
            result += "\"categoryrate\":\"90\",";
            result += "\"hassync\":\"0\",";
            result += "\"userbound\":\"0\"";
        }

        result += "}";

        Response.Write(result);
        Response.End();
    }