예제 #1
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;
        }
예제 #2
0
 private void putTransactionDetails(ImportedTransaction impTran)
 {
     cbImport.Checked         = impTran.Selected;
     dtpDate.Value            = impTran.Transaction.TransactionTime;
     tbTitle.Text             = impTran.Transaction.Title;
     cbImplementsPlan.Checked = (impTran.Transaction.PlannedTransactionsRow != null);
     cbPlan.SelectedItem      = impTran.Transaction.PlannedTransactionsRow;
     cbAccount.SelectedItem   = impTran.Transaction.AccountRow;
     numAmount.Value          = (decimal)impTran.Transaction.Amount;
     ttbTags.Tags             = keeper.GetTransactionTagStrings(impTran.Transaction);
 }
예제 #3
0
        private void showResults(String tag = null)
        {
            dgvSearchResults.Rows.Clear();

            IEnumerable <MoneyDataSet.AccountsRow>            accounts     = null;
            IEnumerable <MoneyDataSet.TransactionsRow>        transactions = null;
            IEnumerable <MoneyDataSet.PlannedTransactionsRow> plans        = null;

            if (String.IsNullOrEmpty(tag))
            {
                keeper.AddTextHistory(Consts.Keeper.HistorySearchID, tsstbSearchText.Text);
                updateSearchSuggestions();

                String searchString = tsstbSearchText.Text.ToLower().Trim();

                accounts     = keeper.Accounts;
                transactions = keeper.Transactions;
                plans        = keeper.PlannedTransactions;

                foreach (String word in searchString.Split(Consts.UI.WordDividers, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (String.IsNullOrEmpty(word))
                    {
                        continue;
                    }

                    accounts = accounts.Where(a => ((a.Title.ToLower().Contains(word)) ||
                                                    (a.Description.ToLower().Contains(word)) || (a.AccountTypesRow.Title.ToLower().Contains(word)) ||
                                                    (a.GetAccountTagsRows().Where(at => (at.TagRow.Title.ToLower().Contains(word))).Any())
                                                    ));

                    transactions = transactions.Where(t => ((t.Title.ToLower().Contains(word)) ||
                                                            (t.Description.ToLower().Contains(word)) || (t.TransactionTypesRow.Title.ToLower().Contains(word)) ||
                                                            (t.GetTransactionTagsRows().Where(tt => (tt.TagRow.Title.ToLower().Contains(word))).Any())
                                                            ));

                    plans = plans.Where(p => ((p.Title.ToLower().Contains(word)) ||
                                              (p.Description.ToLower().Contains(word)) || (p.TransactionTypeRow.Title.ToLower().Contains(word)) ||
                                              (p.AccountTypeRow.Title.ToLower().Contains(word)) ||
                                              (p.GetPlannedTransactionTagsRows().Where(pt => (pt.TagRow.Title.ToLower().Contains(word))).Any())
                                              ));

                    if (!((accounts.Any()) || (transactions.Any()) || (plans.Any())))
                    {
                        // nothing found, no need to look further
                        break;
                    }
                }
            }
            else
            {
                accounts = keeper.Accounts.Where(a =>
                                                 (a.GetAccountTagsRows().Where(at => (at.TagRow.Title.Equals(tag))).Any()));

                transactions = keeper.Transactions.Where(t =>
                                                         (t.GetTransactionTagsRows().Where(tt => (tt.TagRow.Title.Equals(tag))).Any()));

                plans = keeper.PlannedTransactions.Where(p =>
                                                         (p.GetPlannedTransactionTagsRows().Where(pt => (pt.TagRow.Title.Equals(tag))).Any()));
            }

            // accounts
            foreach (MoneyDataSet.AccountsRow a in accounts)
            {
                int i = dgvSearchResults.Rows.Add(Properties.Resources.book_open, a.FullTitle, a.EntryTime,
                                                  a.Balance.ToString(Consts.UI.CurrencyFormat, a.CurrenciesRow.CurrencyCultureInfo),
                                                  String.Join(Consts.UI.EnumerableSeparator, keeper.GetAccountTagStrings(a)));

                dgvSearchResults.Rows[i].Tag = a;
            }

            // transactions
            foreach (MoneyDataSet.TransactionsRow t in transactions)
            {
                int i = dgvSearchResults.Rows.Add(Properties.Resources.application_form, t.FullTitle, t.TransactionTime,
                                                  t.Amount.ToString(Consts.UI.CurrencyFormat, t.AccountRow.CurrenciesRow.CurrencyCultureInfo),
                                                  String.Join(Consts.UI.EnumerableSeparator, keeper.GetTransactionTagStrings(t)));

                dgvSearchResults.Rows[i].Tag = t;
            }

            // plans
            foreach (MoneyDataSet.PlannedTransactionsRow p in plans)
            {
                DateTime?startTime = null;
                if (!p.IsStartTimeNull())
                {
                    startTime = p.StartTime;
                }
                int i = dgvSearchResults.Rows.Add(Properties.Resources.date, p.FullTitle, startTime,
                                                  p.Amount.ToString(Consts.UI.CurrencyFormat, p.CurrenciesRow.CurrencyCultureInfo),
                                                  String.Join(Consts.UI.EnumerableSeparator, keeper.GetPlannedTransactionTagStrings(p)));

                dgvSearchResults.Rows[i].Tag = p;
            }

            dgvcSearchResultsAmount.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dgvcSearchResultsTitle.AutoSizeMode  = DataGridViewAutoSizeColumnMode.AllCells;
            dgvcSearchResultsDate.AutoSizeMode   = DataGridViewAutoSizeColumnMode.AllCells;
            dgvSearchResults.Sort(dgvcSearchResultsDate, ListSortDirection.Descending);
        }