Пример #1
0
        private void cbSourcePlan_SelectionChangeCommitted(object sender, EventArgs e)
        {
            MoneyDataSet.PlannedTransactionsRow plan = cbSourcePlan.SelectedItem as MoneyDataSet.PlannedTransactionsRow;
            // protection from old schema
            if (plan.TransactionTemplatesRow == null)
            {
                ErrorHelper.ShowErrorBox(ErrorHelper.Errors.PlanTemplateIsNull);
                return;
            }

            // cbSourceAccount.DataSource = keeper.GetAccounts(plan.AccountTypeRow, plan.TransactionTemplatesRow.ExactSourceAccountType);
            cbSourceAccount.Items.Clear();
            foreach (var acc in keeper.GetAccounts(plan.AccountTypeRow, plan.TransactionTemplatesRow.ExactSourceAccountType))
            {
                cbSourceAccount.Items.Add(acc);
            }
            cbSourceAccount.SelectedIndex = 0;
            cbSourceAccount_SelectionChangeCommitted(null, null);

            MoneyDataSet.AccountsRow account = cbSourceAccount.SelectedItem as MoneyDataSet.AccountsRow;

            if (!plan.IsAggregated)
            {
                numSourceAmount.Value = (decimal)(plan.Amount * plan.CurrenciesRow.ExchangeRate / account.CurrenciesRow.ExchangeRate);
            }
            else
            {
                numSourceAmount.Value = 0;
            }

            numSourceAmount.Select(0, Int32.MaxValue);

            if ((tbTitle.Text.Equals(template.TransactionDefaultTitle)) || (sourcePlans.Count(p => (p.Title.Equals(tbTitle.Text))) > 0))
            {
                if (String.IsNullOrWhiteSpace(plan.Title))
                {
                    tbTitle.Text = template.Title;
                }
                else
                {
                    tbTitle.Text = plan.Title;
                }
            }
            ttbTags.Tags = keeper.GetPlannedTransactionTagStrings(plan);
        }
Пример #2
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);
            }
        }