// Save transaction from the user // (Requirement 1.1.0) private void BtnAddTransaction_Click(object sender, RoutedEventArgs e) { if (viewModel.NewTransaction.Date.CompareTo(System.DateTime.Now) > 0) { viewModel.NewTransaction.Date = System.DateTime.Now; errorContent.Content = "No future dates!"; return; } if (viewModel.NewTransaction.Payee == "Payee") { errorContent.Content = "Must provide Payee!"; return; } if (viewModel.NewTransaction.Amount == 0) { errorContent.Content = "Must provide Amount!"; return; } if (viewModel.NewTransaction.Category == "Category") { viewModel.NewTransaction.Category = ""; } if (viewModel.NewTransaction.Custom_notes == "Notes") { viewModel.NewTransaction.Custom_notes = ""; } viewModel.AddTrans(cbDirectionTransaction.Text); // refresh current balance label BalanceLabel.GetBindingExpression(Label.ContentProperty).UpdateTarget(); viewModel.NewTransaction.DefaultAll(); errorContent.Content = ""; }
private void ConfirmImportClick(object sender, RoutedEventArgs e) { if (!viewModel.Importing) { return; } CsvImportStatus.Content = $"Status: Processing {viewModel.Imported.Count} new transactions..."; foreach (TransactionModel t in viewModel.Imported) { SqliteDataAccess.SaveTransaction(t); } viewModel.RefreshData(); BalanceLabel.GetBindingExpression(Label.ContentProperty).UpdateTarget(); CsvDatePreview.Content = ""; CsvAmountPreview.Content = ""; CsvPayeePreview.Content = ""; CsvNumberPreview.Content = ""; CsvImportStatus.Content = $"Status: {viewModel.Imported.Count} transactions added"; viewModel.Imported = null; viewModel.Importing = false; }
private void DeleteTransactionButtonClick(object sender, RoutedEventArgs e) { viewModel.RemoveTrans(); // refresh current balance label BalanceLabel.GetBindingExpression(Label.ContentProperty).UpdateTarget(); }
// Updates DB when transaction cells are edited by user private void Transactions_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { if (e.EditAction == DataGridEditAction.Commit) { // Need to get the new user-edited value with a switch statement var c = e.Column as DataGridBoundColumn; if (c != null) { TransactionModel editedTransaction = (TransactionModel)e.Row.DataContext; int rowIndex = e.Row.GetIndex(); var el = e.EditingElement as TextBox; var changedColumn = (c.Binding as Binding).Path.Path; try { switch (changedColumn) { case "Date": DateTime d; try { d = Convert.ToDateTime(el.Text); } catch { // error parsing this.Recent_Transactions.CancelEdit(); return; } if (d.CompareTo(System.DateTime.Now) > 0) { // cannot use a future date this.Recent_Transactions.CancelEdit(); return; } editedTransaction.Date = d; break; case "Amount": Decimal a; try { a = Convert.ToDecimal(el.Text.Replace("$", "")); } catch { // error parsing this.Recent_Transactions.CancelEdit(); return; } //Created bug; unable to maintain an outflow transaction on edit //if (a <= 0) //{ // // amount cannot be negative // this.Recent_Transactions.CancelEdit(); // return; //} editedTransaction.Amount = a; break; case "Payee": editedTransaction.Payee = el.Text; if (el.Text == "") { // payee cannot be blank this.Recent_Transactions.CancelEdit(); return; } break; case "Category": editedTransaction.Category = el.Text; break; case "Custom_notes": editedTransaction.Custom_notes = el.Text; break; default: // not allowed to change balance, return now return; } // save edited transaction to DB and refresh UI viewModel.UpdateTransaction(editedTransaction); BalanceLabel.GetBindingExpression(Label.ContentProperty).UpdateTarget(); } catch { return; } } } }