Exemplo n.º 1
0
        private void btnProcessTransfer_Click(object sender, EventArgs e)
        {
            BLLMngr bllMngr = new BLLMngr();
            string type = "Transfer";

            // Creating debtor and creditor models and adding two transactions to DB
            TransactionModel debtor = new TransactionModel(DebtorID, Amount, type, Description);
            bllMngr.CreateTransaction(debtor);
            int debID = bllMngr.TransactionID; // Taking Id from debtor transaction

            TransactionModel creditor = new TransactionModel(CreditorID, Amount, type, Description);
            bllMngr.CreateTransaction(creditor);
            int credID = bllMngr.TransactionID; // Taking ID from creditor transaction

            TransferModel transfer = new TransferModel(debID, credID, CreditorSortCode, CreditorAccountNumber);

            CreditorBalance += Amount;
            DebtorBalance -= Amount;

            // Creating models so that balance may be updated in UpdateAccountBalance() below
            AccountModel credAcc = new AccountModel(CreditorID, CreditorBalance);
            AccountModel debAcc = new AccountModel(DebtorID, DebtorBalance);

            bllMngr.CreateTransfer(credID, debID, transfer);
            bllMngr.UpdateAccountBalance(debAcc);
            bllMngr.UpdateAccountBalance(credAcc);

            MessageBox.Show("Transfer Complete");

            this.Close();
        }
Exemplo n.º 2
0
 public void UpdateCustomersAccount(CustomerModel customer, AccountModel account)
 {
     DALMngr dalMngr = new DALMngr();
     dalMngr.UpdateCustomersAccount(customer, account);
 }
Exemplo n.º 3
0
 // Taking Objects from AddCustomer //
 public void CreateCustomerAccount(CustomerModel newCustomer, AccountModel newAccount, TransactionModel newTransaction)
 {
     // Sending to DAL //
     DALMngr dalMngr = new DALMngr();
     dalMngr.CreateCustomerAccount(newCustomer, newAccount, newTransaction);
 }
