ranee

досье

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