Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- const string AddNewDossierCommand = "1";
- const string ShowAllDossiersCommand = "2";
- const string RemoveDossierCommand = "3";
- const string SearchLastNameCommand = "4";
- const string ExitCommand = "5";
- bool isWorking = true;
- char splitChar = ' ';
- string[] fullNames = new string[0];
- string[] positionsAtWork = new string[0];
- while (isWorking)
- {
- Console.Clear();
- Console.WriteLine($"{AddNewDossierCommand} ====> Добавить новое досье");
- Console.WriteLine($"{ShowAllDossiersCommand} ====> Вывести все досье");
- Console.WriteLine($"{RemoveDossierCommand} ====> Удалить досье");
- Console.WriteLine($"{SearchLastNameCommand} ====> Поиск по фамилии");
- Console.WriteLine($"{ExitCommand} ====> Выход");
- Console.Write("\nВыберите номер команды: ");
- string inputMessage = Console.ReadLine();
- switch (inputMessage)
- {
- case AddNewDossierCommand:
- AddDossier(ref fullNames, ref positionsAtWork);
- break;
- case ShowAllDossiersCommand:
- ShowAllDossiers(positionsAtWork, fullNames);
- break;
- case RemoveDossierCommand:
- DeleteDossier(ref fullNames, ref positionsAtWork);
- break;
- case SearchLastNameCommand:
- SearchDossier(fullNames, positionsAtWork, ref splitChar);
- break;
- case ExitCommand:
- isWorking = false;
- break;
- default:
- Console.WriteLine("Введина неверная комманда!");
- break;
- }
- if (isWorking == true)
- {
- Console.Write("\nНажмите любую кнопку для того чтобы продолжить...");
- Console.ReadKey();
- }
- }
- }
- private static void AddDossier(ref string[] fullNames, ref string[] positionsAtWork)
- {
- Console.Write("Введите ФИО: ");
- string fullname = Console.ReadLine();
- Console.Write("Введите должность сотрудника: ");
- string position = Console.ReadLine();
- fullNames = IncreasDossiers(fullNames, fullname);
- positionsAtWork = IncreasDossiers(positionsAtWork, position);
- }
- private static string[] IncreasDossiers(string[] array, string text)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = text;
- array = tempArray;
- return array;
- }
- private static void ShowAllDossiers(string[] workPositions, string[] fullNames)
- {
- int indexID = 1;
- for (int i = 0; i < workPositions.Length; i++)
- {
- Console.WriteLine($"ID[{indexID}#] - ФИО : {fullNames[i]} - Должность: {workPositions[i]}");
- indexID++;
- }
- }
- private static void DeleteDossier(ref string[] fullNames, ref string[] workPositions)
- {
- Console.Write("Введите id досье для удаления: ");
- int indexRemove = Convert.ToInt32(Console.ReadLine());
- if (indexRemove <= fullNames.Length && indexRemove >= 0 && fullNames.Length != 0)
- {
- var inputIndexConvert = indexRemove - 1;
- fullNames = DecreaseDossier(fullNames, inputIndexConvert);
- workPositions = DecreaseDossier(workPositions, inputIndexConvert);
- Console.WriteLine($"Досье сотрудника с id {indexRemove} удалено!");
- }
- else
- {
- Console.WriteLine($"Сотрудника с id {indexRemove} Несуществует!");
- }
- }
- private static string[] DecreaseDossier(string[] array, int index)
- {
- string[] temporaryArray = new string[array.Length - 1];
- for (int i = 0; i < index; i++)
- {
- temporaryArray[i] = array[i];
- }
- for (int i = index; i < array.Length - 1; i++)
- {
- temporaryArray[i] = array[i + 1];
- }
- array = temporaryArray;
- return array;
- }
- private static void SearchDossier(string[] fullNames, string[] positions, ref char splitChar)
- {
- Console.Write("Введите фамилию сотрудника: ");
- string surname = Console.ReadLine();
- int indexSurname = 0;
- bool isSearchingSuccessful = false;
- for (int i = 0; i < fullNames.Length; i++)
- {
- string[] split = fullNames[i].Split(splitChar);
- if (split[indexSurname].ToLower() == surname.ToLower())
- {
- Console.WriteLine($"Индекс [{i + 1}#] - ФИО: {fullNames[i]} - должность : {positions[i]}");
- isSearchingSuccessful = true;
- }
- }
- if (isSearchingSuccessful == false)
- {
- Console.WriteLine($"Сотрудник с фамилией {surname} не найден!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement