/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonOk_Click(object sender, RoutedEventArgs e) { var date1 = textBoxDate1.Text; if (!BankUtils.ValidateDate(date1)) { MessageBox.Show("Alkupäivämäärä virheellinen"); return; } var date2 = textBoxDate2.Text; if (!BankUtils.ValidateDate(date2)) { MessageBox.Show("Loppupäivämäärä virheellinen!"); return; } listBoxActivities.Items.Clear(); _bank.Customers.ForEach( customer => { var account = _bank.GetBankAccount(customer.BankAccountNumber); var prevDate = BankUtils.PreviousDate(date1); var balance = account.GetBalance(prevDate); listBoxActivities.Items.Add( $"Asiakas: {customer}, tili: {customer.BankAccountNumber}, saldo {prevDate}: {balance:F2}"); account.GetTransactions(date1, date2).ForEach( transaction => { balance += transaction.Amount; listBoxActivities.Items.Add( $"Päivämäärä: {transaction.Date}, summa: {transaction.Amount,12:F2}, saldo: {balance,12:F2}"); } ); listBoxActivities.Items.Add(""); } ); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonAddActivity_Click(object sender, RoutedEventArgs e) { var date = textBoxDate.Text; if (!BankUtils.ValidateDate(date)) { MessageBox.Show("Virheellinen päivämäärä!"); return; } float amount; if (!float.TryParse(textBoxAmount.Text, out amount)) { MessageBox.Show("Virheellinen summa!"); return; } var transaction = new BankAccountTransaction(date, amount); var account = _bank.GetBankAccount(_customer.BankAccountNumber); account.AddBankAccountTransaction(transaction); List <BankAccountTransaction> items = (List <BankAccountTransaction>)listViewActivities.ItemsSource; if (items == null) { items = new List <BankAccountTransaction>(); } items.Add(transaction); listViewActivities.ItemsSource = items; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listViewActivities.ItemsSource); view.SortDescriptions.Add(new SortDescription("Date", ListSortDirection.Ascending)); textBoxAmount.Clear(); }