private void bSave_Click(object sender, EventArgs e)
        {
            // Category and Date are defaulted.
            Regex regExpresion = new Regex(@"^-*[0-9\.]+$");

            if (!string.IsNullOrEmpty(tbAmount.Text) && regExpresion.IsMatch(tbAmount.Text))
            {
                oTransaction.Description     = tbDescription.Text;
                oTransaction.TransactionDate = dtTransactionDate.Value.ToString("MM/dd/yyyy");
                oTransaction.IgnoreBudget    = checkboxBudget.Checked;
                oTransaction.Category        = cbCategory.SelectedItem.ToString();

                oTransaction.Amount = Math.Round(Convert.ToDecimal(tbAmount.Text), 2);

                if (oTransaction.TransactionID != null)
                {
                    // This is needed for file update. For some reason the file doesn't get updated correctly from this form.
                    oTransaction = oMainForm.oFactory.oDataManager.UpdateTransaction(oTransaction);
                }
                else
                {
                    // This is needed for file update. For some reason the file doesn't get updated correctly from this form.
                    oTransaction = oMainForm.oFactory.oDataManager.AddTransaction(oTransaction);
                }

                if (oTransaction.Success)
                {
                    if (!String.IsNullOrEmpty(oTransaction.Message))
                    {
                        MessageBox.Show(oTransaction.Message);
                    }

                    DataModel.Search oSearch = new DataModel.Search();
                    oSearch.BeginningDate = DateTime.Parse(oTransaction.TransactionDate);
                    oSearch.EndDate       = DateTime.Parse(oTransaction.TransactionDate);
                    oSearch.SearchText    = oTransaction.TransactionID.ToString();
                    oSearch.Category      = nameof(DataModel.Transaction.TransactionID);
                    oSearch.SortBy        = nameof(DataModel.Transaction.TransactionID);
                    oMainForm.SearchModel = oSearch;
                    oMainForm.Search(oSearch);
                    oMainForm.HideEdit(this);
                }
                else
                {
                    MessageBox.Show("Failed to add/update transaction. ");
                }
            }
            else
            {
                MessageBox.Show("Amount is required, please fill it out with a valid number before you save. ");
            }
        }
예제 #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (BeginningDate.Value < EndDate.Value)
            {
                SearchModel               = new DataModel.Search();
                SearchModel.Category      = (string)cbSearchCategory.SelectedItem;
                SearchModel.SortBy        = (string)cbSortBy.SelectedItem;
                SearchModel.SearchText    = tbSearch.Text;
                SearchModel.BeginningDate = BeginningDate.Value;
                SearchModel.EndDate       = EndDate.Value;

                Search(SearchModel);
            }
            else
            {
                MessageBox.Show("Beginning Date needs to be before EndDate");
            }
        }
예제 #3
0
 internal void Search(DataModel.Search oSearch)
 {
     dgTransactions.DataSource = oFactory.oDataManager.SearchTransactions(SearchModel);
     dgTransactions.Refresh();
 }