Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Homework28
- {
- class Program
- {
- static void Main()
- {
- const string CommandUseAddDossier = "1";
- const string CommandUsePrintAllDossier = "2";
- const string CommandUseDeleteDossier = "3";
- const string CommandUseSearchBySurname = "4";
- const string CommandUseExit = "5";
- string[] fullNamesOfEmployees = { "Ivanov Ivan Sergeevich" };
- string[] positionsOfEmployees = { "Programmer" };
- string userInput;
- bool isOpen = true;
- while (isOpen)
- {
- Console.Write($"{CommandUseAddDossier} - Добавить досье сотрудника.\n{CommandUsePrintAllDossier} - Вывести досье всех сотрудников.\n{CommandUseDeleteDossier} - Удалить досье сотрудника.\n{CommandUseSearchBySurname} - Найти досье сотрудника по его фамилии.\n{CommandUseExit} - Выйти из программы.");
- Console.Write("\n\nВведите пункт меню: ");
- userInput = Console.ReadLine();
- Console.Clear();
- switch (userInput)
- {
- case CommandUseAddDossier:
- AddNewEmployeeDosier(ref fullNamesOfEmployees, ref positionsOfEmployees);
- break;
- case CommandUsePrintAllDossier:
- PrintDossierOfAllEmployees(fullNamesOfEmployees, positionsOfEmployees);
- break;
- case CommandUseDeleteDossier:
- DeleteEmployeeDossier(ref fullNamesOfEmployees, ref positionsOfEmployees);
- break;
- case CommandUseSearchBySurname:
- FindEmployeeBySurname(fullNamesOfEmployees, positionsOfEmployees);
- break;
- case CommandUseExit:
- isOpen = false;
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void AddNewEmployeeDosier(ref string[] fullNamesOfEmployees, ref string[] positionsOfEmployees)
- {
- Console.Write("Введите полное имя сотрудника: ");
- string userInput = Console.ReadLine();
- AddNewEmployeeInformation(ref fullNamesOfEmployees, userInput);
- Console.Write("Введите должность сотрудника: ");
- userInput = Console.ReadLine();
- AddNewEmployeeInformation(ref positionsOfEmployees, userInput);
- }
- static void PrintDossierOfAllEmployees(string[] fullNamesOfEmployees, string[] positionsOfEmployees)
- {
- Console.WriteLine("Досье всех сотрудников: ");
- for (int i = 0; i < fullNamesOfEmployees.Length; i++)
- {
- Console.WriteLine($"{i + 1}) {fullNamesOfEmployees[i]} - {positionsOfEmployees[i]}.");
- }
- }
- static void DeleteEmployeeDossier(ref string[] fullNamesOfEmployees, ref string[] positionsOfEmployees)
- {
- Console.Write("Введите номер списка для удаления сотрудника: ");
- int indexOfEmployee = Convert.ToInt32(Console.ReadLine()) - 1;
- if (fullNamesOfEmployees.Length != 0)
- {
- if (indexOfEmployee < fullNamesOfEmployees.Length && indexOfEmployee >= 0)
- {
- DeleteEmployeeInformation(ref fullNamesOfEmployees, indexOfEmployee);
- DeleteEmployeeInformation(ref positionsOfEmployees, indexOfEmployee);
- }
- else
- {
- Console.Write("Сотрудника с таким номером нет.");
- }
- }
- else
- {
- Console.Write("В списке отсутствуют действующие сотруники.");
- }
- }
- static void FindEmployeeBySurname(string[] fullNamesOfEmployees, string[] positionsOfEmployees)
- {
- string userInput;
- bool employeeIsFound = false;
- Console.Write("Введите фамилию сотрудника: ");
- userInput = Console.ReadLine();
- for (int i = 0; i < fullNamesOfEmployees.Length; i++)
- {
- string surname = fullNamesOfEmployees[i].Split()[0];
- if (surname == userInput)
- {
- Console.WriteLine($"{i + 1}) {fullNamesOfEmployees[i]} - {positionsOfEmployees[i]}.");
- employeeIsFound = true;
- }
- }
- if (employeeIsFound == false)
- {
- Console.WriteLine("Сотрудника с такой фамилией нет.");
- }
- }
- static void AddNewEmployeeInformation(ref string[] informationAboutEmployees, string informationAboutEmployee)
- {
- string[] tempArrayInformation = new string[informationAboutEmployees.Length + 1];
- for (int i = 0; i < informationAboutEmployees.Length; i++)
- {
- tempArrayInformation[i] = informationAboutEmployees[i];
- }
- tempArrayInformation[tempArrayInformation.Length - 1] = informationAboutEmployee;
- informationAboutEmployees = tempArrayInformation;
- }
- static void DeleteEmployeeInformation(ref string[] informationAboutEmployee, int indexOfEmployee)
- {
- string[] tempArrayInformation = new string[informationAboutEmployee.Length - 1];
- for (int i = 0; i < indexOfEmployee; i++)
- {
- tempArrayInformation[i] = informationAboutEmployee[i];
- }
- for (int i = indexOfEmployee + 1; i < informationAboutEmployee.Length; i++)
- {
- tempArrayInformation[i - 1] = informationAboutEmployee[i];
- }
- informationAboutEmployee = tempArrayInformation;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement