Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddEditExpenseDialog"/> class.
        /// Edit constructor. Constructs dialog in EditMode for existing expense.
        /// </summary>
        /// <param name="e">The expense data to edit.</param>
        public AddEditExpenseDialog(Expense e)
        {
            this.InitializeComponent();
            this.Expense = e;

            // Set title to Edit
            this.titleTextBox.Text = "Edit an Existing Expense";

            // Assign values to those of passed expense
            this.dateTimePicker.Value = e.Date;

            // Assign purchase method.
            if (e.Method is Cash)
            {
                Cash c = e.Method as Cash;

                this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.CASH;

                this.currencyInputComboBox.Text = c.Currency;
            }
            else if (e.Method is Card)
            {
                Card c = e.Method as Card;

                this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.CARD;

                this.cardTypeInputComboBox.SelectedIndex = c.Debit ? 0 : 1;
                this.providerInputTextBox.Text           = c.Provider;
                this.cardNumberMaskedTextBox.Text        = c.Number.ToString();
                this.cardNameInputTextBox.Text           = c.Name;
            }
            else if (e.Method is DirectDeposit)
            {
                DirectDeposit d = e.Method as DirectDeposit;

                this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.DIRECT_DEPOSIT;

                this.accountTypeInputComboBox.SelectedIndex = d.Savings ? 0 : 1;
                this.bankNameInputTextBox.Text            = d.BankName;
                this.accountNumberInputMaskedTextBox.Text = d.Number.ToString();
                this.accountNameInputTextBox.Text         = d.Name;
            }

            this.amountInputTextBox.Text = e.Value.ToString();
            this.placeInputTextBox.Text  = e.Place;
            this.tagInputTextBox.Text    = string.Join(", ", e.Tag);
            this.notesInputTextBox.Text  = e.Notes;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AddEditFilterDialog"/> class.
        /// Edit constructor. Constructs dialog in EditMode for existing filter.
        /// </summary>
        /// <param name="f">The expense data to edit.</param>
        public AddEditFilterDialog(ExpenseFilter f)
        {
            this.InitializeComponent();
            this.ExpenseFilter = f;

            // Set title to Edit
            this.titleTextBox.Text = "Edit an Existing Filter";

            // first disable everything.
            this.InitializeForm();

            // Assign values to those of passed filter
            this.filterNameInputTextBox.Text     = f.Name;
            this.filterNameInputTextBox.ReadOnly = true;    // Cannot change the name, unique identifier.

            if (f.MinDate != DateTime.MinValue)
            {
                this.lowerBoundDateTimePicker.Value = f.MinDate;
                this.lowerBoundDateLabelButton.PerformClick();
            }

            if (f.MaxDate != DateTime.MaxValue)
            {
                this.upperBoundDateTimePicker.Value = f.MaxDate;
                this.upperBoundDateLabelButton.PerformClick();
            }

            if (f.Method != null)
            {
                // Assign purchase method.
                if (f.Method is Cash)
                {
                    Cash c = f.Method as Cash;

                    this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.CASH;

                    this.currencyInputComboBox.Text = c.Currency;
                }
                else if (f.Method is Card)
                {
                    Card c = f.Method as Card;

                    this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.CARD;

                    this.cardTypeInputComboBox.SelectedIndex = c.Debit ? 0 : 1;
                    this.providerInputTextBox.Text           = c.Provider;
                    this.cardNumberMaskedTextBox.Text        = c.Number.ToString();
                    this.cardNameInputTextBox.Text           = c.Name;
                }
                else if (f.Method is DirectDeposit)
                {
                    DirectDeposit d = f.Method as DirectDeposit;

                    this.purchaseMethodSelectComboBox.SelectedIndex = (int)EPurchaseMethodIndex.DIRECT_DEPOSIT;

                    this.accountTypeInputComboBox.SelectedIndex = d.Savings ? 0 : 1;
                    this.bankNameInputTextBox.Text            = d.BankName;
                    this.accountNumberInputMaskedTextBox.Text = d.Number.ToString();
                    this.accountNameInputTextBox.Text         = d.Name;
                }
            }

            if (f.MinValue != float.MinValue)
            {
                this.lowerBoundAmountInputTextBox.Text = f.MinValue.ToString();
                this.lowerBoundAmountLabelButton.PerformClick();
            }

            if (f.MaxValue != float.MaxValue)
            {
                this.upperBoundAmountInputTextBox.Text = f.MaxValue.ToString();
                this.upperBoundAmountLabelButton.PerformClick();
            }

            if (f.Place.Count > 0)
            {
                this.placesInputTextBox.Text = string.Join(", ", f.Place);
                this.placesLabelButton.PerformClick();
            }

            if (f.Tag.Count > 0)
            {
                this.tagsInputTextBox.Text = string.Join(", ", f.Tag);
                this.tagsLabelButton.PerformClick();
            }

            if (f.Keywords.Count > 0)
            {
                this.notesInputTextBox.Text = string.Join(", ", f.Keywords);
                this.keywordsLabelButton.PerformClick();
            }
        }
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            // wipe last attempt
            this.HideFormError();

            // do data checks here.
            if (!this.InputsAreValid())
            {
                return;
            }

            // if data checks pass assign all values to expense and pass back dialog ok result.
            string           name;
            HashSet <string> places = new HashSet <string>(), tags = new HashSet <string>(), keywords = new HashSet <string>();
            DateTime         maxDate = DateTime.MaxValue, minDate = DateTime.MinValue;
            float            maxValue = float.MaxValue, minValue = float.MinValue;
            PurchaseMethod   p = null;

            name = this.filterNameInputTextBox.Text;

            if (this.lowerBoundDateTimePicker.Enabled)
            {
                minDate = this.lowerBoundDateTimePicker.Value;
            }

            if (this.upperBoundDateTimePicker.Enabled)
            {
                maxDate = this.upperBoundDateTimePicker.Value;
            }

            if (this.lowerBoundAmountInputTextBox.Enabled)
            {
                minValue = float.Parse(this.lowerBoundAmountInputTextBox.Text);
            }

            if (this.upperBoundAmountInputTextBox.Enabled)
            {
                maxValue = float.Parse(this.upperBoundAmountInputTextBox.Text);
            }

            if (this.placesInputTextBox.Enabled)
            {
                places = new HashSet <string>(from string place in this.placesInputTextBox.Text.Split(',') select place.Trim());
            }

            if (this.tagsInputTextBox.Enabled)
            {
                tags = new HashSet <string>(from string tag in this.tagsInputTextBox.Text.Split(',') select tag.Trim());
            }

            if (this.notesInputTextBox.Enabled)
            {
                keywords = new HashSet <string>(from string keyword in this.notesInputTextBox.Text.Split(',') select keyword.Trim());
            }

            if (this.purchaseMethodSelectComboBox.Enabled)
            {
                switch ((EPurchaseMethodIndex)this.purchaseMethodSelectComboBox.SelectedIndex)
                {
                case EPurchaseMethodIndex.CASH:
                    p = new Cash(
                        this.currencyInputComboBox.Text);
                    break;

                case EPurchaseMethodIndex.CARD:
                    p = new Card(
                        this.cardTypeInputComboBox.SelectedIndex == 0 ? true : false,
                        this.providerInputTextBox.Text.Trim(),
                        int.Parse(this.cardNumberMaskedTextBox.Text),
                        this.cardNameInputTextBox.Text.Trim());
                    break;

                case EPurchaseMethodIndex.DIRECT_DEPOSIT:
                    p = new DirectDeposit(
                        this.accountTypeInputComboBox.SelectedIndex == 0 ? true : false,
                        this.bankNameInputTextBox.Text.Trim(),
                        int.Parse(this.accountNumberInputMaskedTextBox.Text),
                        this.accountNameInputTextBox.Text.Trim());
                    break;

                default:
                    Console.WriteLine("Error: unhandled purchase method passed");
                    throw new InvalidEnumArgumentException("Error: unhandled purchase method passed");
                }
            }
            else
            {
                p = null;
            }

            if (this.ExpenseFilter == null)
            {
                this.ExpenseFilter = new ExpenseFilter(
                    name,
                    maxValue,
                    minValue,
                    maxDate,
                    minDate,
                    places,
                    tags,
                    keywords,
                    p);
            }
            else
            {
                this.ExpenseFilter.MinValue = minValue;
                this.ExpenseFilter.MaxValue = maxValue;
                this.ExpenseFilter.MinDate  = minDate;
                this.ExpenseFilter.MaxDate  = maxDate;
                this.ExpenseFilter.Place    = places;
                this.ExpenseFilter.Tag      = tags;
                this.ExpenseFilter.Keywords = keywords;
                this.ExpenseFilter.Method   = p;
            }

            // Set the ok result and close the form.
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #4
0
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            // wipe last attempt
            this.HideFormError();

            // do data checks here.
            if (!this.InputsAreValid())
            {
                return;
            }

            // if data checks pass assign all values to expense and pass back dialog ok result.
            PurchaseMethod p;

            switch ((EPurchaseMethodIndex)this.purchaseMethodSelectComboBox.SelectedIndex)
            {
            case EPurchaseMethodIndex.CASH:
                p = new Cash(
                    this.currencyInputComboBox.Text);
                break;

            case EPurchaseMethodIndex.CARD:
                p = new Card(
                    this.cardTypeInputComboBox.SelectedIndex == 0 ? true : false,
                    this.providerInputTextBox.Text.Trim(),
                    int.Parse(this.cardNumberMaskedTextBox.Text),
                    this.cardNameInputTextBox.Text.Trim());
                break;

            case EPurchaseMethodIndex.DIRECT_DEPOSIT:
                p = new DirectDeposit(
                    this.accountTypeInputComboBox.SelectedIndex == 0 ? true : false,
                    this.bankNameInputTextBox.Text.Trim(),
                    int.Parse(this.accountNumberInputMaskedTextBox.Text),
                    this.accountNameInputTextBox.Text.Trim());
                break;

            default:
                Console.WriteLine("Error: unhandled purchase method passed");
                throw new InvalidEnumArgumentException("Error: unhandled purchase method passed");
            }

            if (this.Expense == null)
            {
                this.Expense = new Expense(
                    float.Parse(this.amountInputTextBox.Text),
                    this.dateTimePicker.Value,
                    this.placeInputTextBox.Text.Trim(),
                    p,
                    new HashSet <string>(from string tag in this.tagInputTextBox.Text.Split(',') select tag.Trim()),
                    this.notesInputTextBox.Text.Trim());
            }
            else
            {
                this.Expense.Value  = float.Parse(this.amountInputTextBox.Text);
                this.Expense.Date   = this.dateTimePicker.Value;
                this.Expense.Place  = this.placeInputTextBox.Text.Trim();
                this.Expense.Method = p;
                this.Expense.Tag    = new HashSet <string>(from string tag in this.tagInputTextBox.Text.Split(',') select tag.Trim());
                this.Expense.Notes  = this.notesInputTextBox.Text.Trim();
            }

            // Set the ok result and close the form.
            this.DialogResult = DialogResult.OK;
            this.Close();
        }