private static void UpdateProcedure(string connect) { int id = MyConsole.GetNumber("Enter the Id:"); string name = MyConsole.GetString("Enter the Name: "); string address = MyConsole.GetString("Enter the Address:"); SqlConnection dbConnection = new SqlConnection(connect); SqlCommand command = new SqlCommand("EmpUpdate", dbConnection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@param1", id); command.Parameters.AddWithValue("@param2", name); command.Parameters.AddWithValue("@param3", address); try { //open Connection dbConnection.Open(); command.ExecuteNonQuery(); } catch (SqlException) { Console.WriteLine("Someting went wrong"); } finally { dbConnection.Close(); } }
static void Main(string[] args) { Console.WriteLine("Welcome to the Product Manager!"); Product p1 = new Product(); p1.code = ".net"; p1.description = "Murach's C# and .Net"; p1.price = 58.99; Product p2 = new Product("java", "Murach's Java Programming", 59.50); Console.WriteLine("p1 = " + p1); Console.WriteLine($"p2 = {p2}"); String code = MyConsole.GetString("\nEnter product code: "); String desc = MyConsole.GetString("Enter product description: "); double price = MyConsole.GetDouble("Enter product price: "); Product p3 = new Product(code, desc, price); Console.WriteLine("\np3 = " + p3); LineItem l1 = new LineItem(); l1.product = p1; l1.quantity = 1; l1.total = p1.price; Console.WriteLine("\nl1 = " + l1); Console.WriteLine("\nBye"); }
private static void UpdateRecords(string connect, string updateQuery) { int id = MyConsole.GetNumber("Enter the Id:"); string name = MyConsole.GetString("Enter the Name: "); string address = MyConsole.GetString("Enter the Address:"); SqlConnection dbConnection = new SqlConnection(connect); SqlCommand command = new SqlCommand(updateQuery, dbConnection); command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@Name", name); command.Parameters.AddWithValue("@Address", address); try { //open Connection dbConnection.Open(); command.ExecuteNonQuery(); } catch (SqlException) { Console.WriteLine("Someting went wrong"); } finally { dbConnection.Close(); } }
private static void addTravelDetails() { if (blog.CurrentUser == null) { Console.WriteLine("U have not logged in to Post a Travel Info"); Console.WriteLine("Please login to add new details"); return; } Travel details = new Travel(); details.NoOfDays = MyConsole.GetNumber("Enter the No of days of Travel"); details.ModeOfTransport = MyConsole.GetMode(); details.DateOfTravel = MyConsole.GetDate("Enter the date as dd/MM/yyyy"); details.Destination = MyConsole.GetString("Enter UR place of Visit"); details.UserDetails = blog.CurrentUser; details.Details = MyConsole.GetString("Please enter UR Experience in the Travel to be shared to all our visitors"); try { blog.AddTravelDetails(details); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { Console.WriteLine("Welcome to the Product Manager"); Product p1 = new Product(); p1.code = ".net"; p1.description = "Murach's C# and .Net"; p1.price = 58.99; Console.WriteLine("p1 = " + p1); Product p2 = new Product("java", "Murach's Java Programming", 59.50); Console.WriteLine($"p2 = {p2}"); string code = MyConsole.GetString("Enter product code: "); string desc = MyConsole.GetString("Enter product description: "); double price = MyConsole.getDouble("Enter product price: "); Product p3 = new Product(code, desc, price); Console.WriteLine("Bye"); }
private static void searchFeature() { string destination = MyConsole.GetString("Enter the Destination or a part of the Destination Name"); var data = blog.FindDetails(destination); foreach (var tr in data) { Console.WriteLine(tr.ToString()); } }
private static void registerUser() { int userId = MyConsole.GetNumber("Enter user id: "); string username = MyConsole.GetString("Enter username:"******"Enter password: "); userCredentials.RegisterNewUser(new User { UserID = userId, UserName = username, Password = password }); //throw new NotImplementedException(); }
static void Main(string[] args) { string contents = getMenu(args[0]); bool processing = true; do { string choice = MyConsole.GetString(contents); processing = processMenu(choice); clearScreen(); } while (processing); }
public static List <String> EditItem(List <String> wizardItems) { int enterNumber = MyConsole.GetInt("Number: "); enterNumber--; String editItem = MyConsole.GetString("Updated name: "); wizardItems[enterNumber] = editItem; enterNumber++; Console.WriteLine("Item number " + enterNumber + " was updated"); return(wizardItems); }
public static ArrayList EditItem(ArrayList inventory) { int itemNum = MyConsole.GetInt("Number: ", 1, 4); int selection = itemNum; itemNum--; String updateItem = MyConsole.GetString("Updated name: "); inventory[itemNum] = updateItem; Console.WriteLine("Item number " + selection + " was updated."); return(inventory); }
static void Main(string[] args) { Console.WriteLine("The Wizard Inventory game!"); List <string> wizardItems = new List <string>(); wizardItems.Add("wooden staff"); wizardItems.Add("wizard hat"); wizardItems.Add("cloth shoes"); Console.WriteLine("The Wizard Inventory Game\n"); Console.WriteLine("COMMAND MENU"); Console.WriteLine("show - Show all items\ngrab - Grab an item\nedit - Edit an item"); Console.WriteLine("drop - Drop an item\nexit - Exit program"); string choice; choice = MyConsole.GetString("\nCommand: \n"); while (!choice.Equals("exit")) { if (choice.Equals("show")) { ShowAll(wizardItems); choice = MyConsole.GetString("\nCommand: \n"); } if (choice.Equals("grab")) { GrabItem(wizardItems); choice = MyConsole.GetString("\nCommand: \n"); } else if (choice.Equals("edit")) { EditItem(wizardItems); choice = MyConsole.GetString("\nCommand: \n"); } else if (choice.Equals("drop")) { DropItem(wizardItems); choice = MyConsole.GetString("\nCommand: \n"); } else if (choice.Equals("exit")) { Console.WriteLine("Bye now :)"); } else { Console.WriteLine("Invalid"); choice = MyConsole.GetString("\nCommand: \n"); } } }
public static List <String> GrabItem(List <String> wizardItems) { if (wizardItems.Count >= 4) { Console.WriteLine("You can't carry any more items. Drop something first."); } else { String addedItem = MyConsole.GetString("Name: "); wizardItems.Add(addedItem); Console.WriteLine(addedItem + " was added."); } return(wizardItems); }
private static void loginFeature() { try { string username = MyConsole.GetString("Enter the Username"); string password = MyConsole.GetString("Enter the password"); IUserLog log = new UserLog(); var user = log.Login(username, password); blog.CurrentUser = user; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static Boolean userLogin() { string username = MyConsole.GetString("Enter username:"******"Enter password: "); var user = userCredentials.Login(username, password); blog.CurrentUser = user; if (user != null) { return(true); } else { return(false); } }
private static void signUpFeature() { int userID = MyConsole.GetNumber("Enter the UserID"); string username = MyConsole.GetString("Enter the Username"); string password = MyConsole.GetString("Enter the password"); string retype = MyConsole.GetString("Retype the pasword"); if (password != retype) { Console.WriteLine("Password mismatch"); return; } try { IUserLog log = new UserLog(); log.RegisterNewUser(new User { UserID = userID, UserName = username, Password = password }); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void Main(string[] args) { //MyConsole.WriteLine("Hallå ja"); //MyConsole.SetCursorPosition(2, 4); //MyConsole.WriteLine("Jodå"); int color = 4; //MyConsole.ForegroundColor = (MyConsoleColor)color; StringWriter writer = new StringWriter(); //writer = MyConsole.Out; //MyConsole.SetOut(writer); string input = Console.ReadLine(); Console.WriteLine(TextAnimation(input)); for (int i = 0; i < 20; i++) { MyConsole.WriteLine(input); } color++; //MyConsole.ForegroundColor = (MyConsoleColor)color; int curPos = 0; for (int a = 0; a < 2; a++) { //Move to the Right for (int i = 0; i < 20; i++) { //input = " " + input; curPos++; MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); } color++; //MyConsole.ForegroundColor = (MyConsoleColor)color; //Move to the left for (int i = 0; i < 20; i++) { //input = input.Remove(0, 1); curPos--; MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); } color++; //MyConsole.ForegroundColor = (MyConsoleColor)color; } char[] characters = input.ToCharArray(); int maxPos = (int)Math.Round(3.75 * characters.Length - 1, MidpointRounding.ToZero); int[] pos = new int[characters.Length]; //string temp = string.Empty; /*for (int i = 0; i < characters.Length; i++) * { * //pos[characters.Length - i - 1] = i; * temp += characters[i] + " "; * } * List<int> indexesUsed = new List<int>(); * for (int i = 0; i < characters.Length; i++) * { * int index = 0; * bool found = false; * while (true) * { * int positoin = temp.IndexOf(characters[i], index); * if (!indexesUsed.Contains(positoin)) * { * pos[i] = positoin; * break; * } * else * { * index = positoin + 1; * } * } * }*/ for (int i = 0; i < pos.Length; i++) { pos[i] = i * 3; } // Cha cha to the right for (int i = 0; i < 7.5 * characters.Length; i++) { //input = input.Insert(input.Length - 1, " "); //string send = string.Empty; //for (int a = characters.Length - 1; a > -1; a--) for (int a = 0; a < characters.Length; a++) { ////send.Insert(i - characters.Length + a * 2 < 0 ? 0 : i - characters.Length + a * 2, " "); ////int spaces = i - characters.Length + (a + 1) * 2 < 0 ? 0 : i - characters.Length + (a + 1) * 2; ////send += String.Concat(Enumerable.Repeat(" ", spaces > maxPos ? maxPos : spaces)); ////send += characters[a].ToString(); //int spaces = a + 1 * (i + 1) - (characters.Length + a + 1) * 3; //spaces = spaces < 0 ? 0 : spaces; //int spaces = (a + 1) * i; //int spaces = i + a - (int)Math.Round(Math.Pow(characters.Length, 2)); //if (a+) //int spaces = a+ (startedMoving[a]? i: 0); //int spaces = characters.Length - a - 1 + (i * a); int spaces = pos[a] - characters.Length + i - characters.Length * 2; spaces = spaces < a ? a : spaces; //spaces = spaces >= maxPos ? a + maxPos - 3 : spaces; spaces = spaces + characters.Length - a - 1 >= maxPos ? maxPos - (characters.Length - a) : spaces; //MyConsole.SetCursorPosition(pos[characters.Length - a - 1], MyConsole.CursorTop); //MyConsole.Write(characters[characters.Length - a - 1].ToString()); MyConsole.SetCursorPosition(spaces, MyConsole.CursorTop); MyConsole.Write(characters[a]); } MyConsole.WriteLine(); //MyConsole.WriteLine(send); } color++; //MyConsole.ForegroundColor = (MyConsoleColor)color; //for (int i = 0; i < 30; i++) // Cha cha to the left for (int i = (int)Math.Round(7.5 * characters.Length - 1, MidpointRounding.ToZero); i > -1; i--) { //input = input.Insert(input.Length - 1, " "); //string send = string.Empty; //for (int a = characters.Length - 1; a > -1; a--) for (int a = 0; a < characters.Length; a++) { ////send.Insert(i - characters.Length + a * 2 < 0 ? 0 : i - characters.Length + a * 2, " "); ////int spaces = i - characters.Length + (a + 1) * 2 < 0 ? 0 : i - characters.Length + (a + 1) * 2; ////send += String.Concat(Enumerable.Repeat(" ", spaces > maxPos ? maxPos : spaces)); ////send += characters[a].ToString(); //int spaces = a + 1 * (i + 1) - (characters.Length + a + 1) * 3; //spaces = spaces < 0 ? 0 : spaces; //int spaces = (a + 1) * i; //int spaces = i + a - (int)Math.Round(Math.Pow(characters.Length, 2)); //if (a+) //int spaces = a+ (startedMoving[a]? i: 0); //int spaces = characters.Length - a - 1 + (i * a); int spaces = pos[a] - characters.Length + i - characters.Length * 2; if (spaces < a) { } spaces = spaces < a ? a : spaces; if (spaces >= maxPos) { } //spaces = spaces >= maxPos ? a + maxPos - 3 : spaces; spaces = spaces + characters.Length - a - 1 >= maxPos ? maxPos - (characters.Length - a) : spaces; //MyConsole.SetCursorPosition(pos[characters.Length - a - 1], MyConsole.CursorTop); //MyConsole.Write(characters[characters.Length - a - 1].ToString()); MyConsole.SetCursorPosition(spaces, MyConsole.CursorTop); MyConsole.Write(characters[a]); } MyConsole.WriteLine(); //MyConsole.WriteLine(send); } color++; //MyConsole.ForegroundColor = (MyConsoleColor)color; // Move to the right curPos = 0; for (int i = 0; i < 15; i++) { //input = " " + input; curPos++; MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); } // Wiggle in the middle string[] splitted = SplitTheString(input, 3); int[] positions = new int[3]; for (int i = 0; i < positions.Length; i++) { //positions[i] = curPos + (i == 0 ? 0 : splitted[i].Length - 1); positions[i] = curPos; //if (i > 0) //{ // positions[i] += splitted[i - 1].Length; //} for (int a = 0; a < i; a++) { positions[i] += splitted[a].Length; } } for (int i = 0; i < 10; i++) { for (int a = 0; a < splitted.Length; a++) { if (a == 0) { positions[a]--; } else if (a == 2) { positions[a]++; } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } bool movingLeft = false; int original = positions[1]; for (int i = 0; i < 30; i++) { if (positions[1] > positions[2] - splitted[1].Length - 4) { movingLeft = true; } else if (positions[1] < positions[0] + splitted[0].Length + 4) { movingLeft = false; } positions[1] += movingLeft ? -1 : 1; for (int a = 0; a < splitted.Length; a++) { MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } for (int i = 0; i < 10; i++) { for (int a = 0; a < splitted.Length; a++) { if (a == 0) { positions[a]++; } else if (a == 2) { positions[a]--; } else if (a == 1 && positions[a] != original) { if (original < positions[a]) { positions[a]--; } else { positions[a]++; } } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } // Move to the left MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); for (int i = 0; i < 15; i++) { //input = " " + input; curPos--; MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); } // Offsets! string offsetted = input; int timesToRun = GetNearestMultiple(20, input.Length); int offset = 1 * (rng.Next(0, 2) == 0 ? 1 : -1); for (int i = 0; i < timesToRun; i++) { offsetted = Offset(offsetted, offset); MyConsole.WriteLine(offsetted); } color++; // Move to the right //MyConsole.ForegroundColor = (MyConsoleColor)color; for (int i = 0; i < 15; i++) { //input = " " + input; curPos++; MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); } // Twist around splitted = SplitTheString(input, 2); positions = new int[2]; for (int i = 0; i < positions.Length; i++) { //positions[i] = curPos + (i == 0 ? 0 : splitted[i].Length - 1); positions[i] = curPos; //if (i > 0) //{ // positions[i] += splitted[i - 1].Length; //} for (int a = 0; a < i; a++) { positions[i] += splitted[a].Length; } } movingLeft = true; int[] originalPos = new int[positions.Length]; for (int i = 0; i < originalPos.Length; i++) { originalPos[i] = positions[i]; } for (int i = 0; i < 50; i++) { if (positions[0] < 1) { movingLeft = false; } else if (positions[1] < 1) { movingLeft = true; } for (int a = 0; a < splitted.Length; a++) { if (a == 0) { positions[a] += movingLeft ? -1 : 1; } else if (a == 1) { positions[a] += movingLeft ? 1 : -1; } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } for (int i = 0; i < 30; i++) { for (int a = 0; a < splitted.Length; a++) { if (positions[a] != originalPos[a]) { positions[a] += positions[a] < originalPos[a] ? 1 : -1; } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } color++; //MyConsole.ForegroundColor = (MyConsoleColor)color; // Move to the left for (int i = 0; i < 15; i++) { //input = " " + input; curPos--; MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); } for (int i = 0; i < 15; i++) { MyConsole.WriteLine(input); } string temp = writer.ToString(); Console.WriteLine(MyConsole.GetString()); Console.ReadKey(true); }
private static string TextAnimation(string input) { for (int i = 0; i < 20; i++) { MyConsole.WriteLine(input); } int curPos = 0; for (int a = 0; a < 2; a++) { //Move to the Right Move(ref curPos, 20, input, false); //Move to the left Move(ref curPos, 20, input, true); } char[] characters = input.ToCharArray(); int maxPos = (int)Math.Round(3.75 * characters.Length - 1, MidpointRounding.ToZero); int[] pos = new int[characters.Length]; for (int i = 0; i < pos.Length; i++) { pos[i] = i * 3; } // Cha cha to the right for (int i = 0; i < 7.5 * characters.Length; i++) { for (int a = 0; a < characters.Length; a++) { int spaces = pos[a] - characters.Length + i - characters.Length * 2; spaces = spaces < a ? a : spaces; spaces = spaces + characters.Length - a - 1 >= maxPos ? maxPos - (characters.Length - a) : spaces; MyConsole.SetCursorPosition(spaces, MyConsole.CursorTop); MyConsole.Write(characters[a]); } MyConsole.WriteLine(); } // Cha cha to the left for (int i = (int)Math.Round(7.5 * characters.Length - 1, MidpointRounding.ToZero); i > -1; i--) { for (int a = 0; a < characters.Length; a++) { int spaces = pos[a] - characters.Length + i - characters.Length * 2; if (spaces < a) { } spaces = spaces < a ? a : spaces; if (spaces >= maxPos) { } spaces = spaces + characters.Length - a - 1 >= maxPos ? maxPos - (characters.Length - a) : spaces; MyConsole.SetCursorPosition(spaces, MyConsole.CursorTop); MyConsole.Write(characters[a]); } MyConsole.WriteLine(); } // Move to the right curPos = 0; Move(ref curPos, 15, input, false); // Wiggle in the middle string[] splitted = SplitTheString(input, 3); int[] positions = new int[3]; for (int i = 0; i < positions.Length; i++) { positions[i] = curPos; for (int a = 0; a < i; a++) { positions[i] += splitted[a].Length; } } for (int i = 0; i < 10; i++) { for (int a = 0; a < splitted.Length; a++) { if (a == 0) { positions[a]--; } else if (a == 2) { positions[a]++; } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } bool movingLeft = false; int original = positions[1]; for (int i = 0; i < 30; i++) { if (positions[1] > positions[2] - splitted[1].Length - 4) { movingLeft = true; } else if (positions[1] < positions[0] + splitted[0].Length + 4) { movingLeft = false; } positions[1] += movingLeft ? -1 : 1; for (int a = 0; a < splitted.Length; a++) { MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } for (int i = 0; i < 10; i++) { for (int a = 0; a < splitted.Length; a++) { if (a == 0) { positions[a]++; } else if (a == 2) { positions[a]--; } else if (a == 1 && positions[a] != original) { if (original < positions[a]) { positions[a]--; } else { positions[a]++; } } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } // Move to the left MyConsole.SetCursorPosition(curPos, MyConsole.CursorTop); MyConsole.WriteLine(input); Move(ref curPos, 15, input, true); // Offsets! string offsetted = input; int timesToRun = GetNearestMultiple(20, input.Length); int offset = 1 * (rng.Next(0, 2) == 0 ? 1 : -1); for (int i = 0; i < timesToRun; i++) { offsetted = Offset(offsetted, offset); MyConsole.WriteLine(offsetted); } // Move to the right Move(ref curPos, 15, input, false); // Twist around splitted = SplitTheString(input, 2); positions = new int[2]; for (int i = 0; i < positions.Length; i++) { positions[i] = curPos; for (int a = 0; a < i; a++) { positions[i] += splitted[a].Length; } } movingLeft = true; int[] originalPos = new int[positions.Length]; for (int i = 0; i < originalPos.Length; i++) { originalPos[i] = positions[i]; } for (int i = 0; i < 50; i++) { if (positions[0] < 1) { movingLeft = false; } else if (positions[1] < 1) { movingLeft = true; } for (int a = 0; a < splitted.Length; a++) { if (a == 0) { positions[a] += movingLeft ? -1 : 1; } else if (a == 1) { positions[a] += movingLeft ? 1 : -1; } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } for (int i = 0; i < 30; i++) { for (int a = 0; a < splitted.Length; a++) { if (positions[a] != originalPos[a]) { positions[a] += positions[a] < originalPos[a] ? 1 : -1; } MyConsole.SetCursorPosition(positions[a], MyConsole.CursorTop); MyConsole.Write(splitted[a]); } MyConsole.WriteLine(); } // Move to the left Move(ref curPos, 15, input, true); for (int i = 0; i < 15; i++) { MyConsole.WriteLine(input); } return(MyConsole.GetString()); }