Ejemplo n.º 1
0
        public static void AddProd()
        {
            ProductsCollection productsCollection = new ProductsCollection();
            Storage            storage            = new Storage();

            while (true)
            {
                Console.Write("name ");
                string name = Console.ReadLine();
                if (name == "quit")
                {
                    break;
                }

                Console.Write("Section ");
                string       sectionStr = Console.ReadLine();
                MenuSections sections   = MenuSections.Гарниры;

                if (sectionStr == "1")
                {
                    sections = MenuSections.Первое;
                }
                else if (sectionStr == "2")
                {
                    sections = MenuSections.Гарниры;
                }
                else if (sectionStr == "3")
                {
                    sections = MenuSections.Салаты;
                }
                else if (sectionStr == "4")
                {
                    sections = MenuSections.Десерты;
                }
                else if (sectionStr == "5")
                {
                    sections = MenuSections.Напитки;
                }

                Console.Write("price ");
                double price = double.Parse(Console.ReadLine());

                productsCollection.Add(new Product(name, sections, price));
                Console.WriteLine(new String('-', 30));
            }

            foreach (Product product in productsCollection)
            {
                Console.Write(product.Name + " Quantity ");
                int quantity = int.Parse(Console.ReadLine());

                storage.Add(product.ProductId, quantity);
            }

            DataBaseController.AllProductsSave(productsCollection);
            DataBaseController.StorageBaseSave(storage);

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public void SendOrder(ShoppingCart cart, ref Client client)
        {
            Dictionary <int, int> productList = new Dictionary <int, int>();

            foreach (KeyValuePair <Product, int> pair in cart)
            {
                storage.Subtract(pair.Key.ProductId, pair.Value);
                productList.Add(pair.Key.ProductId, pair.Value);
            }

            Order order = new Order(client.name, client.phoneNumber, cart.GetSum(), productList);

            client.AddOrderToHistory(order);

            DataBaseController.StorageBaseSave(storage);
            DataBaseController.SendOrder(order);
        }
Ejemplo n.º 3
0
        public void ToRegister(ref ClientsCollection clientsCollection)
        {
            Regex loginPassRuls = new Regex(@"^[a-zA-Z0-9]+$");
            Regex phoneRegex    = new Regex(@"\(?\d{3}\)?-? *\d{3}-? *-?\d{4}");
            Regex nameRegex     = new Regex(@"^[а-яА-Яa-zA-Z]+$");

            Console.WriteLine("ВАЖНО! Вводите только латинские символы и цифры!!!");
            Console.WriteLine(new string('-', 50));

            Console.Write("Введите логин: ");

            while (true)
            {
                login = Console.ReadLine();

                if (login == "quit")
                {
                    Environment.Exit(0);
                    break;
                }

                if (!loginPassRuls.IsMatch(login))
                {
                    Console.WriteLine("Недопустимые символы, повторите попытку!");
                    continue;
                }

                if (clientsCollection.CheckContainsLogin(login))
                {
                    Console.WriteLine("Логин уже занят! Введите другой");
                    continue;
                }
                break;
            }

            Console.Write("Введите пароль: ");

            while (true)
            {
                password = Console.ReadLine();

                if (!loginPassRuls.IsMatch(password))
                {
                    Console.WriteLine("Недопустимые символы, повторите попытку!");
                    continue;
                }

                break;
            }

            Console.Write("Введите имя: ");

            while (true)
            {
                name = Console.ReadLine();

                if (!nameRegex.IsMatch(name))
                {
                    Console.WriteLine("Недопустимые символы, повторите попытку!");
                    continue;
                }

                break;
            }

            Console.Write("Введите номер телефона: ");

            while (true)
            {
                string number = Console.ReadLine();

                if (!phoneRegex.IsMatch(number))
                {
                    Console.WriteLine("Номер указан не верно, повторите попытку!");
                    continue;
                }

                int.TryParse(string.Join("", number.Where(c => char.IsDigit(c))), out phoneNumber);
                break;
            }

            clientsCollection.AddClient(login, password, name, phoneNumber);
            DataBaseController.ClientBaseSave(clientsCollection);

            Console.WriteLine(new string('-', 20) + "Регистрация завершена успешно" + new string('-', 20));

            Console.Write("Нажмите любую клавишу для продолжения");
            Console.ReadKey();
            Console.Clear();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            ClientController clientController = new ClientController();

            clientController.DoFirstChoice(clientData);

            currentClient = clientController.DoAuthorization(clientData);

            Console.WriteLine("Клиент: {0} Статус: {1}", currentClient.name, currentClient.status);

            while (true)
            {
                myCart.Discount = (int)currentClient.status;

                myCart = menu.MakeOrder(ref myCart);

                if (myCart == null)
                {
                    break;
                }

                int proccesCode = myCart.DoChoice();

                if (proccesCode == 1)
                {
                    Console.Clear();
                    continue;
                }
                else if (proccesCode == -1)
                {
                    Console.Clear();
                    menu.SendOrder(myCart, ref currentClient);

                    clientData.ReSaveClient(currentClient);
                    DataBaseController.ClientBaseSave(clientData);

                    myCart = new ShoppingCart();

                    Console.WriteLine("Ваш заказ успешно отправлен. \n1. Сделать еще заказ \n2. Выход");
                    string choice;
                    while (true)
                    {
                        choice = Console.ReadLine();
                        if (choice == "1" || choice == "2")
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Нет такой команды, повторите ввод");
                            continue;
                        }
                    }

                    if (choice == "1")
                    {
                        Console.Clear();
                        continue;
                    }

                    break;
                }
            }

            Console.WriteLine("Спасибо за использование нашего приложения :)");

            Console.ReadKey();
        }