ranee

досье

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