private void sbmtBtn_Click(object sender, RoutedEventArgs e) { var transactionEntry = new TransactionEntry(); transactionEntry.Mode = Mode; transactionEntry.TransationID = TransactionID; transactionEntry.Account = (Account)cbAccount.SelectedItem; transactionEntry.Amount = tbAmount.Text; transactionEntry.CheckNumber = tbCheckNumber.Text; transactionEntry.Notes = tbNotes.Text; if(cbBudget1.SelectedValue != null) transactionEntry.Budget.Add(new DictionaryEntry(cbBudget1.SelectedItem, tbBudget1Amount.Text)); if (cbBudget2.SelectedValue != null) transactionEntry.Budget.Add(new DictionaryEntry(cbBudget2.SelectedItem, tbBudget2Amount.Text)); if (cbBudget3.SelectedValue != null) transactionEntry.Budget.Add(new DictionaryEntry(cbBudget3.SelectedItem, tbBudget3Amount.Text)); if (cbBudget4.SelectedValue != null) transactionEntry.Budget.Add(new DictionaryEntry(cbBudget4.SelectedItem, tbBudget4Amount.Text)); if (cbBudget5.SelectedValue != null) transactionEntry.Budget.Add(new DictionaryEntry(cbBudget5.SelectedItem, tbBudget5Amount.Text)); if (cbBudget6.SelectedValue != null) transactionEntry.Budget.Add(new DictionaryEntry(cbBudget6.SelectedItem, tbBudget6Amount.Text)); transactionEntry.Date = dpDate.SelectedDate; transactionEntry.Payee = (Payee)cbPayee.SelectedItem; List<string> errors; List<string> warnings; SaveTransaction(transactionEntry, out errors, out warnings); }
private void SaveTransaction(TransactionEntry transactionEntry, out List<string> errors, out List<string> warnings, Boolean ignoreWarnings = false) { if (transactionEntry.Save(out errors, out warnings, ignoreWarnings)) { if (Mode == ModeValues.Add) { // add was successful MessageBox.Show("Transaction successfully added."); ClearWindow(); } else if (Mode == ModeValues.Edit) { // update was successful MessageBox.Show("Transaction successfully updated."); this.Close(); } } else { // there was a problem var sb = new StringBuilder(); // show the errors first if (errors.Count > 0) { foreach (string error in errors) { sb.Append(error).Append("\n"); } MessageBox.Show(sb.ToString(), "Error"); } // if no errors, then show the warnings else if (warnings.Count > 0) { sb.Append("The following warnings occurred:\n\n"); foreach (string warning in warnings) { sb.Append(warning).Append("\n"); } sb.Append("\nContinue?"); var result = MessageBox.Show(sb.ToString(), "Warning", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { // if user selects continue, re-attempt the save, but ignore warnings SaveTransaction(transactionEntry, out errors, out warnings, true); } } } }