예제 #1
0
        public void MenuAvto()
        {
            string     strConnection = "  Data Source=PK;Initial Catalog=Avtoria;Integrated Security=True";
            AvtoServis avtoService   = new AvtoServis(strConnection);

            int action = 0;

            do
            {
                Console.WriteLine("0. Виход");
                Console.WriteLine("1. Показать всех");
                Console.WriteLine("2. Добавить");
                Console.WriteLine("3. Удалить");
                Console.WriteLine("4. Корекция");
                Console.WriteLine("5. Поиск");
                Console.Write("->_");
                action = int.Parse(Console.ReadLine());
                switch (action)
                {
                case 1:
                {
                    List <Avto> list1 = avtoService.GetAll_avto();
                    foreach (var item in list1)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                }

                case 2:
                {
                    Avto avto = new Avto();
                    Console.Write("Введите марку авто: ");
                    avto.Name = Console.ReadLine();
                    Console.Write("Укажите номер: ");
                    avto.Namber = Console.ReadLine();
                    avtoService.Add_avto(avto);
                    break;
                }

                case 3:
                {
                    Console.Write("Укажите номер ID: ");
                    int id = int.Parse(Console.ReadLine());
                    avtoService.del_avto(id);
                    break;
                }

                case 4:
                {
                    Console.WriteLine("Enter id for update your database");
                    int  res2 = int.Parse(Console.ReadLine());
                    Avto avto = new Avto();
                    Console.Write("Введите имя: ");
                    avto.Name = Console.ReadLine();
                    Console.Write("Укажите номер: ");
                    avto.Namber = Console.ReadLine();

                    avtoService.Update_avto(res2, avto);
                    break;
                }

                case 5:
                {
                    Avto avto = new Avto();
                    Console.Write("Введите имя: ");
                    avto.Name = Console.ReadLine();
                    Console.Write("Укажите номер: ");
                    avto.Namber = Console.ReadLine();
                    List <Avto> list1 = avtoService.Search(avto);
                    foreach (var item in list1)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                }
                }
            } while (action != 0);
        }
예제 #2
0
        static void Main(string[] args)
        {
            string strConnection = "  Data Source=PK;Initial Catalog=Avtoria;Integrated Security=True";

            //string strConnection = "Data Source=serverpu816.database.windows.net;Initial Catalog=test;User ID=pu816;Password=Qwerty1*";
            try
            {
                SqlConnection conn = new SqlConnection(strConnection);
                conn.Open();
                Console.WriteLine("Сконектились с БД :)");

                CreatTabl creatTabl = new CreatTabl();
                creatTabl.Add_Tabl(conn);

                InsertTabl insertTabl = new InsertTabl();
                insertTabl.Insert_Tabl(conn);

                conn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error" + ex.Message);
                throw;
            }

            DriverServer      driverService = new DriverServer(strConnection);
            AvtoServis        avtoService   = new AvtoServis(strConnection);
            Avto_driverServis a_d_Servis    = new Avto_driverServis(strConnection);

            Console.WriteLine("для работы с БД нажмите  Ent");
            Console.ReadLine();
            int counter = 1;

            while (true)
            {
                ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();
                while (keyInfo.Key != ConsoleKey.Enter)
                {
                    Console.Clear();

                    if (counter == 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.WriteLine("1. Работаем с табличкой Driver");

                    Console.ForegroundColor = ConsoleColor.White;
                    if (counter == 2)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.WriteLine("2. Работаем с табличкой Avto");

                    Console.ForegroundColor = ConsoleColor.White;
                    if (counter == 3)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.WriteLine("3. Работаем с табличкой Avto_Driver");
                    Console.ForegroundColor = ConsoleColor.White;
                    if (counter == 4)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    Console.WriteLine("4. Вихід");
                    Console.ForegroundColor = ConsoleColor.White;

                    keyInfo = Console.ReadKey();
                    switch (keyInfo.Key)
                    {
                    case ConsoleKey.DownArrow:
                    {
                        if (counter < 5)
                        {
                            counter++;
                        }
                        else
                        {
                            counter = 1;
                        }
                        break;
                    }

                    case ConsoleKey.UpArrow:
                    {
                        if (counter > 1)
                        {
                            counter--;
                        }
                        else
                        {
                            counter = 4;
                        }
                        break;
                    }
                    }
                }

                switch (counter)
                {
                case 1: { driverService.MenuDriver();  break; }

                case 2: { avtoService.MenuAvto(); break; }

                case 3: { a_d_Servis.MenuAvto_Driver(); break; }

                case 4: { return; }
                }
            }
        }