/// <summary> /// The click event for the OK Button. Does most of the work interfacing with the controller. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxOKButton_Click(object sender, EventArgs e) { Tuple <AtmStatus, double> s = controller.handle(uxCustomerInputTextbox.Text); uxCustomerInputTextbox.Text = ""; state = s.Item1; double balance = s.Item2; uxDisplayMenuLabel.Text = message[state]; if (state == AtmStatus.ChooseBalanceInquiry) { uxDisplayMenuLabel.Text += balance.ToString("00.00") + ". Please press 'OK' to log out."; } if (state == AtmStatus.CompletedWithdrawal) { uxDisplayMenuLabel.Text += balance.ToString("00.00") + ". Please press 'OK' to log out."; } }
/// <summary> /// The handler method for all of the ATM's states. /// </summary> /// <param name="s">The string taken from the input text box on the ATM from.</param> /// <returns>A tuple containing the next state, as well as the balance of the account when applicable.</returns> public Tuple <AtmStatus, double> handle(string s) { //int acctNum = 0; switch (state) { case AtmStatus.Start: { int acctNum = 0; bool intOK = int.TryParse(s, out acctNum); if (intOK) { if (aDatabase.doesAccountExist(acctNum) == true) { if (aDatabase.logInAccount(acctNum) == true) { balance = 0; state = AtmStatus.LoggedIn; accountNumber = acctNum; } else { state = AtmStatus.AccountAlreadyInUse; } } else { state = AtmStatus.AccountNotFound; } } else { state = AtmStatus.AccountNotFound; } break; } case AtmStatus.AccountNotFound: { state = AtmStatus.Start; break; } case AtmStatus.LoggedIn: { int input = 0; bool intOK = int.TryParse(s, out input); if (intOK) { if (input == 1) { state = AtmStatus.ChooseBalanceInquiry; balance = checkBalance(accountNumber); } else if (input == 2) { state = AtmStatus.ChoseWithdrawalNeedAmount; balance = checkBalance(accountNumber); } else { //Add an invalid input state here. state = AtmStatus.InvalidInput; } } else { state = AtmStatus.InvalidInput; } break; } case AtmStatus.ChooseBalanceInquiry: { state = AtmStatus.Start; aDatabase.logOutAccount(accountNumber); break; } case AtmStatus.ChoseWithdrawalNeedAmount: { double withAmmt = 0; bool doubleOk = Double.TryParse(s, out withAmmt); if (doubleOk == true) { if ((balance - withAmmt) >= 0) { completeWithdrawal(accountNumber, withAmmt); balance = checkBalance(accountNumber); state = AtmStatus.CompletedWithdrawal; MessageBox.Show("Here's $" + withAmmt.ToString("00.00") + ", just for you.", "Dolla Dolla Bills Ya'll"); } else { state = AtmStatus.InvalidInput; } } else { //Add the invalid input state here. state = AtmStatus.InvalidInput; } break; } case AtmStatus.CompletedWithdrawal: { state = AtmStatus.Start; aDatabase.logOutAccount(accountNumber); break; } case AtmStatus.InvalidInput: { state = AtmStatus.Start; aDatabase.logOutAccount(accountNumber); break; } case AtmStatus.AccountAlreadyInUse: { state = AtmStatus.Start; break; } default: { break; } } return(new Tuple <AtmStatus, double>(state, balance)); }
/// <summary> /// The handler method for all of the ATM's states. /// </summary> /// <param name="s">The string taken from the input text box on the ATM from.</param> /// <returns>A tuple containing the next state, as well as the balance of the account when applicable.</returns> public Tuple<AtmStatus, double> handle(string s) { //int acctNum = 0; switch (state) { case AtmStatus.Start: { int acctNum = 0; bool intOK = int.TryParse(s, out acctNum); if (intOK) { if (aDatabase.doesAccountExist(acctNum) == true) { if (aDatabase.logInAccount(acctNum) == true) { balance = 0; state = AtmStatus.LoggedIn; accountNumber = acctNum; } else { state = AtmStatus.AccountAlreadyInUse; } } else { state = AtmStatus.AccountNotFound; } } else { state = AtmStatus.AccountNotFound; } break; } case AtmStatus.AccountNotFound: { state = AtmStatus.Start; break; } case AtmStatus.LoggedIn: { int input = 0; bool intOK = int.TryParse(s, out input); if (intOK) { if (input == 1) { state = AtmStatus.ChooseBalanceInquiry; balance = checkBalance(accountNumber); } else if (input == 2) { state = AtmStatus.ChoseWithdrawalNeedAmount; balance = checkBalance(accountNumber); } else { //Add an invalid input state here. state = AtmStatus.InvalidInput; } } else { state = AtmStatus.InvalidInput; } break; } case AtmStatus.ChooseBalanceInquiry: { state = AtmStatus.Start; aDatabase.logOutAccount(accountNumber); break; } case AtmStatus.ChoseWithdrawalNeedAmount: { double withAmmt = 0; bool doubleOk = Double.TryParse(s, out withAmmt); if (doubleOk == true) { if ((balance - withAmmt) >= 0) { completeWithdrawal(accountNumber, withAmmt); balance = checkBalance(accountNumber); state = AtmStatus.CompletedWithdrawal; MessageBox.Show("Here's $" + withAmmt.ToString("00.00") + ", just for you.", "Dolla Dolla Bills Ya'll"); } else { state = AtmStatus.InvalidInput; } } else { //Add the invalid input state here. state = AtmStatus.InvalidInput; } break; } case AtmStatus.CompletedWithdrawal: { state = AtmStatus.Start; aDatabase.logOutAccount(accountNumber); break; } case AtmStatus.InvalidInput: { state = AtmStatus.Start; aDatabase.logOutAccount(accountNumber); break; } case AtmStatus.AccountAlreadyInUse: { state = AtmStatus.Start; break; } default: { break; } } return new Tuple<AtmStatus, double>(state, balance); }
/// <summary> /// The click event for the OK Button. Does most of the work interfacing with the controller. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uxOKButton_Click(object sender, EventArgs e) { Tuple<AtmStatus, double> s = controller.handle(uxCustomerInputTextbox.Text); uxCustomerInputTextbox.Text = ""; state = s.Item1; double balance = s.Item2; uxDisplayMenuLabel.Text = message[state]; if (state == AtmStatus.ChooseBalanceInquiry) { uxDisplayMenuLabel.Text += balance.ToString("00.00") + ". Please press 'OK' to log out."; } if (state == AtmStatus.CompletedWithdrawal) { uxDisplayMenuLabel.Text += balance.ToString("00.00") + ". Please press 'OK' to log out."; } }