Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddEmployee = "1";
- const string CommandDeleteEmployee = "2";
- const string CommandShowEmployesByJob = "3";
- const string CommandExit = "Exit";
- List<string> fullNames = new List<string>();
- List<string> jobs = new List<string>();
- bool isInProgress = true;
- while (isInProgress)
- {
- Console.WriteLine($"Введите команду: " +
- $"\n {CommandAddEmployee} - Добавить работника " +
- $"\n {CommandDeleteEmployee} - Удлить работника " +
- $"\n {CommandShowEmployesByJob} - Показать работников одной должности " +
- $"\n {CommandExit} - выход ");
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandAddEmployee:
- AddEmployee(jobs, fullNames);
- break;
- case CommandDeleteEmployee:
- TryDeleteEmployee(jobs, fullNames);
- break;
- case CommandShowEmployesByJob:
- ShowEmployesByJob(jobs, fullNames);
- break;
- case CommandExit:
- isInProgress = false;
- break;
- }
- }
- }
- private static void ShowEmployesByJob(List<string> jobs, List<string> fullNames)
- {
- Console.WriteLine("Введите должность работника");
- string job = Console.ReadLine();
- for (int i = 0; i < jobs.Count; i++)
- {
- if (jobs[i] == job)
- {
- Console.WriteLine($"{jobs[i]} - {fullNames[i]}");
- }
- }
- }
- private static void TryDeleteEmployee(List<string> jobs, List<string> fullNames)
- {
- Console.WriteLine("Введите ФИО работника");
- string fullName = Console.ReadLine();
- for (int i = 0; i < fullNames.Count; i++)
- {
- if (fullName == fullNames[i])
- {
- jobs.RemoveAt(i);
- fullNames.RemoveAt(i);
- }
- }
- }
- private static void AddEmployee(List<string> jobs, List<string> fullNames)
- {
- Console.WriteLine("Введите должность");
- string job = Console.ReadLine();
- Console.WriteLine("Введите ФИО");
- string fullName = Console.ReadLine();
- CheckIfJobExist(jobs, job);
- jobs.Add(job);
- fullNames.Add(fullName);
- }
- private static void CheckIfJobExist(List<string> jobs, string job)
- {
- if (jobs.Contains(job) == false)
- {
- Console.WriteLine("В базе создана новая должность");
- }
- else
- {
- Console.WriteLine("Такая должность уже есть в базе");
- }
- }
- private static void TryDeleteJob(List<string> jobs, string job)
- {
- if (jobs.Contains(job) == false)
- {
- jobs.Remove(job);
- Console.WriteLine("Сотрудников с такой должностью больше нет. Должность удалена из базы");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement