static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; //string[] data = { "Вася", "Омск", "10000", "200" }; Informer seller = new Informer(); User user = new User(seller.Greeting()); ProductsList.List(); Console.WriteLine(Help); while (true) { int input = Convert.ToInt32(Console.ReadLine()); if (input == 0) { break; } else { switch (input) { case -1: Console.WriteLine(Help); break; case -2: Console.WriteLine($"Ваш баланс {user.Balance}$\r\n"); break; case -3: ProductsList.List(); break; default: seller.Buy(user, ProductsList.Mass[input - 1]); break; } } } Console.ReadKey(); }
static void Main(string[] args) { Program pr = new Program(); pr.connectionProp.Open(); User nUser = new User(); string login, password; AddDat(out login, out password); SqlCommand sql = new SqlCommand($"select * from ShopUsers where UserName = '******'", pr.connectionProp); using (SqlDataReader reader = sql.ExecuteReader()) { int viewed = 0; //если 0, то пользователя с таким логином нет и ридер не запустится, если 1, то есть while (reader.Read()) { viewed += 1; if (password == reader[2].ToString()) { Console.WriteLine("Заходим на сайт"); nUser = new User ( reader[1].ToString(), reader[3].ToString(), Convert.ToDouble(reader[4]), Convert.ToDouble(reader[5]), Convert.ToInt32(reader[0]) ); } else { Console.WriteLine("Неправильно введённые данные"); return; } } if (viewed == 0) { Console.WriteLine("Нет пользователя с таким логином. Повторите ввод"); return; } } Console.WriteLine("\nСписок товаров"); Bulki bulka = new Bulki( "Булка с изюмом", 35, "OOO Бабушка", "Изюм" ); Tea greenTea = new Tea( "Зелёный чай", 5, "Сам сделяль", "200 мл" ); Bread bread = new Bread( "Королевский хлеб", 100, "Ларёк за углом", "Мука, дрожжи, специи" ); Product[] product = new Product[] { bread, bulka, greenTea }; Informer informer = new Informer(); while (true) { Console.WriteLine(); Console.WriteLine($"Здравствуйте {nUser.Name} ваш баланс {nUser.Balance}"); for (int i = 0; i < product.Length; i++) { Console.WriteLine($"Товар {i}: {product[i].Name} по цене {product[i].Price}"); } Console.WriteLine("Выберите номер товара: "); int productNumber; while (true) { if (!Int32.TryParse(Console.ReadLine(), out productNumber)) { Console.WriteLine("Вы ввели некорректное число"); } else { break; } } if (productNumber >= 0 && productNumber < product.Length) { if (product[productNumber].Price <= nUser.Balance) { informer.Buy(nUser, product[productNumber]); } else { Console.WriteLine("У вас недостаточно средств"); } } else { Console.WriteLine("Таких товаров нет"); } } }
static void Main() { Console.WriteLine("(owo)"); User user1 = new User( "Petro", 21, "0985324950", 34531.50 ); User user2 = new User( "Ivan", 16, "0635814999", 70 ); Cloth tshirt = new Cloth( "tshirt", 98, "Apple", "silk" ); Fruits banana = new Fruits( "banana", 14, "Africa", "honey banana" ); Phone samsungGalaxy = new Phone( "Samsung Galaxy J-500H", 5400, "USA", "10 cm x 24 cm", "Android 6.0.1", "15 Mp" ); Animal cat = new Animal( "mursik", 455, "Ukraine", "cat" ); User[] userlist = new User[] { user1, user2 }; Product[] products = new Product[] { // upcast tshirt, banana, samsungGalaxy, cat }; User currentUser = null; Informer informer = new Informer(); while (true) { // currentUser = user1; // Console.WriteLine(currentUser.Name); // currentUser.Name = "null"; // Console.WriteLine(currentUser.Name); // Console.WriteLine(user1.Name); string str = ""; Console.Write("> "); str = Console.ReadLine(); if (str == "exit") { break; } else if (str == "pricelist") { Console.WriteLine("price list:"); Console.WriteLine("\n"); Console.WriteLine("name " + tshirt.Name); Console.WriteLine("price " + tshirt.Price); Console.WriteLine("manufacturer " + tshirt.Manufacturer); Console.WriteLine("material " + tshirt.Material); Console.WriteLine("\n"); Console.WriteLine("name " + banana.Name); Console.WriteLine("price " + banana.Price); Console.WriteLine("manufacturer " + banana.Manufacturer); Console.WriteLine("variety " + banana.Variety); Console.WriteLine("\n"); Console.WriteLine("name " + samsungGalaxy.Name); Console.WriteLine("price " + samsungGalaxy.Price); Console.WriteLine("manufacturer " + samsungGalaxy.Manufacturer); Console.WriteLine("size " + samsungGalaxy.Size); Console.WriteLine("Operatin system " + samsungGalaxy.OperatingSystem); Console.WriteLine("Camera resolution " + samsungGalaxy.CameraResolution); Console.WriteLine("\n"); Console.WriteLine("name " + cat.Name); Console.WriteLine("price " + cat.Price); Console.WriteLine("manufacturer " + cat.Manufacturer); Console.WriteLine("Type " + cat.Type); Console.WriteLine("\n"); } else if (str == "user") { Console.Write("user name is "); string userLog = Console.ReadLine(); for (int i = 0; i < userlist.Length; i++) { if (userlist[i].Name == userLog) { currentUser = userlist[i]; Console.WriteLine("current user " + currentUser.Name); } } } else if (str == "userlist") { for (int i = 0; i < userlist.Length; i++) { Console.WriteLine(userlist[i].Name); } } else if (str == "currentuser") { if (currentUser == null) { Console.WriteLine("no current user"); } else { Console.WriteLine(currentUser.Name); } } else if (str == "balance") { if (currentUser != null) { Console.WriteLine(currentUser.Balance); } else { Console.WriteLine("no current user"); } } else if (str == "list") { for (int i = 0; i < products.Length; i++) { Console.WriteLine("product " + i + " " + products[i].Name + " price " + products[i].Price); } } else if (str == "info") { Console.Write("number product "); string infoid = Console.ReadLine(); int infonumber = Convert.ToInt32(infoid); // write info } else if (str == "buy") { Console.Write("number product "); string id = Console.ReadLine(); int productnumber = Convert.ToInt32(id); if (productnumber >= 0 && productnumber < products.Length) { if (products[productnumber].Price < currentUser.Balance) { informer.Buy(currentUser, products[productnumber]); } else { Console.WriteLine("not enough money"); } } else { Console.WriteLine("its not product"); } } else if (str == "userinfo") { Console.WriteLine("name " + currentUser.Name); Console.WriteLine("age " + currentUser.Age); Console.WriteLine("phone number " + currentUser.Phone_number); Console.WriteLine("balance " + currentUser.Balance); Console.WriteLine("spend " + currentUser.Spend); } else if (str == "help") { Console.WriteLine("- exit"); Console.WriteLine("- pricelist"); Console.WriteLine("- user - switch user"); Console.WriteLine("- userlist"); Console.WriteLine("- currentuser - show name current user"); Console.WriteLine("- balance"); Console.WriteLine("- list - list with product numbers"); Console.WriteLine("- info - nothing"); Console.WriteLine("- buy - buy product"); Console.WriteLine("- userinfo"); } else if (str == "addbalance") { Console.Write("add balance "); string balancestr = Console.ReadLine(); int balance = Convert.ToInt32(balancestr); currentUser.BalanceReplenishment(balance); } else { Console.WriteLine("Unknown command. Enter 'help' for information."); } } Console.Write("(uwu)"); }