コード例 #1
0
        private void SaveNewExpense(DateTime dtCurrentSaveDate)
        {
            var newExpense =
                new Expense(decimal.Parse(txtAmount.Text), dtCurrentSaveDate,
                            _expenseCategoryService.LoadById(Convert.ToInt32(cmbCategory.SelectedValue)),
                            _paymentMethodService.LoadById(Convert.ToInt32(cmbPayment.SelectedValue)),
                            txtDetail.Text);

            _expenseService.Create(newExpense);
        }
コード例 #2
0
ファイル: InputOutUI.cs プロジェクト: qchouleur/MyHome
        /// <summary>
        ///     Saves the new expense into the cache -validates the amount
        ///     and gives an option to enter more data
        /// </summary>
        /// <param name="sender">Standard sender object</param>
        /// <param name="e">Standard event object</param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            // If the amount is blank
            if (txtAmount.Text == "")
            {
                MessageBox.Show("The amount can not be blank",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
            }
            // Checks that the amount is in numbers
            else if (!txtAmount.Text.IsDouble())
            {
                MessageBox.Show("The amount must be in numbers",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                txtAmount.Text = "";
            }
            // Otherwise saves the new expense
            else
            {
                var newExpense =
                    new Expense(decimal.Parse(txtAmount.Text), dtPick.Value,
                                _expenseCategoryService.LoadById(Convert.ToInt32(cmbCategory.SelectedValue)),
                                _paymentMethodService.LoadById(Convert.ToInt32(cmbPayment.SelectedValue)),
                                txtDetail.Text);

                _expenseService.Create(newExpense);

                // Asks if more data is being entered
                DialogResult = MessageBox.Show("The entry was saved" +
                                               "\nDo you want to add another expense? ",
                                               "Save successful",
                                               MessageBoxButtons.YesNo,
                                               MessageBoxIcon.Question,
                                               MessageBoxDefaultButton.Button1);
                if (DialogResult != DialogResult.Yes)
                {
                    Close();
                }
                // If more data is being entered clears the user entered data for the new data
                else
                {
                    // Puts the focus back to the top of the form and resets the selected values
                    cmbCategory.Focus();
                    txtAmount.Text = "";
                    txtDetail.Text = "";
                }
            }
        }