-
Notifications
You must be signed in to change notification settings - Fork 0
/
withdraw_money.cs
62 lines (47 loc) · 1.9 KB
/
withdraw_money.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
namespace Banking_App
{
public partial class WithdrawMoney : DataForm
{
public WithdrawMoney(Dictionary<string, string> loggedInUser, DashboardShowD dashboardShowB)
: base(loggedInUser, dashboardShowB)
{
InitializeComponent();
}
private void Withdraw_money_button_Click(object sender, EventArgs e)
{
var amount = enter_amount_input.Text.Trim();
if (amount == "" || amount == "0" || amount.All(char.IsDigit) == false)
{
MessageBox.Show("The amount must not be empty and in numbers only.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var amountInt = int.Parse(amount);
var userBalance = int.Parse(user["balance"]);
if( amountInt > userBalance )
{
MessageBox.Show("The amount should not be more than the balance.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// updating amount to current user and file system
var newAmount = (userBalance - amountInt).ToString();
user["balance"] = newAmount;
FileSystemCus.UpdateRow("users", user);
// adding transaction in file
FileSystemCus.WriteData("transactions", new Dictionary<string, string>()
{
["from"] = user["id"],
["to"] = "none",
["amount"] = amount,
["date"] = DateTime.Now.ToString()
});
MessageBox.Show("Successfully withdrew", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
Close();
dashboardShow();
}
private void Back_button_Click(object sender, EventArgs e)
{
Close();
dashboardShow();
}
}
}