Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Xml.Linq;
- using static System.Console;
- namespace HandBook
- {
- class Program
- {
- static List<Employees> EList = new List<Employees>{}; // Список подчиненных
- static List<Chiefs> CList = new List<Chiefs>{}; // Список начальников
- public static int CLC = 0; // Chief List Counter - счётчик для динамического создания экземпляров класса Cheifs
- public static int ELC = 0; // Employees Lisc Counter - счётчик для динамического создания экземпляров класса Employees
- class Human
- {
- private string _Name;
- private int _Age;
- private int _Salary;
- private string _Department;
- public string Name
- {
- get { return _Name;}
- set
- {
- value = value.Trim(); // Удаляем лишние пробелы в начале и конце строки
- while (value.Contains(" "))
- {
- value = value.Replace(" ", " "); // Удаляем все двойные пробелы
- }
- if (value.Where(x => x == ' ').Count() == 2) // Если осталось лишь 2 пробела, значит в строке есть 3 слова, что удовлетворяет ФИО
- {
- if (AlreadyExist(value) == false)
- {
- _Name = value;
- } // Проверка, существует ли уже человек с такими ФИО
- else
- {
- WriteLine(new String('-',61)); // Красиво оформляем вывод ошибки
- WriteLine("Name already exist");
- WriteLine(new String('-',61));
- Environment.Exit(1);
- }
- }
- else
- {
- WriteLine(new String('-',61)); // Красиво оформляем вывод ошибки
- WriteLine("Incorrect Name, must be declared Name, Surname and Third Name");
- WriteLine(new String('-',61));
- Environment.Exit(1);
- }
- }
- } // Имя должно содержать 3 слова: Фамилию Имя Отчество <=> иметь 2 пробела в строке
- public int Age
- {
- get { return _Age; }
- set
- {
- if (value > 0)
- {
- _Age = value;
- }
- else
- {
- WriteLine(new String('-',20));
- WriteLine("Age must be positive");
- WriteLine(new String('-',20));
- Environment.Exit(1);
- }
- }
- } // Возраст должен быть положительным
- public int Salary
- {
- get { return _Salary; }
- set
- {
- if (value > 0)
- {
- _Salary = value;
- }
- else
- {
- WriteLine(new String('-',23));
- WriteLine("Salary must be positive");
- WriteLine(new String('-',23));
- Environment.Exit(1);
- }
- }
- } // ЗП должна быть положительной
- public string Department
- {
- get { return _Department; }
- set { _Department = value; }
- }
- } // Общие данные для подчиненных и начальников, будут унаследованы для след. классов
- class Chiefs : Human
- {
- }
- class Employees : Human
- {
- private Chiefs _Chief_as_class;
- private string _Chief_as_string;
- public Chiefs Chief_as_class
- {
- get { return _Chief_as_class;}
- }
- public string Chief_as_string
- {
- get { return _Chief_as_string; }
- set
- {
- int Cfs_counter = 0;
- foreach (Chiefs CFs in CList)
- {
- if (value == CFs.Name)
- {
- _Chief_as_string = value;
- }
- else
- {
- Cfs_counter++;
- }
- }
- if (Cfs_counter == CList.Count())
- {
- WriteLine(new String('-',37));
- WriteLine("Chief's name not found in Chiefs List");
- WriteLine(new String('-',37));
- Environment.Exit(1);
- }
- }
- }
- }
- static void AddChief()
- {
- CList.Add(new Chiefs());
- WriteLine("Write first name, second name and third name of chief");
- CList[CLC].Name = ReadLine();
- WriteLine("Write age of chief");
- CList[CLC].Age = Convert.ToInt32(ReadLine());
- WriteLine("Write salary of chief");
- CList[CLC].Salary = Convert.ToInt32(ReadLine());
- WriteLine("Write department of chief");
- CList[CLC].Department = ReadLine();
- CLC++;
- }
- static void AddEmployee()
- {
- EList.Add(new Employees());
- WriteLine("Write first name, second name and third name of employee");
- EList[ELC].Name = ReadLine();
- WriteLine("Write age of employee");
- EList[ELC].Age = Convert.ToInt32(ReadLine());
- WriteLine("Write salary of employee");
- EList[ELC].Salary = Convert.ToInt32(ReadLine());
- WriteLine("Write department of employee");
- EList[ELC].Department = ReadLine();
- WriteLine("Write chief of employee");
- EList[ELC].Chief_as_string = ReadLine();
- ELC++;
- }
- static bool AlreadyExist(string name)
- {
- int local_i = 0;
- foreach (Human Hmn in EList)
- {
- if (Hmn.Name == name)
- {
- return true;
- }
- else
- {
- local_i++;
- }
- }
- foreach (Human Hmn in CList)
- {
- if (Hmn.Name == name)
- {
- return true;
- }
- else
- {
- local_i++;
- }
- }
- return false;
- }
- static void InfoByName()
- {
- WriteLine("Write first, second and third name of person:");
- string person = ReadLine();
- if (AlreadyExist(person) == false)
- {
- WriteLine("Person are not exist");
- }
- foreach (Human Hmn in CList)
- {
- if (person == Hmn.Name)
- {
- WriteLine(new String('-',20));
- WriteLine("Name: {0}\nAge: {1}\nSalary: {2}\nDepartment: {3}\nRank: Chief",Hmn.Name,Hmn.Age,Hmn.Salary,Hmn.Department);
- WriteLine(new String('-',20));
- break;
- }
- }
- foreach (Employees Hmn in EList)
- {
- if (person == Hmn.Name)
- {
- WriteLine(new String('-',20));
- 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);
- WriteLine(new String('-',20));
- break;
- }
- }
- }
- static void InfoByType()
- {
- WriteLine(new String('-',21)+"\nWrite type of person: employees or chiefs");
- string typep = ReadLine();
- if (typep != "employees" & typep != "chiefs")
- {
- WriteLine("Incorrect type (only employees or chiefs)");
- return;
- }
- if (typep == "employees")
- {
- foreach (Employees Hmn in EList)
- {
- WriteLine(new String('-',20));
- 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);
- WriteLine(new String('-',20));
- }
- }
- else
- {
- foreach (Human Hmn in CList)
- {
- WriteLine(new String('-',20));
- WriteLine("Name: {0}\nAge: {1}\nSalary: {2}\nDepartment: {3}\nRank: Chief",Hmn.Name,Hmn.Age,Hmn.Salary,Hmn.Department);
- WriteLine(new String('-',20));
- }
- }
- }
- static void Main(string[] args)
- {
- label1:
- WriteLine(new String('-',21)+"\nPrint type of command\n1:Chief" +
- "\n2:Employee (Chiefs must be declared before his employees)" +
- "\n3:Get Info via Name\n4:Get Info via Type\n"+new String('-',21));
- int typeOfCommand = Convert.ToInt32(ReadLine());
- switch (typeOfCommand)
- {
- case 1:
- AddChief();
- goto label1;
- break;
- case 2:
- AddEmployee();
- goto label1;
- break;
- case 3:
- InfoByName();
- goto label1;
- break;
- case 4:
- InfoByType();
- goto label1;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment