Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- namespace homeWorkPersonnelAccounting
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandAddDossier = "1";
- const string CommandShowDossiers = "2";
- const string CommandDeleteDossier = "3";
- const string CommandSearchDossierForSecondName = "4";
- const string CommandExit = "5";
- string[] employeeFullName = new string[0];
- string[] employeePosition = new string[0];
- bool isExit = false;
- string userInput;
- while (isExit == false)
- {
- Console.Clear();
- Console.WriteLine(
- $"Меню: \n" +
- $"{CommandAddDossier} - Добавить досье\n" +
- $"{CommandShowDossiers} - Вывести все досье\n" +
- $"{CommandDeleteDossier} - Удалить досье\n" +
- $"{CommandSearchDossierForSecondName} - Поиск по фамилии\n" +
- $"{CommandExit} - Выход\n");
- Console.Write("Введи номер команды: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandAddDossier:
- AddDossier(ref employeeFullName, ref employeePosition);
- break;
- case CommandShowDossiers:
- ShowDossiers(employeeFullName, employeePosition);
- break;
- case CommandDeleteDossier:
- DeleteDossier(ref employeeFullName, ref employeePosition);
- break;
- case CommandSearchDossierForSecondName:
- SearchDossierForSecondName(employeeFullName, employeePosition);
- break;
- case CommandExit:
- isExit = true;
- break;
- default:
- Console.WriteLine("Ошибка: несуществующая команда. Нажмите любую клавишу для продолжения.");
- Console.ReadKey();
- break;
- }
- }
- Console.WriteLine("Выход из программы...");
- }
- static void AddDossier(ref string[] employeeFullName, ref string[] employeePosition)
- {
- string fullName;
- string position;
- Console.Clear();
- fullName = ReadFullName();
- Console.Write("Введите должность сотрудника: ");
- position = Console.ReadLine();
- employeeFullName = AddToArray(employeeFullName, fullName);
- employeePosition = AddToArray(employeePosition, position);
- Console.WriteLine("Досье добавлено. Нажмите любую клавишу для продолжения.");
- Console.ReadKey();
- }
- static void ShowDossiers(string[] employeeFullName, string[] employeePosition)
- {
- Console.Clear();
- if (employeeFullName.Length > 0)
- {
- for (int i = 0; i < employeeFullName.Length; i++)
- {
- Console.WriteLine($"{i + 1} - {employeePosition[i]} - {employeeFullName[i]}");
- }
- }
- else
- {
- Console.WriteLine("В каталоге нет досье.\n");
- }
- Console.WriteLine("Нажмите любую клавишу для продолжения.");
- Console.ReadKey();
- }
- static void DeleteDossier(ref string[] employeeFullName, ref string[] employeePosition)
- {
- int index;
- bool trueIndexInput;
- Console.Clear();
- if (employeeFullName.Length > 0)
- {
- Console.Write("Введите индекс досье, которое хотите удалить: ");
- trueIndexInput = int.TryParse(Console.ReadLine(), out index);
- if (trueIndexInput == true && index >= 1 && index <= employeeFullName.Length)
- {
- index--;
- employeeFullName = RemoveFromArray(employeeFullName, index);
- employeePosition = RemoveFromArray(employeePosition, index);
- Console.WriteLine("Досье удалено.");
- }
- }
- else
- {
- Console.WriteLine("В каталоге нет досье.\n");
- }
- Console.WriteLine("Нажмите любую клавишу для продолжения.");
- Console.ReadKey();
- }
- static void SearchDossierForSecondName(string[] fullNameArray, string[] position)
- {
- string[] fullNameParts;
- Console.Clear();
- if (fullNameArray.Length > 0)
- {
- int secondNameIndex = 0;
- string userInput;
- bool isFound = false;
- Console.Write("Введите для поиска фамилию человека: ");
- userInput = Console.ReadLine();
- for (int i = 0; i < fullNameArray.Length; i++)
- {
- fullNameParts = fullNameArray[i].Split(' ');
- if (fullNameParts[secondNameIndex].Equals(userInput, StringComparison.OrdinalIgnoreCase))
- {
- Console.WriteLine($"{i + 1} - {fullNameArray[i]} + {position[i]}");
- isFound = true;
- }
- }
- if (isFound == false)
- Console.WriteLine("Такого человека нет в базе данных. Или вы сделали ошибку в фамилии человека.");
- Console.WriteLine("Для продолжения нажмите кнопку.");
- Console.ReadKey();
- }
- else
- {
- Console.WriteLine("Список досье пуст.");
- }
- }
- static string ReadFullName()
- {
- string[] fullNameArray = new string[3];
- string fullName = "";
- string userInput;
- bool isExit = false;
- while (isExit == false)
- {
- Console.Clear();
- Console.Write("Введите ФИО всё через пробел: ");
- userInput = Console.ReadLine();
- fullNameArray = userInput.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- if (fullNameArray.Length == 3)
- {
- fullName = string.Join(" ", fullNameArray);
- isExit = true;
- }
- else
- {
- Console.WriteLine("Ошибка: введите корректное ФИО из трёх слов. Нажмите любую клавишу для повторного ввода.");
- Console.ReadKey();
- }
- }
- return fullName;
- }
- static string[] AddToArray (string[] array, string value)
- {
- string[] newArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- newArray[i] = array[i];
- }
- newArray[array.Length] = value;
- return newArray;
- }
- static string[] RemoveFromArray (string[] array, int index)
- {
- string[] newArray = new string[array.Length - 1];
- for (int i = 0, j = 0; i < array.Length; i++)
- {
- if (i != index)
- {
- newArray[j] = array[i];
- j++;
- }
- }
- return newArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement