private static void UpdatePublisher(SqlParameter bookId) { int newPbId = InputHandling.ReadValue("New Publisher Id: "); SqlParameter newPublisherId = new SqlParameter { Value = newPbId, SqlDbType = SqlDbType.Int, ParameterName = "newPublisherId" }; string updatePublisherIdString = "Update BOOK SET PublisherId = @newPublisherId WHERE BookId = @bookId"; SqlCommand updatePublisherCommand = new SqlCommand(updatePublisherIdString, dbBooksConn); updatePublisherCommand.Parameters.Add(bookId); updatePublisherCommand.Parameters.Add(newPublisherId); try { dbBooksConn.Open(); updatePublisherCommand.ExecuteNonQuery(); OutputHandling.Message($"Book price field for book id {bookId} Updated Successfully", ConsoleColor.Green); } catch { OutputHandling.Error("Invalid Book Id"); } finally { dbBooksConn.Close(); } }
static void RunProgram(ref bool programRunning) { int x = InputHandling.ReadValue("Number to calculate the sum: "); OutputHandling.Message("The sum of the digits of " + x + " is: " + SumOfDigits.Sum(x)); OutputHandling.Question("Do you want to calculate the sum of the digits of another number? Y / N"); programRunning = InputHandling.QuestionOptions(); }
static void RunProgram(ref bool programRunning) { int n = InputHandling.ReadValue("Number to print from fibonacci sequence, starting at 1: "); Console.WriteLine(Fibonacci.FindFiboInSequence(n)); OutputHandling.Question("Do you want to find another number in a fibonacci sequence? Y / N"); programRunning = InputHandling.QuestionOptions(); }
static void Main(string[] args) { int pubId = InputHandling.ReadValue("Publisher Id: "); string pubName = InputHandling.ReadString("Publisher Name: "); PublisherCrud.InsertPublisher(pubId, pubName); Console.ReadKey(); }
private static void PrintTotalBookCostOfPublisher() { Console.Clear(); int pId = InputHandling.ReadValue("Publisher ID: "); OutputHandling.Message(CRUDPublisher.TotalBookCostOfPublisher(pId)); MainMenu(); }
static void RunProgram(ref bool programRunning) { int x = InputHandling.ReadValue("Type in a value to calculate it's factorial: "); Console.WriteLine("How do you want to calculate the factorial? R - Recursion, I - Iteration"); Factorial.CalculateFactorial(x); OutputHandling.Question("Do you want to determine the factorial of another number? Y / N"); programRunning = InputHandling.QuestionOptions(); }
static void RunProgram(ref bool programRunning) { int n = InputHandling.ReadValue("Number to display set bits: "); int[] nToBase2 = BaseConversion.ConvertBase10ToBaseX(n, 2); OutputHandling.Message("The number of bits that are set for " + n + " is " + SetBits.CountSetBits(n)); OutputHandling.PrintArray(nToBase2, nToBase2.Length, "Representation of " + n + " in base 2 is: ", "", "0b", false); OutputHandling.Question("Do you want to calculate the number of set bits of a nother number? Y / N"); programRunning = InputHandling.QuestionOptions(); }
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 RunProgram(ref bool programRunning) { int linkedListLength = InputHandling.ReadValue("Sorted Linked List Length: "); LinkedList <int> linkedList = new LinkedList <int>(); int index = 0; InputHandling.ReadCollectionElements(ref linkedList, linkedListLength, ref index); LinkedListDuplicates.RemoveLinkedListDuplicates(ref linkedList); LinkedListDuplicates.DisplayLinkedList(linkedList); OutputHandling.Question("Do you want to remove duplicates from another sorted Linked List? Y / N"); programRunning = InputHandling.QuestionOptions(); }
static void RunProgram(ref bool programRunning) { int arrLength = InputHandling.ReadCollectionLength(); int sum = InputHandling.ReadValue("Input sum: "); int[] array = new int[arrLength]; int index = 0; InputHandling.ReadCollectionElements(ref array, arrLength, ref index); PairsEqualToSum.PrintElements(array, arrLength, sum); OutputHandling.Question("Do you want to check other array if the sum of elements is equal to given elements in an array? Y / N"); programRunning = InputHandling.QuestionOptions(); }
public static void GetPublisherIdId() { int publisherId = InputHandling.ReadValue("Publisher Id to delete: "); BooksCrud.DeletePublisher(publisherId); OutputHandling.Question("Do you want to delete another publisher? Y / N"); if (InputHandling.QuestionOptions()) { GetPublisherIdId(); } else { ProgramFlowHandling.Exit("Thank you... bye!"); dbBooksConn.Dispose(); } }
static void RunProgram(ref bool programRunning) { int year = InputHandling.ReadValue("Year to check if it is leap or not: "); if (Leap.IsLeap(year)) { OutputHandling.Message(year + " is a leap year", ConsoleColor.Green); } else { OutputHandling.Message(year + " is not a leap year", ConsoleColor.Red); } OutputHandling.Question("Do you want to check another year if it is leap? Y / N"); programRunning = InputHandling.QuestionOptions(); }
static void RunProgram(ref bool programRunning) { int n = InputHandling.ReadValue("Number to check if it is a palindrome or not: "); bool isPalindrome = Palindrome.IsPalindrome(n); if (isPalindrome) { OutputHandling.Message(n + " is a palindrome!", ConsoleColor.Green); } else { OutputHandling.Message(n + " is not a palindrome!", ConsoleColor.Red); } OutputHandling.Question("Do you want to check if another number is a palindrome? Y / N"); programRunning = InputHandling.QuestionOptions(); }
static void RunProgram(ref bool programRunning) { int n = InputHandling.ReadValue("Number to check if it is ARMSTRONG or NOT: "); bool armstrong = Armstrong.IsArmstrong(n); if (armstrong) { OutputHandling.Message(n + " is an armstrong number", ConsoleColor.Green); } else { OutputHandling.Message(n + " is not an armstrong number", ConsoleColor.Magenta); } OutputHandling.Question("Do you want to check another number if it is an Armstrong number? Y / N"); programRunning = InputHandling.QuestionOptions(); }
public static void TotalBookCostOfPublisher() { string selectString = "SELECT SUM(Book.Price) FROM Book " + "WHERE PublisherId = @publisherId"; int pId = InputHandling.ReadValue("Publisher Id: "); SqlParameter publisherId = new SqlParameter { Value = pId, ParameterName = "publisherId", SqlDbType = SqlDbType.Int }; sqlConnection.Open(); SqlCommand totalBookCostOfPublisherCommand = new SqlCommand(selectString, sqlConnection); totalBookCostOfPublisherCommand.Parameters.Add(publisherId); var numberOfBooks = totalBookCostOfPublisherCommand.ExecuteScalar(); sqlConnection.Close(); Console.WriteLine($"Total cost of books for publisher with id {pId} is {numberOfBooks}"); }
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(); } }