ranee

досье

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