コード例 #1
0
ファイル: DriverServer.cs プロジェクト: Andrey0712/step
        public void MenuDriver()
        {
            string       strConnection = "  Data Source=PK;Initial Catalog=Avtoria;Integrated Security=True";
            DriverServer driverService = new DriverServer(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:
                {
                    var list = driverService.GetAll();
                    foreach (var item in list)
                    {
                        Console.WriteLine(item);
                    }
                    break;
                }

                case 2:
                {
                    Driver driver = new Driver();
                    Console.Write("Введите имя: ");
                    driver.Name = Console.ReadLine();
                    Console.Write("Укажите адрес: ");
                    driver.Address = Console.ReadLine();
                    Console.Write("Укажите номер телефона: ");
                    driver.PhoneNumber = Console.ReadLine();
                    driverService.Add(driver);
                    break;
                }

                case 3:
                {
                    driverService.del(id);
                    break;
                }

                case 4:
                {
                    Console.WriteLine("Enter id for update your database");
                    int    res2   = int.Parse(Console.ReadLine());
                    Driver driver = new Driver();
                    Console.Write("Введите имя: ");
                    driver.Name = Console.ReadLine();
                    Console.Write("Укажите адрес: ");
                    driver.Address = Console.ReadLine();
                    Console.Write("Укажите номер телефона: ");
                    driver.PhoneNumber = Console.ReadLine();
                    driverService.Update(res2, driver);
                    break;
                }

                case 5:
                {
                    Driver ds = new Driver();
                    Console.Write("Введите имя: ");
                    ds.Name = Console.ReadLine();
                    Console.Write("Укажите адрес: ");
                    ds.Address = Console.ReadLine();
                    Console.Write("Укажите номер телефона: ");
                    ds.PhoneNumber = Console.ReadLine();
                    var list = driverService.Search(ds);
                    foreach (var item in list)
                    {
                        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; }
                }
            }
        }