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;
- const string firstPoint = "1. Добавить досье.";
- const string secondPoint = "2. Вывести досье.";
- const string thirdPoint = "3. Удалить досье.";
- const string fourthPoint = "4. Выход.";
- List<string> menu = new List<string> { firstPoint, secondPoint, thirdPoint, fourthPoint };
- Dictionary<string, string> dossiers = new Dictionary<string, string>
- {
- { "Иванов Иван Иванович", "Директор" },
- { "Шевцов Глеб Егорыч", "Коллектор" }
- };
- Console.CursorVisible = false;
- while (exit == false)
- {
- bool input = false;
- DrawMenu(ref menuBar, menu);
- CheckingKeystrokes(ref menuBar, menu, ref input);
- Console.Clear();
- if (input)
- {
- switch (menu[menuBar])
- {
- case "1. Добавить досье.":
- AddDossiers(dossiers);
- break;
- case "2. Вывести досье.":
- DrawAllDossier(dossiers);
- Console.ReadKey();
- Console.Clear();
- break;
- case "3. Удалить досье.":
- DrawAllDossier(dossiers);
- RemoveDossiers(dossiers);
- break;
- case "4. Выход.":
- exit = true;
- break;
- }
- }
- }
- }
- static void RemoveDossiers(Dictionary<string, string> dossiers)
- {
- DrawLabels("Ведите ФИО сотрудника:", 0, 40);
- string checkWorker = Console.ReadLine();
- if (dossiers.ContainsKey(checkWorker))
- {
- dossiers.Remove(checkWorker);
- Console.Clear();
- }
- else
- {
- DrawLabels($"Нет сотрудника с фио {checkWorker}", 1, 40);
- }
- }
- static void AddDossiers(Dictionary<string, string> dossiers)
- {
- string newWorker, positonWorker;
- DrawLabels("Ведите ФИО нового сотрудника:", 0, 0);
- newWorker = Console.ReadLine();
- DrawLabels("Ведите должность сотрудника:", 1, 0);
- positonWorker = Console.ReadLine();
- TryAdd(newWorker, positonWorker, dossiers);
- Console.Clear();
- }
- 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 DrawAllDossier(Dictionary<string, string> dossiers)
- {
- if (dossiers.Count == 0)
- {
- DrawLabels("Нет досье в списке.");
- }
- else
- {
- foreach (var dossier in dossiers)
- {
- Console.WriteLine($" {dossier.Key} - {dossier.Value}");
- }
- }
- }
- static void DrawLabels(string text, int x = 0, int y = 30)
- {
- Console.SetCursorPosition(y, x);
- Console.Write(text);
- }
- static void DrawMenu(ref 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 void UpLine(ref int menuBar, List<string> menu)
- {
- if (menuBar <= 0)
- {
- menuBar = menu.Count - 1;
- DrawMenu(ref menuBar, menu);
- }
- else
- {
- menuBar--;
- DrawMenu(ref menuBar, menu);
- }
- }
- static void DownLine(ref int menuBar, List<string> menu)
- {
- if (menuBar == menu.Count - 1)
- {
- menuBar = 0;
- DrawMenu(ref menuBar, menu);
- }
- else
- {
- menuBar++;
- DrawMenu(ref menuBar, menu);
- }
- }
- static void CheckingKeystrokes(ref int menuBar, List<string> menu, ref bool input)
- {
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- UpLine(ref menuBar, menu);
- break;
- case ConsoleKey.DownArrow:
- DownLine(ref menuBar, menu);
- break;
- case ConsoleKey.Enter:
- input = true;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment