Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
71
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.                     fullNames = Add(fullNames, fullNamesStaff);
  69.                     posts = Add(posts, postsStaff);
  70.  
  71.                     Console.Clear();
  72.  
  73.                     ShowMessage("Штатные сотрудники добавленны", ConsoleColor.Green);
  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.  
  127.                     if (foundIndex != -1)
  128.                     {
  129.                         ShowDocument(fullNames, posts, foundIndex);
  130.                         ShowMessage("Досье успешно найдено", ConsoleColor.Green);
  131.                     }
  132.                     else
  133.                         ShowMessage("Досье не найдено", ConsoleColor.Red);
  134.                 }
  135.                 else
  136.                 {
  137.                     Console.Clear();
  138.  
  139.                     ShowMessage("Такой команды нет", ConsoleColor.Red);
  140.                 }
  141.             }
  142.         }
  143.  
  144.         //------------------------------------------------------------------------------------------------------
  145.  
  146.         static string[] Add(string[] array, string addedElement)
  147.         {
  148.             string[] tempArray = new string[array.Length + 1];
  149.  
  150.             for (int i = 0; i < array.Length; i++)
  151.             {
  152.                 tempArray[i] = array[i];
  153.             }
  154.             tempArray[tempArray.Length - 1] = addedElement;
  155.  
  156.             return tempArray;
  157.  
  158.         }
  159.  
  160.         static string[] Add(string[] array, string[] addedArray)
  161.         {
  162.             string[] tempArray = new string[array.Length + addedArray.Length];
  163.             int tempIndex = 0;
  164.             for (int i = 0; i < array.Length; i++)
  165.             {
  166.                 tempArray[i] = array[i];
  167.                 tempIndex = i + 1;
  168.             }
  169.             for (int i = 0; i < addedArray.Length; i++)
  170.             {
  171.                 tempArray[tempIndex + i] = addedArray[i];
  172.             }
  173.  
  174.             return tempArray;
  175.         }
  176.  
  177.         static string[] Remove(string[] array, int removable)
  178.         {
  179.             string[] tempArray = new string[array.Length - 1];
  180.             int tempIndex = 0;
  181.  
  182.             for (int i = 0; i < array.Length - 1; i++)
  183.             {
  184.                 if (i != removable - 1)
  185.                 {
  186.                     tempArray[i] = array[i];
  187.                 }
  188.                 else
  189.                 {
  190.                     tempIndex = i;
  191.                     break;
  192.                 }
  193.             }
  194.  
  195.             for (int i = tempIndex; i < array.Length - 1; i++)
  196.             {
  197.                 tempArray[i] = array[i + 1];
  198.             }
  199.  
  200.             return tempArray;
  201.         }
  202.  
  203.         static int Search(string[] array, string element, int criteria)
  204.         {
  205.             int index = -1;
  206.  
  207.             for (int i = 0; i < array.Length; i++)
  208.             {
  209.                 string[] splitName = array[i].Split(' ');
  210.  
  211.                 if (element == splitName[criteria])
  212.                 {
  213.                     index = i;
  214.                 }
  215.             }
  216.  
  217.             return index;
  218.         }
  219.  
  220.         static void ShowAll(string[] fullNames, string[] posts, int left = 0, int top = 16)
  221.         {
  222.             Console.SetCursorPosition(left, top);
  223.  
  224.             Console.ForegroundColor = ConsoleColor.Yellow;
  225.  
  226.             if (fullNames.Length == posts.Length)
  227.             {
  228.                 for (int i = 0; i < fullNames.Length; i++)
  229.                 {
  230.                     Console.WriteLine($"{i + 1}. {fullNames[i]} - {posts[i]}");
  231.                 }
  232.             }
  233.             else
  234.             {
  235.                 Console.ForegroundColor = ConsoleColor.Red;
  236.                 Console.WriteLine("Кол-во ФИО и должностей должны быть одинаковыми!");
  237.                 Console.ResetColor();
  238.             }
  239.  
  240.             Console.ResetColor();
  241.  
  242.             Console.SetCursorPosition(0, 0);
  243.         }
  244.  
  245.         static void ShowDocument(string[] fullNames, string[] posts, int index, int left = 0, int top = 16)
  246.         {
  247.             string[] fullNamesSplit = fullNames[index].Split();
  248.  
  249.             Console.SetCursorPosition(left, top);
  250.  
  251.             Console.ForegroundColor = ConsoleColor.Yellow;
  252.             Console.WriteLine($"Фамилия: {fullNamesSplit[0]}");
  253.             Console.WriteLine($"Имя: {fullNamesSplit[1]}");
  254.             Console.WriteLine($"Отчество: {fullNamesSplit[2]}");
  255.             Console.WriteLine($"Должность: {posts[index]}");
  256.             Console.ResetColor();
  257.  
  258.             Console.SetCursorPosition(0, 0);
  259.         }
  260.  
  261.         static void ShowMessage(string message, ConsoleColor color, int left = 0, int top = 14)
  262.         {
  263.             Console.SetCursorPosition(left, top);
  264.             Console.ForegroundColor = color;
  265.  
  266.             Console.WriteLine(message);
  267.  
  268.             Console.ResetColor();
  269.             Console.SetCursorPosition(0, 0);
  270.         }
  271.     }
  272.  
  273. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement