示例#1
0
        protected void topUpButton_Click(object sender, EventArgs e)
        {
            string   MSserialNumberInput = serialNumberInput.Text;
            string   MSsecurityCodeInput = securityCodeInput.Text;
            CashCard cc = new CashCard();

            if (MSserialNumberInput.Length < 12 || MSsecurityCodeInput.Length < 12)
            {
                ScriptManager.RegisterStartupScript(this, typeof(string), "topUpFailedScript", "alert('Please double check your Cash Code and Security Code!');", true);
                captchaInput.Text = "";
            }
            else
            {
                try
                {
                    captcha.ValidateCaptcha(captchaInput.Text);

                    if (captcha.UserValidated)
                    {
                        if (cc.checkCashCardAvailability(MSserialNumberInput) == true)
                        {
                            if (cc.validateCashCard(MSserialNumberInput, MSsecurityCodeInput) == true)
                            {
                                cc.updateCashCardUsed(MSserialNumberInput);

                                user = user.retrieveUser(userID);
                                user.updateUserAccountBalance(userID, cc.retrieveCashValue(MSserialNumberInput));

                                TopUpLog topuplog = new TopUpLog();
                                topuplog.createTopUpLog(userID, MSserialNumberInput, DateTime.Now.ToString("MMMM dd, yyyy H:mm:ss tt"));

                                ScriptManager.RegisterStartupScript(this, typeof(string), "topUpSuccessScript", "alert('Top-up success! Please click OK to continue.'); window.location='" + Request.ApplicationPath + "AccountInformation.aspx';", true);
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, typeof(string), "topUpFailedScript", "alert('The MSCashCard you provided does not exist or is already used!');", true);
                                captchaInput.Text = "";
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(string), "topUpFailedScript", "alert('The MSCashCard you provided does not exist or is already used!');", true);
                            captchaInput.Text = "";
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(string), "topUpFailedScript", "alert('Incorrect CAPTCHA input!');", true);
                        captchaInput.Text = "";
                    }
                }
                catch (Exception)
                {
                }
            }
        }