private void btnOk_Click(object sender, EventArgs e) { tbTitle.Text = tbTitle.Text.Trim(); if (account != null) { // updating existing account account = keeper.UpdateAccount(account.ID, tbTitle.Text, tbDescription.Text, cbHideAccount.Checked, ttbTags.Tags); } else { // creating new account account = keeper.PreCreateAccount(cbAccountType.SelectedItem as MoneyDataSet.AccountTypesRow, tbTitle.Text, tbDescription.Text, cbCurrency.SelectedItem as MoneyDataSet.CurrenciesRow, 0); ValidationResult result = keeper.Validate(account: account); if (!result.Success) { if (result.PreventAction) { MessageBox.Show(String.Format(Resources.Labels.AccountValidationErrorsFoundFormat, result.Message), Resources.Labels.AccountValidationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (MessageBox.Show(String.Format(Resources.Labels.AccountValidationWarningsFoundFormat, result.Message), Resources.Labels.AccountValidationTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return; } } } account = keeper.CreateAccount(account, ttbTags.Tags); } keeper.AddTextHistory(Consts.Keeper.AccountTitleHistoryID, tbTitle.Text); this.DialogResult = DialogResult.OK; this.Close(); }
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 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(); }
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(); }