예제 #1
0
 public bool ReturnBook(List <Book> booksToReturn)
 {
     if (booksToReturn.Count > 0)
     {
         foreach (Book book in booksToReturn)
         {
             myLibrary.AddBook(book);
             bookList.Remove(book);
             Console.WriteLine("Книга " + book.Author + " "
                               + book.Name + " возвращена в библиотеку.");
         }
         return(true);
     }
     return(false);
 }
예제 #2
0
        static void Main(string[] args)
        {
            Library libraryPlovdiv = new Library("People's Library of Plovdiv \"Ivan Vazov\"");

            libraryPlovdiv.AddBook("Pod Igoto", "Ivan Vazov", "Koala Press", 1893, "3782123456803");
            libraryPlovdiv.AddBook("Indzhe", "Yordan Yovkov", "Koala Press", 1927, "3785183426813");
            libraryPlovdiv.AddBook("Rich Man, Poor Man", "Irwin Shaw", "Koala Press", 1969, "3785183426813");
            libraryPlovdiv.AddBook("Po Zhitsata", "Elin Pelin", "Koala Press", 1904, "37841834126813");
            libraryPlovdiv.AddBook("The Shining", "Stephen King", "Koala Press", 1977, "3785183426813");
            libraryPlovdiv.AddBook("The Stand", "Stephen King", "Koala Press", 1978, "3782183416813");
            libraryPlovdiv.AddBook("Misery", "Stephen King", "Koala Press", 1987, "3785883422813");

            Console.WriteLine("Print the whole library: ");
            Console.WriteLine("--------------------------");
            libraryPlovdiv.PrintAllBooksInfo();

            Console.WriteLine("------------------------");
            Console.WriteLine("pt. 2");
            Console.WriteLine("Print all books by Stephen King");
            Console.WriteLine();

            libraryPlovdiv.SearchBookByAuthor("Stephen King");

            Console.WriteLine();
            Console.WriteLine("------------------------");
            Console.WriteLine("Delete books by Stephen King");
            Console.WriteLine();

            libraryPlovdiv.DeleteBook("Stephen King");

            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Delete books by Stephen King: ");
            Console.WriteLine();

            libraryPlovdiv.DeleteBook("", "Stephen King");
            libraryPlovdiv.PrintBooksList();
            Console.WriteLine();

            Console.WriteLine("-----------------------");
            Console.WriteLine("pt. 3 Clear books list");
            Console.WriteLine("------------------------");
            Console.WriteLine();

            libraryPlovdiv.ClearBooksList();
            libraryPlovdiv.PrintBooksList();
        }
예제 #3
0
파일: Form1.cs 프로젝트: admirall32/Library
        private void fillIn() //заполняет библиотеку
        {
            library.AddReader(new Reader("Иванов Н.С.", 0, "Юридический",
                                         new DateTime(2000, 10, 6), "240-00-50", library));
            library.AddReader(new Reader("Петров А.Е.", 1, "Юридический",
                                         new DateTime(2001, 12, 26), "240-00-51", library));
            library.AddReader(new Reader("Сидоров В.П.", 2, "Управление",
                                         new DateTime(1999, 11, 16), "240-00-52", library));

            foreach (Reader reader in library.GetReaders())
            {
                ReadersComboBox.Items.Add(reader.Name);
            }

            library.AddBook(new Book("Почта духов", "Иван Крылов"));
            library.AddBook(new Book("Зритель", "Иван Крылов"));
            library.AddBook(new Book("Меркурий", "Иван Крылов"));
            library.AddBook(new Book("Государство", "Василий Жуковский"));
            library.AddBook(new Book("Азбука", "Лев Толстой"));
            library.AddBook(new Book("Песенник", "Лев Толстой"));
        }
