private void btnOk_Click(object sender, EventArgs e) { MoneyDataSet.AccountsRow account = cbAccount.SelectedItem as MoneyDataSet.AccountsRow; double amount = account.Balance - ((double)numBalance.Value); MoneyDataSet.TransactionsRow preCreate = keeper.PreCreateTransaction(keeper.GetTransactionType(MoneyDataSet.IDs.TransactionTypes.Correction), Resources.Labels.AccountCorrectionLabel, tbDescription.Text, DateTime.Now, account, amount); ValidationResult result = keeper.Validate(transaction: preCreate); if (!result.Success) { if (result.PreventAction) { MessageBox.Show(String.Format(Resources.Labels.TransactionValidationErrorsFoundFormat, result.Message), Resources.Labels.TransactionValidationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (MessageBox.Show(String.Format(Resources.Labels.TransactionValidationWarningsFoundFormat, result.Message), Resources.Labels.TransactionValidationTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return; } } } keeper.CreateTransaction(preCreate, ttbTags.Tags); this.DialogResult = DialogResult.OK; this.Close(); }
private void btnOk_Click(object sender, EventArgs e) { tbTitle.Text = tbTitle.Text.Trim(); MoneyDataSet.AccountsRow sourceAccount = cbSourceAccount.SelectedItem as MoneyDataSet.AccountsRow; double sourceAmount = (double)numSourceAmount.Value; MoneyDataSet.PlannedTransactionsRow sourcePlan = null; if (cbSourceImplementsPlan.Checked) { sourcePlan = cbSourcePlan.SelectedItem as MoneyDataSet.PlannedTransactionsRow; } MoneyDataSet.TransactionsRow preCreateSource = keeper.PreCreateTransaction(template.TransactionTypesRowByFK_TransactionTypes_Source_TransactionTemplates, tbTitle.Text, tbDescription.Text, dtpTransactionDate.Value, sourceAccount, sourceAmount, plan: sourcePlan, template: template); MoneyDataSet.TransactionsRow preCreateDestination = null; ValidationResult resultSource = keeper.Validate(transaction: preCreateSource); ValidationResult resultDestination = new ValidationResult(success: true, preventAction: false, message: String.Empty); if (template.HasDestinationAccount) { MoneyDataSet.AccountsRow destinationAccount = cbDestinationAccount.SelectedItem as MoneyDataSet.AccountsRow; double destinationAmount = (double)numDestinationAmount.Value; MoneyDataSet.PlannedTransactionsRow destinationPlan = null; if (cbDestinationImplementsPlan.Checked) { destinationPlan = cbDestinationPlan.SelectedItem as MoneyDataSet.PlannedTransactionsRow; } preCreateDestination = keeper.PreCreateTransaction(template.TransactionTypesRowByFK_TransactionTypes_Destination_TransactionTemplates, tbTitle.Text, tbDescription.Text, dtpTransactionDate.Value, destinationAccount, destinationAmount, plan: destinationPlan, template: template, pairReference: preCreateSource.ID); resultDestination = keeper.Validate(transaction: preCreateDestination); } if (!((resultSource.Success) && (resultDestination.Success))) { StringBuilder message = new StringBuilder(); if (String.IsNullOrWhiteSpace(resultSource.Message)) { message.AppendLine(Resources.Labels.TransactionDestinationValidation); message.Append(resultDestination.Message); } else if (String.IsNullOrWhiteSpace(resultDestination.Message)) { if (template.HasDestinationAccount) { message.AppendLine(Resources.Labels.TransactionSourceValidation); } message.Append(resultSource.Message); } else { message.Append(String.Join(Environment.NewLine, new String[] { Resources.Labels.TransactionSourceValidation, resultSource.Message, String.Empty, Resources.Labels.TransactionDestinationValidation, resultDestination.Message })); } if ((resultSource.PreventAction) || (resultDestination.PreventAction)) { MessageBox.Show(String.Format(Resources.Labels.TransactionValidationErrorsFoundFormat, message.ToString()), Resources.Labels.TransactionValidationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (MessageBox.Show(String.Format(Resources.Labels.TransactionValidationWarningsFoundFormat, message.ToString()), Resources.Labels.TransactionValidationTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return; } } } transaction = keeper.CreateTransaction(preCreateSource, ttbTags.Tags); if (template.HasDestinationAccount) { keeper.CreateTransaction(preCreateDestination, ttbTags.Tags); } keeper.AddTextHistory(String.Format(Consts.Keeper.TransactionTitleHistoryIDFormat, template.ID), tbTitle.Text); this.DialogResult = DialogResult.OK; this.Close(); }