Exemplo n.º 4
0
        public void CreateCustomerAccount(CustomerModel newCustomer, AccountModel newAccount, TransactionModel newTransaction)
        {
            using (SqlConnection cxn = new SqlConnection(cxnString))
            {
                SqlCommand cmdCustomer = new SqlCommand("spAddCustomer", cxn);
                cmdCustomer.CommandType = CommandType.StoredProcedure;

                SqlParameter firstNameParam = new SqlParameter("@FirstName", SqlDbType.NVarChar, 50);
                firstNameParam.Value = newCustomer.FirstName;

                SqlParameter surnameParam = new SqlParameter("@Surname", SqlDbType.NVarChar, 50);
                surnameParam.Value = newCustomer.Surname;

                SqlParameter emailParam = new SqlParameter("@Email", SqlDbType.NVarChar, 50);
                emailParam.Value = newCustomer.Email;

                SqlParameter phoneParam = new SqlParameter("@Phone", SqlDbType.NVarChar, 50);
                phoneParam.Value = newCustomer.Phone;

                SqlParameter add1Param = new SqlParameter("@Address1", SqlDbType.NVarChar, 50); // will change to address 1 in db
                add1Param.Value = newCustomer.Address1;

                SqlParameter add2Param = new SqlParameter("@Address2", SqlDbType.NVarChar, 50); // will change to address 1 in db
                add2Param.Value = newCustomer.Address2;

                SqlParameter cityParam = new SqlParameter("@City", SqlDbType.NVarChar, 50);
                cityParam.Value = newCustomer.City;

                SqlParameter countyParam = new SqlParameter("@County", SqlDbType.NVarChar, 50);
                countyParam.Value = newCustomer.County;

                SqlParameter custIDParam = new SqlParameter("@CustomerID", SqlDbType.Int);
                custIDParam.Direction = ParameterDirection.Output;

                cmdCustomer.Parameters.Add(firstNameParam);
                cmdCustomer.Parameters.Add(surnameParam);
                cmdCustomer.Parameters.Add(emailParam);
                cmdCustomer.Parameters.Add(phoneParam);
                cmdCustomer.Parameters.Add(add1Param);
                cmdCustomer.Parameters.Add(add2Param);
                cmdCustomer.Parameters.Add(cityParam);
                cmdCustomer.Parameters.Add(countyParam);
                cmdCustomer.Parameters.Add(custIDParam);

                cxn.Open();
                cmdCustomer.ExecuteNonQuery();
                cxn.Close();

                // Taking CustomerID from customer table and assigning it to the account CustomerID
                newAccount.CustomerID = Convert.ToInt32(cmdCustomer.Parameters["@CustomerID"].Value);

                SqlCommand cmdAccount = new SqlCommand("spAddAccount", cxn);
                cmdAccount.CommandType = CommandType.StoredProcedure;

                SqlParameter CustIDParam = new SqlParameter("@CustomerID", SqlDbType.Int);
                CustIDParam.Value = newAccount.CustomerID;

                SqlParameter AccTypeParam = new SqlParameter("@AccountType", SqlDbType.NVarChar, 50);
                AccTypeParam.Value = newAccount.AccountType;

                SqlParameter AccNumberParam = new SqlParameter("@AccountNumber", SqlDbType.Int);
                AccNumberParam.Value = newAccount.AccountNumber;

                SqlParameter SortCodeParam = new SqlParameter("@SortCode", SqlDbType.Int);
                SortCodeParam.Value = newAccount.SortCode;

                SqlParameter BalParam = new SqlParameter("@Balance", SqlDbType.Int);
                BalParam.Value = newAccount.Balance;

                SqlParameter OverDraftParam = new SqlParameter("@OverdraftLimit", SqlDbType.Int);
                OverDraftParam.Value = newAccount.OverdraftLimit;

                SqlParameter AccIDParam = new SqlParameter("@AccountID", SqlDbType.Int);
                AccIDParam.Direction = ParameterDirection.Output;

                cmdAccount.Parameters.Add(CustIDParam);
                cmdAccount.Parameters.Add(AccTypeParam);
                cmdAccount.Parameters.Add(AccNumberParam);
                cmdAccount.Parameters.Add(SortCodeParam);
                cmdAccount.Parameters.Add(BalParam);
                cmdAccount.Parameters.Add(OverDraftParam);
                cmdAccount.Parameters.Add(AccIDParam);

                cxn.Open();
                cmdAccount.ExecuteNonQuery();
                cxn.Close();

                SqlCommand cmdTransaction = new SqlCommand("spAddTransaction", cxn);
                cmdTransaction.CommandType = CommandType.StoredProcedure;

                newTransaction.AccountID = Convert.ToInt32(cmdAccount.Parameters["@AccountID"].Value);

                SqlParameter accountIDParam = new SqlParameter("@AccountID", SqlDbType.Int);
                accountIDParam.Value = newTransaction.AccountID;

                SqlParameter amountParam = new SqlParameter("@Amount", SqlDbType.Int);
                amountParam.Value = newTransaction.Amount;

                SqlParameter typeParam = new SqlParameter("@Type", SqlDbType.NVarChar, 50);
                typeParam.Value = newTransaction.Type;

                SqlParameter descriptionParam = new SqlParameter("@Description", SqlDbType.NVarChar, 250);
                descriptionParam.Value = newTransaction.Description;

                SqlParameter transactionIDParam = new SqlParameter("@TransactionID", SqlDbType.Int);
                transactionIDParam.Direction = ParameterDirection.Output;

                cmdTransaction.Parameters.Add(accountIDParam);
                cmdTransaction.Parameters.Add(amountParam);
                cmdTransaction.Parameters.Add(typeParam);
                cmdTransaction.Parameters.Add(descriptionParam);
                cmdTransaction.Parameters.Add(transactionIDParam);

                cxn.Open();
                cmdTransaction.ExecuteNonQuery();
                cxn.Close();
            }
        }
