namespace BankAccountsApp
{
public partial class Form1 : Form
{
List<BankAccount> BankAccounts = new List<BankAccount>();
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = BankAccounts;
}
private void CreateAccountBtn_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(OwnerTxt.Text))
{
MessageBox.Show("Enter the username!");
return;
}
BankAccount bankAccount = new BankAccount(OwnerTxt.Text);
BankAccounts.Add(bankAccount);
RefreshGrid();
OwnerTxt.Text = string.Empty;
}
private void RefreshGrid()
{
dataGridView1.DataSource = null;
dataGridView1.DataSource = BankAccounts;
}
private void DepositBtn_Click(object sender, EventArgs e)
{
if(dataGridView1.SelectedRows.Count == 1 && AmountNum.Value > 0)
{
BankAccount selectedBankAccount = dataGridView1.SelectedRows
[0].DataBoundItem as BankAccount;
selectedBankAccount.Balance += AmountNum.Value;
RefreshGrid();
}
}
}
}