Beispiel #1
0
        public static void CreateSampleLibrary()
        {
            // book 1
            Author author1 = new Author("JK Rowling", "*****@*****.**");
            Author author2 = new Author("Tolkien", "*****@*****.**");

            Book book1 = new Book("Harry Potter", "SF", 2008, (decimal)30);

            book1.AddAuthor(author1);
            book1.AddAuthor(author2);

            // book 2
            Author author3 = new Author("Teodoreanu", "*****@*****.**");
            Author author4 = new Author("Sadoveanu", "*****@*****.**");

            Book book2 = new Book("Baltagul", "Drama", 1980, (decimal)18.75);

            book2.AddAuthor(author3);
            book2.AddAuthor(author4);

            // book 3
            Book book3 = new Book("The Hobbit", "Mystery", 2011, (decimal)15.50);

            book3.AddAuthor(author2);

            Library library1 = new Library("BCU");

            library1.AddBook(book1);
            library1.AddBook(book2);
            library1.AddBook(book3);

            library1.Print();
        }
Beispiel #2
0
        static void FillLib(Library lib)
        {
            var readers = new[]
            {
                lib.RegReader("r1"),
                lib.RegReader("r2"),
                lib.RegReader("r3"),
            };

            var items = new LibItem[]
            {
                lib.AddBook("bb01", "50 Shades Of Grey", "E. L. James"),
                lib.AddBook("bb02", "Harry Potter And Some Thing", "J. K. Rolling"),
                lib.AddMagazine("m001", "Cosmopolitan", "Jan, 2015"),
                lib.AddMagazine("m002", "Занимательная механика", "Янв, 2015"),
            };

            lib.TakeItem(readers[0], items[0]);
            lib.TakeItem(readers[0], items[2]);

            lib.TakeItem(readers[1], items[0]);
            lib.TakeItem(readers[1], items[1]);
            lib.TakeItem(readers[1], items[2]);
            lib.TakeItem(readers[1], items[3]);
        }
        private void libraryAutocomplete_Click(object sender, EventArgs e)
        {
            Stream      stream      = new MemoryStream(Resources.bookTest);
            var         serializer  = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            List <Book> listOfBooks = (List <Book>)serializer.Deserialize(stream);

            foreach (Book book in listOfBooks)
            {
                Library.AddBook(book.Name, book.Author.Name, book.Genre.Name, book.Year, book.Annotation);
            }
        }
Beispiel #4
0
 public void ReturnBook(Library library, Subscriber sub)
 {
     sub.Books.Remove(this);
     Begin = DateTime.MinValue;
     OverdueBook();
     Sub = null;
     if (IsRarity)
     {
         sub.HasRarityBook = false;
     }
     library.AddBook(this);
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            Author author1 = new Author("Creanga", "*****@*****.**");
            Author author2 = new Author("Pietroi", "*****@*****.**");

            Book book2 = new Book("Ultima noapte", "Drama", (decimal)1.5);

            book2.AddAuthors(author1);
            book2.AddAuthors(author2);


            Book book3 = new Book("La Scaldat", "Action", (decimal)90.00);

            book3.AddAuthors(author1);

            Library library1 = new Library("Biblioteca");

            library1.AddBook(book3);
            library1.AddBook(book2);
            library1.AddBook(book3);

            library1.Print();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var book  = new Book(30, "Drama");
            var book1 = new Book(15, "Action");
            var book2 = new Book(13, "SF");

            var author  = new Author("Bob", "*****@*****.**");
            var author1 = new Author("Jim", "*****@*****.**");
            var author2 = new Author("Jake", "*****@*****.**");

            book.AddAuthor(author);
            book1.AddAuthor(author2);
            book2.AddAuthor(author1);


            Library librarie = new Library("GHEORGHE ASACHI");

            librarie.AddBook(book);
            librarie.AddBook(book1);
            librarie.AddBook(book2);
            librarie.RemoveBook(book1);

            librarie.Print();
        }
