Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = false;
- int menuBar = 0;
- List<string> menu = new List<string> { "1. Добавить досье.", "2. Вывести досье.", "3. Удалить досье.", "4. Выход." };
- Dictionary<string, string> dossiers = new Dictionary<string, string>
- {
- { "Иванов Иван Иванович", "Директор" },
- { "Шевцов Глеб Егорыч", "Коллектор" }
- };
- Console.CursorVisible = false;
- while (exit == false)
- {
- DrawMenu(menuBar, menu);
- ChangeDirection(ref menuBar, menu, out string selectMenuItems);
- Console.Clear();
- switch (selectMenuItems)
- {
- case "1. Добавить досье.":
- string newWorker, positonWorker;
- DrawLabels("Ведите ФИО нового сотрудника:", 0, 0);
- newWorker = Console.ReadLine();
- DrawLabels("Ведите должность сотрудника:", 1, 0);
- positonWorker = Console.ReadLine();
- TryAdd(newWorker,positonWorker,dossiers);
- Console.Clear();
- break;
- case "2. Вывести досье.":
- DrawAllDossier(dossiers);
- Console.ReadKey();
- Console.Clear();
- break;
- case "3. Удалить досье.":
- DrawAllDossier(dossiers);
- DrawLabels("Ведите ФИО сотрудника для удаления:", 0, 40);
- string checkWorker = Console.ReadLine();
- if (dossiers.ContainsKey(checkWorker))
- {
- dossiers.Remove(checkWorker);
- Console.Clear();
- }
- else
- {
- DrawLabels($"Нет сотрудника с фио {checkWorker}", 1, 40);
- }
- break;
- case "4. Выход.":
- exit = true;
- break;
- }
- }
- }
- static void TryAdd(string key, string value, Dictionary<string, string> dossiers)
- {
- if(dossiers.ContainsKey(key))
- {
- Console.WriteLine("Работник уже внесен.");
- Console.ReadKey();
- Console.Clear();
- }
- else
- {
- dossiers.Add(key, value);
- }
- }
- static void DrawLabels(string text, int x = 0, int y = 30)
- {
- Console.SetCursorPosition(y, x);
- Console.Write(text);
- }
- static void DrawAllDossier(Dictionary<string, string> dossiers)
- {
- if (dossiers.Count == 0)
- {
- DrawLabels("Нет досье в списке.");
- }
- else
- {
- int i = 1;
- foreach (var dossier in dossiers)
- {
- DrawLabels($"{i} {dossier.Key} - {dossier.Value}", i - 1, 0);
- i++;
- }
- }
- }
- static void DrawMenu(int menuBar, List<string> menu)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < menu.Count; i++)
- {
- if (i == menuBar)
- {
- Console.BackgroundColor = ConsoleColor.Gray;
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine(menu[i]);
- }
- else
- {
- Console.WriteLine(menu[i]);
- }
- Console.ResetColor();
- }
- }
- static string GetChoise(List<string> menu, int menuBar)
- {
- return menu[menuBar];
- }
- static void ChangeDirection(ref int menuBar, List<string> menu, out string selectMenuItems)
- {
- selectMenuItems = "";
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- if (menuBar <= 0)
- {
- menuBar = menu.Count - 1;
- DrawMenu(menuBar, menu);
- }
- else
- {
- menuBar--;
- DrawMenu(menuBar, menu);
- }
- break;
- case ConsoleKey.DownArrow:
- if (menuBar == menu.Count - 1)
- {
- menuBar = 0;
- DrawMenu(menuBar, menu);
- }
- else
- {
- menuBar++;
- DrawMenu(menuBar, menu);
- }
- break;
- case ConsoleKey.Enter:
- {
- selectMenuItems = GetChoise(menu, menuBar);
- }
- break;
- }
- }
- }
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement