Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Ijunior
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddDossier = "1";
- const string CommandShowDossier = "2";
- const string CommandRemoveDossier = "3";
- const string CommandExit = "4";
- bool isWork = true;
- string userInput;
- Dictionary<string, List<string>> dossiers = new Dictionary<string, List<string>>();
- while (isWork)
- {
- Console.Write($"{CommandAddDossier} - добавить досье" +
- $"\n{CommandShowDossier} - посмотреть все досье" +
- $"\n{CommandRemoveDossier} - удалить досье" +
- $"\n{CommandExit} - выход" +
- $"\nВведите команду: ");
- userInput = Console.ReadLine();
- Console.Clear();
- switch (userInput)
- {
- case CommandAddDossier:
- AddDossier(dossiers);
- break;
- case CommandShowDossier:
- ShowDossiers(dossiers);
- break;
- case CommandRemoveDossier:
- RemoveDossier(dossiers);
- break;
- case CommandExit:
- isWork = false;
- break;
- default:
- Console.WriteLine("Некорректный запрос");
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void AddDossier(Dictionary<string, List<string>> dossiers)
- {
- Console.Write("Введите должность: ");
- string post = Console.ReadLine();
- Console.Write("Введите ФИО: ");
- string name = Console.ReadLine();
- if (dossiers.ContainsKey(post))
- {
- dossiers[post].Add(name);
- }
- else
- {
- List<string> names = new List<string>() { name };
- dossiers.Add(post, names);
- }
- }
- static void ShowDossiers(Dictionary<string, List<string>> dossiers)
- {
- if (dossiers.Count > 0)
- {
- foreach (var post in dossiers)
- {
- Console.WriteLine(post.Key + ":");
- foreach (var name in post.Value)
- {
- Console.WriteLine(name);
- }
- }
- }
- else
- {
- Console.WriteLine("Список пуст");
- }
- }
- static void RemoveDossier(Dictionary<string, List<string>> dossiers)
- {
- string post = "";
- string name = "";
- ShowDossiers(dossiers);
- if (dossiers.Count > 0)
- {
- FindDossier(dossiers, ref post, ref name);
- if (dossiers.ContainsKey(post))
- {
- if (dossiers[post].Count > 1)
- {
- dossiers[post].Remove(name);
- }
- else
- {
- dossiers.Remove(post);
- }
- }
- }
- }
- static void FindDossier(Dictionary<string, List<string>> dossiers, ref string post, ref string name)
- {
- Console.Write("Введите должность сотрудника для удаления: ");
- string userInputPost = Console.ReadLine();
- if (dossiers.ContainsKey(userInputPost))
- {
- bool isName = true;
- post = userInputPost;
- Console.Write("Введите ФИО сотрудника для удаления: ");
- string userInputName = Console.ReadLine();
- foreach (var worker in dossiers[userInputPost])
- {
- if (worker == userInputName)
- {
- name = worker;
- isName = false;
- }
- }
- if (isName)
- {
- Console.WriteLine("Такого сотрудника нет");
- }
- }
- else
- {
- Console.WriteLine("Такой должности нет");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment