private void lbx_accs_SelectionChanged(object sender, SelectionChangedEventArgs e) { Account selected = lbx_accs.SelectedItem as Account; //Selected cannot be null if (selected != null) { tblk_fName.Text = selected.FirstName; tblk_lName.Text = selected.LastName; tblk_bal.Text = selected.Balance.ToString(); tblk_balance.Text = selected.Balance.ToString(); //if its a current account, make a new one and take the details from it, if (selected is CurrentAccount) { CurrentAccount cA = lbx_accs.SelectedItem as CurrentAccount; tblk_type.Text = "Current Account"; tblk_interestDate.Text = null; } else if (selected is SavingsAccount) { SavingsAccount sA = lbx_accs.SelectedItem as SavingsAccount; tblk_type.Text = "Savings Account"; tblk_interestDate.Text = null; } } }
public MainWindow() { InitializeComponent(); //makes both checkboxes checked upon initialization cboxCurrentAccount.IsChecked = true; cboxSavingsAccount.IsChecked = true; //create objects CurrentAccount acc1 = new CurrentAccount("John", "Doe", 100000); CurrentAccount acc2 = new CurrentAccount("Adam", "Apple", 200000); SavingsAccount acc3 = new SavingsAccount("Sarah", "Farrel", 15000); SavingsAccount acc4 = new SavingsAccount("Darragh", "Weir", 20000); //add objects to list accounts.Add(acc1); accounts.Add(acc2); accounts.Add(acc3); accounts.Add(acc4); }
private void btnInterest_Click(object sender, RoutedEventArgs e) { //check which account was selected Account selectedAccount = lbxAccounts.SelectedItem as Account; //check if selected account is Current or Savings if (selectedAccount is CurrentAccount) { //puts selected account in new account of correct derived class (CurrentAccount) so you can call the correct properties (InterestRate) CurrentAccount selectedCurrentAccount = selectedAccount as CurrentAccount; tblkInterest.Text = selectedCurrentAccount.CalculateInterest().ToString(); } else if (selectedAccount is SavingsAccount) { //puts selected account in new account of correct derived class (SavingsAccount) so you can call the correct properties (InterestRate) SavingsAccount selectedSavingsAccount = selectedAccount as SavingsAccount; tblkInterest.Text = selectedSavingsAccount.CalculateInterest().ToString(); } }
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //clear tbx each time a new account is selected tbxTransactionAmount.Clear(); tblkInterest.Text = ""; tblkInterestDate.Text = ""; //check which account is selected Account selectedAccount = lbxAccounts.SelectedItem as Account; //check to see if there is an account selected if (selectedAccount != null) { //display account's name and balance tblkFirstName.Text = selectedAccount.FirstName; tblkLastName.Text = selectedAccount.LastName; tblkBalance.Text = selectedAccount.Balance.ToString(); //tblkInterestDate = selectedAccount.InterestDate; //check if selected account is Current or Savings if (selectedAccount is CurrentAccount) { //puts selected account in new account of correct derived class (CurrentAccount) so you can call the correct properties (InterestRate) CurrentAccount selectedCurrentAccount = selectedAccount as CurrentAccount; //displays Account Type tblkAccountType.Text = "Current Account"; //displays accounts monthly pay by calling the class method //tblkCalcMonthlyPay.Text = ("€" + selectedFTEmployee.CalculateMonthlyPay().ToString("F")); } else if (selectedAccount is SavingsAccount) { //puts selected account in new account of correct derived class (SavingsAccount) so you can call the correct properties (InterestRate) SavingsAccount selectedSavingsAccount = selectedAccount as SavingsAccount; //displays Account Type tblkAccountType.Text = "Savings Account"; //displays employees monthly pay by calling the class method //tblkCalcMonthlyPay.Text = ("€" + selectedPTEmployee.CalculateMonthlyPay().ToString("F")); } } }