Beispiel #7
0
 private void save_Click(object sender, EventArgs e)
 {
     if (ValidateBookData())
     {
         if (Book == null)
         {
             Book currentBook = Library.AddBook(name.Text, author.Text, genres.Text, Convert.ToInt32(year.Value), annotation.Text);
             if (read_now.Checked)
             {
                 Library.getBook(currentBook);
             }
             if (press_like.Checked)
             {
                 Library.pressLike(currentBook);
             }
         }
         else
         {
             if (read_now.Checked)
             {
                 Library.getBook(Book);
             }
             else
             {
                 Library.returnBook(Book);
             }
             if (press_like.Checked)
             {
                 Library.pressLike(Book);
             }
             else
             {
                 Library.removeLike(Book);
             }
         }
         this.Hide();
     }
 }
Beispiel #8
0
        static void Main(string[] args)
        {
            Library library = new Library("Junimea");

            // books
            Book book1 = new Book("The Prisoner of Azkaban", 38, "SF");
            Book book2 = new Book("The Order of the Phoenix", 37, "SF");
            Book book3 = new Book("The Deathly Hallows", 39, "SF");
            Book book4 = new Book("The Dark Half", 33, "Horror");
            Book book5 = new Book("The Darkside of The Moon", 34, "Horror");

            // authors
            Author a1 = new Author("J.K. Rowling", "*****@*****.**"); // valide email
            Author a2 = new Author("Stephen King", "SKing");               // invalide email
            Author a3 = new Author();                                      // no name, no email

            // adding authors to books
            book1.AddAuthor(a1); // J.K. R.
            book2.AddAuthor(a1); // J.K. R.
            book3.AddAuthor(a1); // J.K. R.
            book4.AddAuthor(a2); // S. K.
            book5.AddAuthor(a3);

            // adding and removing books from the library
            library.AddBook(book1);
            library.AddBook(book2);
            library.AddBook(book3);
            library.AddBook(book4);
            library.AddBook(book5); Console.Write("\n");
            library.AddBook(book1);                        // testing an already added book
            library.RemoveBook("The Prisoner of Azkaban"); // testing removing a book that is in the library
            library.RemoveBook("The Half-Blood Prince");   // testing removing a book that it is not in the library

            // Print()
            library.Print();

            // testing the GetPrice() method
            Console.WriteLine($"The book: {book3.Name} costs {book3.GetPrice()} $.");
            Console.WriteLine($"The book: {book4.Name} costs {book4.GetPrice()} $.");

            Console.ReadKey();
        }
