// Bypass reading directory for files for Windows users. Note that Windows will block updating files, so this method remakes files only. private void UpdateAccountsTxt(int number, bool add) { string file = "accounts.txt"; if (add == true) { List <int> accTemp = new List <int>(); foreach (int i in accounts) { if (i.ToString() != "0") { accTemp.Add(i); } } accTemp.Add(number); accounts = accTemp.ToArray(); // Converts back to int[] fe.deleteFile(file); // Deletes existing file List <string> temp = new List <string>(); foreach (int i in accounts) { temp.Add(i.ToString()); } string[] contents = temp.ToArray(); fe.createFile(file, fe.compress(contents)); // Remakes file } else { // Delete account List <int> temp = new List <int>(); // New List to hold updated accounts array for (int i = 0; i < this.accounts.Length; i++) { if (this.accounts[i].ToString() != number.ToString()) { temp.Add(this.accounts[i]); } } this.accounts = temp.ToArray(); // Update accounts string[] contents = new string[temp.Count]; // Convert List to string[] if (temp.Count > 0) { for (int i = 0; i < temp.Count; i++) { contents[i] = temp[i].ToString(); } } fe.deleteFile(file); fe.createFile(file, fe.compress(contents)); // Remake file } }
// Overload for creating new accounts public Account(int[] accounts, string fn, string ln, string addr, int phone, string email, FileExplorer fe) { FirstName = fn; LastName = ln; Address = addr; PhoneNo = phone; Email = email; Balance = 0; AccountNumber = generateAccountNumber(accounts); string fileName = accountNumber + ".txt"; fn = "First Name|" + fn; ln = "Last Name|" + ln; addr = "Address|" + addr; string phonen = "Phone Number|" + phone.ToString(); email = "Email Address|" + email; string accn = "Account Number|" + accountNumber.ToString(); string balance = "Balance|0"; string[] fileContents = new string[7] { fn, ln, addr, phonen, email, accn, balance }; string c = fe.compress(fileContents); try { // Create file with account details fe.createFile(fileName, c); } catch (Exception e) { fe.log(e.ToString(), e.StackTrace); throw new Exception(); } }