//******************************************************************************************************************************************* public static int BuildBankTransactionsFromTextfile( ) { //******************************************************************************************************************************************* string fi = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankTransData.txt"; int count = 0; if (File.Exists(fi)) { string input = File.ReadAllText(fi); // you gotta delete them first, else it appends the data constantly char[] ch1 = { '\t' }; char[] ch2 = { ',' }; string[] record = input.Split(ch1); int x = 0; for (int i = 0; i < record.Length - 1; i++) { // There is n empty record for some reason, hence Length - 1 string str = record[i]; string[] Item = str.Split(ch2); BankTransaction BT = new BankTransaction( Convert.ToDateTime(Item[x]), Convert.ToInt16(Item[x + 1]), Convert.ToInt32(Item[x + 2]), Convert.ToInt32(Item[x + 3]), Convert.ToDecimal(Item[x + 4]), Item[x + 5], Convert.ToInt16(Item[x + 6])); BankTransaction.allBankTransactions.AddLast((BankTransaction)BT); count++; } } return(count); }
//*******************************************************************************************// public static bool DeleteBankAccount(string accountNo) //**********************************************************************************************************// { bool result = false; //First we need the relevant bank account object foreach (var Bank in BankAccountsLinkedList) { // check for matching AccountNumber in each BankAccount Object if (Bank.CustAccountNumber == Convert.ToInt32(accountNo)) { // Found the BankAccount object we want to close // first, remove it from the LinkedList BankAccountsLinkedList.Remove(Bank); // now do the bankno array int index = DataArray.ArrayFindBank(Bank); DataArray.BankNo.RemoveAt(index); // Update our new Dictionary system if (BankDict != null) { BankDict.Remove(index); } // Then delete the bank object itself // Bank.Dispose(); // Finally,we need to add a transactions record for this account BankTransaction bt = new BankTransaction(); bt.TransDate = DateTime.Now; bt.AccountType = 9; bt.CustAccountNumber = Convert.ToInt32(accountNo); bt.BankAccountNumber = Bank.BankAccountNumber; bt.Transamount = 0; bt.Notes = "Account has been closed"; bt.Status = 2; // closed BankTransaction.allBankTransactions.AddLast(bt); result = true; //Trigger our event BankListChangedEvent?.Invoke(Bank, "BANKACCOUNT DELETED"); break; } } if (!result) { MessageBox.Show("Failed to delete the entry from the Transactions list..."); return(false); } else { return(true); } }
//************************************************************************************************************************************************ public static void ReWriteBankLinkedList( ) //************************************************************************************************************************************************ { // iterate thru bankaccount objects and add threm to our linkedList string dir = BankAccount.ReadBankFilePath( ); string[] files = System.IO.Directory.GetFiles(dir, "*.bnk"); // iterate thru all the files on disk, startinmg at 1 // Iterate trhu them and handle as required int count = 0; foreach (var fi in files) { bool result = fi.Contains("BankObject"); if (!result) { continue; } { using BankAccount B = (BankAccount)SerializeData.ReadBankAccountFromDisk(fi); // As we have red it in, we need to delete it so we do not // duplicate it when saving all files at end of a user sessoin. if (B != null) { BankAccount.BankAccountsLinkedList.AddLast(B); // Add this one to our linked list of customers. BankTransaction newbankaccount = new BankTransaction(B.DateOpened, B.AccountType, B.CustAccountNumber, B.BankAccountNumber, B.Balance, "Customer account updated successfuly", B.Status); BankTransaction.allBankTransactions.AddLast(newbankaccount); } count++; } } // save linked list to disk in text format Lists.SaveAllBankAccountListData( ); }
// find account private void DeleteButton_Click(object sender, EventArgs e) { string accno = AccountNumber.Text; string balstr = ""; if (Cust == null) { Cust = Customer.GetCustomerAccount(accno); } if (Cust == null) { MessageBox.Show("Unable to find the Customer Record on Disk", "Database system ERROR"); return; } // now check all the objects first, then finally delete it all Bank = Search.FindBankObjectfromCustNo(accno); // get the full file name/path if (Bank == null) { MessageBox.Show("Unable to open the Bank Account Record File (Object for deletion)!", "Database system ERROR"); // Cu . Dispose ( ); // delete Customer object in memory sraight away return; } else { balstr = Bank.Balance.ToString( ); if (Bank.Balance > 0) { DialogResult result; result = MessageBox.Show("This Customer has a positive balance of " + Bank.Balance.ToString( ) + " in their main account!\nDo you really want to continue to delete it ?", "Financial Adjustment Required", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } // Find CUSTOMER in LINKED LIST and DELETE IT. foreach (var L in Customer.CustomersLinkedList) { if (L.CustomerNumber == Convert.ToInt32(accno)) { Customer.CustomersLinkedList.Remove(L); // L.Dispose ( ); break; } } // Find CUSTOMER in ArrayLIST and DELETE IT. // remember to also delete ALL other Bank A/cs // DeleteSecondaryBankAccounts handles both LinkedList and ArrayList // and the disk file itself if (Cust.accountnums[1] > 0) { DeleteSecondaryBankAccounts(Bank, Cust.accountnums[1]); } if (Cust.accountnums[2] > 0) { DeleteSecondaryBankAccounts(Bank, Cust.accountnums[2]); } if (Cust.accountnums[3] > 0) { DeleteSecondaryBankAccounts(Bank, Cust.accountnums[3]); } // dont forget the original account DeleteSecondaryBankAccounts(Bank, Cust.accountnums[0]); BankTransaction newtransrecord = new BankTransaction( DateTime.Now, // Transaction Date Bank.AccountType, // Account Type Bank.CustAccountNumber, // Cust Account # Bank.BankAccountNumber, // Bank Account # Convert.ToDecimal("0.00"), // Transaction Amount "Customer " + Bank.CustAccountNumber.ToString( ) + " has been deleted", // Notes Bank.Status); // Status // remove the customer from our ArrayList if (!DataArray.ArrayDeleteCust(Cust)) { MessageBox.Show("Failed to delete the Customer record from ArrayList", "Data processing ERROR"); } // write a transaction record so we rmeeber th eCustomer has GONE... BankTransaction.allBankTransactions.AddLast(newtransrecord); // Finally Delete the Customer record if (File.Exists(Cust.FullFileName)) { File.Delete(Cust.FullFileName); } // now delete the Textfile copy string fi = Customer.GetCustFilePath( ) + "Textfiles\\custobj" + Bank.CustAccountNumber.ToString( ) + ".txt"; if (File.Exists(fi)) { File.Delete(fi); } File.Delete(Bank.FullFileName); // now delete the actual Bank Account file // clean up our memeory usage after ourselves so far // Bank . Dispose ( ); // delete BankAccount object in memory // Cust . Dispose ( ); // delete our file wide Customer object in memory } // Bank. fc . Text = "Customer # " + accno + " has been deleted from the system successfully..\r\n"; command.Text = "Account " + accno + " has been deleted completely"; FirstName.Text = ""; LastName.Text = ""; //AccountNumber . Text = ""; info.Text = "including all attached Bank Account(s)"; if (balstr.Length > 0) { MessageBox.Show("The selected Customer # had a balance of " + Bank.Balance.ToString( ) + " in their main account!\nbut the account has still been deleted?", "Financial Adjustment Required", MessageBoxButtons.YesNo); } else { MessageBox.Show("The selected Customer # has been deleted succesfully including their main and auxuiliary accounts?", "Customer Deletion Utility", MessageBoxButtons.YesNo); } AccountNumber.Focus( ); }
// Save the new customer data as an Object and add it to the Customer List // plus create a BankAccount object and add it to the BankAccount List // and add a bak transaction //*************************************************************************************************************************************************// private void SaveBankButton_Click(object sender, EventArgs e) //*************************************************************************************************************************************************// { if (AccountNo.Text.Length == 0 || AccountBalance.Text.Length == 0 || Interest.Text.Length == 0 || OpenDate.Text.Length == 0 || fname.Text.Length == 0 || lname.Text.Length == 0 || day.Text.Length == 0 || month.Text.Length == 0 || year.Text.Length == 0) { MessageBox.Show("One or more fields are empty, All fields must be populated", "User Input Error"); return; } Int16 type = 0; if (AccountType.Text.Contains("Normal")) { type = 1; } if (AccountType.Text.Contains("Savings")) { type = 2; } if (AccountType.Text.Contains("Deposit")) { type = 3; } if (AccountType.Text.Contains("Business")) { type = 4; } //====================BANK ACCOUNT ======================================== // READ BANK OBJECT FROM DISK and update it // Bank should be valid as it is a global in this file ? if (allbankaccounts.SelectedIndex == -1) { MessageBox.Show("The Bank Account list does not appear to have an item selected\nWe No data has been changed, but we are UNABLE to continue with update...", "Database system ERROR"); return; } string target = allbankaccounts.Items[allbankaccounts.SelectedIndex].ToString(); char[] ch = { '\t' }; char[] dashch = { '-' }; string[] tempacno = target.Split(ch); Int32 accountno = Convert.ToInt32(tempacno[0]); Bank = Search.FindBankObjectfromBankNo(accountno); int actype = Convert.ToInt16(AccountType.SelectedIndex + 1); string actypeselected = AccountType.SelectedItem.ToString(); string[] newselaccount = actypeselected.Split(dashch); if (newselaccount[0] != tempacno[1]) { // the type of account has been changed - handle it for (int i = 0; i < allbankaccounts.Items.Count; i++) { string temp = ""; temp = allbankaccounts.Items[i].ToString(); string[] thisentry = temp.Split(ch); if (thisentry[0] == tempacno[0] && thisentry[1] != newselaccount[0]) { listupdateneeded = false; //This simply avoids the auto update of the listbox, set back to true afterwards allbankaccounts.Items.RemoveAt(i); temp = Bank.BankAccountNumber.ToString() + "\t" + actype.ToString(); allbankaccounts.Items.Add(temp); allbankaccounts.SelectedIndex = i; listupdateneeded = true; break; } } } // Thkis call sends Event data to Bankaccount.cs so the handlers can handle it // cos we cannot call them directly in BankAccount.cs BankAccount.SendBankEventData(Bank, "BANKACCOUNT MODIFIED"); // we need to delete the old account and insert the new details in our ArrayList int index = DataArray.ArrayFindBank(Bank); DataArray.BankNo.RemoveAt(index); BankAccount.BankDict.Remove(index); Bank.Balance = Convert.ToDecimal(AccountBalance.Text); Bank.InterestRate = Convert.ToDecimal(Interest.Text); Bank.DateOpened = Convert.ToDateTime(OpenDate.Text); Bank.AccountType = Convert.ToInt16(actype); //SAVE BANK OBJECT BACK TO DISK SerializeData.WriteBankAccountToDiskAndText(Bank, Bank.FullFileName); DataArray.ArrayAddBank(Bank); if (BankAccount.BankDict != null) { if (!BankAccount.BankDict.ContainsKey(Bank.BankAccountNumber)) { BankAccount.BankDict.Add(Bank.BankAccountNumber, Bank); } } // handle the Linkedlist as well // CREATE A NEW BANK TRANSACTION BankTransaction newbankaccount = new BankTransaction(); newbankaccount.TransDate = DateTime.Now; newbankaccount.AccountType = Bank.AccountType; newbankaccount.CustAccountNumber = Bank.CustAccountNumber; newbankaccount.BankAccountNumber = Bank.BankAccountNumber; newbankaccount.Transamount = Bank.Balance; newbankaccount.Notes = "Opening Balance"; newbankaccount.Status = Bank.Status; BankTransaction.allBankTransactions.AddLast(newbankaccount); //Update the Customer HASH TABLE CustomerBalanceHashTable.UpdateCustBalHashTable(Bank.CustAccountNumber.ToString(), Bank.Balance); //NOW UPDATE CUSTOMER RECORD Cust = Customer.GetCustomerAccount(Bank.CustAccountNumber.ToString()); if (Cust == null) { MessageBox.Show("Unable to find the Customer Record from LinkedList", "Database system ERROR"); return; } else { // we need to delete the old Customer account and insert the new details in our ArrayList int indx = DataArray.ArrayFindCust(Cust); DataArray.CustNo.RemoveAt(indx); Customer.CustDict.Remove(indx); // Now update the Customer record so we can add it to the array Cust.FirstName = fname.Text; Cust.LastName = lname.Text; Cust.DOB = Convert.ToDateTime(day.Text + "/" + month.Text + "/" + year.Text); if (Cust.accountnums[0] == Convert.ToInt32(Bank.BankAccountNumber)) { Cust.accounttypes[0] = type; } else if (Cust.accountnums[1] == Convert.ToInt32(Bank.BankAccountNumber)) { Cust.accounttypes[1] = type; } else if (Cust.accountnums[2] == Convert.ToInt32(Bank.BankAccountNumber)) { Cust.accounttypes[2] = type; } else if (Cust.accountnums[3] == Convert.ToInt32(Bank.BankAccountNumber)) { Cust.accounttypes[3] = type; } Cust.Address1 = addr1.Text; Cust.Address2 = addr2.Text; Cust.Town = town.Text; Cust.County = county.Text; Cust.PostCode = postcode.Text; Cust.PhoneNumber = phone.Text; Cust.MobileNumber = mobile.Text; // SAVE CUSTOMER OBJECT BACK TO DISK Customer.WriteCustObjectToDiskAndText(Cust, Cust.FullFileName); try { // update Customer Linked List & ArrayList Customer.CustomersLinkedList.Remove(Cust); Customer.CustomersLinkedList.AddLast(Cust); // save our Customer LinkedList to disk as binary and txt files Lists.SaveAllCustomerListData(Customer.CustomerFilePath + "CustSortedListData.cust"); DataArray.ArrayAddCust(Cust); if (Customer.CustDict != null) { if (!Customer.CustDict.ContainsKey(Cust.CustomerNumber)) { Customer.CustDict.Add(Cust.CustomerNumber, Cust); } } } catch { new Exception("Customer Linked List coukld not be updated in bankaccountEdit.cs cline 103"); } } MessageBox.Show("Bank & Customer accounts have been updated successfully...,", "Bank account Edit Facility"); }
// Save the new customer data as an Object and add it to the Customer List // plus create a BankAccount object and add it to the BankAccount List //*************************************************************************************************************// private void SaveCustButton_Click(object sender, EventArgs e) //*************************************************************************************************************// { if (!dirty) { MessageBox.Show("No changes appear to have been made ?... \nPlease make any changes needed, and then try again" + "", " FULL Customer EDIT entry System"); return; } try { int test = Convert.ToInt16(day.Text); test = Convert.ToInt16(month.Text); test = Convert.ToInt16(year.Text); } catch { new Exception("Date of Birth entry data is invalid..." + day + "/" + month + "/" + year); } /* * if ( AccountType. Text. Contains ( "Normal" ) ) type = 1; * if ( AccountType. Text. Contains ( "Savings" ) ) type = 2; * if ( AccountType. Text. Contains ( "Deposit" ) ) type = 3; * if ( AccountType. Text. Contains ( "Business" ) ) type = 4; */ if (day.Text == "" | month.Text == "" | year.Text == "") { MessageBox.Show("The DOB date you have entered is not valid... Please correct this", " New Customer entry System"); return; } if (Convert.ToInt16(day.Text) < 0 | Convert.ToInt16(day.Text) > 31 | Convert.ToInt16(month.Text) < 0 | Convert.ToInt16(month.Text) > 12 | Convert.ToInt16(year.Text) < 1920 | Convert.ToInt16(year.Text) > DateTime.Now.Year) { MessageBox.Show("The DOB date you have entered is not valid... Please correct this", " New Customer entry System"); return; } string dob = day.Text + "/" + month.Text + "/" + year.Text; /// make sure our DOB data is sound, else we crqash everywhere try { DateTime DOB = Convert.ToDateTime(dob); } catch { MessageBox.Show("The DOB date you have entered is not valid... Please correct this", " New Customer entry System"); return; } if (lname.Text == "") { MessageBox.Show("You must enter a valid Last Name... Please correct this", " New Customer entry System"); return; } if (town.Text == "") { MessageBox.Show("You must enter a valid Town... Please correct this", " New Customer entry System"); return; } if (county.Text == "") { MessageBox.Show("You must enter a valid County... Please correct this", " New Customer entry System"); return; } if (pcode.Text == "") { MessageBox.Show("You must enter a valid PostCode... Please correct this", " New Customer entry System"); return; } if (!dirty) { MessageBox.Show("No changes appear to have been made, so saving it is not required", "Data Validation Warning "); return; } if (Cust != null) { // first grab the ArrayList entry index using original data int index = DataArray.ArrayFindCust(Cust); if (index == -1) { MessageBox.Show("This Customer account details cannot be found in ArrayList...,", "Customer FULL Edit facility"); return; } // go ahead and update the object Cust.FirstName = fname.Text; Cust.LastName = lname.Text; Cust.Address1 = addr1.Text; Cust.Address2 = addr2.Text; Cust.Town = town.Text; Cust.County = county.Text; Cust.PostCode = pcode.Text; Cust.PhoneNumber = tel.Text; Cust.MobileNumber = mob.Text; // Update Customer Object on disk Customer.WriteCustObjectToDiskAndText(Cust, Cust.FullFileName); // update Now we can actually the ArrayList DataArray.CustNo.RemoveAt(index); DataArray.ArrayAddCust(Cust); /* * // already updated previously * // update Customer LinkedList * foreach ( var L in Customer . CustomersLinkedList ) * { * if ( L . CustomerNumber == Convert . ToInt32 ( AccountNo . Text ) ) * { // got it * if ( Customer . CustomersLinkedList . Contains ( L ) ) * { * Customer . CustomersLinkedList . Remove ( L ); * Customer . CustomersLinkedList . AddLast ( Cust ); * } * break; * } * } */ // get the bank account for this customer // and update the relevant fields string s = accountnums.SelectedItem.ToString( ); char[] c = { '\t' }; string[] opts = s.Split(c); Bank = Search.FindBankObjectfromBankNo(opts[0]); // Find the original Bank object in ArrayList int indx = DataArray.ArrayFindBank(Bank); if (indx == -1) { MessageBox.Show("This Bank account details cannot be found in ArrayList...,", "Customer FULL Edit facility"); return; } try { DataArray.BankNo.RemoveAt(indx); // I do this in case the value is formatted eg : 1,235.76 !! which definitely does not compuute easily !! Bank.Balance = Convert.ToDecimal(Convert.ToDecimal(AccountBalance.Text).ToString( )); Bank.InterestRate = Convert.ToDecimal(Interest.Text); // save the changes to our bank account SerializeData.WriteBankAccountToDiskAndText(Bank, Bank.FullFileName); } catch { MessageBox.Show("This Bank account details cannot be updated , Data system is NOW inconsistent !...,", "Customer FULL Edit facility"); return; } // Now we can update ArrayList safely if (indx != -1) { DataArray.ArrayAddBank(Bank); } // Write a transaction record too.... BankTransaction newbankaccount = new BankTransaction( ); newbankaccount.TransDate = DateTime.Now; newbankaccount.AccountType = Bank.AccountType; newbankaccount.CustAccountNumber = Bank.CustAccountNumber; newbankaccount.BankAccountNumber = Bank.BankAccountNumber; newbankaccount.Transamount = Bank.Balance; newbankaccount.Notes = "Opening Balance"; newbankaccount.Status = Bank.Status; BankTransaction.allBankTransactions.AddLast(newbankaccount); //our TWO hash tables do not hold any data that can be changed // update the interest in BankAccount LinkedList in case it hs been chnaged foreach (var BL in BankAccount.BankAccountsLinkedList) { if (BL.CustAccountNumber == Convert.ToInt32(AccountNo.Text)) { BL.InterestRate = Convert.ToDecimal(Interest.Text); // this is the ONLY thing we can update in a bank account break; } } dirty = false; } MessageBox.Show("This Customer account details have been updated successfully...,", "Customer FULL Edit facility"); }
//******************************************************************************************************************************************* public static int RebuildBankTransactions( ) //******************************************************************************************************************************************* { // use data from disk object StringBuilder SB = ReadAllBankTransactions( ); // read data from binary disk objuect int count = 0; if (SB == null) { return(0); } // parse bt out the various fields to a string array // ech record ends with '\n' string datain = SB.ToString( ); string[] item = datain.Split(','); int i = 0; string temp = ""; while (true) { try { if (item[i].Contains('\t')) { temp = item[i].Substring(1); } else { temp = item[i]; } DateTime d = Convert.ToDateTime(temp); // Transaction Date Int16 b = Convert.ToInt16(item[i + 1]); // Account Type Int32 c = Convert.ToInt32(item[i + 2]); // Cust Account # Int32 f = Convert.ToInt32(item[i + 3]); // Bank Account # decimal e = Convert.ToDecimal(item[i + 4]); // Transaction Amount string s = item[i + 5]; // Notes Int16 a = Convert.ToInt16(item[i + 6]); // char [ ] ch = { '\t' }; // string [ ] str = temp . Split ( ch ); // Int16 a = Convert . ToInt16 ( str [ 0 ] ); // actype = item [ i + 7 ] . Substring ( 0, 1 ); // remove the \n from this field // a = Convert . ToInt16 ( actype ); BankTransaction newtransrecord = new BankTransaction( d, // Transaction Date b, // Account Type c, // Cust Account # f, // Bank Account # e, // Transaction Amount s, // Notes a); // Status allBankTransactions.AddLast(newtransrecord); count++; i += 7; if (i + 1 >= item.Count( )) { break; } } catch { new Exception("Failed to handle data in ReadBankTransactions Function, line 163 in Serialize.cs"); } } return(count); }
//**************************************************************************************************************************** // 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); }
//*************************************************************************************************************************************************// private void SaveCustButton_Click(object sender, EventArgs e) //*************************************************************************************************************************************************// { // update the details if (!dirty) { MessageBox.Show("No changes appear to have been made, so saving it is not required", "Data Validation Warning "); return; } if (!VerifyData( )) { MessageBox.Show("Various important data items appear to be empty. Please complete the necessary fields", "Data Validation Warning "); return; } if (Cust != null) { // go ahead and update the object Cust.FirstName = fname.Text; Cust.LastName = lname.Text; Cust.Address1 = addr1.Text; Cust.Address2 = addr2.Text; Cust.Town = town.Text; Cust.County = county.Text; Cust.PostCode = pcode.Text; Cust.PhoneNumber = tel.Text; Cust.MobileNumber = mob.Text; // Update Customer Object on disk Customer.WriteCustObjectToDiskAndText(Cust, Cust.FullFileName); // update Customer LinkedList foreach (var L in Customer.CustomersLinkedList) { if (L.CustomerNumber == Convert.ToInt32(accountno.Text)) { // got it L.FirstName = Cust.FirstName; L.LastName = Cust.LastName; L.Address1 = Cust.Address1; L.Address2 = Cust.Address2; L.Town = Cust.Town; L.County = Cust.County; L.PostCode = Cust.PostCode; L.PhoneNumber = Cust.PhoneNumber; L.MobileNumber = Cust.MobileNumber; break; } } // get the bank account for this customer // and update the relevant fields B = Search.FindBankObjectfromBankNo(accountno.Text); B.Balance = Convert.ToDecimal(AccountBalance.Text); B.InterestRate = Convert.ToDecimal(Interest.Text); // save the changes to our bank account SerializeData.WriteBankAccountToDiskAndText(B, B.FullFileName); // Write a transaction record too.... BankTransaction newbankaccount = new BankTransaction( ); newbankaccount.TransDate = DateTime.Now; newbankaccount.AccountType = B.AccountType; newbankaccount.CustAccountNumber = B.CustAccountNumber; newbankaccount.BankAccountNumber = B.BankAccountNumber; newbankaccount.Transamount = B.Balance; newbankaccount.Notes = "Opening Balance"; newbankaccount.Status = B.Status; BankTransaction.allBankTransactions.AddLast(newbankaccount); //our TWO hash tables do not hold any data that can be changed // update the interest in List in case it hs been chnaged foreach (var BL in BankAccount.BankAccountsLinkedList) { if (BL.CustAccountNumber == Convert.ToInt32(accountno.Text)) { BL.InterestRate = Convert.ToDecimal(Interest.Text); // this is the ONLY thing we can update in a bank account break; } } MessageBox.Show("The Customer details have been fully updated...", "Customer Update System"); // tidy up after ourselves // Cust.Dispose ( ); } dirty = false; //this.Close(); // do not close it on saving }
// 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; }
//====================================================================== private void rewrite_Click(object sender, EventArgs e) //====================================================================== { string output = ""; if (notes.Text == "" || AccountNumber.Text == "" || AccountBalance.Text == "" || OpenDate.Text == "" || Interest.Text == "" || custno.Text == "") { MessageBox.Show("One or more data items are Empty - All fields must be completed before saving it ..." + "\nRecommeded action is to use the DropDown list to reselect a valid Bank Account", "Data Validation ERROR"); info.Text = "One or more data items are Empty - All fields must be completed before saving it ..."; return; } string stat; if (status.Text == "Active") { stat = "1"; } else { stat = "0"; } int type = AccountType.SelectedIndex + 1; // format is "Bank A/c # + "," + Customer A/c # + "," + A/c Type + "," + Balance + "," + Date Opened (short) + "," + Date Closed (short) + "," + Interest + "," + Status (0/1)+ "\r\n" output = AccountNumber.Text + "," + custno.Text + "," + type.ToString() + "," + AccountBalance.Text + ","; output += Convert.ToDateTime(OpenDate.Text).ToShortDateString() + "," + Convert.ToDateTime("01/01/0001").ToShortDateString() + "," + Interest.Text; output += "," + stat + "\r\n"; string path = BankAccount.ReadBankFilePath(); path += "Textfiles\\BankObject" + AccountNumber.Text + ".txt"; if (File.Exists(path)) { File.Delete(path); // you gotta delete them first, else it appends the data constantly } File.AppendAllText(path, output); // update the bank object path = BankAccount.ReadBankFilePath(); path += "Bankobject" + AccountNumber.Text + ".bnk"; // read the bank a/c in fresh from disk so it is clean BankAccount Bank = SerializeData.ReadBankAccountFromDisk(path); if (Bank == null) { MessageBox.Show("Bank Account Object file cannot be loaded (or saved)!", "Bank Object Error"); return; } Int32 bankno = Bank.BankAccountNumber; // update the Bank object Bank.AccountType = Convert.ToInt16(AccountType.SelectedIndex); Bank.AccountType++;// cos th reindex starts at ZERO !! Bank.Balance = Convert.ToDecimal(AccountBalance.Text); Bank.InterestRate = Convert.ToDecimal(Interest.Text); string banknostring = Bank.BankAccountNumber.ToString(); //Update the version in Bank Array int index = DataArray.ArrayFindBank(Bank); DataArray.BankNo[index] = Bank; // Update the version in our Bank LinkedList foreach (var B in BankAccount.BankAccountsLinkedList) { if (B.BankAccountNumber == bankno) { // got it, rpelace with our new one BankAccount.BankAccountsLinkedList.Remove(B); BankAccount.BankAccountsLinkedList.AddLast(Bank); break; } } // This saves the bank LinkedList to both an object file and a Text file Lists.SaveAllBankAccountListData(); // write theBank object to disk SerializeData.WriteBankAccountToDiskAndText(Bank, path); // Add a bank Transaction BankTransaction newbankaccount = new BankTransaction(Bank.DateOpened, Bank.AccountType, Bank.CustAccountNumber, Bank.BankAccountNumber, Bank.Balance, "Bank details edited from Textfile input", Bank.Status); BankTransaction.allBankTransactions.AddLast(newbankaccount); // that's it ***ALL***all Bank Data structures have been updated info.Text = "Bank Account data has been fully updated throughout System"; }