Beispiel #9
0
        public static void Main()
        {
            Library library = new Library();

            Subscriber sub1 = new Subscriber("First", "8999999999");
            Subscriber sub2 = new Subscriber("Second", "8999954945");

            Book book1 = new Book("1", "11", true);
            Book book2 = new Book("2", "22", false);
            Book book3 = new Book("3", "33", false);
            Book book4 = new Book("4", "44", false);
            Book book5 = new Book("5", "55", false);
            Book book6 = new Book("6", "66", false);
            Book book7 = new Book("7", "77", false);
            Book book8 = new Book("8", "88", true);
            Book book9 = new Book("9", "99", false);

            EventHandler <string> changeStateHandler = (sender, str) => Console.WriteLine(str);
            EventHandler <Book>   addBookHandler     = (sender, book) =>
            {
                Console.WriteLine($"Book Add by {sender}");
                Console.WriteLine("{0} - {1} ({2})", book.Author, book.Name, book.IsRarity ? "Rarity" : "Not rarity");
            };
            EventHandler <Subscriber> addSubHandler = (sender, sub) =>
            {
                Console.WriteLine($"Book Add by {sender}");
                Console.WriteLine("Name: {0}\nPhone: {1}", sub.Name, sub.Phone);
            };

            library.ChangeStateHandler += changeStateHandler;
            library.AddBookHandler     += addBookHandler;
            library.AddSubHandler      += addSubHandler;


            library.AddBook(book1);
            library.AddBook(book2);
            library.AddBook(book3);
            library.AddBook(book4);
            library.AddBook(book5);
            library.AddBook(book6);
            library.AddBook(book7);
            library.AddBook(book8);
            library.AddBook(book9);

            sub1.TakeBook(library, book1);
            sub1.TakeBook(library, book2);
            sub1.TakeBook(library, book3);
            sub1.TakeBook(library, book4);
            sub1.TakeBook(library, book5);

            sub1.TakeBook(library, book6);
            sub2.TakeBook(library, book1);

            sub2.TakeBook(library, book6);
            sub2.TakeBook(library, book7);
            sub2.TakeBook(library, book8);
            sub2.TakeBook(library, book9);

            Console.WriteLine(sub1.HasRarityBook);
            library.ReturnBook(sub1, book1);
            Console.WriteLine(sub1.HasRarityBook);
            Console.WriteLine(sub1.ListBooks().Count);
            Console.WriteLine(library.ListBooks().Count);
            book2.WhereAreBook();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("************************");
            Console.WriteLine("Welcome to my Library");
            Console.WriteLine("***************************");
            while (true)
            {
                Console.WriteLine("Please choose an option below:");
                Console.WriteLine("0. Exit");
                Console.WriteLine("1. Create an account");
                Console.WriteLine("2. Issue a book");
                Console.WriteLine("3. Deposit a book");
                Console.WriteLine("4. Print all issued books");
                Console.WriteLine("5. Print all transactions");
                Console.WriteLine("6. Print all books in library");
                Console.WriteLine("7. Add a book to library");

                var choice = Console.ReadLine();
                switch (choice)
                {
                case "0":
                    return;

                case "1":
                    Console.Write("Email Address: ");
                    var emailAddress = Console.ReadLine();
                    var account      = Library.CreateAccount(emailAddress);
                    Console.WriteLine($"AN: {account.AccountNumber}, Number of issued books:{account.NumberOfIssuedBooks}, created dated : {account.CreatedDate}");
                    break;

                case "2":
                    try
                    {
                        Console.Write("Account Number: ");
                        var aNumber = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Book Number: ");
                        var bookNumber = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Number of Books:");
                        var quantity = Convert.ToInt32(Console.ReadLine());
                        Library.Issue(aNumber, bookNumber, quantity);
                        Console.WriteLine("Book issued successfully !");
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Either the account number or book number or number of books is invalid");
                    }
                    catch (OverflowException)
                    {
                        Console.WriteLine("Either the account number or book number or number of books is beyond the range");
                    }
                    catch (ArgumentOutOfRangeException ax)
                    {
                        Console.WriteLine(ax.Message);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Oops! Try again!");
                    }
                    break;

                case "3":
                    try
                    {
                        Console.Write("Account Number: ");
                        var aNumber = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Book Number: ");
                        var bookNumber = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Number of Books:");
                        var quantity = Convert.ToInt32(Console.ReadLine());
                        Library.Deposit(aNumber, bookNumber, quantity);
                        Console.WriteLine("Book deposited successfully !");
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("Either the account number or book number or number of books is invalid");
                    }
                    catch (OverflowException)
                    {
                        Console.WriteLine("Either the account number or book number or number of books is beyond the range");
                    }
                    catch (ArgumentOutOfRangeException ax)
                    {
                        Console.WriteLine(ax.Message);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Oops! Try again!");
                    }


                    break;

                case "4":
                    break;

                case "5":
                    Console.WriteLine("Account Number:");
                    var accountNumber = Convert.ToInt32(Console.ReadLine());
                    var transactions  = Library.GetAllTransactions(accountNumber);
                    foreach (var tran in transactions)
                    {
                        Console.WriteLine($"Id : {tran.TransactionId}, Date: {tran.TransactionDate}, Type: {tran.TypeOfTransaction}, Account Number :{tran.AccountNumber}, Book Number: {tran.BookNumber}");
                    }

                    break;

                case "6":
                    var books = Library.GetAllBooks();
                    foreach (var item in books)
                    {
                        Console.WriteLine($"Book Number:{item.BookNumber}, Title:{item.Title}, Quantity:{item.Quantity}, Book Added Date:{item.BookAddedOn}");
                    }
                    break;

                case "7":
                    Console.Write("Book title: ");
                    var bookTitle = Console.ReadLine();
                    Console.Write("Number of Books: ");
                    var bookQuantity = Convert.ToInt32((Console.ReadLine()));
                    var book         = Library.AddBook(bookTitle, bookQuantity);
                    Console.WriteLine($"BN: {book.BookNumber}, BT:{book.Title}, Quantity : {book.Quantity}");
                    break;
                }
            }
        }