Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CSLight
- {
- public class Program
- {
- static void Main(string[] args)
- {
- const string AddDossierCommand = "1";
- const string ShowAllDossierCommand = "2";
- const string SearchLastnameCommand = "3";
- const string DeleteDossierCommand = "4";
- const string ExitProgrammCommand = "5";
- string[] listEmployees = new string[0];
- string[] positions = new string[0];
- bool isRunning = true;
- while (isRunning)
- {
- Console.WriteLine(
- $"{AddDossierCommand})Добавить досье\n" +
- $"{ShowAllDossierCommand})Вывести все досье\n" +
- $"{SearchLastnameCommand})Поиск по фамилии\n" +
- $"{DeleteDossierCommand})Удалить досье\n" +
- $"{ExitProgrammCommand})Выход из программы\n");
- switch (Console.ReadLine())
- {
- case AddDossierCommand:
- AddDossier(ref listEmployees, ref positions);
- break;
- case ShowAllDossierCommand:
- ShowAllDossier(listEmployees, positions);
- break;
- case SearchLastnameCommand:
- SearchLastname(listEmployees);
- break;
- case DeleteDossierCommand:
- DeleteDossier(ref listEmployees, ref positions);
- break;
- case ExitProgrammCommand:
- isRunning = false;
- break;
- }
- }
- }
- static void AddDossier(ref string[] listEmployees, ref string[] positions)
- {
- Console.WriteLine("Введите ФИО сотрудинка через пробел.");
- string fullName = Console.ReadLine();
- Console.WriteLine("Введите должность сотрудинка через пробел.");
- string post = Console.ReadLine();
- listEmployees = ExpandArray(listEmployees, fullName);
- positions = ExpandArray(positions, post);
- }
- static void ShowAllDossier(string[] listEmployees, string[] positions)
- {
- if (listEmployees.Length == 0)
- {
- Console.WriteLine("Досье отсутствуют.");
- return;
- }
- for (int i = 0; i < listEmployees.Length; i++)
- {
- Console.WriteLine($"{i + 1}){listEmployees[i]} - {positions[i]}");
- }
- Console.ReadKey();
- }
- static void SearchLastname(string[] array)
- {
- bool isSearch = false;
- Console.WriteLine("Введите нужную фамилию для поиска");
- string lastName = Console.ReadLine();
- for (int i = 0; i < array.Length; i++)
- {
- char space = ' ';
- string[] surnames = array[i].Split(space);
- if (lastName.ToLower() == surnames[0].ToLower())
- {
- Console.WriteLine(array[i]);
- isSearch = true;
- }
- }
- if (isSearch == false)
- {
- Console.WriteLine($"Сотрудники с фамилией '{lastName}' не найдены.");
- }
- }
- static void DeleteDossier(ref string[] listEmployees, ref string[] positions)
- {
- bool isRunning = true;
- ShowAllDossier(listEmployees, positions);
- Console.WriteLine("Введите номер досье которое хотите удалить.");
- int number = ReadInt();
- if (number > listEmployees.Length)
- {
- isRunning = false;
- }
- if (isRunning == true)
- {
- listEmployees = DeleteArrayElement(listEmployees, number);
- positions = DeleteArrayElement(positions, number);
- }
- else
- {
- Console.WriteLine("Такого индекса нет.");
- }
- }
- static string[] ExpandArray(string[] array, string word)
- {
- string[] temporaryArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- temporaryArray[i] = array[i];
- }
- temporaryArray[temporaryArray.Length - 1] = word;
- array = temporaryArray;
- return array;
- }
- static string[] DeleteArrayElement(string[] array, int number)
- {
- string[] temporaryArray = new string[array.Length - 1];
- for (int i = 0; i < (number - 1); i++)
- {
- temporaryArray[i] = array[i];
- }
- for (int i = (number - 1); i < (temporaryArray.Length); i++)
- {
- temporaryArray[i] = array[i + 1];
- }
- array = temporaryArray;
- return array;
- }
- static int ReadInt()
- {
- int number = 0;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("Это не число.");
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement