public partial class frmBanking : Form
{
List<Customer> customers;
MySettings settings;
private bool dataSourceChange;
public frmBanking()
{
InitializeComponent();
}
private void frmBanking_Load(object sender, EventArgs e)
{
this.dataSourceChange = true;
this.lbxCustomers.DataSource = new string[] { "foo", "bar" };
this.dataSourceChange = false;
try
{
settings = Program.Configuration.GetSection("MySettings").Get<MySettings>();
this.Text = settings.Text;
lblStatus.ForeColor = Color.Black;
//customers = CustomerManager.Populate();
customers = CustomerManager.ReadXML(settings.CustomerXMLFilename);
Refresh();
}
catch (Exception ex)
{
lblStatus.ForeColor = Color.Red;
lblStatus.Text = ex.Message;
}
}
private void Refresh()
{
lbxCustomers.DataSource = null;
lbxCustomers.DataSource = customers;
lbxCustomers.DisplayMember = "FullName";
lbxCustomers.ValueMember = "Id";
lblStatus.Text = $"{lbxCustomers.Items.Count} Customers loaded";
lblStatus.ForeColor = Color.Blue;
}
private void lbxCustomers_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.dataSourceChange)
{
this.lbxCustomers.SelectedIndex = -1;
return;
}
try
{
lblStatus.ForeColor = Color.Black;
lblStatus.Text = string.Empty;
if (lbxCustomers.SelectedIndex >= 0)
{
Customer customer = customers[lbxCustomers.SelectedIndex];
txtFirstName.Text = customer.FirstName;
txtLastName.Text = customer.LastName;
txtSSN.Text = customer.SSN;
txtId.Text = customer.Id.ToString();
dtBirthDate.Text = customer.Birthdate.ToString();
dgvDeposits.DataSource = null;
dgvWithdrawals.DataSource = null;
}
}
catch (Exception ex)
{
lblStatus.ForeColor = Color.Red;
lblStatus.Text = ex.Message;
}
}