//**************************************************************************************************************************** // this handles making a deposit call. creating the unique a/c #... // and creates a transaction record, and adds it to the linkedlist //**********************************************************************************************************// public static BankAccount CreateNewBankAccount(BankAccount bank, string CustNo, Int16 accounttype, decimal amount, decimal interest, string reason = "") //**********************************************************************************************************// { // create unique account number and set it in the account. bank.BankAccountNumber = GetBankAccountNumberSeed();// this post increments it's value internally bank.CustAccountNumber = Convert.ToInt32(CustNo); bank.Balance = amount; bank.AccountType = accounttype; bank.DateOpened = DateTime.Today.Date; bank.InterestRate = interest; // //This call increments the file numbering seed data bank.FileName = "BankObject" + bank.BankAccountNumber + ".bnk"; // add full filename to the object bank.FullFileName = BankAccount.ReadBankFilePath() + bank.FileName; //This call increments the total banks seed data // Even though we do NOT need its content here. IncrementTotalBanks(); // Ensure we save the file to disk for the Bank object itself SerializeData.WriteBankAccountToDiskAndText(bank, bank.FullFileName); BankTransaction newbankaccount = new BankTransaction(); newbankaccount.TransDate = DateTime.Now; newbankaccount.AccountType = bank.AccountType; newbankaccount.CustAccountNumber = bank.CustAccountNumber; newbankaccount.BankAccountNumber = bank.BankAccountNumber; newbankaccount.Transamount = (decimal)bank.Balance; if (reason == "") { newbankaccount.Notes = "Opening Balance"; } else { if (reason.Contains("Secondary Bank account for Customer")) { reason += bank.BankAccountNumber.ToString(); } newbankaccount.Notes = reason; } newbankaccount.Status = bank.Status; // Add a transaction record BankTransaction.allBankTransactions.AddLast(newbankaccount); BankAccountsLinkedList.AddLast(bank); DataArray.ArrayAddBank(bank); // Update our new Dictionary system if (BankAccount.BankDict != null) { if (!BankAccount.BankDict.ContainsKey(bank.BankAccountNumber)) { BankAccount.BankDict.Add(bank.BankAccountNumber, bank); } } // This saves the bank LinkedList to both an object file and a Text file Lists.SaveAllBankAccountListData(); //Add data ot our TWO hash tables // First the Customer hash tables try { if (CustomerBalanceHashTable.FindHashCustBalEntry(bank.CustAccountNumber.ToString())) { CustomerBalanceHashTable.DeleteHashCustBalEntry(bank.CustAccountNumber.ToString()); } CustomerBalanceHashTable.AddHashCustBalEntry(bank.CustAccountNumber.ToString(), bank.Balance); if (CustomerFileHashTable.CustFileNoHashTable.ContainsKey(bank.CustAccountNumber)) { CustomerFileHashTable.CustFileNoHashTable.Remove(bank.CustAccountNumber.ToString()); } CustomerFileHashTable.CustFileNoHashTable.Add(bank.CustAccountNumber.ToString(), bank.FullFileName.ToString()); } catch { } BankArrayChangedEvent?.Invoke(bank, "NEW BANKACCOUNT"); return(bank); }
// Go ahead and make bank account deposit //****************************************************************************************************************************** private void MakeDeposit_Click_1(object sender, EventArgs e) //****************************************************************************************************************************** { // Caution, this bank account may be one of several for this customer, // so make NO assumptions // Bank is already the correct record Int32 bankaccountno = 0; if (accountnumber.Text.Length == 0 || textBox2.Text.Length == 0) { info.Text = "Please complete both fields before pressing Go"; MessageBox.Show("Please complete both fields before pressing Go", "Data Input Error"); return; } if (notes.Text == "") { MessageBox.Show("You have not entered a reason for this deposit ?\nDo you want to continue without doing so ?", "Data Input Error", MessageBoxButtons.YesNo); if (DialogResult == DialogResult.No) { return; } } // This is the bank account # bankaccountno = Convert.ToInt32(accountnumber.Text); string acnostring = accountnumber.Text; string amountstr = textBox2.Text.Trim( ); if (!amountstr.Contains(".")) { amountstr += ".00"; } decimal amount = Convert.ToDecimal(amountstr); if (amount <= 0) { throw new ArgumentOutOfRangeException(nameof(amount), "Amount of Deposit [" + amount + "] must be positive"); } // Update the Bank ArrayList Bank = DataArray.ArrayGetBank(bankaccountno); if (Bank == null) { MessageBox.Show("Unable to Find Bank Account in LinkedList??..\nDeposit transaction aborted.", "Fatal Error"); return; } string custnostring = Bank.CustAccountNumber.ToString( ); // This call updates BOTH the Bank A/c and the entry in the LinkedList if (!BankAccount.UpdateBankLinkedList(bankaccountno, amount)) { MessageBox.Show("Failed to update BankAccount Linked List for Account " + acnostring, "Bank Account Deposit"); } // Also save the updated bank account back to disk SerializeData.WriteBankAccountToDiskAndText(Bank, Bank.FullFileName); // now add a new transaction for this operation BankTransaction Deposit = new BankTransaction( ); Deposit.TransDate = DateTime.Now; Deposit.AccountType = Bank.AccountType; Deposit.CustAccountNumber = Bank.CustAccountNumber; Deposit.BankAccountNumber = Bank.BankAccountNumber; Deposit.Transamount = amount; Deposit.Notes = "New Deposit : " + notes.Text; Deposit.Status = Bank.Status; BankTransaction.allBankTransactions.AddLast(Deposit); // update the Customer Balance Hash Table cos it holds the balance value CustomerBalanceHashTable.DeleteHashCustBalEntry(custnostring); CustomerBalanceHashTable.AddHashCustBalEntry(custnostring, Bank.Balance); MessageBox.Show("Deposit of " + amount.ToString( ) + " has been added to account # " + custnostring + "\nThe new balance is £" + Bank.Balance.ToString( ), "Bank Account Deposit"); textBox2.Text = ""; notes.Text = ""; accountnumber.Focus( ); return; }