Пример #1
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");
                    }
                }
            }
        }
Пример #2
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");
                    }
                }
            }
        }
Пример #3
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");
                    }
                }
            }
        }