static void Main(string[] args) { Console.WriteLine("Cwiczenie 9\n"); BookLibrary lib = new BookLibrary(); lib.AddBook(new Book("Tytul_1", "Autor1", 12.50, "123", new DateTime(2019, 11, 2))); lib.AddBook(new Book("Tytul_2", "Autor2", 22.50, "124", new DateTime(2018, 9, 30))); lib.AddBook(new Book("Tytul_3", "Autor3", 13.99, "125", new DateTime(2017, 6, 23))); lib.AddBook(new Book("Tytul_4", "Autor1", 6.66, "126", new DateTime(2016, 7, 14))); lib.AddBook(new Book("Tytul_5", "Autor2", 77.99, "127", new DateTime(2015, 5, 3))); lib.AddBook(new Book("Tytul_6", "Autor3", 12.80, "128", new DateTime(2014, 12, 17))); lib.AddBook(new Book("Tytul_7", "Autor1", 17.50, "129", new DateTime(2013, 5, 22))); lib.AddBook(new Book("Tytul_8", "Autor2", 2.50, "130", new DateTime(2012, 3, 5))); lib.AddBook(new Book("Tytul_9", "Autor3", 13.13, "131", new DateTime(2011, 1, 24))); lib.print(); Console.WriteLine("------------------------------"); List <Book> BookList = new List <Book>(); BookList = lib.FindByTitle("Tytul_3"); for (int i = 0; i < BookList.Count; i++) { Console.WriteLine(); BookList[i].print(); } BookList = lib.FindByAuthor("Autor2"); for (int i = 0; i < BookList.Count; i++) { Console.WriteLine(); BookList[i].print(); } BookList = lib.FindByPrice(6.66); for (int i = 0; i < BookList.Count; i++) { Console.WriteLine(); BookList[i].print(); } BookList = lib.FindByISBN("130"); for (int i = 0; i < BookList.Count; i++) { Console.WriteLine(); BookList[i].print(); } Console.WriteLine("\n{0}", lib.IsExists(new Book("Tytul_9", "Autor3", 13.13, "131", new DateTime(2011, 1, 24)))); Console.WriteLine("\n-----------------------------\n"); lib.RemoveBook("125"); lib.print(); }
static void Main(string[] args) { MenuForm mn = new MenuForm(); mn.addMenuItem("1. Add a book"); mn.addMenuItem("2. Find a book"); mn.addMenuItem("3. Show book list"); mn.addMenuItem("4. Remove a book"); mn.addMenuItem("5. Exit"); int choice = 0; BookLibrary bookLibrary = new BookLibrary(); do { Console.WriteLine("********** Book Management **********"); choice = mn.GetChoice(0, 5); switch (choice) { case 1: string id = Util.getString("Input ID: ", "ID is invalid"); string name = Util.getString("Input Book Name: ", "Book name is invalid"); string author = Util.getString("Input Author: ", "Author is invalid"); string publisher = Util.getString("Input Publisher: ", "Publisher is invalid"); Book book = new Book(id, name, author, publisher); bookLibrary.AddBook(book); Console.WriteLine("Added new book!"); break; case 2: string searchedID = Util.getString("Input ID to find book: ", "ID is invalid"); Book foundBook = bookLibrary.FindBook(searchedID); if (foundBook != null) { Console.WriteLine(foundBook.ToString()); } else { Console.WriteLine("Book not found!"); } break; case 3: bookLibrary.ShowBookList(); break; case 4: string removedID = Util.getString("Input ID to remove book: ", "ID is invalid"); bool removed = bookLibrary.RemoveBook(removedID); if (removed) { Console.WriteLine("Removed " + removedID + " book successfully"); } else { Console.WriteLine("Removed " + removedID + " book failed"); } break; } } while (choice > 0 && choice < 5); }
static void Main(string[] args) { Author author1 = new Author("Ray", "Bradbury", new DateTime(1920, 8, 22)); Author author2 = new Author("Ben", "Elton", new DateTime(1959, 5, 3)); Author author3 = new Author("John Ronald Reuel", "Tolkien", new DateTime(1892, 1, 3)); collection.Add(author1); collection.Add(author2); collection.Add(author3); Book book1 = new Book(Genre.ScienceFiction, "Dandelion Wine", author1, true); Book book2 = new Book(Genre.Adventure, "Popcorn", author2, false); Book book3 = new Book(Genre.Fantasy, "The Lord of the Rings", author3, true); bookCollection.AddBook(book1); bookCollection.AddBook(book2); bookCollection.AddBook(book3); bookCollection.SetBookAvailable(book2); }
static void Main(string[] args) { BookLibrary bookLibrary = new BookLibrary(); bookLibrary.AddBook(new Book("C# via CLR", "Jeffrey Richter", 2013)); bookLibrary.AddBook(new Book("C# via CLR", "Jeffrey Richter", 2010)); bookLibrary.AddBook(new Book("Test Book", "Фамилия автора", 2007)); bookLibrary.AddBook(new Book("C# 4.0", "Bart De Smet", 2010)); bookLibrary.AddBook(new Book("Book name", "Автор 2", 2007)); Console.WriteLine($"Books count: {bookLibrary.Books.Count}"); bookLibrary.RemoveBook(new Book("Test Book", "Фамилия автора", 2007)); Console.WriteLine($"Books count: {bookLibrary.Books.Count}"); bookLibrary.Save(new BinaryManager("books.txt")); bookLibrary.RemoveBook(new Book("C# via CLR", "Jeffrey Richter", 2010)); Console.WriteLine($"Books count: {bookLibrary.Books.Count}\n"); bookLibrary.Load(new BinaryManager("books.txt")); bookLibrary.AddBook(new Book("Паттерны проектирования на платформе .NET", "Тепляков Сергей", 2015)); foreach (var book in bookLibrary.Books) { Console.WriteLine($"Название: {book.Name}\nАвтор: {book.Author}\nГод: {book.Year}\n------------"); } Console.WriteLine($"\nFound books count: {bookLibrary.FindBooks((x) => { return String.Compare(x.Author, "Jeffrey Richter") == 0; }).Count}\n"); bookLibrary.SortBooks(); foreach (var book in bookLibrary.Books) { Console.WriteLine($"Название: {book.Name}\nАвтор: {book.Author}\nГод: {book.Year}\n------------"); } Console.WriteLine(); bookLibrary.SortBooks(new Logic.SortConditions.SortByAuthor()); foreach (var book in bookLibrary.Books) { Console.WriteLine($"Название: {book.Name}\nАвтор: {book.Author}\nГод: {book.Year}\n------------"); } Console.WriteLine($"Books count: {bookLibrary.Books.Count}"); bookLibrary.Save(new BinarySerializationManager("books.bin")); bookLibrary.RemoveBook(new Book("C# 4.0", "Bart De Smet", 2010)); bookLibrary.Load(new BinarySerializationManager("books.bin")); Console.WriteLine($"Books count: {bookLibrary.Books.Count}"); Console.WriteLine($"Books count: {bookLibrary.Books.Count}"); bookLibrary.Save(new XmlManager("books.xml")); bookLibrary.RemoveBook(new Book("C# 4.0", "Bart De Smet", 2010)); bookLibrary.Load(new XmlManager("books.xml")); Console.WriteLine($"Books count: {bookLibrary.Books.Count}"); Console.ReadKey(); }