コード例 #1
0
        public void ReturnItem()
        {
            StudentDictionary();
            Console.Write("\tEnter Student Name: ");
            string inputName = Console.ReadLine();

            while (true)
            {
                if (this.students.hasName(inputName))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("\tError: Request Unavailable. Please try again!");
                    Console.Write("\t");
                    inputName = Console.ReadLine();
                }
            }
            Students.Student currentStudent = this.students.findByName(inputName);

            ResourceDictionary();
            Console.Write("\tEnter Title of Resource to Return: ");
            string inputTitle = Console.ReadLine();

            while (true)
            {
                if (this.resources.hasTitle(inputTitle))
                {
                    if (!this.resources.findByTitle(inputTitle).isAvailable() && this.resources.findByTitle(inputTitle).isCheckedOutBy(currentStudent.id))
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("\tError: Request Unavailable. Please try again!");
                        Console.Write("\t");
                        inputTitle = Console.ReadLine();
                    }
                }
                else
                {
                    Console.WriteLine("\tError: Request Unavailable. Please try again!");
                    Console.Write("\t");
                    inputTitle = Console.ReadLine();
                }
            }


            Resources.Resource resource = this.resources.findByTitle(inputTitle);


            if (this.resources.zeroCheckedOut(currentStudent.id))
            {
                Console.WriteLine("\n\t\t\tNo resources are checked out to this student.");
            }
            else if (resource.isCheckedOutBy(currentStudent.id))
            {
                resource.checkin();

                string line = null;
                using (StreamReader reader = new StreamReader(this.resourceFile))
                {
                    using (StreamWriter writer = new StreamWriter(this.resourceFile + "sdf.txt"))
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (String.Compare(line, resource.Title) == 0)
                            {
                                continue;
                            }

                            writer.WriteLine(line);
                        }
                    }
                }
                File.Delete(this.resourceFile);
                File.Move(this.resourceFile + "sdf.txt", this.resourceFile);

                using (StreamReader reader = new StreamReader(Regex.Replace(currentStudent.Name, @"\s+", "") + ".txt"))
                {
                    using (StreamWriter writer = new StreamWriter(Regex.Replace(currentStudent.Name, @"\s+", "") + "slek.txt"))
                    {
                        while ((line = reader.ReadLine()) != null)
                        {
                            if (String.Compare(line, resource.Title) == 0)
                            {
                                continue;
                            }

                            writer.WriteLine(line);
                        }
                    }
                }
                File.Delete(Regex.Replace(currentStudent.Name, @"\s+", "") + ".txt");
                File.Move(Regex.Replace(currentStudent.Name, @"\s+", "") + "slek.txt", Regex.Replace(currentStudent.Name, @"\s+", "") + ".txt");

                Console.WriteLine("\n\t\t" + inputName + " returned " + resource.Title + ".");
            }
        }
コード例 #2
0
        public void CheckoutItem()
        {
            StudentDictionary();
            Console.Write("\tEnter Student Name: ");
            string inputName = Console.ReadLine();

            while (true)
            {
                if (this.students.hasName(inputName))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("\tError: Request Unavailable. Please try again!");
                    Console.Write("\t");
                    inputName = Console.ReadLine();
                }
            }

            ResourceDictionary();
            Console.Write("\tEnter Title of Resource: ");
            string inputTitle = Console.ReadLine();

            while (true)
            {
                if (this.resources.hasTitle(inputTitle) && this.resources.findByTitle(inputTitle).isAvailable())
                {
                    break;
                }
                else
                {
                    Console.WriteLine("\tError: Request Unavailable. Please try again!");
                    Console.Write("\t");
                    inputTitle = Console.ReadLine();
                }
            }

            Students.Student   currentStudent = this.students.findByName(inputName);
            Resources.Resource resource       = this.resources.findByTitle(inputTitle);



            if (this.resources.hasLessThanThree(currentStudent.id))
            {
                resource.checkout(currentStudent.id);
                StreamWriter writer = new StreamWriter(this.resourceFile, true);
                writer.WriteLine(resource.Title);
                writer.Close();

                StreamWriter writerStudent = new StreamWriter(Regex.Replace(currentStudent.Name, @"\s+", "") + ".txt", true);
                writerStudent.WriteLine(resource.Title);
                writerStudent.Close();

                Console.WriteLine("\n\t\t" + inputName + " checked out " + resource.Title + ".");
            }
            else
            {
                Console.WriteLine("\t" + inputName + " has checked out the max number of resources.");
            }
        }