Пример #1
0
        public static void Main()
        {
            Console.WriteLine("Hello, and welcome to my bakery!");
            Console.WriteLine("Our special today is buy 2, get 1 free bread rolls and 1 for $2 or 3 for $5 pastries");
            Console.WriteLine("What would you like to buy?");
            Console.WriteLine("[bread] [pastry] [checkout]");
            string buySomething = Console.ReadLine();

            if (buySomething == "bread")
            {
                Console.WriteLine("How many bread rolls would you like?");
                int customerBread = int.Parse(Console.ReadLine());
                Bread.FinalBreadPrice(customerBread);
                Console.WriteLine("You added " + Bread.BreadAmount + " loaves to your cart");
                Main();
            }
            else if (buySomething == "pastry")
            {
                Console.WriteLine("How many sweet rolls would you like?");
                int customerSweets = int.Parse(Console.ReadLine());
                Pastry.FinalPastryPrice(customerSweets);
                Console.WriteLine("You added " + Pastry.PastryAmount + " loaves to your cart");
                Main();
            }
            else if (buySomething == "checkout")
            {
                Console.WriteLine("Your total is:" + " $" + (Pastry.PastryPrice + Bread.BreadPrice));
                Console.WriteLine("Thank you for shopping with us!");
            }
            else
            {
                Console.WriteLine("You entered something wrong! Please try again");
                Console.WriteLine("--------------------------------------");
                Main();
            }
        }
Пример #2
0
        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("Таких товаров нет");
                }
            }
        }