예제 #1
0
        static void UserMenu(Project proj, User user, CreateProject createProject)
        {
start:
            Console.Clear();
            Console.WriteLine("1 - Машина\n2 - Компонент\n3 - Останов");
            Int32.TryParse(Console.ReadLine(), out int userChoice);
            switch (userChoice)
            {
            case 1:
            {
                Console.Clear();
                Console.WriteLine("------------------------Контроль технического обслуживания машин-------------------------");
                Console.WriteLine("1 - Отображение всего парка машин на проекте\n" +
                                  "2 - Поиск машины по его гаражному номеру и модели\n" +
                                  "3 - Сделать останов машины\n" +
                                  "4 - Прикрепить компонент к машине\n" +
                                  "5 - Сделать машину активной/неактивной\n" +
                                  "6 - Создать машину");
                Console.WriteLine("Вернуться в меню - enter x2");
                Int32.TryParse(Console.ReadLine(), out int choice);
                switch (choice)
                {
                case 1:
                {
                    createProject.ShowAllCarsInProject(ref proj);
                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }

                case 2:
                {
                    SearchCar(ref proj);
                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }

                    break;
                }

                case 3:
                {
                    Car car = SearchCarForStop(ref proj);
                    if (car != null)
                    {
                        if (createProject.IsBroken(ref car))
                        {
                            Console.WriteLine("Машина уже не в рабочем состоянии");
                        }
                        else
                        {
                            createProject.CreateBreaks(ref car, ref proj, ref user);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Проверьте корректность ввода");
                    }

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }

                case 4:
                {
                    Car car = SearchCar(ref proj);
                    if (car != null)
                    {
                        if (CarCreate.IsComponentInThatCar(ref car, out int id))
                        {
                            Console.WriteLine("Компонент уже есть в данной машине");
                            Console.WriteLine("Создать новый компонент 1 - да Любая клавиша - выход в меню");
                            Int32.TryParse(Console.ReadLine(), out int ch);
                            if (ch == 1)
                            {
                                Console.WriteLine("Введите id компонента");
                                Int32.TryParse(Console.ReadLine(), out id);
                                Part component = CreateComponent.CtComponent(id);
                                CarCreate.AttachComponentToCar(ref car, ref component, out string message);
                                Console.WriteLine(message);
                            }
                            else
                            {
                                goto start;
                            }
                        }
                        else
                        {
                            Part component = CreateComponent.CtComponent(id);
                            CarCreate.AttachComponentToCar(ref car, ref component, out string message);
                            Console.WriteLine(message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Проверьте корректность ввода");
                    }

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }

                case 5:
                {
                    Car car = SearchCar(ref proj);
                    if (car != null)
                    {
                        Console.WriteLine("1 - Активной 2 - Неактивной");


                        Int32.TryParse(Console.ReadLine(), out int v);
                        switch (v)
                        {
                        case 1:
                        {
                            CarCreate.GetCarActiveOrNot(ref car, true);
                            Console.WriteLine("Машина активна");
                            break;
                        }

                        case 2:
                        {
                            CarCreate.GetCarActiveOrNot(ref car, false);
                            Console.WriteLine("Машина неактивна");
                            break;
                        }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Проверьте корректность ввода");
                    }

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }

                    break;
                }

                case 6:
                {
                    CarCreate.CreateCar(ref proj);
                    Console.WriteLine("Машина добавлена в список машин на проекте");

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }
                }
                if (Console.ReadKey().Key == ConsoleKey.Enter)
                {
                    goto start;
                }
                break;
            }