Ejemplo n.º 1
0
        private void DisplayUpdateTransactionToolTip(object sender, EventArgs e)
        {
            var ttm = new ToolTipModel(
                "Updating Transactions",
                "Press ENTER to save your changes.",
                (sender as RichTextBox)
                );

            _toolTipHandler.Draw(ttm);
        }
Ejemplo n.º 2
0
        private void Submit_Click(object sender, EventArgs e)
        {
            double amount = 0;

            // If this value remaines fales then a feild was invalid.
            bool valid = false;

            try
            {
                // Parse the amount as a double
                amount = double.Parse(amountTextBox.Text);

                // Check that the description is not empty but is also less than the maximum length of the description.
                if (amount <= 0)
                {
                    var ttm = new ToolTipModel("Error", "Amounts must be positive and greater than zero.", (amountTextBox));
                    toolTipHandler.Draw(ttm);
                }
                else if (descriptionTextBox.Equals(""))
                {
                    var ttm = new ToolTipModel("Error", "Please input a description.", descriptionTextBox);
                    toolTipHandler.Draw(ttm);
                }
                else
                {
                    valid = true;
                }
            }
            catch (Exception ex)
            {
                // Must not be a valid double value.
                Console.WriteLine(ex);
                var ttm = new ToolTipModel("Error", "Please input a valid monetary value.", amountTextBox);
                toolTipHandler.Draw(ttm);
            }

            // If all the fields are valid.
            if (valid)
            {
                if (moneyOut)
                {
                    amount *= -1;
                }

                using (var model = controller.Database())
                {
                    var transaction = new Transaction(date.Value, CleanDescription(), amount);

                    model.Transactions.Add(transaction);
                }

                controller.RefreshViews();

                Console.WriteLine("Data Sent");

                // Close this window
                Close();
            }
        }
        private void submit_Click(object sender, EventArgs e)
        {
            try
            {
                // If the user has inputted a monthly allowance that is different to the current one.
                if (oldAllowanceBox.Text.Equals(newAllowanceBox.Text))
                {
                    var ttm = new ToolTipModel(
                        "Error",
                        "Allowance is unchanged. Please enter a new allowance or 'Cancel'.",
                        newAllowanceBox
                        );

                    // Feedback to user.
                    toolTipHandler.Draw(ttm);

                    return;
                }

                // If the user has not left the new monthly allowance text box empty.
                if ((newAllowanceBox.Text.Equals(string.Empty)))
                {
                    var ttm = new ToolTipModel(
                        "Error",
                        "No new Allowance specified. Please enter a new allowance or 'Cancel'.",
                        newAllowanceBox
                        );

                    // Feedback to user.
                    toolTipHandler.Draw(ttm);

                    return;
                }
                // Parse the new monthly allowance as a double value.
                double newBudget = double.Parse(newAllowanceBox.Text);

                // If the monthly allowance is greater than zero.
                if (newBudget <= 0)
                {
                    var ttm = new ToolTipModel(
                        "Error",
                        "New Monthly allowance must be greater than zero.",
                        newAllowanceBox

                        );

                    // Feedback to user.
                    toolTipHandler.Draw(ttm);
                    return;
                }

                using (var model = controller.Database()) {
                    var existingBudget = model.Budgets.Find(month.Value);

                    if (existingBudget == null)
                    {
                        var budget = new Budget(month.Value, newBudget);
                        model.Budgets.Add(budget);
                    }
                    else
                    {
                        existingBudget.Amount = newBudget;
                        model.SaveChanges();
                    }
                }

                controller.RefreshViews();

                Dispose();
            }
            catch (Exception ex)
            {
                var ttm = new ToolTipModel("Error", ex.Message, newAllowanceBox);
                // Feedback to user.
                toolTipHandler.Draw(ttm);
            }
        }