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();
        }
Пример #2
0
        public TransactionViewForm(MoneyDataSet.TransactionsRow transaction)
        {
            InitializeComponent();
            this.transaction = transaction;

            MoneyDataSet.TransactionsRow sourceTransaction      = null;
            MoneyDataSet.TransactionsRow destinationTransaction = null;

            // lookup paired transaciton
            if ((!transaction.IsPairReferenceIDNull()) && (transaction.PairReferenceID != 0))
            {
                foreach (MoneyDataSet.TransactionsRow t in
                         keeper.Transactions.Where(t => ((!t.IsPairReferenceIDNull()) && (t.PairReferenceID == transaction.PairReferenceID))))
                {
                    // setting source and destination
                    if (t.TypeID.Equals(transaction.TransactionTemplatesRow.SourceTransactionTypeID))
                    {
                        sourceTransaction = t;
                    }
                    else if (t.TypeID.Equals(transaction.TransactionTemplatesRow.DestinationTransactionTypeID))
                    {
                        destinationTransaction = t;
                    }
                }

                if ((sourceTransaction == null) || (destinationTransaction == null))
                {
                    ErrorHelper.ShowErrorBox(ErrorHelper.Errors.InvalidTransaction);
                    return;
                }

                tbDestinationAccount.Text = destinationTransaction.AccountRow.FullTitle;
                tbDestinationAmount.Text  = destinationTransaction.Amount.ToString(Consts.UI.CurrencyFormat,
                                                                                   destinationTransaction.AccountRow.CurrenciesRow.CurrencyCultureInfo);
            }
            else
            {
                sourceTransaction = transaction;
                // only one transaction, removing second column
                tlpTemplateTransaction.Controls.Remove(gbDestination);
                tlpTemplateTransaction.SetColumnSpan(gbSource, 2);
            }
            tbTitle.Text         = sourceTransaction.FullTitle;
            tbSourceAccount.Text = sourceTransaction.AccountRow.FullTitle;
            tbSourceAmount.Text  = sourceTransaction.Amount.ToString(Consts.UI.CurrencyFormat,
                                                                     sourceTransaction.AccountRow.CurrenciesRow.CurrencyCultureInfo);
            tbDescription.Text = sourceTransaction.Description;
            ttbTags.Tags       = keeper.GetTransactionTagStrings(sourceTransaction);
            if (sourceTransaction.PlannedTransactionsRow != null)
            {
                tbImplementsPlan.Text = sourceTransaction.PlannedTransactionsRow.FullTitle;
            }
            else
            {
                tbImplementsPlan.Text = Resources.Labels.TransactionNotPlanned;
            }
            this.DialogResult = DialogResult.Cancel;
        }
Пример #3
0
        public static bool DeleteTransaction(MoneyDataSet.TransactionsRow transaction)
        {
            String message = transaction.IsPairReferenceIDNull() ? String.Format(Resources.Labels.DeleteTransactionFormat, transaction.FullTitle) :
                             String.Format(Resources.Labels.DeletePairedTransactionFormat, transaction.FullTitle);

            if (MessageBox.Show(message, Resources.Labels.DeleteTransactionTitle, MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK)
            {
                MoneyDataKeeper.Instance.DeleteTransaction(transaction.ID);
                return(true);
            }
            return(false);
        }
Пример #4
0
        private void openSearchResult(bool editMode = false)
        {
            object tag = dgvSearchResults.CurrentRow.Tag;

            if (tag is MoneyDataSet.AccountsRow)
            {
                MoneyDataSet.AccountsRow account = tag as MoneyDataSet.AccountsRow;
                if (editMode)
                {
                    AccountEditForm form = new AccountEditForm(account.AccountTypesRow.IsDebit, account: account);
                    if (form.ShowDialog() != DialogResult.Cancel)
                    {
                        updateTagCloud();
                        dgvSearchResults.Rows.Clear();
                    }
                }
                else
                {
                    AccountViewForm form = new AccountViewForm(account);
                    if (form.ShowDialog() != DialogResult.Cancel)
                    {
                        updateTagCloud();
                        dgvSearchResults.Rows.Clear();
                    }
                }
            }
            else if (tag is MoneyDataSet.TransactionsRow)
            {
                MoneyDataSet.TransactionsRow transaction = tag as MoneyDataSet.TransactionsRow;
                TransactionViewForm          form        = new TransactionViewForm(transaction);
                if (form.ShowDialog() != DialogResult.Cancel)
                {
                    dgvSearchResults.Rows.Remove(dgvSearchResults.CurrentRow);
                }
            }
            else if (tag is MoneyDataSet.PlannedTransactionsRow)
            {
                MoneyDataSet.PlannedTransactionsRow plan = tag as MoneyDataSet.PlannedTransactionsRow;
                if (editMode)
                {
                    MoneyDataSet.PlannedTransactionsRow sourcePlan      = null;
                    MoneyDataSet.PlannedTransactionsRow destinationPlan = null;

                    if (plan.TransactionTemplatesRow == null)
                    {
                        ErrorHelper.ShowErrorBox(ErrorHelper.Errors.PlanWithoutTemplate);
                        Log.Write("Plan", plan);
                        return;
                    }

                    if (plan.TransactionTemplatesRow.HasDestinationAccount)
                    {
                        sourcePlan = keeper.PlannedTransactions.SingleOrDefault(p => ((!p.IsPairReferenceIDNull()) &&
                                                                                      (p.PairReferenceID == plan.PairReferenceID) &&
                                                                                      (p.TransactionTypeID.Equals(plan.TransactionTemplatesRow.SourceTransactionTypeID))));

                        destinationPlan = keeper.PlannedTransactions.SingleOrDefault(p => ((!p.IsPairReferenceIDNull()) &&
                                                                                           (p.PairReferenceID == plan.PairReferenceID) &&
                                                                                           (p.TransactionTypeID.Equals(plan.TransactionTemplatesRow.DestinationTransactionTypeID))));
                    }
                    else
                    {
                        sourcePlan = plan;
                    }

                    PlanEditForm form = new PlanEditForm(sourcePlan.TransactionTemplatesRow,
                                                         sourcePlan, destinationPlan);

                    if (form.ShowDialog(this) != DialogResult.Cancel)
                    {
                        updateTagCloud();
                        dgvSearchResults.Rows.Clear();
                    }
                }
                else
                {
                    PlanViewForm form = new PlanViewForm(plan);
                    if (form.ShowDialog(this) != DialogResult.Cancel)
                    {
                        updateTagCloud();
                        dgvSearchResults.Rows.Clear();
                    }
                }
            }
            else
            {
                ErrorHelper.ShowErrorBox(ErrorHelper.Errors.UnknownSearchResult);
                Log.Write("Found in search", tag);
            }

            //updateTagCloud();
            //dgvSearchResults.Rows.Clear();
        }
Пример #5
0
 public ImportedTransaction(MoneyDataImporter.ImportedRecord record, MoneyDataSet.TransactionsRow transaction)
 {
     Record      = record;
     Transaction = transaction;
     Selected    = false;
 }
Пример #6
0
        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();
        }