private static void UpdateTitle(SqlParameter bookId) { string newBkTitle = InputHandling.ReadString("New book Title: "); SqlParameter newBookTitle = new SqlParameter { Value = newBkTitle, SqlDbType = SqlDbType.VarChar, ParameterName = "newTitle" }; string updateTitleString = "Update BOOK SET Title = @newTitle WHERE BookId = @bookId"; SqlCommand updateTitleCommand = new SqlCommand(updateTitleString, dbBooksConn); updateTitleCommand.Parameters.Add(bookId); updateTitleCommand.Parameters.Add(newBookTitle); try { dbBooksConn.Open(); updateTitleCommand.ExecuteNonQuery(); } catch { OutputHandling.Error("Invalid Book Id"); } finally { dbBooksConn.Close(); } }
static void Main(string[] args) { int pubId = InputHandling.ReadValue("Publisher Id: "); string pubName = InputHandling.ReadString("Publisher Name: "); PublisherCrud.InsertPublisher(pubId, pubName); Console.ReadKey(); }
public static void ReadPublisher() { int pubId = InputHandling.ReadValue("New publisher id: "); string pubName = InputHandling.ReadString("Publisher Name: "); BooksCrud.InsertPublisher(pubId, pubName); //OutputHandling.Question("Do you want to insert another Publisher? Y / N"); //bool isRunning = InputHandling.QuestionOptions(); //if (isRunning) // ReadPublisher(); }
static void Main(string[] args) { string url = InputHandling.ReadString("Url to download from: "); Downloader.Download(url); OutputHandling.Question("Do you want to download another file? Y / N"); if (InputHandling.QuestionOptions()) { Main(args); } }
static void Main(string[] args) { string url = InputHandling.ReadString("Url to download from: "); Downloader.Download(url); }
static void Main(string[] args) { string filePath = InputHandling.ReadString("Path to file to read: "); FileProcessing.ReadFileContents(filePath); }
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(); } }