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. Выход." };
- List<string> fullNames = new List<string> { "Иванов Иван Иванович", "Шевцов Глеб Егорыч" };
- List<string> positions = new List<string> { "Директор", "Коллектор" };
- Console.CursorVisible = false;
- while (exit == false)
- {
- string selectMenuItems;
- DrawMenu(menuBar, menu);
- ChangeDirection(ref menuBar, menu, out selectMenuItems);
- Console.Clear();
- switch (selectMenuItems)
- {
- case "1. Добавить досье.":
- string newWorker, positonWorker;
- DrawLabels("Ведите ФИО нового сотрудника:", 0, 0);
- newWorker = Console.ReadLine();
- fullNames.Add(newWorker);
- DrawLabels("Ведите должность сотрудника:", 1, 0);
- positonWorker = Console.ReadLine();
- positions.Add(positonWorker);
- Console.Clear();
- break;
- case "2. Вывести досье.":
- DrawaAllDossier(fullNames, positions);
- break;
- case "3. Удалить досье.":
- int dossierNumber;
- Console.Clear();
- if (CheckDossierNumber(out dossierNumber, fullNames, positions))
- {
- fullNames.RemoveAt(dossierNumber);
- positions.RemoveAt(dossierNumber);
- }
- Console.SetCursorPosition(20, 20);
- break;
- case "4. Выход.":
- exit = true;
- break;
- }
- }
- }
- static bool CheckDossierNumber(out int dossierNumber, List<string> fullNames, List<string> positions)
- {
- dossierNumber = 0;
- if (fullNames.Count == 0)
- {
- DrawLabels("Нет досье в списке.");
- return false;
- }
- else
- {
- DrawaAllDossier(fullNames, positions);
- DrawLabels("Досье для удаления:", 0, 0);
- dossierNumber = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- if (dossierNumber > fullNames.Count || dossierNumber <= 0)
- {
- DrawLabels("Нет досье с таким номером");
- return false;
- }
- else
- {
- dossierNumber--;
- return true;
- }
- }
- }
- static void DrawLabels(string text, int x = 0, int y = 30)
- {
- Console.SetCursorPosition(y, x);
- Console.Write(text);
- }
- static void DrawaAllDossier(List<string> fullNames, List<string> positions)
- {
- if (fullNames.Count == 0)
- {
- DrawLabels("Нет досье в списке.");
- }
- else
- {
- for (int i = 0; i < fullNames.Count; i++)
- {
- Console.SetCursorPosition(30, i);
- Console.WriteLine($"{i + 1}) {fullNames[i]} - {positions[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
Add Comment
Please, Sign In to add comment