// Method to control what happens when a pin number has been entered public void EnterPin() { if (account.checkPin(Int32.Parse(userInput))) // Convert userInput to an int and compare against the real pin { DisplayMenuOptions(); MessageBank(account.getAccountNum() + " entered their pin number"); } else // If the pin wasn't valid { Screen.Items.Clear(); // Clear the screen Screen.Items.Add(lastMessage); // Add back the last message Screen.Items.Add("Incorrect pin"); // Tell the user that the pin was incorrect userInput = ""; MessageBank(account.getAccountNum() + " entered an incorrect pin"); if (account.CheckFail()) // Check if the account has been incorrectly accessed too many times { Screen.Items.Clear(); Screen.Items.Add("Too many attempts"); // Tell the user that they have attempted too many times lastMessage = "Enter your account number:"; Screen.Items.Add(lastMessage); mode = 0; // Tell the system that an account number is expected MessageBank(account.getAccountNum() + "'s account has been locked"); } } }
// check provided by user data and proceed to the next step. Called by 2 methods above private void nextStep() { switch (state) { case 0: activeAccount = findAccount(textBox1.Text); if (activeAccount != null) // if account found, go to the next step { textBox1.Text = "Enter your pin here"; screen1(); pinTry = 4; } else // if account was not found, program stays in the same state { textBox1.Text = "Insert your card here"; text[4].Text = "Wrong card"; } break; case 1: try { int input = Convert.ToInt32(IsDigitsOnly(textBox1.Text)); if (activeAccount.checkPin(input)) // if entered pin is correct { textBox1.Text = ""; textBox1.PasswordChar = '\0'; screen2(); } else // if pin is wrong { pinFail(); } } catch (Exception) // if pin is wrong { pinFail(); } break; case 6: //Take user input and deposit it into their acount try { int depositValue = Convert.ToInt32(IsDigitsOnly(textBox1.Text)); if (depositValue != 0) //Checks if deposit value is { int oldBal = activeAccount.getBalance(); Thread.Sleep(3000); activeAccount.setBalance(oldBal + depositValue); activeAccount.Unlock(); //Go to stage 2 textBox1.Text = ""; textBox1.PasswordChar = '\0'; screen2(); } else { textBox1.Text = "Invalid value"; } } catch (Exception) // if user input causes error { textBox1.Text = "Invalid value"; } break; case 7: //read the amount of money provided by user to the taken from account int userCash = Convert.ToInt32(IsDigitsOnly(textBox1.Text)); if (userCash % 5 == 0) // amount must be devisible by 5 { if (datarace) { takeCashTrue(userCash); } else { takeCashFalse(userCash); } } else { textBox1.Text = ""; label1.Text = "Enter Amount\n Invalid number"; } break; default: textBox1.Text = ""; break; } }
private void EnterButton_Click(object sender, EventArgs e) { // Checks if there is something in box when enter is pressed if (DisplayInput.Text.Length > 0) { // Withdraw stage if (withdraw == true) { int input = Convert.ToInt32(DisplayInput.Text); // Only allows certain input and if it's divisble by 5 if (input == 0 || input > 400 || input % 5 != 0) { MessageBox.Show("Please enter a valid withdrawal amount (must be divisible by 5)"); DisplayInput.Text = ""; } else { withdrawInstructions(input); changePanel(panelWithdraw); DisplayInstruction.Text = "Please select a withdraw option"; allignText(); DisplayInput.Text = ""; } } //Account number stage else if (inputPin == false) { int input = Convert.ToInt32(DisplayInput.Text); DisplayInput.Text = ""; // Tries to find account Boolean found = false; for (int i = 0; i < this.ac.Length - 1; i++) { if (ac[i].getAccountNum() == input) { activeAccount = ac[i]; // atmManager.log("Account successfully logged in."); DisplayInstruction.Text = "Please enter your pin"; allignText(); inputPin = true; found = true; account = false; } } if (found == false) { MessageBox.Show("Please write a valid account number"); } } else { // Pin input stage if (check >= 0) { int input = Convert.ToInt32(DisplayInput.Text); DisplayInput.Text = ""; // If pin is correct if (activeAccount.checkPin(input) == true) { //Display the options and change panel atmManager.log("Account number " + activeAccount.getAccountNum() + " successfully logged in."); inputPin = false; changePanel(accountPanel); DisplayInstruction.Text = "Select an option you would like to do"; allignText(); check = 3; } else { // if pin is wrong attempts(); } } } } else { // if the user presses enter when it's blank dispaly certain error message if (inputPin == true) { attempts(); } else { if (withdraw == true) { MessageBox.Show("Please Type a valid withdrawal amount"); } else { MessageBox.Show("Please enter a valid account number"); } } } }
// When green enter button is pressed private void enterBtn_Click(object sender, EventArgs e) { if (loginTextbox.Text == "") { wrongInputLbl.Text = "Ivalid input, Please try again"; } else if (state == 1) // Account Number State { activeAccount = findAccount(Int32.Parse(loginTextbox.Text)); loginTextbox.Text = ""; if (activeAccount != null) // If account number successful { state = 2; // PIN State display(); } else { wrongInputLbl.Text = "Wrong Account Number"; } } else if (state == 2) // PIN State { if (activeAccount.checkPin(Int32.Parse(loginTextbox.Text))) // If PIN correct { state = 3; // Main Menu State display(); incorrectPIN = 0; } else { incorrectPIN++; wrongInputLbl.Text = "Wrong PIN"; } loginTextbox.Text = ""; } else if (state == 6) // Choose Amount State { if (usingSemaphore) { activeAccount.accessed.WaitOne(); } if (activeAccount.decrementBalance(Int32.Parse(loginTextbox.Text), usingSemaphore)) { state = 5; } else { state = 7; } if (usingSemaphore) { activeAccount.accessed.Release(); } display(); loginTextbox.Text = ""; } if (incorrectPIN >= 3) // If the PIN is incorrect 3 times deactivate the acoount. { activeAccount.destroyAccount(); state = 1; display(); incorrectPIN = 0; wrongInputLbl.Text = "PIN wrong 3 times. Account deactivated."; } }