Example #1
0
        // 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.");
            }
        }
Example #2
0
        // Overload for initialising existing accounts
        public Account(int number, FileExplorer fe, Validator v)
        {
            string[] contents = fe.getFileContents(number.ToString() + ".txt");
            for (int i = 0; i < contents.Length; i++)
            {
                switch (i)
                {
                case 0:
                    FirstName = v.deleteFormLabel(contents[i]);
                    break;

                case 1:
                    LastName = v.deleteFormLabel(contents[i]);
                    break;

                case 2:
                    Address = v.deleteFormLabel(contents[i]);
                    break;

                case 3:
                    PhoneNo = Convert.ToInt32(v.deleteFormLabel(contents[i]));
                    break;

                case 4:
                    Email = v.deleteFormLabel(contents[i]);
                    break;

                case 5:
                    AccountNumber = Convert.ToInt32(v.deleteFormLabel(contents[i]));
                    break;

                case 6:
                    Balance = Convert.ToInt32(v.deleteFormLabel(contents[i]));
                    break;

                default:
                    this.Activities.Add(parseActivity(contents[i]));
                    break;
                }
            }
        }
Example #3
0
        // 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();
            }
        }
Example #4
0
        public FileExplorer()
        {
            FileExplorer fe = this;

            fe.os = fe.osDivider();
        }