public override void RunScene(float framesPerSecond) { MySqlHelper.ConnectToMySql(); MySqlDataReader reader = null; int id; decimal currentBalance = 0.00M; int dollarsToDeposit = 0; int centsToDeposit = 0; decimal amountToDeposit = 0.00M; decimal newBalance = 0.00M; string dollarsString; string centsString; if (!isLoggedIn) { do { Console.WriteLine(GetXmlText(@"general/enter_username")); username = Console.ReadLine(); Console.WriteLine(); reader = MySqlHelper.ExecuteQueryCommand("select * from customer_accounts where username = @0;", new string[] { username }); //Make sure there is data for this username. No rows = no data. if (!reader.HasRows) { reader.Close(); Console.WriteLine(GetXmlText(@"general/invalid_username") + "'{0}'", username); Console.WriteLine(); } }while (!reader.HasRows); } else { reader = MySqlHelper.ExecuteQueryCommand("select * from customer_accounts where username = @0;", new string[] { username }); } //Get first (and only) record to get data from reader.Read(); id = reader.GetInt32("id"); string pin = reader.GetString("pin"); currentBalance = reader.GetDecimal("balance"); reader.Close(); //CHECK PIN IF NOT LOGGED IN if (!isLoggedIn) { bool isPINValid = CheckPIN(validPin: pin, attemptsAllowed: 5); //EXIT TO WELCOME SCENE IF ATTEMPTS EXCEED LIMIT if (!isPINValid) { Console.WriteLine(GetXmlText("general/attempts_exceeded")); Console.WriteLine(); Director.GetInstance().ChangeScene(new WelcomeScene()); return; } } bool isInputValid = false; //Get dollars to deposit do { Console.WriteLine(GetXmlText(@"deposit/deposit_dollars")); dollarsString = Console.ReadLine(); Console.WriteLine(); if (dollarsString == "" || int.TryParse(dollarsString, out dollarsToDeposit)) { //Can't deposit negative dollars if (dollarsToDeposit >= 0) { isInputValid = true; } } else { Console.WriteLine(GetXmlText(@"deposit/invalid_dollars")); Console.WriteLine(); } }while (!isInputValid); //Reset switch for next check isInputValid = false; //Get cents to deposit do { Console.WriteLine(GetXmlText(@"deposit/deposit_cents")); centsString = Console.ReadLine(); Console.WriteLine(); if (centsString == "" || (int.TryParse(centsString, out centsToDeposit) && centsToDeposit >= 0 && centsToDeposit <= 99)) { isInputValid = true; } else { Console.WriteLine(GetXmlText(@"deposit/invalid_cents")); Console.WriteLine(); } }while (!isInputValid); amountToDeposit = dollarsToDeposit + centsToDeposit / 100.00M; newBalance = currentBalance + amountToDeposit; MySqlHelper.ExecuteNonQueryCommand("update customer_accounts set balance=@0 where id=@1;", new string[] { newBalance.ToString(), id.ToString() }); //CONFIRMATION Console.WriteLine(GetXmlText("deposit/success") + GetXmlText("general/new_balance") + string.Format("${0:0.00}", newBalance)); Console.WriteLine(); Director.GetInstance().ChangeScene(new WelcomeScene()); return; }
public override void RunScene(float framesPerSecond) { string selectionString; int? selection = null; Console.WriteLine(GetXmlText("greeting")); Console.WriteLine(GetXmlText("assist")); Console.WriteLine(); Console.WriteLine(GetXmlText("main_menu")); Console.WriteLine(); Console.WriteLine(GetXmlText("enter_number")); bool isSelectionValid = false; do { //User didn't enter blank if (GetStringInput(out selectionString)) { //Assume true, will set to false if all cases fail isSelectionValid = true; //Check if user typed in phrase, or number along with phrase, or number + '.' switch (selectionString[0]) { //DEPOSIT FUNDS case '1': case 'd': case 'D': selection = 1; break; //WITHDRAW FUNDS case '2': case 'w': case 'W': selection = 2; break; //GET BALANCE STATEMENT case '3': case 'g': case 'G': case 'b': case 'B': case 's': case 'S': selection = 3; break; //CREATE NEW ACCOUNT case '4': case 'c': case 'C': case 'n': case 'N': case 'a': case 'A': selection = 4; break; //INVALID INPUT default: isSelectionValid = false; Console.WriteLine(); Console.WriteLine(GetXmlText("error")); Console.WriteLine(); Console.WriteLine(GetXmlText("assist")); Console.WriteLine(); Console.WriteLine(GetXmlText("main_menu")); Console.WriteLine(); break; } } //User entered blank else { Console.WriteLine(GetXmlText("error")); Console.WriteLine(); Console.WriteLine(GetXmlText("assist")); Console.WriteLine(); Console.WriteLine(GetXmlText("main_menu")); Console.WriteLine(); } }while (!isSelectionValid); //Lower selection by one so it matches up to enumerated types if (selection != null) { selection--; } Director director = Director.GetInstance(); switch (selection) { case (int)(SELECTION.DEPOSIT): director.ChangeScene(new DepositScene()); break; case (int)(SELECTION.WITHDRAW): director.ChangeScene(new WithdrawScene()); break; case (int)(SELECTION.STATEMENT): director.ChangeScene(new StatementScene()); break; case (int)(SELECTION.NEW): director.ChangeScene(new CreateAccountScene()); break; } Console.WriteLine(); return; }