// Creates a new login.txt if none is found. Also displays a message if Windows is detected.
        private static void startup()
        {
            FileExplorer fe      = new FileExplorer();
            DisplayMenu  display = new DisplayMenu();

            if (File.Exists("login.txt") == false)
            {
                display.interfaceHeader("Welcome to simple banking app");
                string path     = System.IO.Directory.GetCurrentDirectory();
                string filepath = path + "/login.txt";
                display.interfaceMessage("error", "'login.txt' cannot be found in " + path);
                Console.Clear();
                display.interfaceHeader("info");
                bool choice = display.interfaceModalYesNo("Do you want to create a new 'login.txt' in " + filepath + "?", 5);
                if (choice)
                { // Depending on the time of day, weather, r% and OS, folder permissions will fail.
                    try
                    {
                        string loginContents = "guest|1234\nuser1|password123\nuser2|321password";
                        fe.createFile("login.txt", loginContents);
                        Console.Clear();
                        display.interfaceHeader("info");
                        display.interfaceMessage("Success", "A new login.txt has been created.");
                        Console.Clear();
                    }
                    catch (System.UnauthorizedAccessException)
                    {
                        display.interfaceHeader("info");
                        display.interfaceMessage("System.UnauthorizedAccessException", "This application does not have access to the working directory. Please navigate to " + path + " " + "and create a new 'login.txt'.");
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Console.Clear();
                    display.interfaceHeader("info");
                    display.interfaceMessage("Option cancelled", "Please make a login.txt file manually at " + filepath);
                    Environment.Exit(0);
                }
            }
            OperatingSystem os  = Environment.OSVersion;
            PlatformID      pid = os.Platform;

            if (pid != PlatformID.Unix)
            {
                display.interfaceHeader("info");
                display.interfaceMessage("Windows OS detected", "There is an unresolved file directory issue related to Windows sandboxing. To resolve this, an accounts.txt will be automatically generated for tracking accounts between sessions. If there are still errors, please run this program on a Linux-based OS instead.");
            }
        }
Exemple #2
0
        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);
            }
        }