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; }
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); }
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); }
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); }