Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }