Advertisement
pavviaz

Otdely

Nov 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace RABOTYAGA
  5. {
  6.     class Department
  7.     {
  8.         public string Title;
  9.         public Boss Boss;
  10.  
  11.         public static string Output(string a)
  12.         {
  13.             if (a != null)
  14.                 return a;
  15.             return "#Информация не найдена";
  16.         }
  17.  
  18.         public static string CorrNameInput()
  19.         {
  20.             string a;
  21.             bool c = false;
  22.             while(true)
  23.             {
  24.                 a = Console.ReadLine();
  25.                 foreach (char b in a)
  26.                     if (!char.IsLetter(b) & b != ' ')
  27.                     {
  28.                         Console.WriteLine("Введите корректное имя");
  29.                         c = true;
  30.                         break;
  31.                     }
  32.                 if (c)
  33.                 {
  34.                     c = false;
  35.                     continue;
  36.                 }
  37.                    
  38.                 break;
  39.             }
  40.             return a;
  41.         }
  42.  
  43.         public static int CorrIntInput()
  44.         {
  45.             int a;
  46.             string b = Console.ReadLine();
  47.             while (true)
  48.             {
  49.                 try
  50.                 {
  51.                     a = Convert.ToInt32(b);
  52.                     break;
  53.                 }
  54.                 catch (FormatException)
  55.                 {
  56.                     Console.WriteLine("Что-то пошло не так, попробуйте ввести еще раз");
  57.                     b = Console.ReadLine();
  58.                 }
  59.             }
  60.             return a;
  61.         }
  62.  
  63.         public void Dep_Init()
  64.         {
  65.             Console.Write($"Вы вошли в меню инициализации отдела, номер текущего отдела - {Program.Departments.Count}\nВведите название отдела : ");
  66.             Title = Console.ReadLine();
  67.             Console.Write("Вы успешно создали отдел. Необходимо добавить начальника?\n1)Да\n2)Нет\nВаш выбор : ");
  68.             switch (Convert.ToInt32(Console.ReadLine()))
  69.             {
  70.                 case 1:
  71.                     Boss_Init();
  72.                     break;
  73.                 case 2:
  74.                     return;
  75.             }
  76.  
  77.         }
  78.         public void Boss_Init()
  79.         {
  80.             Boss = new Boss();
  81.             Console.Write("Вы успешно добавили начальника в отдел. Необходимо добавить сотрудников?\n1)Да\n2)Нет\nВаш выбор : ");
  82.             switch (Convert.ToInt32(Console.ReadLine()))
  83.             {
  84.                 case 1:
  85.                     Empl_Init();
  86.                     break;
  87.                 case 2:
  88.                     return;
  89.             }
  90.  
  91.  
  92.         }
  93.         public void Empl_Init()
  94.         {
  95.             Console.Write("Введите, сколько сотрудников необходимо добавить в отдел : ");
  96.             int j = CorrIntInput();
  97.             for (int n = 0; n < j; n++)
  98.                 Boss.Empl_Add();
  99.             Console.WriteLine("Инициализация отдела полностью завершена");
  100.         }
  101.  
  102.     }
  103.  
  104.     class Boss
  105.     {
  106.         public string Name;
  107.         public int Age;
  108.         public int Salary;
  109.         public List<Employee> Employees = new List<Employee>();
  110.  
  111.         public Boss()
  112.         {
  113.             Console.Write("Введите ФИО начальника отдела : ");
  114.             Name = Department.CorrNameInput();
  115.             Console.Write("\nВведите возраст : ");
  116.             Age = Department.CorrIntInput();
  117.             Console.Write("\nВведите зарплату : ");
  118.             Salary = Department.CorrIntInput();
  119.         }
  120.  
  121.         public void Empl_Add()
  122.         {
  123.             Employees.Add(new Employee());
  124.         }
  125.     }
  126.  
  127.     class Employee
  128.     {
  129.         public string Name;
  130.         public int Age;
  131.         public int Salary;
  132.  
  133.         public Employee()
  134.         {
  135.             Console.Write("Введите ФИО сотрудника : ");
  136.             Name = Department.CorrNameInput();
  137.             Console.Write("\nВведите возраст : ");
  138.             Age = Department.CorrIntInput();
  139.             Console.Write("\nВведите зарплату : ");
  140.             Salary = Department.CorrIntInput();
  141.         }
  142.  
  143.     }
  144.  
  145.  
  146.     class Program
  147.     {
  148.         public static List<Department> Departments = new List<Department>();
  149.         static void Main()
  150.         {
  151.            
  152.             Console.WriteLine("Вас приветствует терминал по управлению компанией");
  153.             while (true)
  154.             {
  155.                 Console.Write("\nВведите номер команды : \n1)Добавить новый отдел\n2)Вывести все существующие отделы\n3)Вывести информацию об отделе\nКоманда : ");
  156.                 switch(Convert.ToInt32(Console.ReadLine()))
  157.                 {
  158.                     case 1:
  159.                         Departments.Add(new Department());
  160.                         Departments[Departments.Count - 1].Dep_Init();
  161.                         break;
  162.                     case 2:
  163.                         if (Departments.Count != 0)
  164.                             for (int i = 0; i < Departments.Count; i++)
  165.                                 Console.WriteLine("\n" + (i + 1) + ")" + Departments[i].Title);
  166.                         else
  167.                             Console.WriteLine("Отделов нет");
  168.                         break;
  169.                     case 3:
  170.                         Console.Write("Введите номер отдела : ");
  171.                         int x = Department.CorrIntInput();
  172.                         Console.WriteLine("Название отдела : " + Departments[x].Title);
  173.                         if (Departments[x].Boss != null)
  174.                         {
  175.                             Console.WriteLine($"ФИО начальника отдела : {Departments[x].Boss.Name} , возраст - {Departments[x].Boss.Age} , зарплата - {Departments[x].Boss.Salary}\nСотрудники : ");
  176.                             if(Departments[x].Boss.Employees.Count > 0)
  177.                                 foreach (Employee a in Departments[x].Boss.Employees)
  178.                                     Console.WriteLine($"ФИО сотрудника : {a.Name} , возраст - {a.Age} , зарплата - {a.Salary}\n");
  179.                             else
  180.                                 Console.WriteLine("#Информация не найдена#");
  181.                             Console.WriteLine("");
  182.  
  183.                         }
  184.                         else
  185.                             Console.WriteLine("ФИО начальника отдела : #Информация не найдена#\n\nСотрудники : #Информация не найдена#");
  186.                        
  187.                        
  188.                         break;
  189.                     default:
  190.                         Console.WriteLine("Что-то не так, попробуйте еще раз");
  191.                         break;
  192.                 }
  193.             }
  194.            
  195.         }
  196.     }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement