예제 #1
0
        static public int GetNumber(int choiceRange, string title, string[] options)
        {
            int  number;
            bool badchoice = false;

            while (true)
            {
                MenuPrinter.PrintMenu(title, options, null);
                if (badchoice)
                {
                    Console.Write("> Invalid input.\n");
                }
                try
                {
                    Console.Write("> ");
                    number = Convert.ToInt32(Console.ReadLine());
                    if (number > choiceRange)
                    {
                        badchoice = true;
                        continue;
                    }
                    if (number < 1)
                    {
                        badchoice = true;
                        continue;
                    }
                    return(number);
                }
                catch
                {
                    badchoice = true;
                }
            }
        }
예제 #2
0
        //public void inputCheckerCreateDeleteList(string purpose, string username, string list, string[] lists)
        //{

        //            if (purpose.ToUpper() == "DELETE")
        //            {
        //                file_handler.DelteFile(listDirectory, username, list, lists);
        //            }

        //            if (purpose.ToUpper() == "CREATE")
        //            {
        //                bool existing = ifDuplicating(listDirectory);
        //                if (!existing)
        //                {
        //                    file_handler.WriteToFile(listDirectory, "");
        //                    Console.WriteLine("\n> success.");
        //                }
        //                else
        //                {
        //                    Console.WriteLine("\nStatus: A title list is already taken...");
        //                    Console.ReadLine();
        //                    Console.WriteLine("\nGoing back to the main menu...");
        //                }
        //            }
        //            Console.Clear();
        //}

        public void CreateList()
        {
            MenuPrinter.PrintMenu("Create List", null, new string[] { "What is the name of the list?" });
            Console.Write("> ");
            string list = Console.ReadLine();

            File.Create($@"{listDirectory}/{list}.txt").Dispose();

            Console.WriteLine("\n> Done...");
            Console.ReadKey();
        }
예제 #3
0
        public string[] ShowList(string username) // for current user show list, or get list
        {
            var    file          = new MyFileHandler(username);
            string listDirectory = $@"./account_list/{username}/lists";

            string[] lists = file.GetAvailableList(listDirectory);

            if (lists.Length != 0) //check if any list exists
            {
                while (true)
                {
                    int listNumber = ValidateChoice.GetNumber(lists.Length, "Lists created by " + username, lists);

                    if (listNumber == 0) //exit
                    {
                        break;
                    }

                    try
                    {
                        string[] toDoList = File.ReadAllLines($@"{listDirectory}/{lists[listNumber-1]}.txt");
                        if (toDoList.Length == 0)
                        {
                            MenuPrinter.PrintMenu(lists[listNumber - 1] + " List", null, new string[] { "List is empty..." });
                            break;
                        }
                        else
                        {
                            MenuPrinter.PrintMenu(lists[listNumber - 1] + " List", toDoList, null);
                            return(toDoList);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("> The list you gave us does not exist!");
                        Console.ReadKey();
                        Console.Clear();
                        continue;
                    }
                }
            }
            else
            {
                Console.WriteLine("> No List Exists...");
            }
            return(null);
        }
예제 #4
0
        static public string GetUserName(string title, string[] options)
        {
            bool badchoice = false;

            while (true)
            {
                MenuPrinter.PrintMenu(title, null, options);
                if (badchoice)
                {
                    Console.Write("> Invalid input.\n> ");
                }

                Console.Write("Username> ");
                string username = Console.ReadLine();
                if (username.Contains(" "))
                {
                }
                else
                {
                    return(username);
                }
                badchoice = true;
            }
        }