Mauzzz0

Untitled

Nov 16th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Xml.Linq;
  5. using static System.Console;
  6. namespace HandBook
  7. {
  8.     class Program
  9.     {
  10.         static List<Employees> EList = new List<Employees>{}; // Список подчиненных
  11.         static List<Chiefs> CList = new List<Chiefs>{}; // Список начальников
  12.  
  13.         public static int CLC = 0; // Chief List Counter - счётчик для динамического создания экземпляров класса Cheifs
  14.         public static int ELC = 0; // Employees Lisc Counter - счётчик для динамического создания экземпляров класса Employees
  15.         class Human
  16.         {
  17.             private string _Name;
  18.             private int _Age;
  19.             private int _Salary;
  20.             private string _Department;
  21.  
  22.             public string Name
  23.             {
  24.                 get { return _Name;}
  25.                 set
  26.                 {
  27.                     value = value.Trim(); // Удаляем лишние пробелы в начале и конце строки
  28.                     while (value.Contains("  "))
  29.                     {
  30.                         value = value.Replace("  ", " "); // Удаляем все двойные пробелы
  31.                     }
  32.  
  33.                     if (value.Where(x => x == ' ').Count() == 2) // Если осталось лишь 2 пробела, значит в строке есть 3 слова, что удовлетворяет ФИО
  34.                     {
  35.                         if (AlreadyExist(value) == false)
  36.                         {
  37.                             _Name = value;
  38.                         } // Проверка, существует ли уже человек с такими ФИО
  39.                         else
  40.                         {
  41.                             WriteLine(new String('-',61)); // Красиво оформляем вывод ошибки
  42.                             WriteLine("Name already exist");
  43.                             WriteLine(new String('-',61));
  44.                             Environment.Exit(1);
  45.                         }
  46.                     }
  47.                     else
  48.                     {
  49.                         WriteLine(new String('-',61)); // Красиво оформляем вывод ошибки
  50.                         WriteLine("Incorrect Name, must be declared Name, Surname and Third Name");
  51.                         WriteLine(new String('-',61));
  52.                         Environment.Exit(1);
  53.                     }
  54.                 }
  55.             } // Имя должно содержать 3 слова: Фамилию Имя Отчество <=> иметь 2 пробела в строке
  56.  
  57.             public int Age
  58.             {
  59.                 get { return _Age; }
  60.                 set
  61.                 {
  62.                     if (value > 0)
  63.                     {
  64.                         _Age = value;
  65.                     }
  66.                     else
  67.                     {
  68.                         WriteLine(new String('-',20));
  69.                         WriteLine("Age must be positive");
  70.                         WriteLine(new String('-',20));
  71.                         Environment.Exit(1);
  72.                     }
  73.                 }
  74.             } // Возраст должен быть положительным
  75.  
  76.             public int Salary
  77.             {
  78.                 get { return _Salary; }
  79.                 set
  80.                 {
  81.                     if (value > 0)
  82.                     {
  83.                         _Salary = value;
  84.                     }
  85.                     else
  86.                     {
  87.                         WriteLine(new String('-',23));
  88.                         WriteLine("Salary must be positive");
  89.                         WriteLine(new String('-',23));
  90.                         Environment.Exit(1);
  91.                     }
  92.                 }
  93.             } // ЗП должна быть положительной
  94.  
  95.             public string Department
  96.             {
  97.                 get { return _Department; }
  98.                 set { _Department = value; }
  99.             }
  100.         } // Общие данные для подчиненных и начальников, будут унаследованы для след. классов
  101.  
  102.         class Chiefs : Human
  103.         {
  104.            
  105.         }
  106.        
  107.         class Employees : Human
  108.         {
  109.             private Chiefs _Chief_as_class;
  110.             private string _Chief_as_string;
  111.  
  112.             public Chiefs Chief_as_class
  113.             {
  114.                 get { return _Chief_as_class;}
  115.                
  116.             }
  117.  
  118.             public string Chief_as_string
  119.             {
  120.                 get { return _Chief_as_string; }
  121.                 set
  122.                 {
  123.                     int Cfs_counter = 0;
  124.                     foreach (Chiefs CFs in CList)
  125.                     {
  126.                         if (value == CFs.Name)
  127.                         {
  128.                             _Chief_as_string = value;
  129.                         }
  130.                         else
  131.                         {
  132.                             Cfs_counter++;
  133.                         }
  134.                     }
  135.  
  136.                     if (Cfs_counter == CList.Count())
  137.                     {
  138.                         WriteLine(new String('-',37));
  139.                         WriteLine("Chief's name not found in Chiefs List");
  140.                         WriteLine(new String('-',37));
  141.                         Environment.Exit(1);
  142.                     }
  143.                 }
  144.             }
  145.            
  146.            
  147.         }
  148.  
  149.  
  150.  
  151.         static void AddChief()
  152.         {
  153.             CList.Add(new Chiefs());
  154.            
  155.             WriteLine("Write first name, second name and third name of chief");
  156.             CList[CLC].Name = ReadLine();
  157.            
  158.             WriteLine("Write age of chief");
  159.             CList[CLC].Age = Convert.ToInt32(ReadLine());
  160.            
  161.             WriteLine("Write salary of chief");
  162.             CList[CLC].Salary = Convert.ToInt32(ReadLine());
  163.            
  164.             WriteLine("Write department of chief");
  165.             CList[CLC].Department = ReadLine();
  166.             CLC++;
  167.         }
  168.  
  169.         static void AddEmployee()
  170.         {
  171.             EList.Add(new Employees());
  172.            
  173.             WriteLine("Write first name, second name and third name of employee");
  174.             EList[ELC].Name = ReadLine();
  175.            
  176.             WriteLine("Write age of employee");
  177.             EList[ELC].Age = Convert.ToInt32(ReadLine());
  178.            
  179.             WriteLine("Write salary of employee");
  180.             EList[ELC].Salary = Convert.ToInt32(ReadLine());
  181.            
  182.             WriteLine("Write department of employee");
  183.             EList[ELC].Department = ReadLine();
  184.            
  185.             WriteLine("Write chief of employee");
  186.             EList[ELC].Chief_as_string = ReadLine();
  187.            
  188.             ELC++;
  189.         }
  190.  
  191.         static bool AlreadyExist(string name)
  192.         {
  193.             int local_i = 0;
  194.             foreach (Human Hmn in EList)
  195.             {
  196.                 if (Hmn.Name == name)
  197.                 {
  198.                     return true;
  199.                 }
  200.                 else
  201.                 {
  202.                     local_i++;
  203.                 }
  204.             }
  205.  
  206.             foreach (Human Hmn in CList)
  207.             {
  208.                 if (Hmn.Name == name)
  209.                 {
  210.                     return true;
  211.                 }
  212.                 else
  213.                 {
  214.                     local_i++;
  215.                 }
  216.             }
  217.  
  218.             return false;
  219.         }
  220.  
  221.         static void InfoByName()
  222.         {
  223.             WriteLine("Write first, second and third name of person:");
  224.             string person = ReadLine();
  225.             if (AlreadyExist(person) == false)
  226.             {
  227.                 WriteLine("Person are not exist");
  228.             }
  229.  
  230.             foreach (Human Hmn in CList)
  231.             {
  232.                 if (person == Hmn.Name)
  233.                 {
  234.                     WriteLine(new String('-',20));
  235.                     WriteLine("Name: {0}\nAge: {1}\nSalary: {2}\nDepartment: {3}\nRank: Chief",Hmn.Name,Hmn.Age,Hmn.Salary,Hmn.Department);
  236.                     WriteLine(new String('-',20));
  237.                     break;
  238.                 }
  239.             }
  240.  
  241.             foreach (Employees Hmn in EList)
  242.             {
  243.                 if (person == Hmn.Name)
  244.                 {
  245.                     WriteLine(new String('-',20));
  246.                     WriteLine("Name: {0}\nAge: {1}\nSalary: {2}\nDepartment: {3}\nChief: {4}\nRank: Employee",Hmn.Name,Hmn.Age,Hmn.Salary,Hmn.Department, Hmn.Chief_as_string);
  247.                     WriteLine(new String('-',20));
  248.                     break;
  249.                 }
  250.             }
  251.         }
  252.  
  253.         static void InfoByType()
  254.         {
  255.             WriteLine(new String('-',21)+"\nWrite type of person: employees or chiefs");
  256.             string typep = ReadLine();
  257.             if (typep != "employees" & typep != "chiefs")
  258.             {
  259.                 WriteLine("Incorrect type (only employees or chiefs)");
  260.                 return;
  261.             }
  262.             if (typep == "employees")
  263.             {
  264.                 foreach (Employees Hmn in EList)
  265.                 {
  266.                     WriteLine(new String('-',20));
  267.                     WriteLine("Name: {0}\nAge: {1}\nSalary: {2}\nDepartment: {3}\nChief: {4}\nRank: Employee",Hmn.Name,Hmn.Age,Hmn.Salary,Hmn.Department, Hmn.Chief_as_string);
  268.                     WriteLine(new String('-',20));
  269.                 }
  270.             }
  271.             else
  272.             {
  273.                 foreach (Human Hmn in CList)
  274.                 {
  275.                     WriteLine(new String('-',20));
  276.                     WriteLine("Name: {0}\nAge: {1}\nSalary: {2}\nDepartment: {3}\nRank: Chief",Hmn.Name,Hmn.Age,Hmn.Salary,Hmn.Department);
  277.                     WriteLine(new String('-',20));
  278.                 }
  279.             }
  280.         }
  281.        
  282.        
  283.        
  284.        
  285.        
  286.        
  287.         static void Main(string[] args)
  288.         {
  289.             label1:
  290.             WriteLine(new String('-',21)+"\nPrint type of command\n1:Chief" +
  291.                       "\n2:Employee (Chiefs must be declared before his employees)" +
  292.                       "\n3:Get Info via Name\n4:Get Info via Type\n"+new String('-',21));
  293.             int typeOfCommand = Convert.ToInt32(ReadLine());
  294.             switch (typeOfCommand)
  295.             {
  296.                 case 1:
  297.                     AddChief();
  298.                     goto label1;
  299.                     break;
  300.                 case 2:
  301.                     AddEmployee();
  302.                     goto label1;
  303.                     break;
  304.                 case 3:
  305.                     InfoByName();
  306.                     goto label1;
  307.                     break;
  308.                 case 4:
  309.                     InfoByType();
  310.                     goto label1;
  311.                     break;
  312.             }
  313.         }
  314.     }
  315. }
Advertisement
Add Comment
Please, Sign In to add comment