-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWithdrawForm.cs
109 lines (94 loc) · 3.47 KB
/
WithdrawForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BankSystem
{
public partial class WithdrawForm : Form
{
private SummaryForm parentForm;
private ChequingAccount currentCheqAcc;
private SavingAccount currentSaveAcc;
public WithdrawForm(SummaryForm parentForm, ChequingAccount currentCheqAcc, SavingAccount currentSaveAcc)
{
this.parentForm = parentForm;
this.currentCheqAcc = currentCheqAcc;
this.currentSaveAcc = currentSaveAcc;
InitializeComponent();
if (this.currentCheqAcc == null) { this.checkChequing.Enabled = false; }
else { this.chequingBalance.Text = this.currentCheqAcc.GetBalance().ToString(); }
if (this.currentSaveAcc == null) { this.checkSaving.Enabled = false; }
else { this.savingBalance.Text = this.currentSaveAcc.GetBalance().ToString(); }
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
this.parentForm.Show();
this.parentForm.RefreshSummary();
this.Close();
}
private void Withdraw_button_Click(object sender, EventArgs e)
{
if (!(float.TryParse(this.txt_Amount.Text, out float amount)))
{
MessageBox.Show("Invalid amount");
return;
}
if (amount < 0)
{
MessageBox.Show("Invalid amount");
return;
}
bool flag;
if (this.checkChequing.Checked)
{
if (
MessageBox.Show(
$"Are you sure you would like to withdraw this amount ?\nYour Chequing account balance after this action : ${(Math.Round((float.Parse(this.currentCheqAcc.GetBalance()) - amount) * 100f) / 100f).ToString()}",
"Confirmation",
MessageBoxButtons.OKCancel) != DialogResult.OK
) { return; }
flag = this.currentCheqAcc.Withdraw(amount);
}
else
{
if (
MessageBox.Show(
$"Are you sure you would like to withdraw this amount ?\nYour Saving account balance after this action : ${(float.Parse(this.currentSaveAcc.GetBalance()) - amount).ToString()}",
"Confirmation",
MessageBoxButtons.OKCancel) != DialogResult.OK
) { return; }
flag = this.currentSaveAcc.Withdraw(amount);
}
if (flag == true)
{
MessageBox.Show("Withdraw Successful");
this.Hide();
this.parentForm.RefreshSummary();
this.parentForm.Show();
this.Close();
}
else
{
MessageBox.Show("Withdraw Unsuccessful");
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Escape)
{
this.button1.PerformClick();
}
if (keyData == Keys.Enter)
{
this.Withdraw_button.PerformClick();
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
}