示例#1
0
        /// <summary>
        /// Registers a customer account
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RegisterBtn_Click(object sender, EventArgs e)
        {
            if (isDataValid() == true)
            {
                //Create a new Account object from user input
                Account customer = new Account()
                {
                    AccountNumber   = GenerateAccountNumber(),
                    DebitCardNumber = DebitCardNumTxt.Text.Replace("-", ""),
                    FirstName       = FirstNameTxt.Text,
                    LastName        = LastNameTxt.Text,
                    Email           = EmailTxt.Text,
                    Pin             = pinTxt.Text,
                    PhoneNumber     = PhoneNumberTxt.Text,
                    Address         = AddressTxt.Text,
                    Checking        = Convert.ToDouble(FirstDepositTxt.Text),
                    Savings         = 0.00
                };

                //Add the Account object to the database
                try
                {
                    AccountDb.Add(customer);
                    MessageBox.Show("Account successfully created");
                    DialogResult = DialogResult.OK;
                }
                catch (SqlException)
                {
                    MessageBox.Show("We're currently having server issues");
                }
            }
        }
示例#2
0
        /// <summary>
        /// Transfers the desired amount to the user's checking
        /// or savings account.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConfirmTransferBtn_Click(object sender, EventArgs e)
        {
            if (isDataValid() == true)
            {
                double amount = Convert.ToDouble(TransferAmountTxt.Text);

                //If user selected to transfer from checking to savings
                if (TransferFromCBox.SelectedItem.Equals("Checking") && TransferToTxt.Text.Equals("Savings"))
                {
                    double savings  = _user.GetSavingsAmount() + amount;
                    double checking = _user.GetCheckingAmount() - amount;
                    try
                    {
                        _user.Savings  = savings;
                        _user.Checking = checking;
                        AccountDb.Update(_user);
                        MessageBox.Show("Transfer from checking to savings was successful");
                        GenerateReceipt(amount);
                        DialogResult = DialogResult.OK;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Something went wrong with the transfer from checking to savings");
                    }
                }
                //If user selected to transfer from savings to checking
                else if (TransferFromCBox.SelectedItem.Equals("Savings") && TransferToTxt.Text.Equals("Checking"))
                {
                    double checking = _user.GetCheckingAmount() + amount;
                    double savings  = _user.GetSavingsAmount() - amount;
                    try
                    {
                        _user.Checking = checking;
                        _user.Savings  = savings;
                        AccountDb.Update(_user);
                        MessageBox.Show("Transfer from savings to checking was successful");
                        GenerateReceipt(amount);
                        DialogResult = DialogResult.OK;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Something went wrong with the transfer from checking to savings");
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Deposits the amount to the user's account.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConfirmDepositBtn_Click(object sender, EventArgs e)
        {
            if (isDataValid() == true)
            {
                //Grab the amount to be deposited
                double amount = Convert.ToDouble(DepositAmountTxt.Text);

                if (DepositToCBox.SelectedItem.Equals("Checking")) //If user wants to deposit the funds to their checking account
                {
                    double total = _user.GetCheckingAmount() + amount;
                    try
                    {
                        //Update the user's checking account with the amount given
                        _user.Checking = total;
                        AccountDb.Update(_user);
                        MessageBox.Show("Deposit to your checking acount was successful");
                        GenerateReceipt(amount);
                        DialogResult = DialogResult.OK;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Something went wrong when updating the checking account");
                    }
                }
                else if (DepositToCBox.SelectedItem.Equals("Savings")) //If user wants to deposit the funds to their savings account
                {
                    double total = _user.GetSavingsAmount() + amount;
                    try
                    {
                        //Update the user's savings account with the amount given
                        _user.Savings = total;
                        AccountDb.Update(_user);
                        MessageBox.Show("Deposit to your savings acount was successful");
                        GenerateReceipt(amount);
                        DialogResult = DialogResult.OK;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Something went wrong when updating the savings account");
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// Withdraws the desired amount to the user's checking
        /// or savings account.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConfirmWithdrawalBtn_Click(object sender, EventArgs e)
        {
            if (isDataValid() == true)
            {
                double amount = Convert.ToDouble(WithdrawAmountTxt.Text);

                //If user chooses to withdraw from their checking
                if (WithdrawFromCBox.SelectedItem.Equals("Checking"))
                {
                    double checking = _user.GetCheckingAmount() - amount;
                    try
                    {
                        _user.Checking = checking;
                        AccountDb.Update(_user);
                        MessageBox.Show("Withdrawal was successful, please remember to take your money.");
                        GenerateReceipt(amount);
                        DialogResult = DialogResult.OK;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Something went wrong with the withdrawal from your checking account");
                    }
                }
                //If user chooses to withdraw from their savings
                else if (WithdrawFromCBox.SelectedItem.Equals("Savings"))
                {
                    double savings = _user.GetSavingsAmount() - amount;
                    try
                    {
                        _user.Savings = savings;
                        AccountDb.Update(_user);
                        MessageBox.Show("Withdrawal was successful, please remember to take your money.");
                        GenerateReceipt(amount);
                        DialogResult = DialogResult.OK;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Something went wrong with the withdrawal from your savings account");
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Deletes the user's account if delete account button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteAccountBtn_Click(object sender, EventArgs e)
        {
            string       message = $"Are you sure you want to delete this account? WARNING: This cannot be undone!";
            DialogResult result  = MessageBox.Show(text: message,
                                                   caption: "Delete Account?",
                                                   buttons: MessageBoxButtons.YesNo,
                                                   icon: MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    AccountDb.Delete(_user);
                    MessageBox.Show("Account successfully deleted");
                    Close();
                }
                catch (SqlException)
                {
                    MessageBox.Show("Something went wrong while trying to delete this account. Please try again later.");
                }
            }
        }