Esempio n. 1
0
        static void addBooks(ref Library myLibrary)
        {
            do
            {
                string name, author;
                bookTypes bookType;
                Console.Write("\nPlease insert a name of a book for the library: ");
                if (string.IsNullOrWhiteSpace(name = Console.ReadLine()))
                    Console.WriteLine("Invalid book name! ");
                else
                {
                    Console.Write("Please insert a name of the book's author: ");
                    author = Console.ReadLine();
                    Console.WriteLine("\nThe books in our library are from this types:");
                    Console.WriteLine(Library.BookTypesTostring);
                    Console.WriteLine("Please insert the book's type number: ");
                    int theint = MyFunctions.StringToInt(Console.ReadLine());
                    bookType = (bookTypes)(theint);

                    if (bookType.ToString().Length <= 1)
                        Console.WriteLine("Invalid book type!");
                    else
                    {
                        ReadingBook.bookCategories category;
                        if (bookType == bookTypes.Reading)
                        {
                            Console.WriteLine("\nThe reading-books in our library are from this categories:");
                            Console.WriteLine(ReadingBook.BookCategoriesToString);
                            Console.WriteLine("Please insert the book's category number: ");
                            category = (ReadingBook.bookCategories)(MyFunctions.StringToInt(Console.ReadLine()));
                        }
                        else
                            category = 0;
                        if (category.ToString().Length <= 1)
                            Console.WriteLine("Invalid book category! ");
                        else
                        {
                            int BookID = myLibrary.addBook(name, author, bookType, category);
                            if (BookID > 0)
                            {
                                Console.WriteLine("Book no. {0} has been inserted successfully.", BookID);
                                Console.Write("How much copies of this book exist in the library (at least one)? ");
                                ((LibraryBook)myLibrary.Books[myLibrary.indexByBookID(BookID)]).Copies =
                                    (uint)MyFunctions.StringToInt(Console.ReadLine());
                            }
                            else
                            {
                                Console.WriteLine(string.Format("Error in insert."));
                            }
                        }
                    }
                }
                Console.Write("Do you want to add another book (yes/no)? ");
            } while ((Console.ReadLine() + 'n').TrimStart().StartsWith("y", true, calendarType));
        }