ranee

досье

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