Exemplo n.º 5
0
 public void UpdateAccountBalance(AccountModel accountToUpdate)
 {
     DALMngr dalMngr = new DALMngr();
     dalMngr.UpdateAccountBalance(accountToUpdate);
 }
Exemplo n.º 6
0
        private void UpdateAccount(AccountModel existingAccount)
        {
            using (SqlConnection cxn = new SqlConnection(cxnString))
            {

                SqlCommand cmdAccount = new SqlCommand("spUpdateAccount", cxn);
                cmdAccount.CommandType = CommandType.StoredProcedure;

                SqlParameter CustIDParam = new SqlParameter("@CustomerID", SqlDbType.Int);
                CustIDParam.Value = existingAccount.CustomerID;

                SqlParameter AccTypeParam = new SqlParameter("@AccountType", SqlDbType.NVarChar, 50);
                AccTypeParam.Value = existingAccount.AccountType;

                SqlParameter AccNumberParam = new SqlParameter("@AccountNumber", SqlDbType.Int);
                AccNumberParam.Value = existingAccount.AccountNumber;

                SqlParameter SortCodeParam = new SqlParameter("@SortCode", SqlDbType.Int);
                SortCodeParam.Value = existingAccount.SortCode;

                SqlParameter BalParam = new SqlParameter("@Balance", SqlDbType.Int);
                BalParam.Value = existingAccount.Balance;

                SqlParameter OverDraftParam = new SqlParameter("@OverdraftLimit", SqlDbType.Int);
                OverDraftParam.Value = existingAccount.OverdraftLimit;

                SqlParameter AccIDParam = new SqlParameter("@AccountID", SqlDbType.Int);
                AccIDParam.Value = existingAccount.AccountID;

                cmdAccount.Parameters.Add(AccTypeParam);
                cmdAccount.Parameters.Add(AccNumberParam);
                cmdAccount.Parameters.Add(SortCodeParam);
                cmdAccount.Parameters.Add(BalParam);
                cmdAccount.Parameters.Add(OverDraftParam);
                cmdAccount.Parameters.Add(AccIDParam);

                cxn.Open();
                cmdAccount.ExecuteNonQuery();
                cxn.Close();
            }
        }
Exemplo n.º 7
0
 public void UpdateCustomersAccount(CustomerModel customer, AccountModel account)
 {
     UpdateCutomer(customer);
     UpdateAccount(account);
 }
Exemplo n.º 8
0
        public void UpdateAccountBalance(AccountModel accountToUpdate)
        {
            using (SqlConnection cxn = new SqlConnection(cxnString))
            {
                SqlCommand cmdBalanceUpdate = new SqlCommand("spUpdateBalance", cxn);
                cmdBalanceUpdate.CommandType = CommandType.StoredProcedure;

                SqlParameter accountIDParam = new SqlParameter("@AccountID", SqlDbType.Int);
                accountIDParam.Value = accountToUpdate.AccountID;

                SqlParameter accountBalanceParam = new SqlParameter("@Balance", SqlDbType.Int);
                accountBalanceParam.Value = accountToUpdate.Balance;

                cmdBalanceUpdate.Parameters.Add(accountIDParam);
                cmdBalanceUpdate.Parameters.Add(accountBalanceParam);

                cxn.Open();
                cmdBalanceUpdate.ExecuteNonQuery();
                cxn.Close();
            }
        }
