// 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(); } }
public void viewDeleteAccount(User user) { string header = "Delete account"; string prompt = "Continue searching for an account to delete?"; try { Account account = loopSearchAccount(user, header, prompt); Console.Clear(); bool confirm = display.interfaceBankDeleteAccount(account, header); if (confirm != true) { viewMainMenu(user); } else { try { deleteAccount(account); // Deletes account file only updateAccountsArray(account.AccountNumber, false); // Rebuild accounts array account = null; Console.Clear(); viewMainMenu(user); } catch (Exception e) { fe.log(e.ToString(), e.StackTrace); Console.Clear(); display.interfaceHeader(header); display.interfaceMessage("error", "Failed to delete the account. Please delete " + account.AccountNumber + ".txt in the program directory manually."); Console.Clear(); viewMainMenu(user); } } } catch (Exception e) // There is a non-zero possibility of loopSearchAccount() returning a null on Windows { fe.log(e.ToString(), e.StackTrace); Console.Clear(); display.interfaceHeader(header); display.interfaceMessage("error", "An error occurred while searching for the account and the account failed to load. Please check that the account file is not corrupted. For Windows users, please check that accounts.txt contains the correct account number."); Console.Clear(); viewMainMenu(user); } }