Example #1
0
 static void Main(string[] args)
 {
     readers = new Readers();
     readers.users.Add(new User(1, "Qwer", "Try", new int[] { 1, 2, 3, 4 }));
     readers.users.Add(new User(2, "Asd", "Rfv"));
     readers.users.Add(new User(3, "Ivan", "Ivanov"));
     readers.users.Add(new User(4, "Admin", "Dcsaa", true));
     catalog = new Catalog(readers);
     catalog.books.Add(new Book(1, 123, "FFF", "are", new string[] { "Qw", "RT", "KJ" }));
     catalog.books.Add(new Book(2, 897, "AAA", "Asdg", new string[] { "GH", "RT", "SX" }));
     catalog.books.Add(new Book(3, 444, "XGGX", "Xsdq", new string[] { "PO", "ZX", "GB" }));
     catalog.books.Add(new Book(4, 897, "XX", "Xqq", new string[] { "PO", "ZX", "GB" }));
     catalog.books.Add(new Book(5, 44, "Xgh", "Some", new string[] { "PO", "ZX", "GB" }));
     catalog.books.Add(new Book(6, 146, "XwX", "thing", new string[] { "PO", "ZX", "GB" }));
     catalog.books.Add(new Book(7, 45, "XeX", "here", new string[] { "PO", "ZxX", "Xd" }));
     catalog.books.Add(new Book(8, 755, "X8X", "are", new string[] { "Pqe", "ZX", "ВdB" }));
     catalog.books.Add(new Book(9, 1540, "XewX", "Yrr", new string[] { "PsaO", "ZfdvX", "GdB" }));
     catalog.books.Add(new Book(10, 47, "XqqX", "rege", new string[] { "PzxcO", "ZsX", "GttB" }));
     catalog.books.Add(new Book(11, 478, "XcX", "tww", new string[] { "PccO", "ZwX", "GuiB" }));
     catalog.books.Add(new Book(12, 453, "XXX", "Yee", new string[] { "PsaO", "ZaX", "GiuB" }));
     catalog.Inventarisation();
     AddInformation += catalog.AddBook;
     AllBooks       += catalog.WriteAboutBooks;
     do
     {
         try
         {
             Console.WriteLine("1. Add information about book");
             Console.WriteLine("2. All books in library");
             Console.WriteLine("3. Find book");
             Console.WriteLine("4. List of user`s books");
             Console.WriteLine("5. List of users");
             Console.WriteLine("6. Return book to library");
             Console.WriteLine("7. Create acount");
             Console.WriteLine("0. Exit");
             int k;
             k = Int32.Parse(Console.ReadLine());
             if (k == 0)
             {
                 break;
             }
             else if (k == 1)
             {
                 AddInformation();
                 Console.ReadKey();
                 Console.Clear();
             }
             else if (k == 2)
             {
                 AllBooks();
                 Console.ReadKey();
                 Console.Clear();
             }
             else if (k == 3)
             {
                 int k3;
                 do
                 {
                     Console.WriteLine("1. Find book by Author");
                     Console.WriteLine("2. Find book by Genre");
                     Console.WriteLine("3. Find book by Name");
                     try
                     {
                         k3 = Int32.Parse(Console.ReadLine());
                     }
                     catch
                     {
                         Console.WriteLine("Number must be 1..3");
                         Console.ReadKey();
                         continue;
                     }
                     if (k3 == 1)
                     {
                         Console.WriteLine("Enter author");
                         string author = Console.ReadLine();
                         catalog.FindIsbnByAuthor(author);
                         SelectBook();
                         break;
                     }
                     else if (k3 == 2)
                     {
                         Console.WriteLine("Enter Genre");
                         string tematics = Console.ReadLine();
                         catalog.FindIsbnByTematics(tematics);
                         SelectBook();
                         break;
                     }
                     else if (k3 == 3)
                     {
                         Console.WriteLine("Enter Name");
                         string name = Console.ReadLine();
                         catalog.FindIsbnByName(name);
                         SelectBook();
                         break;
                     }
                 } while (true);
                 Console.WriteLine();
             }
             else if (k == 4)
             {
                 if (readers.Authorisation())
                 {
                     catalog.ShowUserBooks(readers.IdUser);
                 }
                 Console.ReadKey();
                 Console.Clear();
             }
             else if (k == 5)
             {
                 readers.Write();
                 Console.ReadKey();
                 Console.Clear();
             }
             else if (k == 6)
             {
                 if (readers.Authorisation())
                 {
                     catalog.ShowUserBooks(readers.IdUser);
                     Console.WriteLine("Enter ID book which you want to return");
                     int k2 = Int32.Parse(Console.ReadLine());
                     catalog.ReturnBookFromUser(readers.IdUser, k2);
                 }
                 Console.ReadKey();
                 Console.Clear();
             }
             else if (k == 7)
             {
                 Console.WriteLine("Enter name");
                 string name = Console.ReadLine();
                 Console.WriteLine("Enter surname");
                 string surname = Console.ReadLine();
                 Console.WriteLine("Enter type of user(1. Admin  2.User)");
                 int  k2 = Int32.Parse(Console.ReadLine());
                 bool f  = k2 == 1 ? true : false;
                 readers.AddUser(surname, name, f);
                 Console.ReadKey();
                 Console.Clear();
             }
         }
         catch
         {
             Console.WriteLine("Incorrect data");
             Console.ReadKey();
             continue;
         }
     } while (true);
 }