ranee

досье

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