Exemplo n.º 1
0
 public PlanEditForm(MoneyDataSet.TransactionTemplatesRow template,
     MoneyDataSet.PlannedTransactionsRow sourcePlan = null, MoneyDataSet.PlannedTransactionsRow destinationPlan = null, bool isCopy = false)
 {
     InitializeComponent();
     this.keeper = MoneyDataKeeper.Instance;
     this.template = template;
     this.sourcePlan = sourcePlan;
     this.destinationPlan = destinationPlan;
     this.isCopy = isCopy;
 }
Exemplo n.º 2
0
        public PlanViewForm(MoneyDataSet.PlannedTransactionsRow plan)
        {
            InitializeComponent();

            // locate source and destination plans
            if ((!plan.IsPairReferenceIDNull()) && (plan.PairReferenceID != 0))
            {
                foreach (MoneyDataSet.PlannedTransactionsRow p in
                    keeper.PlannedTransactions.Where(p => ((!p.IsPairReferenceIDNull()) &&
                        (p.PairReferenceID == plan.PairReferenceID))))
                    // setting source and destination
                    if (p.TransactionTypeID.Equals(plan.TransactionTemplatesRow.SourceTransactionTypeID))
                    {
                        sourcePlan = p;
                    }
                    else if (p.TransactionTypeID.Equals(plan.TransactionTemplatesRow.DestinationTransactionTypeID))
                    {
                        destinationPlan = p;
                    }

                if ((sourcePlan == null) || (destinationPlan == null))
                {
                    ErrorHelper.ShowErrorBox(ErrorHelper.Errors.InvalidTransaction);
                    return;
                }

                tbDestinationAccountType.Text = destinationPlan.AccountTypeRow.Title;
                tbDestinationAmount.Text = destinationPlan.Amount.ToString(Consts.UI.CurrencyFormat,
                    destinationPlan.CurrenciesRow.CurrencyCultureInfo);
            }
            else
            {
                sourcePlan = plan;
                // only one planned transaction, removing second column
                tlpTemplatePlan.Controls.Remove(gbDestination);
                tlpTemplatePlan.SetColumnSpan(gbSource, 2);
            }

            tbTitle.Text = sourcePlan.FullTitle;
            tbSourceAccountType.Text = sourcePlan.AccountTypeRow.Title;
            tbSourceAmount.Text = sourcePlan.Amount.ToString(Consts.UI.CurrencyFormat,
                sourcePlan.CurrenciesRow.CurrencyCultureInfo);
            tbDescription.Text = sourcePlan.Description;
            ttbTags.Tags = keeper.GetPlannedTransactionTagStrings(sourcePlan);

            this.DialogResult = DialogResult.Cancel;
        }
Exemplo n.º 3
0
        public TransactionEditForm(MoneyDataSet.TransactionTemplatesRow template, MoneyDataSet.PlannedTransactionsRow plan = null)
        {
            InitializeComponent();
            this.keeper = MoneyDataKeeper.Instance;
            this.template = template;
            this.sourcePlan = plan;

            sourceAccounts = keeper.GetAccounts(template.AccountTypesRowByFK_AccountTypes_Source_TransactionTemplates,
                template.ExactSourceAccountType);

            if (template.HasDestinationAccount)
            {
                if (sourcePlan != null)
                {
                    int pairID = sourcePlan.PairReferenceID;
                    sourcePlan = null;

                    // trying to find source and destination plans
                    foreach(MoneyDataSet.PlannedTransactionsRow pairedPlan in keeper.PlannedTransactions.Where(p =>
                        ((!p.IsPairReferenceIDNull()) && (p.PairReferenceID != 0) && (p.PairReferenceID == pairID))))
                    {
                        if (pairedPlan.TransactionTypeID.Equals(template.SourceTransactionTypeID))
                        {
                            sourcePlan = pairedPlan;
                        }
                        if (pairedPlan.TransactionTypeID.Equals(template.DestinationTransactionTypeID))
                        {
                            destinationPlan = pairedPlan;
                        }
                    }
                }

                destinationAccounts = keeper.GetAccounts(template.AccountTypesRowByFK_AccountTypes_Destination_TransactionTemplates,
                    template.ExactDestinationAccountType);
            }
        }
