示例#1
0
        /// <summary>
        ///     Метод який виводить меню з елементів таблички City
        /// </summary>
        public override void Select()
        {
            int skipped = 0;

            if (UserCRUD.cities == null)
            {
                UserCRUD.cities = UserCRUD.GetCitiesFromDB(this.sql);
            }
            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                Console.Clear();
                foreach (var item in UserCRUD.cities.Skip(skipped).Take(5))
                {
                    Console.WriteLine(item);
                }
                Console.SetCursorPosition(5, 5);
                Console.WriteLine("<<<< ENTER >>>>");
                keyInfo = Console.ReadKey();

                switch (keyInfo.Key)
                {
                case ConsoleKey.LeftArrow:
                {
                    if (skipped > 0)
                    {
                        skipped -= 5;
                    }
                    break;
                }

                case ConsoleKey.RightArrow:
                {
                    if (skipped + 5 < UserCRUD.cities.Count)
                    {
                        skipped += 5;
                    }
                    break;
                }
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Оновлює інформацію про користувача
        /// </summary>
        public override void Update()
        {
            Console.WriteLine("Виберіть номер користувача та жміть Enter: ");
            Thread.Sleep(2000);
            this.Select();
            Console.WriteLine("Ведіть Id: ");
            int Id = 0;

            Id = EnterIntValue();

            string query = "UPDATE [dbo].[tblUser] SET ";

            bool isBegin = true;

            Console.Write("Ведіть ім'я: ");
            string name = Console.ReadLine();

            if (!string.IsNullOrEmpty(name))
            {
                isBegin = false;
                query  += "Name = N'" + name + "'";
            }

            Console.Write("Ведіть номер телефону: ");
            string tel = Console.ReadLine();

            if (!string.IsNullOrEmpty(tel))
            {
                if (!isBegin)
                {
                    query += ", ";
                }
                else
                {
                    isBegin = false;
                }
                query += "telNummer = " + "N'" + tel + "'";
            }

            City   city   = null;
            string cityId = "1";

            while (city == null)
            {
                Console.Write("Ведіть номер міста: ");
                cityId = Console.ReadLine();
                if (!string.IsNullOrEmpty(cityId))
                {
                    if (UserCRUD.cities == null)
                    {
                        UserCRUD.cities = UserCRUD.GetCitiesFromDB(this.sql);
                    }
                    try
                    {
                        city = UserCRUD.cities.Where(delegate(City c) { return(c.id == int.Parse(cityId)); }).FirstOrDefault();
                    }
                    catch
                    {
                        Console.Clear();
                        Console.WriteLine("Помилка вводу данних (процес анульовано)");
                        Thread.Sleep(1000);
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            if (!string.IsNullOrEmpty(cityId))
            {
                if (!isBegin)
                {
                    query += ", ";
                }
                else
                {
                    isBegin = false;
                }
                try
                {
                    query += "CityId = " + "N'" + int.Parse(cityId) + "'";
                }
                catch
                {
                    Console.Clear();
                    Console.WriteLine("Помилка вводу данних (процес анульовано)");
                    Thread.Sleep(1000);

                    return;
                }
            }

            query += " WHERE Id = " + Id;
            if (!isBegin)
            {
                SqlCommand command = new SqlCommand(query, this.sql);
                command.ExecuteNonQuery();
                this.users = null;
            }
        }
示例#3
0
        /// <summary>
        ///     Створює нових користувачів і додає у БД
        /// </summary>
        public override void Create()
        {
            Console.Clear();
            Console.Write("Ведіть ім'я: ");
            string name = Console.ReadLine();

            Console.Write("Ведіть номер телефону: ");
            string telNummer = Console.ReadLine();



            int skipped = 0;

            if (UserCRUD.cities == null)
            {
                UserCRUD.cities = UserCRUD.GetCitiesFromDB(this.sql);
            }

            ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                Console.Clear();
                Console.WriteLine("Перегляньте міста та виберіть Id і жміть Enter:");
                foreach (var item in UserCRUD.cities.Skip(skipped).Take(5))
                {
                    Console.WriteLine(item);
                }
                Console.SetCursorPosition(15, 6);
                Console.WriteLine("<<<< Enter >>>>");
                keyInfo = Console.ReadKey();

                switch (keyInfo.Key)
                {
                case ConsoleKey.LeftArrow:
                {
                    if (skipped > 0)
                    {
                        skipped -= 5;
                    }
                    break;
                }

                case ConsoleKey.RightArrow:
                {
                    if (skipped + 5 < UserCRUD.cities.Count)
                    {
                        skipped += 5;
                    }
                    break;
                }
                }
            }

            City c      = null;
            int  cityId = 1;

            while (c == null)
            {
                Console.Clear();
                Console.WriteLine("Ведіть Id: ");

                cityId = EnterIntValue();


                c = UserCRUD.cities.Where(c => c.id == cityId).FirstOrDefault();
            }


            string     query   = $"INSERT INTO [dbo].[tblUser] (Name, telNummer, CityId) VALUES (N'{name}', N'{telNummer}', N'{cityId}')";
            SqlCommand command = new SqlCommand(query, this.sql);

            command.ExecuteNonQuery();

            this.users = null;
        }
示例#4
0
        /// <summary>
        ///     Відображає меню для роботи з користувачами
        /// </summary>
        /// <param name="conn">Приймає строку підключення</param>
        public static void MenuForUser(string conn)
        {
            using (UserCRUD user = new UserCRUD(conn))
            {
                int counter = 1;
                while (true)
                {
                    ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();

                    while (keyInfo.Key != ConsoleKey.Enter)
                    {
                        Console.Clear();
                        Console.WriteLine("_________MENU_________");
                        if (counter == 1)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        Console.WriteLine("1. Переглянути усі записи");
                        Console.ForegroundColor = ConsoleColor.White;
                        if (counter == 2)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        Console.WriteLine("2. Добавити запис");
                        Console.ForegroundColor = ConsoleColor.White;
                        if (counter == 3)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        Console.WriteLine("3. Редагувати запис");
                        Console.ForegroundColor = ConsoleColor.White;
                        if (counter == 4)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        Console.WriteLine("4. Видалити запис");
                        Console.ForegroundColor = ConsoleColor.White;
                        if (counter == 5)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }
                        Console.WriteLine("5. Вийти");
                        Console.ForegroundColor = ConsoleColor.White;

                        keyInfo = Console.ReadKey();

                        switch (keyInfo.Key)
                        {
                        case ConsoleKey.UpArrow:
                        {
                            if (counter > 1)
                            {
                                counter--;
                            }
                            else
                            {
                                counter = 5;
                            }
                            break;
                        }

                        case ConsoleKey.DownArrow:
                        {
                            if (counter < 5)
                            {
                                counter++;
                            }
                            else
                            {
                                counter = 1;
                            }
                            break;
                        }
                        }
                    }

                    switch (counter)
                    {
                    case 1: { user.Select(); break; }

                    case 2: { user.Create(); break; }

                    case 3: { user.Update(); break; }

                    case 4: { user.Delete(); break; }

                    case 5: { return; }
                    }
                }
            }
        }