Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CSLight
- {
- public class Program
- {
- private static object cw;
- static void Main(string[] args)
- {
- string[] listEmployees = new string[0];
- string[] positions = new string[0];
- bool canWork = true;
- const string FillingDossierCommand = "1";
- const string ShowAllDossierCommand = "2";
- const string SearchLastnameCommand = "3";
- const string DeleteDossierCommand = "4";
- const string ExitProgrammCommand = "5";
- while (canWork)
- {
- Console.WriteLine(
- $"{FillingDossierCommand})Добавить досье\n" +
- $"{ShowAllDossierCommand})Вывести все досье\n" +
- $"{SearchLastnameCommand})Поиск по фамилии\n" +
- $"{DeleteDossierCommand})Удалить досье\n" +
- $"{ExitProgrammCommand})Выход из программы\n");
- switch (Console.ReadLine())
- {
- case FillingDossierCommand:
- FillDossier(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:
- canWork = false;
- break;
- }
- }
- }
- static void FillDossier(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)
- {
- Console.WriteLine("Введите нужную фамилию для поиска");
- string lastName = Console.ReadLine();
- Console.WriteLine($"Сотрудники с фамилией '{lastName}':");
- foreach (var worker in array)
- {
- if (worker.StartsWith(lastName, StringComparison.OrdinalIgnoreCase))
- {
- Console.WriteLine(worker);
- }
- }
- }
- static void DeleteDossier(ref string[] listEmployees, ref string[] positions)
- {
- ShowAllDossier(listEmployees, positions);
- Console.WriteLine("Введите номер досье которое хотите удалить.");
- int number = ReadInt();
- listEmployees = DeleteArrayElement(listEmployees, number);
- positions = DeleteArrayElement(positions, number);
- }
- 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];
- string dossier = array[number - 1];
- int index = 0;
- foreach (var item in array)
- {
- if (item != dossier)
- {
- temporaryArray[index++] = item;
- }
- }
- 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