private void depositToolStripMenuItem_Click(object sender, EventArgs e) { if (listBoxBankAccounts.SelectedItem == null) { return; } BankAccount account = listBoxBankAccounts.SelectedItem as BankAccount; SingleValueInputForm dlg = new SingleValueInputForm(); dlg.MustBeDecimalValue = true; dlg.Text = "Deposit"; dlg.Prompt = "Enter amount"; if (dlg.ShowDialog() == DialogResult.OK) { // Assumption: dialog already validated input as a Decimal value. decimal amount = decimal.Parse(dlg.Input); account.Deposit(amount); repopulateAccountsList(); } dlg.Dispose(); }
private void withdrawToolStripMenuItem_Click(object sender, EventArgs e) { if (listBoxBankAccounts.SelectedItem == null) { return; } BankAccount account = listBoxBankAccounts.SelectedItem as BankAccount; SingleValueInputForm dlg = new SingleValueInputForm(); dlg.MustBeDecimalValue = true; dlg.Text = "Withdrawal"; dlg.Prompt = "Enter amount"; if (dlg.ShowDialog() == DialogResult.OK) { // Assumption: dialog already validated input as a Decimal value. decimal amount = decimal.Parse(dlg.Input); try { account.Withdraw(amount); repopulateAccountsList(); } catch (NoSufficientFundsException ex) { MessageBox.Show( string.Format("{0}\n\nAccount Balance:\t{1:N2}\nWithdraw Amount:\t{2:N2}", ex.Message , ex.Account.Balance , ex.TransactionAmount) , "No Sufficient Funds Exception" , MessageBoxButtons.OK , MessageBoxIcon.Exclamation); } catch (NoSufficientFundsSimpleException ex) { MessageBox.Show(ex.Message, "No Sufficient Funds Simple Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.Message, "General Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } dlg.Dispose(); }