-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmShowAccounts.cs
114 lines (100 loc) · 4.08 KB
/
frmShowAccounts.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
110
111
112
113
114
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;
using Bank_Cashier.Model;
namespace Bank_Cashier
{
public partial class frmShowAccounts : Form
{
public frmShowAccounts()
{
InitializeComponent();
}
private void frmShowAccounts_Load(object sender, EventArgs e)
{
gvAccounts.DataSource = Program.AppDB.DB;
gvAccounts.Columns["btncredit"].DisplayIndex = 5;
gvAccounts.Columns["btnUpdate"].DisplayIndex = 4;
lblNote.Text = String.Empty;
}
private void gvAccounts_CellClick(object sender, DataGridViewCellEventArgs e)
{
int ID = int.Parse(gvAccounts.Rows[e.RowIndex].Cells[2].Value.ToString());
Account account = Program.AppDB.GetByAccountId(ID);
int indx = Program.AppDB.DB.IndexOf(account);
if (gvAccounts.Columns[e.ColumnIndex].Name == "btncredit")
{
lblNote.Text = String.Empty;
frmCredit frmcedit = new frmCredit();
if (frmcedit.ShowDialog() == DialogResult.OK)
if (account != null)
{
double ammount = double.Parse(frmcedit.txtAmount.Text);
bool stat = false;
if (frmcedit.rbtnCredit.Checked)
{
stat= Program.AppDB.updateAmountCredit(account, ammount);
}
else if (frmcedit.rbtnDepit.Checked)
{
stat = Program.AppDB.updateAmountDepit(account, ammount);
}
if (stat)
{
lblNote.Text = "Operation has been done to the account";
}
else lblNote.Text = "Operation has been failed";
}
}
else if (gvAccounts.Columns[e.ColumnIndex].Name == "btnUpdate")
{
frmEditAccount frmEdit=new frmEditAccount();
frmEdit.txtName.Text = account.Name;
frmEdit.txtEmail.Text = account.Email;
frmEdit.txtBalance.Text =Convert.ToString(account.Balance);
if(account is SavingAccount)
{
frmEdit.rbtnSaving.Checked = true;
}
else if (account is CheckingAccount)
{
frmEdit.rbtnChecking.Checked = true;
frmEdit.txtFees.Text = Convert.ToString(((CheckingAccount)account).Fee);
}
frmEdit.rbtnChecking.Enabled = false;
frmEdit.rbtnSaving.Enabled = false;
frmEdit.txtFees.Enabled = false;
frmEdit.txtBalance.Enabled = false;
DialogResult res = frmEdit.ShowDialog();
if (res == DialogResult.OK)
{
bool x = false;
if(frmEdit.rbtnChecking.Checked)
{
x = Program.AppDB.updateAccount(ID, frmEdit.txtName.Text, frmEdit.txtEmail.Text, double.Parse(frmEdit.txtFees.Text));
}
else if(frmEdit.rbtnSaving.Checked)
{
x = Program.AppDB.updateAccount(ID, frmEdit.txtName.Text, frmEdit.txtEmail.Text);
}
if (x)
{
lblNote.Text = "Acount has been edited";
foreach (DataGridViewRow row in gvAccounts.Rows)
{
if (row.Selected)
row.Selected = false;
}
}
else lblNote.Text = "Edited had been failed";
}
}
}
}
}