ranee

1qaz

Apr 10th, 2021 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.Dynamic;
  6. using System.Globalization;
  7. using System.Linq;
  8. using System.Runtime.Serialization;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.IO;
  13. namespace CSLight
  14. {
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             bool exit = true;
  20.             int surnameSearch = 0;
  21.             string[] menu = { "1. Добавить досье.", "2. Вывести досье.", "3. Удалить досье.", "4. Поиск по фамилии.", "5. Выход." };
  22.             string[] fullName = { "Иванов Иван Иванович", "Шевцов Глеб Егорыч" };
  23.             string[] position = { "Директор", "Коллектор" };
  24.             string newWorker = "";
  25.             string positonWorker = "";
  26.             string command;
  27.             int dossierNumber;
  28.             int hitCoincidence = 0;
  29.             Console.CursorVisible = false;
  30.             while (exit)
  31.             {
  32.                 Console.SetCursorPosition(0, 0);
  33.                 string selectMenuItems = DrawMenu(ref surnameSearch, menu);
  34.                 switch (selectMenuItems)
  35.                 {
  36.                     case "1. Добавить досье.":
  37.                         Console.Write("Ведите ФИО нового сотрудника:");
  38.                         newWorker = Console.ReadLine();
  39.                         IncreaseDossier(ref fullName, newWorker);
  40.                         Console.Write("Ведите должность сотрудника:");
  41.                         positonWorker = Console.ReadLine();
  42.                         IncreaseDossier(ref position, positonWorker);
  43.                         Console.Clear();
  44.                         break;
  45.                     case "2. Вывести досье.":
  46.                         Console.Clear();
  47.                         DrawaAllDossier(fullName, position);
  48.                         break;
  49.                     case "3. Удалить досье.":
  50.                         Console.Clear();
  51.                         if (fullName.Length == 0)
  52.                         {
  53.                             DrawLabels("Нет досье в списке.");
  54.                         }
  55.                         else
  56.                         {
  57.                             DrawaAllDossier(fullName, position);
  58.                             Console.SetCursorPosition(0, 0);
  59.                             Console.Write("Досье для удаления:");
  60.                             dossierNumber = Convert.ToInt32(Console.ReadLine());
  61.                             if(dossierNumber > fullName.Length)
  62.                             {
  63.                                 DrawLabels("Нет досье с таким номером");
  64.                             }
  65.                             else
  66.                             {
  67.                                 DecreaseDossier(ref fullName, ref dossierNumber);
  68.                                 DecreaseDossier(ref position, ref dossierNumber);
  69.                                 Console.Clear();
  70.                             }
  71.                         }
  72.                         break;
  73.                     case "4. Поиск по фамилии.":
  74.                         Console.Clear();
  75.                         Console.Write("Введите фамилию:");
  76.                         command = Console.ReadLine();
  77.                         SearchSurname(fullName, position, command, ref hitCoincidence);
  78.                         break;
  79.                     case "5. Выход.":
  80.                         exit = false;
  81.                         break;
  82.                 }
  83.             }
  84.         }
  85.         static void DrawLabels(string text)
  86.         {
  87.             Console.SetCursorPosition(30, 0);
  88.             Console.Write(text);
  89.         }
  90.         static void SearchSurname(string[]array, string[]array1, string command,ref int hitCoincidence)
  91.         {
  92.             for (int i = 0; i < array.Length; i++)
  93.             {
  94.                 if (array[i].StartsWith(command))
  95.                 {
  96.                     Console.SetCursorPosition(30, i);
  97.                     Console.WriteLine($"{i + 1}) {array[i]} - {array1[i]}");
  98.                     hitCoincidence++;
  99.                 }
  100.             }
  101.             if(hitCoincidence == 0)
  102.             {
  103.                 DrawLabels("Cовпадений нет.");
  104.             }
  105.         }
  106.         static string[] IncreaseDossier(ref string[] array, string value)
  107.         {
  108.             string[] temp = new string[array.Length + 1];
  109.             for (int i = 0; i < array.Length; i++)
  110.             {
  111.                 temp[i] = array[i];
  112.             }
  113.             temp[temp.Length-1] = value;
  114.             array = temp;
  115.             return array;
  116.         }
  117.         static string[] DecreaseDossier(ref string[] array, ref int value)
  118.         {
  119.                 string[] temp = new string[array.Length - 1];
  120.                 for (int i = 0, j = 0; i < array.Length; i++)
  121.                 {
  122.                     if (i == (value - 1))
  123.                         continue;
  124.                     temp[j] = array[i];
  125.                     j++;
  126.                 }
  127.                 array = temp;
  128.                 return array;
  129.         }
  130.         static void DrawaAllDossier(string[]arra1, string[]array2)
  131.         {
  132.             if (arra1.Length == 0)
  133.             {
  134.                 DrawLabels("Нет досье в списке.");
  135.             }
  136.             else
  137.             {
  138.                 for (int i = 0; i < arra1.Length; i++)
  139.                 {
  140.                     Console.SetCursorPosition(30, i);
  141.                     Console.WriteLine($"{i + 1}) {arra1[i]} - {array2[i]}");
  142.                 }
  143.             }
  144.         }
  145.         static string DrawMenu(ref int surnameSearch, string[] items)
  146.         {
  147.             for (int i = 0; i < items.Length; i++)
  148.             {
  149.                 if (i == surnameSearch)
  150.                 {
  151.                     Console.BackgroundColor = ConsoleColor.Gray;
  152.                     Console.ForegroundColor = ConsoleColor.Black;
  153.                     Console.WriteLine(items[i]);
  154.                 }
  155.                 else
  156.                 {
  157.                     Console.WriteLine(items[i]);
  158.                 }
  159.                 Console.ResetColor();
  160.             }
  161.             ConsoleKeyInfo ckey = Console.ReadKey();
  162.             if (ckey.Key == ConsoleKey.DownArrow)
  163.             {
  164.                 if (surnameSearch == items.Length - 1)
  165.                 {
  166.                     surnameSearch = 0;
  167.                 }
  168.                 else
  169.                 {
  170.                     surnameSearch++;
  171.                 }
  172.             }
  173.             else if (ckey.Key == ConsoleKey.UpArrow)
  174.             {
  175.                 if (surnameSearch <= 0)
  176.                 {
  177.                     surnameSearch = items.Length - 1;
  178.                 }
  179.                 else
  180.                 {
  181.                     surnameSearch--;
  182.                 }
  183.             }
  184.             else if (ckey.Key == ConsoleKey.Enter)
  185.             {
  186.                 return items[surnameSearch];
  187.             }
  188.             else
  189.             {
  190.                 Console.Clear();
  191.             }
  192.             Console.Clear();
  193.             return "";
  194.         }
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment