private void btnUpdateAccount_Click(object sender, EventArgs e) { accountBLL = new AccountBLLManager(); UpdateCustomer = new Customer(); //Control validation if (ValidateFields()) { //Capture any changes in controls and pass into Customer object UpdateCustomer.FirstName = txtFirstName.Text; UpdateCustomer.Surname = txtSurname.Text; UpdateCustomer.Email = txtEmail.Text; UpdateCustomer.Phone = txtPhone.Text; UpdateCustomer.AddressLine1 = txtAddress1.Text; UpdateCustomer.AddressLine2 = txtAddress2.Text; UpdateCustomer.City = txtCity.Text; UpdateCustomer.County = txtCounty.Text; UpdateCustomer.CustomerID = int.Parse(txtCustomerID.Text); //Passing values into UpdateCustomer method in the BLL if (customerBLL.UpdateCustomer(UpdateCustomer)) { MessageBox.Show("Account Updated", "Success"); this.Close(); } } else MessageBox.Show("please ensure all fields are filled out correctly", "Error"); }
private void btnAddAccount_Click(object sender, EventArgs e) { //bllAccountManager bll = new bllAccountManager(); AccountBLLManager accountBll = new AccountBLLManager(); string accType = string.Empty; //Hard-code account type if (rdoCurrent.Checked) accType = "Current Account"; if (rdoSavings.Checked) accType = "Savings Account"; Customer newCustomer = new Customer(); //Checking that all fields are validated using ValidateFields bool if (ValidateFields()) { newCustomer.FirstName = txtFirstName.Text; //Perform validation here newCustomer.Surname = txtSurname.Text; newCustomer.Email = txtEmail.Text; newCustomer.Phone = txtPhone.Text; newCustomer.AddressLine1 = txtAddress1.Text; newCustomer.AddressLine2 = txtAddress2.Text; newCustomer.City = txtCity.Text; newCustomer.County = cboCounties.SelectedValue.ToString(); newCustomer.OnlineCustomer = false; //Instantiate Account class for new account Account newAccount = new Account(); newAccount.AccountType = accType; newAccount.Balance = accountBll.FormatCurrency(txtInitialBalance.Text);//FormatCurrency method to covert from ##.## to int newAccount.OverDraftLimit = accountBll.FormatCurrency(txtOverdraftLimit.Text); if (accountBll.CreateAccount(newCustomer, newAccount)) { MessageBox.Show("Account created."); this.Close(); } } else MessageBox.Show("Please ensure all fields are filled out correctly"); }
private void btnDeposit_Click_1(object sender, EventArgs e) { AccountBLLManager accountBLL = new AccountBLLManager(); Account updateBalance = new Account(); int oldBalance, deposit; //Passing amount to deposit into validation to ensure correct format if (Validation.IsCurrencyFormat(txtAmountToDeposit.Text)) { //Assigning values and passing to MakeDeposit method in the BLL oldBalance = accountBLL.FormatCurrency(txtFromBalance.Text); deposit = accountBLL.FormatCurrency(txtAmountToDeposit.Text); updateBalance.Balance = accountBLL.MakeDeposit(oldBalance, deposit); updateBalance.AccountNumber = int.Parse(txtFromAccountNumber.Text); try { //If balance is successfully updated, enter record into TransactionTable by passing //following values into method RecordTransaction in the BLL if (accountBLL.UpdateAccountBalance(updateBalance)) { try { Transaction newTransaction = new Transaction(); TransactionBLLManager transactionBLL = new TransactionBLLManager(); newTransaction.TransactionType = txtTransactionType.Text; newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToDeposit.Text); newTransaction.TransactionDate = DateTime.Now; newTransaction.TransactionReference = txtReference.Text; newTransaction.AccountNumber = int.Parse(txtAccountNumber.Text); newTransaction.TransactionDescription = txtDescription.Text; if (transactionBLL.RecordTransaction(newTransaction)) MessageBox.Show("Deposit Success", "SUCCESS!"); } catch (Exception ex) { throw ex; } this.Close(); } else MessageBox.Show("Deposit Failure", "ERROR!"); } catch (Exception ex) { throw ex; } } else MessageBox.Show("Please enter currency format: 0.00"); }
private void btnWithdraw_Click(object sender, EventArgs e) { AccountBLLManager accountBLL = new AccountBLLManager(); Account updateBalance = new Account(); int oldBalance, withdraw, newBalance; //Check for validation errors if (Validation.IsCurrencyFormat(txtAmountToWithdraw.Text)) { //Passing values into FormatCurrency method to change format oldBalance = accountBLL.FormatCurrency(txtFromBalance.Text); withdraw = accountBLL.FormatCurrency(txtAmountToWithdraw.Text); //Checking if account has sufficient funds to withdraw if (accountBLL.HasSufficientFunds(oldBalance, withdraw, Convert.ToInt32(accountBLL.FormatCurrency(txtOverdraftLimit.Text)))) { newBalance = oldBalance - withdraw; updateBalance.AccountNumber = int.Parse(txtFromAccountNumber.Text); updateBalance.Balance = newBalance; //If true then pass values into UpdateAccountBalance in the BLL if (accountBLL.UpdateAccountBalance(updateBalance)) { try { //And record the transaction in the TransactionTable Transaction newTransaction = new Transaction(); TransactionBLLManager transactionBLL = new TransactionBLLManager(); newTransaction.TransactionType = txtWithdrawTransactionType.Text; newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToWithdraw.Text); newTransaction.TransactionDate = DateTime.Now; newTransaction.TransactionReference = txtWithdrawReference.Text; newTransaction.AccountNumber = int.Parse(txtWithdrawAccountNumber.Text); newTransaction.TransactionDescription = txtWithdrawDescription.Text; if (transactionBLL.RecordTransactionWithdraw(newTransaction)) MessageBox.Show("Withdrawl Success", "SUCCESS!"); else MessageBox.Show("Error In Withdrawl", "ERROR!"); } catch (Exception ex) { throw ex; } this.Close(); } else MessageBox.Show("Error in withdrawl", "ERROR!"); } else MessageBox.Show("Insufficient Funds", "ERROR!"); } }
private void btnTransfer_Click(object sender, EventArgs e) { AccountBLLManager accountBLL = new AccountBLLManager(); Account fromAccount = new Account(); Account toAccount = new Account(); fromAccount.AccountNumber = int.Parse(txtFromAccountNumber.Text); toAccount.AccountNumber = int.Parse(txtToAccountNumber.Text); int amount; int updateSourceAccBalance; //If transfer is an external account, ignore searched account balance and just record transaction //and update senders account balance. No updating of external account balance. if (cbExternalYes.Checked) { if (accountBLL.ExternalTransfer(fromAccount, toAccount)) { try { Transaction newTransaction = new Transaction(); TransactionBLLManager transactionBLL = new TransactionBLLManager(); newTransaction.TransactionType = txtTransferTransactionType.Text; newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToTransfer.Text); newTransaction.TransactionDate = DateTime.Now; newTransaction.TransactionReference = txtTransferReference.Text; newTransaction.AccountNumber = int.Parse(txtFromAccountNumber.Text); newTransaction.DestinationAccountNumber = int.Parse(txtToAccountNumber.Text); newTransaction.TransactionDescription = txtTransferDescription.Text; if (transactionBLL.RecordTransactionTransfer(newTransaction)) MessageBox.Show("Transfer Success", "SUCCESS!"); else MessageBox.Show("Error in DB, contact Admin", "ERROR!"); } catch (Exception ex) { throw ex; } this.Close(); } } //If transfer is internal, validate fields, update sender and reciever account balance and record //transaction in TransactionTable else if (!cbExternalYes.Checked) { if (Validation.IsCurrencyFormat(txtFromBalance.Text) && Validation.IsCurrencyFormat(txtAmountToTransfer.Text) && Validation.IsCurrencyFormat(txtAmountToTransfer.Text)) { amount = accountBLL.FormatCurrency(txtAmountToTransfer.Text); if (accountBLL.TransferFrom(accountBLL.FormatCurrency(txtFromBalance.Text), amount, out updateSourceAccBalance)) { toAccount.Balance = accountBLL.TransferTo(accountBLL.FormatCurrency(txtToBalance.Text), amount); fromAccount.Balance = updateSourceAccBalance; try { if (accountBLL.Transfer(fromAccount, toAccount)) { try { Transaction newTransaction = new Transaction(); TransactionBLLManager transactionBLL = new TransactionBLLManager(); newTransaction.TransactionType = txtTransferTransactionType.Text; newTransaction.Amount = accountBLL.FormatCurrency(txtAmountToTransfer.Text); newTransaction.TransactionDate = DateTime.Now; newTransaction.TransactionReference = txtTransferReference.Text; newTransaction.AccountNumber = int.Parse(txtFromAccountNumber.Text); newTransaction.DestinationAccountNumber = int.Parse(txtToAccountNumber.Text); newTransaction.TransactionDescription = txtTransferDescription.Text; if (transactionBLL.RecordTransactionTransfer(newTransaction)) MessageBox.Show("Transfer Success", "SUCCESS!"); else MessageBox.Show("Error in DB, contact Admin", "ERROR!"); } catch (Exception ex) { throw ex; } this.Close(); } else MessageBox.Show("Error in transfer", "ERROR!"); } catch (Exception ex) { throw ex; } } } else MessageBox.Show("Insufficient Funds", "ERROR!"); } else MessageBox.Show("Please enter currency in 0.00 format"); }
//Calling method in the account business logic layer to populate data grid. private void PrimeGrid() { AccountBLLManager accountBll = new AccountBLLManager(); DataSet ds = accountBll.GetDetailsForMainGrid(); //Setting the data source for the data grid dgvAccounts.DataSource = ds.Tables[0]; }