ranee

досье

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