예제 #4
0
        static void Main(string[] args)
        {
            // Create authors and books
            var joyce = new Author {
                Id = 1, Name = "James Joyce", BirthDate = new DateTime(1882, 2, 2, 0, 0, 0)
            };
            var ulysses = new Book
            {
                Id          = 1,
                Title       = "Ulysses",
                PublishDate = new DateTime(1922, 2, 2, 0, 0, 0),
                Author      = joyce,
                Categories  = { Category.Action, Category.Fantasy }
            };

            joyce.Books.Add(ulysses);

            var tolstoi = new Author {
                Id = 2, Name = "Lev Tolstoi", BirthDate = new DateTime(1828, 8, 28, 0, 0, 0)
            };
            var warAndPeace = new Book
            {
                Id          = 2,
                Title       = "War and Peace",
                PublishDate = new DateTime(1931, 2, 3, 0, 0, 0),
                Author      = tolstoi,
                Categories  = { Category.Drama, Category.Romance }
            };
            var annaKarenina = new Book
            {
                Id          = 6,
                Title       = "Anna Karenina",
                PublishDate = new DateTime(1931, 2, 3, 0, 0, 0),
                Author      = tolstoi,
                Categories  = { Category.Drama, Category.Romance }
            };

            tolstoi.Books.Add(warAndPeace);
            tolstoi.Books.Add(annaKarenina);

            var faur = new Author {
                Id = 3, Name = "Daniela Faur", BirthDate = new DateTime(1982, 10, 5, 0, 0, 0)
            };
            var natureForces1 = new Book
            {
                Id          = 3,
                Title       = "Nature Forces - vol 1",
                PublishDate = new DateTime(2015, 2, 15, 0, 0, 0),
                Author      = faur,
                Categories  = { Category.Action, Category.Fantasy, Category.Romance, Category.SF }
            };

            var natureForces2 = new Book
            {
                Id          = 4,
                Title       = "Nature Forces - vol 2",
                PublishDate = new DateTime(2017, 2, 15, 0, 0, 0),
                Author      = faur,
                Categories  = { Category.Action, Category.Fantasy, Category.Romance, Category.SF }
            };

            var natureForces3 = new Book
            {
                Id          = 5,
                Title       = "Nature Forces - vol 3",
                PublishDate = new DateTime(2019, 2, 15, 0, 0, 0),
                Author      = faur,
                Categories  = { Category.Action, Category.Fantasy, Category.Romance, Category.SF }
            };

            faur.Books.Add(natureForces1);
            faur.Books.Add(natureForces2);
            faur.Books.Add(natureForces3);

            // Create library
            var library = new Library();


            // 1. Add books to the collection
            library.AddBooks(new List <Book> {
                ulysses, warAndPeace, natureForces1, natureForces2, natureForces3
            });
            library.AddBook(annaKarenina);


            // 2. Remove a book from the collection
            library.RemoveBook(annaKarenina);


            //3. Retrieve the list of all books
            Console.WriteLine("List of all books:");
            library.GetAllBooks().Display();


            //4. Retrieve the list of all books published after 1980

            Console.WriteLine("List of all books published after 1980:");
            library.ListAllBooksAfterYear(1980).Display();


            //5. Retrieve the list of all books with one of the categories: "drama"

            Console.WriteLine("List of all books in drama category:");
            library.ListAllBooksInCategory(Category.Drama).Display();


            //6. Get the names of all authors that have published at least 3 books

            Console.WriteLine($"All authors that have published at least 3 books: ");
            library.ListAuthorsWithAtLeastAGivenNumberOfBooks(3).Display();


            //7. Get the names of all authors that are born before 1990 and have written at
            //   least 2 books of category "science-fiction"

            Console.WriteLine("All authors born before 1990 and with at least 2 SF books:");
            library.ListAuthorsBornBeforeAndWithANumberofBooksInCategory(1990, 2, Category.SF).Display();


            //8.Write a method that returns an IGrouping of Books grouped by the decade they were published in.

            Console.WriteLine("Books grouped by the decade they were published in:");
            library.ListBooksGroupedByPublishingDecade().DisplayIGrouping();
        }
예제 #5
0
        static void AddBook(Library lib)
        {
            String name, numOfPages, year, nameA, surnameA, yearA, monthA, dayA;

            while (true)
            {
                try
                {
                    Console.WriteLine("Введите название книги :");
                    name = Console.ReadLine();
                    if (name != null && name.Length < 2)
                    {
                        throw new ArgumentException("Неккоректное название!");
                    }
                    else
                    {
                        break;
                    }
                }
                catch (ArgumentException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите количество страниц в книге :");
                    numOfPages = Console.ReadLine();
                    // ReSharper disable once BuiltInTypeReferenceStyle
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Int32.Parse(numOfPages);
                    break;
                }
                catch (FormatException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
                catch (OverflowException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите год издания книги :");
                    year = Console.ReadLine();
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Int32.Parse(year);
                    break;
                }
                catch (FormatException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
                catch (OverflowException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите имя автора книги :");
                    nameA = Console.ReadLine();
                    if (nameA != null && nameA.Length < 2)
                    {
                        throw new ArgumentException("Неккоректное название!");
                    }
                    else
                    {
                        break;
                    }
                }
                catch (ArgumentException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите фамилию автора книги :");
                    surnameA = Console.ReadLine();
                    if (surnameA != null && surnameA.Length < 2)
                    {
                        throw new ArgumentException("Неккоректное название!");
                    }
                    else
                    {
                        break;
                    }
                }
                catch (ArgumentException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите год рождения автора :");
                    yearA = Console.ReadLine();
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Int32.Parse(yearA);
                    break;
                }
                catch (FormatException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
                catch (OverflowException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите месяц рождения автора :");
                    monthA = Console.ReadLine();
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Int32.Parse(monthA);
                    break;
                }
                catch (FormatException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
                catch (OverflowException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            while (true)
            {
                try
                {
                    Console.WriteLine("Введите день рождения автора :");
                    dayA = Console.ReadLine();
                    // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                    // ReSharper disable once AssignNullToNotNullAttribute
                    Int32.Parse(dayA);
                    break;
                }
                catch (FormatException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
                catch (OverflowException s)
                {
                    Console.WriteLine("Error! : " + s.Message);
                }
            }
            DateTime date = new DateTime(Int32.Parse(yearA), Int32.Parse(monthA), Int32.Parse(dayA));

            lib.AddBook(name, Int32.Parse(numOfPages), Int32.Parse(year), nameA, surnameA, date);
        }