public static int RebuildBankDataFromTextFiles( ) //************************************************************************************************************************************************ { // iterate thru reading bankaccount objects from disk and add them to our LinkedList and /BankArray int count = 0; string dir = BankAccount.ReadBankFilePath( ); dir += "Textfiles\\"; string[] files = Directory.GetFiles(dir); // clear the lists- JIC DataArray.ArrayClearBank( ); // Clear ( ); BankAccount.BankAccountsLinkedList.Clear( ); foreach (var fi in files) { bool result = fi.Contains("BankObject"); if (!result) { continue; } else { string input = File.ReadAllText(fi); char[] ch = { ',' }; string[] items = input.Split(ch); BankAccount B = new BankAccount( ); B.BankAccountNumber = Convert.ToInt32(items[0]); B.CustAccountNumber = Convert.ToInt32(items[1]); B.AccountType = Convert.ToInt16(items[2]); B.Balance = Convert.ToDecimal(items[3]); B.DateOpened = Convert.ToDateTime(items[4]); B.DateClosed = Convert.ToDateTime(items[5]); B.Balance = Convert.ToDecimal(items[6]); B.Status = Convert.ToInt16(items[7]); //Write it back as OBj and TXT - yes even though we onlt just read it in. SerializeData.WriteBankAccountToDiskAndText(B, B.FullFileName); // add each one to our new List so we cna use the Enumeration later try { BankAccount.BankAccountsLinkedList.AddLast(B); DataArray.ArrayAddBank(B); if (BankAccount.BankDict != null) { if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber)) { BankAccount.BankDict.Add(B.BankAccountNumber, B); } } } catch { new Exception(" Failed to update LinkeList or Bank array in RebuildBankDataFromTextFiles at line 311"); } count++; B.Dispose( ); } } // This saves the bank LinkedList to both an object file and a Text file Lists.SaveAllBankAccountListData( ); BankListChangedEvent?.Invoke(null, "ALLDATA REBUILT FROM TEXTFILES"); return(count); }
//=========================================================================// public static int RebuildBankArrayFromLinkedList( ) //=========================================================================// { int count = 0; DataArray.ArrayClearBank( ); foreach (BankAccount Bank in BankAccount.BankAccountsLinkedList) { if (Bank ! != null) { DataArray.ArrayAddBank(Bank); count++; } } return(count); }
//******************************************************************************************// //************************************************************************************************************************************************ public static int RebuildBankLinkedListFromObjects() //************************************************************************************************************************************************ { // iterate thru reading bankaccount objects from disk and add them to our linkedList int count = 0; string dir = ReadBankFilePath(); string[] files = Directory.GetFiles(dir, "*.bnk"); // clear the lists- JIC DataArray.ArrayClearBank(); // Clear ( ); foreach (var fi in files) { bool result = fi.Contains("BankObject"); if (!result) { continue; } { BankAccount B = SerializeData.ReadBankAccountFromDisk(fi); //BankAccount B = directories . GetBankObjectFromPath ( fi ); // add each one to our new List so we cna use the Enumeration later if (B != null) { try { count++; BankAccountsLinkedList.AddLast(B); DataArray.ArrayAddBank(B); if (BankAccount.BankDict != null) { if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber)) { BankAccount.BankDict.Add(B.BankAccountNumber, B); } } } catch { } new Exception(" Failed ot update LinkeList of sortedlist in RebuildCustLinkedList atliner 366"); } B.Dispose(); } } // This saves the bank LinkedList to both an object file and a Text file Lists.SaveAllBankAccountListData(); BankListChangedEvent?.Invoke(null, "ALLDATA REBUILT FROM OBJECTS"); return(count); }
public static int RebuildBankListsFromText( ) { int count = 0; string fi = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankAccountListData.txt"; if (File.Exists(fi)) { string input = File.ReadAllText(fi); // you gotta delete them first, else it appends the data constantly char[] ch1 = { '\r' }; char[] ch2 = { ',' }; // char [ ] ch3 = { '~' }; string[] record = input.Split(ch1); string[] BAccts; DataArray.ArrayClearBank( ); BankAccount.BankAccountsLinkedList.Clear( ); // record now has an array of strings that were split on \t // this means we should have at least one, possibly multiple B.Accs in the last element // iterate through and split these out of record into string[] Item2 for (int i = 0; i < record.Length; i++) { string str = record[i]; //This should give us x strings,, the first one can be ignored //, the rest will be bank account numbers cos the format is "xxxxxx,xxxx,yyyy,~4455554544~65645 // and we are after the data immediately past the first ~ string[] Item2 = str.Split(ch2); // check. The plit always gives us ~ONE element, even though it is empty if (Item2.Length == 1 && Item2[0].Length == 0) { break; // Were all done here } BAccts = Item2[7].Split('~'); // go get em (one or more B Accts in a BAccts[] string[] if (BAccts.Length > 1) { // got one or more - do something with them ? } //Baacts MAY contain a leading EMPTY string, so beware // by here , we have an array of strings of Bank accounts owned by this customer. ? for (int x = 0; x < record.Length; x++) { // get a string from string[] array Item1[] BankAccount B = new BankAccount( ); if (B != null) { B.AccountType = Convert.ToInt16(Item2[x]); B.CustAccountNumber = Convert.ToInt32(Item2[x + 1]); B.BankAccountNumber = Convert.ToInt32(Item2[x + 2]); B.Balance = Convert.ToDecimal(Item2[x + 3]); B.DateClosed = Convert.ToDateTime(Item2[x + 4]); B.InterestRate = Convert.ToDecimal(Item2[x + 6]); // We dont seem to save this ????? B.Status = 1; BankAccount.BankAccountsLinkedList.AddLast(B); // Add this one to our linked list of customers. DataArray.ArrayAddBank(B); if (BankAccount.BankDict != null) { if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber)) { BankAccount.BankDict.Add(B.BankAccountNumber, B); } } SerializeData.WriteBankAccountToDiskAndText(B, fi); count++; break; } } // save linked list to disk in text format Lists.SaveAllBankAccountListData( ); } } return(count); }