Esempio n. 1
0
        static void action(ref Library myLibrary)
        {
            while (myLibrary.Books.Count * myLibrary.Clients.Count != 0)
            {
                Console.WriteLine("\nIf you want to boroow a book - Insert 1 or \"b\".");
                Console.WriteLine("If you want to return a book - Insert 2 or \"r\".");
                Console.WriteLine("If you want to get information of the library - Insert 3 or \"i\".");
                Console.WriteLine("If you have finished - Insert 0 or \"f\".");
                char selector = (Console.ReadLine() + "0").TrimStart().ToLower()[0];
                bool taking;
                if (selector == '1' || selector == 'b')
                    taking = true;
                else if (selector == '2' || selector == 'r')
                    taking = false;
                else if (selector == '3' || selector == 'i')
                {
                    main.printLibrary(myLibrary);
                    continue;
                }
                else
                    break;
                Console.Write("Insert client-ID: ");
                int client = MyFunctions.StringToInt(Console.ReadLine());
                client = myLibrary.indexByClientID(client);
                if (client < 0)
                {
                    Console.WriteLine("This client does not exists in the library");
                    continue;
                }
                Console.Write("Insert book-ID: ");
                int book = MyFunctions.StringToInt(Console.ReadLine());
                book = myLibrary.indexByBookID(book);
                string message, number;
                uint expiration;
                if (book < 0)
                {
                    Console.WriteLine("This book does not exists in the library");
                    continue;
                }
                if (taking)
                {
                    if (myLibrary.Books[book] is EnrichmentBook)
                    {
                        Console.WriteLine("You want to borrow an enrichment-book. Therefore you have to put a deposit {0} NIS.",
                            EnrichmentBook.Deposit);
                        Console.WriteLine("If you want to do it with a credit-card or with a check - insert its number.");
                        Console.WriteLine("If you want to cancel the borowwing - insert \"-1\".");
                        number = Console.ReadLine();
                        if (string.IsNullOrWhiteSpace(number) || number[0] == '-')
                            continue;
                        number = number.Trim();
                        if (MyFunctions.StringToInt(number) <= 0)
                        {
                            Console.WriteLine("Invalid number. You can't borrow this book without a deposit!");
                            continue;
                        }

                        Console.WriteLine("If this is a credit-card number - insert the year of expiration");
                        Console.WriteLine("If this is a check number - insert 0.");
                        expiration = (uint)MyFunctions.StringToInt(Console.ReadLine());
                        if (expiration > 0)
                        {
                            Console.Write("insert the month of expiration (only numbers): ");
                            expiration = expiration * 12 + (uint)MyFunctions.StringToInt(Console.ReadLine());
                        }
                    }
                    else
                    {
                        number = "";
                        expiration = 0;
                    }
                    myLibrary.borrow(out message, client, book, number, expiration);
                }
                else
                {
                    myLibrary.returnBook(out message, client, book);
                }
                Console.WriteLine(message);
            }
            if (myLibrary.Clients.Count == 0)
                Console.WriteLine("The library has no clients...");
            if (myLibrary.Books.Count == 0)
                Console.WriteLine("The library has no books...");
        }