Exemplo n.º 4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            tbTitle.Text = tbTitle.Text.Trim();

            DateTime? startDate = null;
            DateTime? endDate = null;
            MoneyDataSet.RecurrenciesRow recurrency = cbRecurrency.SelectedItem as MoneyDataSet.RecurrenciesRow;
            if (dtpStartDate.Checked)
            {
                startDate = dtpStartDate.Value;
            }
            else
            {
                recurrency = keeper.Recurrencies.SingleOrDefault(r => (r.ID.Equals(MoneyDataSet.IDs.Recurrencies.None)));
            }

            if ((dtpEndDate.Enabled) && (dtpEndDate.Checked))
            {
                endDate = dtpEndDate.Value;
            }

            MoneyDataSet.PlannedTransactionsRow preCreateSource =
                keeper.PreCreatePlannedTransaction(template.TransactionTypesRowByFK_TransactionTypes_Source_TransactionTemplates,
                tbTitle.Text, tbDescription.Text, startDate, cbSourceAccountType.SelectedItem as MoneyDataSet.AccountTypesRow,
                (double)numSourceAmount.Value, cbSourceCurrency.SelectedItem as MoneyDataSet.CurrenciesRow,
                recurrency, endDate, cbIsAggregated.Checked, template);

            MoneyDataSet.PlannedTransactionsRow preCreateDestination = null;

            ValidationResult resultSource = keeper.Validate(plan: preCreateSource);
            ValidationResult resultDestination = new ValidationResult(success: true, preventAction: false, message: String.Empty);

            if (template.HasDestinationAccount)
            {
                preCreateDestination = keeper.PreCreatePlannedTransaction(template.TransactionTypesRowByFK_TransactionTypes_Destination_TransactionTemplates,
                    tbTitle.Text, tbDescription.Text, startDate, cbDestinationAccountType.SelectedItem as MoneyDataSet.AccountTypesRow,
                    (double)numDestinationAmount.Value, cbDestinationCurrency.SelectedItem as MoneyDataSet.CurrenciesRow,
                    recurrency, endDate, cbIsAggregated.Checked, template, preCreateSource.PairReferenceID);

                resultDestination = keeper.Validate(plan: preCreateDestination);
            }

            if (!((resultSource.Success) && (resultDestination.Success)))
            {
                String message = String.Empty;

                if (String.IsNullOrWhiteSpace(resultSource.Message))
                {
                    message = Resources.Labels.TransactionDestinationValidation + resultDestination.Message;
                }
                else if (String.IsNullOrWhiteSpace(resultDestination.Message))
                {
                    if (template.HasDestinationAccount)
                    {
                        message = Resources.Labels.TransactionSourceValidation + Environment.NewLine;
                    }
                    message += resultSource.Message;
                }
                else
                {
                    message = 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),
                        Resources.Labels.TransactionValidationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }
                else
                {
                    if (MessageBox.Show(String.Format(Resources.Labels.TransactionValidationWarningsFoundFormat, message),
                        Resources.Labels.TransactionValidationTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }

            if (sourcePlan != null)
            {
                // updating existing plans
                selectedPlan = keeper.UpdatePlannedTransaction(sourcePlan.ID, preCreateSource.Title, preCreateSource.Description, startDate, preCreateSource.AccountTypeRow,
                    preCreateSource.Amount, preCreateSource.CurrenciesRow, preCreateSource.RecurrenciesRow, endDate, cbIsAggregated.Checked, ttbTags.Tags, template);

                if (template.HasDestinationAccount)
                {
                    keeper.UpdatePlannedTransaction(destinationPlan.ID, preCreateDestination.Title, preCreateDestination.Description, startDate,
                        preCreateDestination.AccountTypeRow, preCreateDestination.Amount, preCreateDestination.CurrenciesRow, preCreateDestination.RecurrenciesRow, endDate,
                        cbIsAggregated.Checked, ttbTags.Tags, template);
                }
            }
            else
            {
                // creating new plans
                selectedPlan = keeper.CreatePlannedTransaction(preCreateSource, ttbTags.Tags);
                if (template.HasDestinationAccount)
                {
                    keeper.CreatePlannedTransaction(preCreateDestination, ttbTags.Tags);
                }
            }
            keeper.AddTextHistory(String.Format(Consts.Keeper.TransactionTitleHistoryIDFormat, template.ID), tbTitle.Text);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemplo n.º 5
0
        private void PlanFromTemplateForm_Load(object sender, EventArgs e)
        {
            // some pre-checks
            if (template == null)
            {
                ErrorHelper.ShowErrorBox(ErrorHelper.Errors.PlanTemplateIsNull);
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            if ((sourcePlan != null) && (template.HasDestinationAccount) && (destinationPlan == null))
            {
                ErrorHelper.ShowErrorBox(ErrorHelper.Errors.PlanDestinationAccountIsNull);
                Log.Write("Source plan", sourcePlan);
                Log.Write("Template", template);
                this.DialogResult = DialogResult.Cancel;
                this.Close();
                return;
            }

            this.Text = String.Format(Resources.Labels.PlannedTemplateFormat, template.Title);
            lblTransactionMessage.Text = template.Message;

            tbTitle.AutoCompleteCustomSource.AddRange(keeper.GetTextHistory(String.Format(Consts.Keeper.TransactionTitleHistoryIDFormat, template.ID)));

            if (sourcePlan != null)
            {
                if (isCopy)
                {
                    tbTitle.Text = String.Format(Resources.Labels.CopyFormat, sourcePlan.Title);
                }
                else
                {
                    tbTitle.Text = sourcePlan.Title;
                }

                cbIsAggregated.Checked = sourcePlan.IsAggregated;
            }
            else
            {
                tbTitle.Text = template.TransactionDefaultTitle;
            }
            ttbTags.SetAvailableTags(keeper.Tags);

            cbSourceAccountType.DisplayMember = keeper.DataSet.AccountTypes.TitleColumn.ColumnName;
            cbSourceAccountType.ValueMember = keeper.DataSet.AccountTypes.IDColumn.ColumnName;
            // cbSourceAccountType.DataSource = keeper.GetAccountTypes(template.AccountTypesRowByFK_AccountTypes_Source_TransactionTemplates,
            //    template.ExactSourceAccountType);
            foreach (var accountType in keeper.GetAccountTypes(template.AccountTypesRowByFK_AccountTypes_Source_TransactionTemplates, template.ExactSourceAccountType))
            {
                cbSourceAccountType.Items.Add(accountType);
            }
            cbSourceAccountType.SelectedIndex = 0;

            cbSourceCurrency.DisplayMember = keeper.DataSet.Currencies.TitleColumn.ColumnName;
            cbSourceCurrency.ValueMember = keeper.DataSet.Currencies.IDColumn.ColumnName;
            //cbSourceCurrency.DataSource = keeper.Currencies;
            cbDestinationCurrency.DisplayMember = keeper.DataSet.Currencies.TitleColumn.ColumnName;
            cbDestinationCurrency.ValueMember = keeper.DataSet.Currencies.IDColumn.ColumnName;
            //cbDestinationCurrency.DataSource = keeper.Currencies;

            foreach (MoneyDataSet.CurrenciesRow currency in keeper.Currencies)
            {
                cbSourceCurrency.Items.Add(currency);
                cbDestinationCurrency.Items.Add(currency);
            }
            cbSourceCurrency.SelectedIndex = 0;
            cbDestinationCurrency.SelectedIndex = 0;

            cbRecurrency.DisplayMember = keeper.DataSet.Recurrencies.TitleColumn.ColumnName;
            cbRecurrency.ValueMember = keeper.DataSet.Recurrencies.IDColumn.ColumnName;
            // cbRecurrency.DataSource = keeper.Recurrencies;
            foreach (var recurrency in keeper.Recurrencies)
            {
                cbRecurrency.Items.Add(recurrency);
            }
            cbRecurrency.SelectedIndex = 0;

            cbRecurrency_SelectionChangeCommitted(null, null);

            if (template.HasDestinationAccount)
            {
                cbDestinationAccountType.DisplayMember = keeper.DataSet.AccountTypes.TitleColumn.ColumnName;
                cbDestinationAccountType.ValueMember = keeper.DataSet.AccountTypes.IDColumn.ColumnName;
                //cbDestinationAccountType.DataSource = keeper.GetAccountTypes(template.AccountTypesRowByFK_AccountTypes_Destination_TransactionTemplates,
                //    template.ExactDestinationAccountType);
                foreach (var accountType in keeper.GetAccountTypes(template.AccountTypesRowByFK_AccountTypes_Destination_TransactionTemplates, template.ExactDestinationAccountType))
                {
                    cbDestinationAccountType.Items.Add(accountType);
                }
                cbDestinationAccountType.SelectedIndex = 0;

                if (template.IsAmountIdentical)
                {
                    numDestinationAmount.Enabled = false;
                }
                updateDestinationAmount();
            }
            else
            {
                tlpTemplatePlan.Controls.Remove(gbDestination);
                tlpTemplatePlan.SetColumnSpan(gbSource, 2);

                // renaming Source to Account
                gbSource.Text = Resources.Labels.AccountAmountGroupBoxLabel;
            }

            if (sourcePlan != null)
            {
                cbSourceAccountType.SelectedItem = sourcePlan.AccountTypeRow;
                cbSourceCurrency.SelectedItem = sourcePlan.CurrenciesRow;
                cbRecurrency.SelectedItem = sourcePlan.RecurrenciesRow;
                ttbTags.Tags = keeper.GetPlannedTransactionTagStrings(sourcePlan);
                numSourceAmount.Value = (decimal)sourcePlan.Amount;

                if (sourcePlan.IsStartTimeNull())
                {
                    dtpStartDate.Checked = false;
                }
                else
                {
                    dtpStartDate.Checked = true;
                    dtpStartDate.Value = sourcePlan.StartTime;
                }
                dtpStartDate_ValueChanged(null, null);

                if (destinationPlan != null)
                {
                    cbDestinationAccountType.SelectedItem = destinationPlan.AccountTypeRow;
                    cbDestinationCurrency.SelectedItem = destinationPlan.CurrenciesRow;
                    numDestinationAmount.Value = (decimal)destinationPlan.Amount;
                }
            }
            else
            {
                dtpStartDate.Checked = true;
            }

            if ((sourcePlan != null) && (!sourcePlan.RecurrencyID.Equals(MoneyDataSet.IDs.Recurrencies.None)) && (!sourcePlan.IsEndTimeNull()))
            {
                dtpEndDate.Value = sourcePlan.EndTime;
                dtpEndDate.Enabled = true;
                lblEndDate.Enabled = true;
            }
            else
            {
                // default end date - next month, unchecked
                dtpEndDate.Value = DateTime.Now.AddMonths(1);
                dtpEndDate.Checked = false;
                lblEndDate.Enabled = false;
            }

            if (isCopy)
            {
                // clearing info, so submit will create new entries
                sourcePlan = null;
                destinationPlan = null;
            }
            numSourceAmount.Select(0, Int32.MaxValue);
            numDestinationAmount.Select(0, Int32.MaxValue);
        }
Exemplo n.º 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();
        }