Example #1
0
        /// <summary>
        /// Updates the transactionStackPanel by adding a label to it.
        /// The information of the label is the amount deposited into the account.
        /// </summary>
        /// <remarks>
        /// <para>If there is no item selected in the resourceComboBox, then no label and separator will be added.</para>
        /// <para>If there is a space in the amountTextBox, then no label and separator wil be added.</para>
        /// <para>If there are more than one ".", then no label and separator wil be added.</para>
        /// <para>If there is no amount in the amountTextbox, then no label and separator will be added.</para>
        /// <para>If there is a zero for the amount in the amountTextBox, then no label and separator will be added.</para>
        /// <para>If the previous four comments are true, then the account values will not be updated.</para>
        /// </remarks>
        private void DepositButton_Click(object sender, RoutedEventArgs e)
        {
            DataValidation data = new DataValidation();

            if (resourceComboBox.SelectedItem == null)
            {
                return;
            }
            if (data.ValidateSpace(amountTextBox.Text.ToString()))
            {
                return;
            }
            if (HasPeriods(amountTextBox.Text, "."[0]) == true)
            {
                return;
            }
            if (data.ValidateString(amountTextBox.Text.ToString()))
            {
                return;
            }
            else
            {
                double amount = double.Parse(amountTextBox.Text.ToString());
                if (data.ValidateDouble(amount))
                {
                    Transaction transaction = new Transaction();
                    string      item        = GetItem();

                    switch (item)
                    {
                    case "Savings":
                        savingsAmountLabel.Content = transaction.DepositSavings(account, amount).ToString("N");
                        totalAmountLabel.Content   = (account.Savings + account.Cash).ToString("N");
                        if (savingsAmountLabel.Content.ToString() == "0.00")
                        {
                            savingsAmountLabel.Content = 0;
                        }
                        if (totalAmountLabel.Content.ToString() == "0.00")
                        {
                            totalAmountLabel.Content = 0;
                        }
                        break;

                    case "Cash":
                        cashAmountLabel.Content  = transaction.DepositCash(account, amount).ToString("N");
                        totalAmountLabel.Content = (account.Savings + account.Cash).ToString("N");
                        if (cashAmountLabel.Content.ToString() == "0.00")
                        {
                            cashAmountLabel.Content = 0;
                        }
                        if (totalAmountLabel.Content.ToString() == "0.00")
                        {
                            totalAmountLabel.Content = 0;
                        }
                        break;

                    case "Crypto":
                        cryptoAmountLabel.Content = transaction.DepositCrypto(account, amount).ToString("N");
                        if (cryptoAmountLabel.Content.ToString() == "0.00")
                        {
                            cryptoAmountLabel.Content = 0;
                        }
                        break;
                    }
                    CustomControl control = new CustomControl();

                    Label depositLabel = new Label();
                    depositLabel = control.DepositLabel(amount);
                    if (item.Equals("Savings"))
                    {
                        depositLabel.Content = depositLabel.Content + "  Savings";
                    }
                    if (item.Equals("Cash"))
                    {
                        depositLabel.Content = depositLabel.Content + "  Cash";
                    }
                    if (item.Equals("Crypto"))
                    {
                        depositLabel.Content = depositLabel.Content.ToString().Replace("$", "") + "  Crypto";
                    }

                    Separator separator = new Separator();
                    separator = control.LineSeparator();

                    transactionStackPanel.Children.Add(depositLabel);
                    transactionStackPanel.Children.Add(separator);
                }
            }
        }