Пример #1
0
        public static void UpdateMenu(int bookId)
        {
            OutputHandling.Message("1 - Update Title");
            OutputHandling.Message("2 - Update Publisher");
            OutputHandling.Message("3 - Update Year");
            OutputHandling.Message("4 - Update Price");
            OutputHandling.Message("5 - Back To Main Menu");
            ConsoleKeyInfo cki = Console.ReadKey(true);

            BooksCrud.UpdateBook(bookId, cki);
        }
Пример #2
0
        public static void MainMenu()
        {
            Console.WriteLine();
            OutputHandling.Message("1 - Add a book");
            OutputHandling.Message("2 - Print book info");
            OutputHandling.Message("3 - Update book info");
            OutputHandling.Message("4 - Delete book from database");
            OutputHandling.Message("5 - Exit");

            ConsoleKeyInfo cki = Console.ReadKey(true);

            if (cki.Key.Equals(ConsoleKey.D1) || cki.Key.Equals(ConsoleKey.NumPad1))
            {
                Console.Clear();
                string title = InputHandling.ReadString("Book Title: ");
                int    pId   = InputHandling.ReadValue("PublisherId: ");
                int    year  = InputHandling.ReadValue("Year: ");
                int    price = InputHandling.ReadValue("Price: ");
                BooksCrud.InsertBook(title, pId, year, price);
                MainMenu();
            }

            else if (cki.Key.Equals(ConsoleKey.D2) || cki.Key.Equals(ConsoleKey.NumPad2))
            {
                Console.Clear();
                int          bId    = InputHandling.ReadValue("Book Id:");
                SqlParameter bookId = new SqlParameter {
                    Value = bId, SqlDbType = SqlDbType.Int, ParameterName = "bookId"
                };
                EnumerableRowCollection <DataRow> bookInfo = BooksCrud.ReadBook(bookId);

                foreach (DataRow row in bookInfo)
                {
                    Console.WriteLine($"Id: {row[0]}");
                    Console.WriteLine($"Title: {row[1]}");
                    Console.WriteLine($"Publisher: {row[2]}");
                    Console.WriteLine($"Year: {row[3]}");
                    Console.WriteLine($"Price: {row[4]}");
                }
                MainMenu();
            }

            else if (cki.Key.Equals(ConsoleKey.D3) || cki.Key.Equals(ConsoleKey.NumPad3))
            {
                Console.Clear();
                int bId = InputHandling.ReadValue("Book Id:");
                UpdateMenu(bId);
                MainMenu();
            }

            else if (cki.Key.Equals(ConsoleKey.D4) || cki.Key.Equals(ConsoleKey.NumPad4))
            {
                int          bId    = InputHandling.ReadValue("Book Id:");
                SqlParameter bookId = new SqlParameter {
                    Value = bId, SqlDbType = SqlDbType.Int, ParameterName = "bookId"
                };
                BooksCrud.DeleteBook(bookId);
                MainMenu();
            }

            else if (cki.Key.Equals(ConsoleKey.D5) || cki.Key.Equals(ConsoleKey.NumPad5))
            {
                ProgramFlowHandling.Exit("Program will now exit...");
                dbBooksConn.Dispose();
            }
            else
            {
                MainMenu();
            }
        }