Exemplo n.º 1
0
        public void WriteNewStudentFile(string name) //makes a new file for a new student in admin menu
        {
            StringBuilder makeName = new StringBuilder();

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

            string filename = makeName.ToString();

            FileWriter writing = new FileWriter(data);

            StreamWriter writer = new StreamWriter(filename);

            using (writer)
            {
                writer.WriteLine(writing.StudentHeader(name));
            }
        }
Exemplo n.º 2
0
        public void CheckOutResource(Dictionary <string, List <string> > studentCheckOuts, string name)
        {   //writes the student's file when checking out and updates the resources dictionary bools
            FileWriter writer = new FileWriter(data);

            Dictionary <string, bool> resources = data.Resources;

            foreach (KeyValuePair <string, List <string> > pair in studentCheckOuts)
            {
                if (pair.Key.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    name = pair.Key;
                    break;
                }
            }

            List <string> studentList = studentCheckOuts[name];

            string fileName = name + ".txt";

            string header = writer.StudentHeader(name);

            StreamWriter writing = new StreamWriter(fileName);

            using (writing)
            {
                writing.WriteLine(header);
                writing.WriteLine();
                writing.WriteLine("Checked Out Resources: ");

                for (int i = 0; i < studentList.Count; i++)
                {
                    writing.WriteLine(studentList[i]);
                }
            }

            for (int i = 0; i < studentList.Count; i++) //updates the resources dictionary
            {
                if (resources.ContainsKey(studentList[i]))
                {
                    resources[studentList[i]] = false; //false because its no longer available
                }
            }
        }
Exemplo n.º 3
0
        public void CheckOutResource(Dictionary<string, List<string>> studentCheckOuts, string name)
        {
            //writes the student's file when checking out and updates the resources dictionary bools
            FileWriter writer = new FileWriter(data);

            Dictionary <string, bool> resources = data.Resources;

            foreach (KeyValuePair<string, List<string>> pair in studentCheckOuts)
            {
                if (pair.Key.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    name = pair.Key;
                    break;
                }
            }

            List<string> studentList = studentCheckOuts[name];

            string fileName = name + ".txt";

            string header = writer.StudentHeader(name);

            StreamWriter writing = new StreamWriter(fileName);
            using (writing)
            {
                writing.WriteLine(header);
                writing.WriteLine();
                writing.WriteLine("Checked Out Resources: ");

                for (int i = 0; i < studentList.Count; i++)
                {
                    writing.WriteLine(studentList[i]);
                }
            }

            for (int i = 0; i < studentList.Count; i++) //updates the resources dictionary
            {
                if (resources.ContainsKey(studentList[i]))
                {
                    resources[studentList[i]] = false; //false because its no longer available
                }
            }
        }
Exemplo n.º 4
0
        //makes a new file for a new student in admin menu
        public void WriteNewStudentFile(string name)
        {
            StringBuilder makeName = new StringBuilder();
            makeName.Append(name);
            makeName.Append(".txt");

            string filename = makeName.ToString();

            FileWriter writing = new FileWriter(data);

            StreamWriter writer = new StreamWriter(filename);
            using (writer)
            {
                writer.WriteLine(writing.StudentHeader(name));
            }
        }
Exemplo n.º 5
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;
                }
            }
        }