Exemplo n.º 9
0
        private void btnProcessTransaction_Click(object sender, EventArgs e)
        {
            // TRANSACTION DETAILS //
            string type = cboType.Text;
            string description = txtDescription.Text;
            string amountEuro = txtAmountEuro.Text.Trim();

            // Takes Euro and Cent values, Adds them and stores cent value as int in Database
            string amountString = amountEuro + amountCent;
            int amount;
            int.TryParse(amountString, out amount);
            //method used to update the balance in users account
            int currentBalance = CurrentBalance(balance, amount);

            AccountModel account = new AccountModel(accountID, currentBalance);
            TransactionModel transaction = new TransactionModel(accountID, amount, type, description);

            BLLMngr bllMngr = new BLLMngr();

            if(cboType.SelectedIndex == 2)
            {
                // Making a record of transaction and Updating Balance
                bllMngr.CreateTransaction(transaction);
                bllMngr.UpdateAccountBalance(account);
                MessageBox.Show("Deposit Complete");
            }
            else if(cboType.SelectedIndex == 1)
            {
                if (bllMngr.ValidateWithdrawal(balance, overdraftLimit, amount))
                {
                    bllMngr.CreateTransaction(transaction);
                    bllMngr.UpdateAccountBalance(account);
                    MessageBox.Show("Withdrawal Complete");
                }
                else
                {
                    MessageBox.Show("Insufficient Funds");
                }
            }
            else if(cboType.SelectedIndex == 0)
            {
                using(ProcessTransfer procTransfer = new ProcessTransfer())
                {
                    this.Hide();
                    // common variables
                    procTransfer.Amount = amount;
                    procTransfer.Description = txtDescription.Text;

                    // debtor (cutomer who will send the money)
                    procTransfer.DebtorAccountNumber = int.Parse(txtAccountNumber.Text);
                    procTransfer.DebtorName = txtName.Text;
                    procTransfer.DebtorID = accountID;
                    procTransfer.DebtorSortCode = 101010;
                    procTransfer.DebtorBalance = balance;

                    //creditor (account to which money will be sent)
                    procTransfer.CreditorAccountNumber = int.Parse(txtRecipientAccNo.Text);
                    procTransfer.CreditorSortCode = int.Parse(txtRecipientSortCode.Text);
                    procTransfer.CreditorID = bllMngr.GetAccountID(int.Parse(txtRecipientAccNo.Text));
                    procTransfer.CreditorBalance = bllMngr.GetAccountBalance(int.Parse(txtRecipientAccNo.Text));

                    //put values from previous form in here//
                    procTransfer.ShowDialog();
                }
                this.Close();
            }

            this.Close();
        }
Exemplo n.º 10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // CUSTOMER INFO //
            string firstName = txtFirstName.Text;
            string surname = txtSurname.Text;
            string address1 = txtAddress1.Text;
            string address2 = txtAddress2.Text;
            string city = txtCity.Text;
            string county = cboCounty.SelectedItem.ToString();

            // ACCOUNT INFO //
            accountNo = 0;
            int.TryParse(txtAccountNo.Text, out accountNo);
            int sortCode = 0;
            int.TryParse(txtSortCode.Text, out sortCode);
            string amountEuro = txtAmountEuro.Text.Trim();
            string amountCent = txtAmountCent.Text.Trim();
            string amountString = amountEuro + amountCent;
            int amount;
            int.TryParse(amountString, out amount);

            string accountType = "";
            if (rdoCurrent.Checked)
            {
                accountType = "Current";
            }
            else if (rdoSavings.Checked)
            {
                accountType = "Savings";
            }

            // TRANSACTION INFO //
            string description = "Initial Transaction";

            string type = "Deposit";

            // Creating three Objects //
            CustomerModel customer = new CustomerModel(firstName, surname, email, phone, address1, address2, city, county);
            AccountModel account = new AccountModel(accountType, accountNo, sortCode, amount, overDraftLimit);
            TransactionModel transaction = new TransactionModel(amount, type, description);

            // Sending to BLL //
            BLLMngr bllMngr = new BLLMngr();
            bllMngr.CreateCustomerAccount(customer, account, transaction);

            MessageBox.Show("Customer Account Added");

            this.Close();
        }