Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Task1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.SetWindowSize(100, 55);
  14.  
  15.             string[] fullNames = new string[0];
  16.             string[] posts = new string[0];
  17.  
  18.             string[] fullNamesStaff = new string[]
  19.             {
  20.                 "Колесников Андрей Викторович",
  21.                 "Кондратьев Владимир Сергеевич",
  22.                 "Соловьёв Михаил Юрьевич",
  23.                 "Максимов Александр Константинович",
  24.                 "Петров Илья Валерьеви"
  25.             };
  26.             string[] postsStaff = new string[]
  27.             {
  28.                 "CEO",
  29.                 "Project Manager",
  30.                 "Middle developer",
  31.                 "Junior developer",
  32.                 "QA tester"
  33.             };
  34.  
  35.             int searchLastName = 0;
  36.             int searchFirstName = 1;
  37.             int searchMiddleName = 2;
  38.  
  39.             string command = "";
  40.  
  41.             while (command != "/exit")
  42.             {
  43.                 Console.WriteLine("Меню. Выберите команду");
  44.                 Console.WriteLine("/add - добавить досье\n/addstaff - добавить штатных сотрудников" +
  45.                                   "\n/remove - удалить досье\n/show - вывести все досье" +
  46.                                   "\n/search - поиск досье по фамилии\n/exit - выход из программы");
  47.  
  48.                 command = Console.ReadLine().ToLower();
  49.  
  50.                 if (command == "/add")
  51.                 {
  52.                     Console.WriteLine("Введите ФИО:");
  53.                     string fullName = Console.ReadLine();
  54.  
  55.                     Console.WriteLine($"Введите должность сотрудника: {fullName}");
  56.                     string post = Console.ReadLine();
  57.  
  58.                     fullNames = Add(fullNames, fullName);
  59.                     posts = Add(posts, post);
  60.  
  61.                     Console.Clear();
  62.  
  63.                     ShowMessage("Досье успешно добавлено", ConsoleColor.Green);
  64.  
  65.                 }
  66.                 else if (command == "/addstaff")
  67.                 {
  68.                     Console.Clear();
  69.  
  70.                     ShowMessage("Штатные сотрудники добавленны", ConsoleColor.Green);
  71.  
  72.                     fullNames = Add(fullNames, fullNamesStaff);
  73.                     posts = Add(posts, postsStaff);
  74.                 }
  75.                 else if (command == "/remove")
  76.                 {
  77.                     Console.WriteLine("Введите номер досье который хотите удалить");
  78.                     int removable = Convert.ToInt32(Console.ReadLine());
  79.  
  80.                     fullNames = Remove(fullNames, removable);
  81.                     posts = Remove(posts, removable);
  82.  
  83.                     Console.Clear();
  84.  
  85.                     ShowMessage("Досье удалено", ConsoleColor.Green);
  86.                 }
  87.                 else if (command == "/show")
  88.                 {
  89.                     Console.Clear();
  90.  
  91.                     if (fullNames.Length != 0)
  92.                         ShowAll(fullNames, posts);
  93.                     else
  94.                         ShowMessage("Список досье пуст", ConsoleColor.Red);
  95.                 }
  96.                 else if (command == "/search")
  97.                 {
  98.                     int foundIndex = -1;
  99.                     string element;
  100.  
  101.                     Console.WriteLine("По какому критерию искать?");
  102.                     Console.WriteLine("/lastname - по фамилии\n/firstname - по имени\n/middlename - по отчеству");
  103.  
  104.                     command = Console.ReadLine();
  105.  
  106.                     if (command == "/lastname")
  107.                     {
  108.                         Console.WriteLine("Введите фамилию для поиска:");
  109.                         element = Console.ReadLine();
  110.                         foundIndex = Search(fullNames, element, searchLastName);
  111.                     }
  112.                     else if (command == "/firstname")
  113.                     {
  114.                         Console.WriteLine("Введите имя для поиска:");
  115.                         element = Console.ReadLine();
  116.                         foundIndex = Search(fullNames, element, searchFirstName);
  117.                     }
  118.                     else if (command == "/middlename")
  119.                     {
  120.                         Console.WriteLine("Введите отчество для поиска:");
  121.                         element = Console.ReadLine();
  122.                         foundIndex = Search(fullNames, element, searchMiddleName);
  123.                     }
  124.  
  125.                     Console.Clear();
  126.                     if (foundIndex != -1)
  127.                     {
  128.                         ShowDocument(fullNames, posts, foundIndex);
  129.                         ShowMessage("Досье успешно найдено", ConsoleColor.Green);
  130.                     }
  131.                     else
  132.                         ShowMessage("Досье не найдено", ConsoleColor.Red);
  133.                 }
  134.                 else
  135.                 {
  136.                     Console.Clear();
  137.  
  138.                     ShowMessage("Такой команды нет", ConsoleColor.Red);
  139.                 }
  140.             }
  141.         }
  142.  
  143.         //------------------------------------------------------------------------------------------------------
  144.  
  145.         static string[] Add(string[] array, string addedElement)
  146.         {
  147.             string[] tempArray = new string[array.Length + 1];
  148.  
  149.             for (int i = 0; i < array.Length; i++)
  150.             {
  151.                 tempArray[i] = array[i];
  152.             }
  153.             tempArray[tempArray.Length - 1] = addedElement;
  154.  
  155.             return tempArray;
  156.  
  157.         }
  158.  
  159.         static string[] Add(string[] array, string[] addedArray)
  160.         {
  161.             string[] tempArray = new string[array.Length + addedArray.Length];
  162.             int tempIndex = 0;
  163.             for (int i = 0; i < array.Length; i++)
  164.             {
  165.                 tempArray[i] = array[i];
  166.                 tempIndex = i + 1;
  167.             }
  168.             for (int i = 0; i < addedArray.Length; i++)
  169.             {
  170.                 tempArray[tempIndex + i] = addedArray[i];
  171.             }
  172.  
  173.             return tempArray;
  174.         }
  175.  
  176.         static string[] Remove(string[] array, int removable)
  177.         {
  178.             string[] tempArray = new string[array.Length - 1];
  179.             int tempIndex = 0;
  180.  
  181.             for (int i = 0; i < array.Length - 1; i++)
  182.             {
  183.                 if (i != removable - 1)
  184.                 {
  185.                     tempArray[i] = array[i];
  186.                 }
  187.                 else
  188.                 {
  189.                     tempIndex = i;
  190.                     break;
  191.                 }
  192.             }
  193.  
  194.             for (int i = tempIndex; i < array.Length - 1; i++)
  195.             {
  196.                 tempArray[i] = array[i + 1];
  197.             }
  198.  
  199.             return tempArray;
  200.         }
  201.  
  202.         static int Search(string[] array, string element, int criteria)
  203.         {
  204.             int index = -1;
  205.  
  206.             for (int i = 0; i < array.Length; i++)
  207.             {
  208.                 string[] splitName = array[i].Split(' ');
  209.  
  210.                 if (element == splitName[criteria])
  211.                 {
  212.                     index = i;
  213.                 }
  214.             }
  215.  
  216.             return index;
  217.         }
  218.  
  219.         static void ShowAll(string[] fullNames, string[] posts, int left = 0, int top = 16)
  220.         {
  221.             Console.SetCursorPosition(left, top);
  222.  
  223.             Console.ForegroundColor = ConsoleColor.Yellow;
  224.  
  225.             if (fullNames.Length == posts.Length)
  226.             {
  227.                 for (int i = 0; i < fullNames.Length; i++)
  228.                 {
  229.                     Console.WriteLine($"{i + 1}. {fullNames[i]} - {posts[i]}");
  230.                 }
  231.             }
  232.             else
  233.             {
  234.                 Console.ForegroundColor = ConsoleColor.Red;
  235.                 Console.WriteLine("Кол-во ФИО и должностей должны быть одинаковыми!");
  236.                 Console.ResetColor();
  237.             }
  238.  
  239.             Console.ResetColor();
  240.  
  241.             Console.SetCursorPosition(0, 0);
  242.         }
  243.  
  244.         static void ShowDocument(string[] fullNames, string[] posts, int index, int left = 0, int top = 16)
  245.         {
  246.             string[] fullNamesSplit = fullNames[index].Split();
  247.  
  248.             Console.SetCursorPosition(left, top);
  249.  
  250.             Console.ForegroundColor = ConsoleColor.Yellow;
  251.             Console.WriteLine($"Фамилия: {fullNamesSplit[0]}");
  252.             Console.WriteLine($"Имя: {fullNamesSplit[1]}");
  253.             Console.WriteLine($"Отчество: {fullNamesSplit[2]}");
  254.             Console.WriteLine($"Должность: {posts[index]}");
  255.             Console.ResetColor();
  256.  
  257.             Console.SetCursorPosition(0, 0);
  258.         }
  259.  
  260.         static void ShowMessage(string message, ConsoleColor color, int left = 0, int top = 14)
  261.         {
  262.             Console.SetCursorPosition(left, top);
  263.             Console.ForegroundColor = color;
  264.  
  265.             Console.WriteLine(message);
  266.  
  267.             Console.ResetColor();
  268.             Console.SetCursorPosition(0, 0);
  269.         }
  270.     }
  271.  
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement