Last active
December 26, 2025 12:06
-
-
Save VladimirYus/30c69da97425853e98437893cc5f87b6 to your computer and use it in GitHub Desktop.
PersonnelRecords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace PersonnelRecords | |
| { | |
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| const string CommandAddDossier = "1"; | |
| const string CommandShowDoissers = "2"; | |
| const string CommandDeleteDossier = "3"; | |
| const string CommandSearchLastName = "4"; | |
| const string CommandExit = "5"; | |
| string[] employeeNames = new string[0]; | |
| string[] jobTitles = new string[0]; | |
| string inputCommands; | |
| bool isWork = true; | |
| while (isWork) | |
| { | |
| Console.WriteLine($"{CommandAddDossier} - Добавить досье"); | |
| Console.WriteLine($"{CommandShowDoissers} - Вывести все досье"); | |
| Console.WriteLine($"{CommandDeleteDossier} - Удалить досье"); | |
| Console.WriteLine($"{CommandSearchLastName} - Поиск по фамилии"); | |
| Console.WriteLine($"{CommandExit} - Выход"); | |
| inputCommands = Console.ReadLine(); | |
| switch (inputCommands) | |
| { | |
| case CommandAddDossier: | |
| GetData(ref employeeNames, ref jobTitles); | |
| break; | |
| case CommandShowDoissers: | |
| ShowEmployees(employeeNames, jobTitles); | |
| break; | |
| case CommandDeleteDossier: | |
| CheckDelete(ref employeeNames, ref jobTitles); | |
| break; | |
| case CommandSearchLastName: | |
| SearchLastName(employeeNames); | |
| break; | |
| case CommandExit: | |
| CloseProgramm(ref isWork); | |
| break; | |
| default: | |
| Console.WriteLine("Неверная команда. Попробуйте снова."); | |
| break; | |
| } | |
| } | |
| } | |
| static void GetData(ref string[] employeeNames, ref string[] jobTitles) | |
| { | |
| string newEmployee; | |
| string titlesNewEmployee; | |
| Console.Write("Введите ФИО нового сотрудника: "); | |
| newEmployee = Console.ReadLine(); | |
| Console.Write("Введите должность нового сотрудника: "); | |
| titlesNewEmployee = Console.ReadLine(); | |
| employeeNames = AddEmployee(employeeNames, newEmployee); | |
| jobTitles = AddEmployee(jobTitles, titlesNewEmployee); | |
| } | |
| static string[] AddEmployee(string[] array, string newElement) | |
| { | |
| string[] tempArray = new string[array.Length + 1]; | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| tempArray[i] = array[i]; | |
| } | |
| tempArray[array.Length] = newElement; | |
| return tempArray; | |
| } | |
| static void ShowEmployees(string[] employees, string[] titles) | |
| { | |
| if (employees.Length == 0) | |
| Console.WriteLine("Данных о сотрудниках нет."); | |
| else | |
| for (int i = 0; i < employees.Length; i++) | |
| { | |
| Console.WriteLine($"{i + 1} {employees[i]} - {titles[i]}"); | |
| } | |
| } | |
| static void CheckDelete(ref string[] employeeNames, ref string[] jobTitles) | |
| { | |
| if (employeeNames.Length == 0) | |
| { | |
| Console.WriteLine("Сотрудников нет."); | |
| return; | |
| } | |
| Console.Write("Введите порядковый номер сотрудника, которого хотите удалить: "); | |
| string input = Console.ReadLine(); | |
| if (int.TryParse(input, out int numberEmployee)) | |
| { | |
| if (numberEmployee < 1 || numberEmployee > employeeNames.Length) | |
| { | |
| Console.WriteLine("Такого сотрудника нет."); | |
| } | |
| else | |
| { | |
| employeeNames = DeleteDossier(employeeNames, numberEmployee); | |
| jobTitles = DeleteDossier(jobTitles, numberEmployee); | |
| Console.WriteLine("Сотрудник удален."); | |
| } | |
| } | |
| else | |
| { | |
| Console.WriteLine("Ошибка. Введите корректный номер."); | |
| } | |
| } | |
| static string[] DeleteDossier(string[] array, int number) | |
| { | |
| string[] tempArray = new string[array.Length - 1]; | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| if (i < number - 1) | |
| tempArray[i] = array[i]; | |
| else if (i > number - 1) | |
| tempArray[i - 1] = array[i]; | |
| } | |
| return tempArray; | |
| } | |
| static void SearchLastName(string[] employees) | |
| { | |
| bool isFound = false; | |
| string searchSurname; | |
| Console.Write("Введите фамилию сотрудника: "); | |
| searchSurname = Console.ReadLine(); | |
| foreach (string fullName in employees) | |
| { | |
| string surname = fullName.Split(' ')[0]; | |
| if (surname.ToLower() == searchSurname.ToLower()) | |
| { | |
| Console.WriteLine(fullName); | |
| isFound = true; | |
| } | |
| } | |
| if (isFound == false) | |
| { | |
| Console.WriteLine($"Сотрудник с фамилией {searchSurname} не найден."); | |
| } | |
| } | |
| static bool CloseProgramm(ref bool isWork) | |
| { | |
| isWork = false; | |
| Console.WriteLine("Программа завершена."); | |
| return isWork; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment