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) { } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["userID"] != null) { if (!Page.IsPostBack) { try { userid = Convert.ToInt32(Session["userID"]); List <String> topUpLogList = TopUpLog.retrieveFullTopUpLog(); try { for (int i = 0; i <= topUpLogList.Count; i++) { if (topUpLogList[i].Trim() != "") { var row = new TableRow(); var reviewCell = new TableCell(); reviewCell.Font.Bold = true; reviewCell.Font.Name = "Calibri"; reviewCell.BorderWidth = 1; reviewCell.BorderStyle = BorderStyle.Dotted; reviewCell.Width = 600; reviewCell.Text = "</br>" + HttpUtility.HtmlEncode(topUpLogList[i]) + "</br></br>"; row.Controls.Add(reviewCell); Table1.Controls.Add(row); } else { if (topUpLogList[i] == "") { var row = new TableRow(); var reviewCell = new TableCell(); reviewCell.Font.Bold = true; reviewCell.Font.Name = "Calibri"; reviewCell.BorderWidth = 1; reviewCell.BorderStyle = BorderStyle.Dotted; reviewCell.Width = 600; reviewCell.Text = "</br>" + "There are no existing top-ups yet!" + "</br></br>"; row.Controls.Add(reviewCell); Table1.Controls.Add(row); } else { } } } } catch (Exception) { var row = new TableRow(); var reviewCell = new TableCell(); reviewCell.Font.Bold = true; reviewCell.Font.Name = "Calibri"; reviewCell.BorderWidth = 1; reviewCell.BorderStyle = BorderStyle.Dotted; reviewCell.Width = 600; reviewCell.Text = "</br>" + "There are no existing top-ups yet!" + "</br></br>"; row.Controls.Add(reviewCell); Table1.Controls.Add(row); } } catch (Exception) { Response.Redirect("Mainpage.aspx"); } } } }