Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main()
- {
- const ConsoleKey CommandAddDossier = ConsoleKey.F1;
- const ConsoleKey CommandShowDossiers = ConsoleKey.F2;
- const ConsoleKey CommandDeleteDossier = ConsoleKey.F3;
- const ConsoleKey CommandExit = ConsoleKey.F4;
- List<string> dossiers = new List<string>();
- ConsoleKey userInput;
- bool isContinue = true;
- while (isContinue)
- {
- Console.Clear();
- Console.WriteLine($"{CommandAddDossier} - Добавить досье.");
- Console.WriteLine($"{CommandShowDossiers} - Вывести все досье.");
- Console.WriteLine($"{CommandDeleteDossier} - Удалить досье.");
- Console.WriteLine($"{CommandExit} - Выход.");
- userInput = Console.ReadKey().Key;
- switch (userInput)
- {
- case CommandAddDossier:
- AddDossier(dossiers);
- break;
- case CommandShowDossiers:
- ShowDossiers(dossiers);
- Console.ReadKey();
- break;
- case CommandDeleteDossier:
- TryDeleteDossier(dossiers);
- break;
- case CommandExit:
- isContinue = false;
- break;
- default:
- Console.WriteLine("\nНе корректен ввод.");
- Console.ReadKey();
- break;
- }
- }
- }
- static void AddDossier(List<string> dossiers)
- {
- string dossier = string.Empty;
- char separator = '-';
- Console.Clear();
- dossier += Read("Введите фамилию", false);
- dossier += Read("Введите имя");
- dossier += Read("Введите отчество");
- dossier += $" {separator} {Read("Введите должность", false)}";
- dossiers.Add(dossier);
- }
- static string Read(string message, bool haveSeparator = true)
- {
- char separator = ' ';
- string userInput = string.Empty;
- Console.Write($"{message}: ");
- if (haveSeparator)
- userInput += separator;
- userInput += Console.ReadLine();
- return userInput;
- }
- static void ShowDossiers(List<string> dossiers)
- {
- Console.Clear();
- if (IsEmptyDossier(dossiers))
- {
- Console.Write("Досье пустое.");
- }
- else
- {
- for (int i = 0; i < dossiers.Count; i++)
- {
- Console.WriteLine($"{i + 1} - {dossiers[i]}");
- }
- }
- }
- static void TryDeleteDossier(List<string> dossiers)
- {
- Console.Clear();
- if (IsEmptyDossier(dossiers))
- {
- Console.Write("Досье пустое.");
- Console.ReadKey();
- }
- else
- {
- ShowDossiers(dossiers);
- Console.Write("Введите номер удаляемого пункта досье: ");
- string userInput = Console.ReadLine();
- if (Int32.TryParse(userInput, out int number))
- {
- if (number > 0 && number <= dossiers.Count)
- {
- dossiers.RemoveAt(number - 1);
- Console.WriteLine("Досье удалено.");
- }
- else
- {
- Console.WriteLine("Такого пунтка нет.");
- }
- }
- else
- {
- Console.WriteLine("Введено не число.");
- }
- Console.ReadKey();
- }
- }
- static bool IsEmptyDossier(List<string> dossiers)
- {
- return dossiers.Count <= 0 || dossiers == null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement