Esempio n. 1
0
        public void CheckOut()
        {
            Dictionary <string, List <string> > studentCheckOuts = data.StudentCheckOuts;

            Console.Clear();

            string name  = "";
            string title = "";

            while (true)
            {
                Console.Clear();
                Console.WriteLine("All Students: ");
                reader.CheckOutStudentList();
                Console.WriteLine("\nEnter a name or \"quit\" to return to the main menu. ");
                name = Console.ReadLine();

                bool quitter = data.MenuQuitter(name);
                if (quitter == true)
                {
                    return;
                }

                if (DoThingers.CIContains(studentCheckOuts, name)) //my case insensitive contains method
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter a valid name.");
                    System.Threading.Thread.Sleep(1500);
                    continue;
                }
            }

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Available Resources: ");
                reader.CheckOutPrintAvailableResources();
                Console.WriteLine("\nEnter the name of the resource you want to check out: ");
                title = Console.ReadLine();

                bool quitter = data.MenuQuitter(title);
                if (quitter == true)
                {
                    return;
                }

                if (DoThingers.CIContains(resources, title))
                {
                    AddToList(studentCheckOuts, name, title);

                    bool checker;
                    resources.TryGetValue(title, out checker);

                    if (checker == true)
                    {
                        UpdateCheckOutDictionaryAvailability(resources, title); //updates resources dictionary
                        writer.CheckOutResource(studentCheckOuts, name);        //writes the student files
                        writer.WriteResourceFiles(resources);                   //writes the resource files
                    }
                    else
                    {
                        Console.WriteLine("That resource is already checked out or does not exist. Please select another.");
                        continue;
                    }
                }
                else
                {
                    Console.WriteLine("That resource does not exist.");
                }

                string input = "";

                while (input != "yes" || input != "no" || input != "y" || input != "n")
                {
                    Console.WriteLine("Do you want to check out another resource? Y or N");
                    input = Console.ReadLine().ToLower();

                    if (input != "yes" || input != "no" || input != "y" || input != "n")
                    {
                        break;
                    }
                }

                if (input == "yes" || input == "y")
                {
                    continue;
                }

                if (input == "no" || input == "n")
                {
                    break;
                }
            }
        }
Esempio n. 2
0
        public void ReturnItem()
        {
            string name;
            string filename;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Student names: ");
                reader.CheckOutStudentList();
                Console.WriteLine("\nEnter your name or \"quit\" to return to the main menu.");
                name = Console.ReadLine();

                bool quitter = data.MenuQuitter(name);
                if (quitter == true)
                {
                    return;
                }

                if (data.StudentCheckOuts.Keys.Contains(name.ToLower()))
                {
                    StringBuilder fileName = new StringBuilder();

                    fileName.Append(name);
                    fileName.Append(".txt");

                    filename = fileName.ToString();

                    if (!File.Exists(filename))
                    {
                        Console.WriteLine("That user doesn't have anything checked out.");
                        Console.WriteLine("Press any key to return to the main menu.");
                        Console.ReadKey();
                        return;
                    }
                    else
                    {
                        ShowCheckedOutResources(filename);
                        break;
                    }
                }
                else
                {
                    continue;
                }
            }

            while (true)
            {
                Console.WriteLine("Enter the name of the resource you wish to return or \"quit\" to return to the main menu. ");
                string title = Console.ReadLine();

                bool quitter = data.MenuQuitter(title);
                if (quitter == true)
                {
                    return;
                }

                if (resources.ContainsKey(title))
                {
                    string toDelete = "";
                    string line;

                    using (StreamReader reader = new StreamReader(filename))
                    {
                        while (!reader.EndOfStream)
                        {
                            line = reader.ReadLine();

                            if (resources.ContainsKey(line))
                            {
                                toDelete = title;
                                reader.Close();
                                break;
                            }
                        }

                        bool success = RemoveReturnedItemFromStudentFile(filename, toDelete);
                        if (success == true)
                        {
                            resources[title] = true;
                            writer.WriteResourceFiles(resources);
                            writer.StudentHeader(name);
                            Console.WriteLine(title + " has been returned. Press any key to continue.");
                            Console.ReadKey();
                            break;
                        }
                        else
                        {
                            Console.WriteLine("That user has not checked out that resource.");
                            Console.WriteLine("\nPress any key to return to the main menu.");
                            Console.ReadKey();
                            break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nThat title does not exist. Please try again or enter \"quit\" to go back to the main menu.\n");
                    continue;
                }
            }
        }