Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace RABOTYAGA
- {
- class Department
- {
- public string Title;
- public Boss Boss;
- public static string Output(string a)
- {
- if (a != null)
- return a;
- return "#Информация не найдена";
- }
- public static string CorrNameInput()
- {
- string a;
- bool c = false;
- while(true)
- {
- a = Console.ReadLine();
- foreach (char b in a)
- if (!char.IsLetter(b) & b != ' ')
- {
- Console.WriteLine("Введите корректное имя");
- c = true;
- break;
- }
- if (c)
- {
- c = false;
- continue;
- }
- break;
- }
- return a;
- }
- public static int CorrIntInput()
- {
- int a;
- string b = Console.ReadLine();
- while (true)
- {
- try
- {
- a = Convert.ToInt32(b);
- break;
- }
- catch (FormatException)
- {
- Console.WriteLine("Что-то пошло не так, попробуйте ввести еще раз");
- b = Console.ReadLine();
- }
- }
- return a;
- }
- public void Dep_Init()
- {
- Console.Write($"Вы вошли в меню инициализации отдела, номер текущего отдела - {Program.Departments.Count}\nВведите название отдела : ");
- Title = Console.ReadLine();
- Console.Write("Вы успешно создали отдел. Необходимо добавить начальника?\n1)Да\n2)Нет\nВаш выбор : ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Boss_Init();
- break;
- case 2:
- return;
- }
- }
- public void Boss_Init()
- {
- Boss = new Boss();
- Console.Write("Вы успешно добавили начальника в отдел. Необходимо добавить сотрудников?\n1)Да\n2)Нет\nВаш выбор : ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Empl_Init();
- break;
- case 2:
- return;
- }
- }
- public void Empl_Init()
- {
- Console.Write("Введите, сколько сотрудников необходимо добавить в отдел : ");
- int j = CorrIntInput();
- for (int n = 0; n < j; n++)
- Boss.Empl_Add();
- Console.WriteLine("Инициализация отдела полностью завершена");
- }
- }
- class Boss
- {
- public string Name;
- public int Age;
- public int Salary;
- public List<Employee> Employees = new List<Employee>();
- public Boss()
- {
- Console.Write("Введите ФИО начальника отдела : ");
- Name = Department.CorrNameInput();
- Console.Write("\nВведите возраст : ");
- Age = Department.CorrIntInput();
- Console.Write("\nВведите зарплату : ");
- Salary = Department.CorrIntInput();
- }
- public void Empl_Add()
- {
- Employees.Add(new Employee());
- }
- }
- class Employee
- {
- public string Name;
- public int Age;
- public int Salary;
- public Employee()
- {
- Console.Write("Введите ФИО сотрудника : ");
- Name = Department.CorrNameInput();
- Console.Write("\nВведите возраст : ");
- Age = Department.CorrIntInput();
- Console.Write("\nВведите зарплату : ");
- Salary = Department.CorrIntInput();
- }
- }
- class Program
- {
- public static List<Department> Departments = new List<Department>();
- static void Main()
- {
- Console.WriteLine("Вас приветствует терминал по управлению компанией");
- while (true)
- {
- Console.Write("\nВведите номер команды : \n1)Добавить новый отдел\n2)Вывести все существующие отделы\n3)Вывести информацию об отделе\nКоманда : ");
- switch(Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Departments.Add(new Department());
- Departments[Departments.Count - 1].Dep_Init();
- break;
- case 2:
- if (Departments.Count != 0)
- for (int i = 0; i < Departments.Count; i++)
- Console.WriteLine("\n" + (i + 1) + ")" + Departments[i].Title);
- else
- Console.WriteLine("Отделов нет");
- break;
- case 3:
- Console.Write("Введите номер отдела : ");
- int x = Department.CorrIntInput();
- Console.WriteLine("Название отдела : " + Departments[x].Title);
- if (Departments[x].Boss != null)
- {
- Console.WriteLine($"ФИО начальника отдела : {Departments[x].Boss.Name} , возраст - {Departments[x].Boss.Age} , зарплата - {Departments[x].Boss.Salary}\nСотрудники : ");
- if(Departments[x].Boss.Employees.Count > 0)
- foreach (Employee a in Departments[x].Boss.Employees)
- Console.WriteLine($"ФИО сотрудника : {a.Name} , возраст - {a.Age} , зарплата - {a.Salary}\n");
- else
- Console.WriteLine("#Информация не найдена#");
- Console.WriteLine("");
- }
- else
- Console.WriteLine("ФИО начальника отдела : #Информация не найдена#\n\nСотрудники : #Информация не найдена#");
- break;
- default:
- Console.WriteLine("Что-то не так, попробуйте еще раз");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement