ranee

досье

Apr 11th, 2021 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.33 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 = false;
  20.             int surnameSearch = 0;
  21.             string[] menu = { "1. Добавить досье.", "2. Вывести досье.", "3. Удалить досье.", "4. Поиск по фамилии.", "5. Выход." };
  22.             string[] fullNames = { "Иванов Иван Иванович", "Шевцов Глеб Егорыч" };
  23.             string[] positions = { "Директор", "Коллектор" };
  24.             Console.CursorVisible = false;
  25.             while (!exit)
  26.             {
  27.                 DrawMenu(surnameSearch, menu);
  28.                 string selectMenuItems = ChangeDirection(ref surnameSearch, menu);
  29.                 switch (selectMenuItems)
  30.                 {
  31.                     case "1. Добавить досье.":
  32.                         string newWorker = "";
  33.                         string positonWorker = "";
  34.                         ClearConsole();
  35.                         Console.Write("Ведите ФИО нового сотрудника:");
  36.                         newWorker = Console.ReadLine();
  37.                         IncreaseDossier(ref fullNames, newWorker);
  38.                         Console.Write("Ведите должность сотрудника:");
  39.                         positonWorker = Console.ReadLine();
  40.                         IncreaseDossier(ref positions, positonWorker);
  41.                         ClearConsole();
  42.                         break;
  43.                     case "2. Вывести досье.":
  44.                         DrawaAllDossier(fullNames, positions);
  45.                         break;
  46.                     case "3. Удалить досье.":
  47.                         bool verificationWasSuccessful = false;
  48.                         int dossierNumber = 0;
  49.                         ClearConsole();
  50.                         CheckDossierNumber(fullNames, positions, ref dossierNumber, ref verificationWasSuccessful);
  51.                         if (verificationWasSuccessful)
  52.                         {
  53.                             DecreaseDossier(ref fullNames, dossierNumber);
  54.                             DecreaseDossier(ref positions, dossierNumber);
  55.                             ClearConsole();
  56.                         }
  57.                         break;
  58.                     case "4. Поиск по фамилии.":
  59.                         ClearConsole();
  60.                         int hitCoincidence = 0;
  61.                         string command;
  62.                         Console.Write("Введите фамилию:");
  63.                         command = Console.ReadLine();
  64.                         SearchSurname(fullNames, positions, command, ref hitCoincidence);
  65.                         break;
  66.                     case "5. Выход.":
  67.                         exit = true;
  68.                         break;
  69.                 }
  70.             }
  71.         }
  72.  
  73.         static void CheckDossierNumber(string[] array, string[] array1, ref int dossierNumber, ref bool verificationWasSuccessful)
  74.         {
  75.             if (array.Length == 0)
  76.             {
  77.                 DrawLabels("Нет досье в списке.");
  78.             }
  79.             else
  80.             {
  81.                 DrawaAllDossier(array, array1);
  82.                 Console.SetCursorPosition(0, 0);
  83.                 Console.Write("Досье для удаления:");
  84.                 dossierNumber = Convert.ToInt32(Console.ReadLine());
  85.                 if (dossierNumber > array.Length || dossierNumber <= 0)
  86.                 {
  87.                     ClearConsole();
  88.                     DrawLabels("Нет досье с таким номером");
  89.                 }
  90.                 else
  91.                 {
  92.                     verificationWasSuccessful = true;
  93.                     ReturnIndexArray(array, ref dossierNumber);
  94.                 }
  95.             }
  96.         }
  97.  
  98.         static int ReturnIndexArray(string[] array, ref int index)
  99.         {
  100.             return index;
  101.         }
  102.  
  103.         static void DrawLabels(string text)
  104.         {
  105.             Console.SetCursorPosition(30, 0);
  106.             Console.Write(text);
  107.         }
  108.        
  109.         static void SearchSurname(string[] array, string[] array1, string command, ref int hitCoincidence)
  110.         {
  111.             for (int i = 0; i < array.Length; i++)
  112.             {
  113.                 if (array[i].StartsWith(command))
  114.                 {
  115.                     Console.SetCursorPosition(30, i);
  116.                     Console.WriteLine($"{i + 1}) {array[i]} - {array1[i]}");
  117.                     hitCoincidence++;
  118.                 }
  119.             }
  120.             if (hitCoincidence == 0)
  121.             {
  122.                 DrawLabels("Cовпадений нет.");
  123.             }
  124.         }
  125.        
  126.         static string[] IncreaseDossier(ref string[] array, string value)
  127.         {
  128.             string[] temp = new string[array.Length + 1];
  129.             for (int i = 0; i < array.Length; i++)
  130.             {
  131.                 temp[i] = array[i];
  132.             }
  133.             temp[temp.Length - 1] = value;
  134.             array = temp;
  135.             return array;
  136.         }
  137.        
  138.         static string[] DecreaseDossier(ref string[] array, int value)
  139.         {
  140.             string[] temp = new string[array.Length - 1];
  141.             for (int i = 0, j = 0; i < array.Length; i++)
  142.             {
  143.                 if (i == (value - 1))
  144.                     continue;
  145.                 temp[j] = array[i];
  146.                 j++;
  147.             }
  148.             array = temp;
  149.             return array;
  150.         }
  151.        
  152.         static void DrawaAllDossier(string[] array1, string[] array2)
  153.         {
  154.             if (array1.Length == 0)
  155.             {
  156.                 DrawLabels("Нет досье в списке.");
  157.             }
  158.             else
  159.             {
  160.                 for (int i = 0; i < array1.Length; i++)
  161.                 {
  162.                     Console.SetCursorPosition(30, i);
  163.                     Console.WriteLine($"{i + 1}) {array1[i]} - {array2[i]}");
  164.                 }
  165.             }
  166.         }
  167.  
  168.         static void DrawMenu(int surnameSearch, string[] items)
  169.         {
  170.             Console.SetCursorPosition(0, 0);
  171.             for (int i = 0; i < items.Length; i++)
  172.             {
  173.                 if (i == surnameSearch)
  174.                 {
  175.                     Console.BackgroundColor = ConsoleColor.Gray;
  176.                     Console.ForegroundColor = ConsoleColor.Black;
  177.                     Console.WriteLine(items[i]);
  178.                 }
  179.                 else
  180.                 {
  181.                     Console.WriteLine(items[i]);
  182.                 }
  183.                 Console.ResetColor();
  184.             }
  185.         }
  186.        
  187.         static string ChangeDirection(ref int surnameSearch, string[] items)
  188.         {
  189.             ConsoleKeyInfo key = Console.ReadKey();
  190.             switch (key.Key)
  191.             {
  192.                 case ConsoleKey.UpArrow:
  193.                     if (surnameSearch <= 0)
  194.                     {
  195.                         surnameSearch = items.Length - 1;
  196.                         DrawMenu(surnameSearch, items);
  197.                     }
  198.                     else
  199.                     {
  200.                         surnameSearch--;
  201.                         DrawMenu(surnameSearch, items);
  202.                     }
  203.                     break;
  204.                 case ConsoleKey.DownArrow:
  205.                     if (surnameSearch == items.Length - 1)
  206.                     {
  207.                         surnameSearch = 0;
  208.                         DrawMenu(surnameSearch, items);
  209.                     }
  210.                     else
  211.                     {
  212.                         surnameSearch++;
  213.                         DrawMenu(surnameSearch, items);
  214.                     }
  215.                     break;
  216.                 case ConsoleKey.Enter:
  217.                     {
  218.                         return items[surnameSearch];
  219.                     }
  220.             }
  221.             return "";
  222.         }
  223.  
  224.         static void ClearConsole()
  225.         {
  226.             Console.Clear();
  227.         }
  228.     }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment