Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLight
- {
- internal class Program
- {
- static void Main()
- {
- const string CommandAddDossier = "1";
- const string CommandDeduceDossiers = "2";
- const string CommandDeleteDossier = "3";
- const string CommandSearchLastName = "4";
- const string CommandExit = "5";
- string[] fullNames = new string[0];
- string[] posts = new string[0];
- bool isWork = true;
- Console.CursorVisible = false;
- while (isWork)
- {
- Console.WriteLine("Меню команд:");
- Console.SetCursorPosition(0, 2);
- Console.WriteLine(CommandAddDossier + " - Добавить досье");
- Console.WriteLine(CommandDeduceDossiers + " - Вывести все досье");
- Console.WriteLine(CommandDeleteDossier + " - Удалить досье");
- Console.WriteLine(CommandSearchLastName + " - Поиск по фамилии");
- Console.WriteLine(CommandExit + " - Выход");
- Console.SetCursorPosition(0, 8);
- Console.Write("Введите команду: ");
- switch (Console.ReadLine())
- {
- case CommandAddDossier:
- FillDossier(ref fullNames, ref posts);
- break;
- case CommandDeduceDossiers:
- ShowDossier(fullNames, posts);
- break;
- case CommandDeleteDossier:
- DeleteDossier(ref fullNames, ref posts);
- break;
- case CommandSearchLastName:
- FindLastName(fullNames, posts);
- break;
- case CommandExit:
- isWork = false;
- break;
- default:
- Console.WriteLine("\nОшибка. Введена неверная команда...");
- break;
- }
- Console.ReadKey(true);
- Console.Clear();
- }
- }
- static void FillDossier(ref string[] fullNames, ref string[] posts)
- {
- Console.Write("\nВведите ФИО: ");
- fullNames = AddData(fullNames);
- Console.Write("\nВведите должность: ");
- posts = AddData(posts);
- }
- static void ShowDossier(string[] fullNames, string[] posts)
- {
- int sequenceNumber = 1;
- if (fullNames.Length == 0)
- {
- Console.WriteLine("\nНа данный момент у вас нет ни одного досье.");
- }
- else
- {
- for (int i = 0; i < fullNames.Length; i++)
- {
- Console.WriteLine($"\n| {sequenceNumber++}. {fullNames[i]} - {posts[i]} |");
- }
- }
- }
- static void DeleteDossier(ref string[] fullNames, ref string[] posts)
- {
- int deletedNumber;
- Console.Write("\nВведите номер досье на удаление: ");
- deletedNumber = ReadInt() - 1;
- if (deletedNumber < 0 || fullNames.Length == 0 || deletedNumber + 1 > fullNames.Length)
- {
- Console.WriteLine("\nТакого номера нет.");
- }
- else
- {
- fullNames = DeleteElement(fullNames, deletedNumber);
- posts = DeleteElement(posts, deletedNumber);
- }
- }
- static void FindLastName(string[] fullNames, string[] posts)
- {
- string[] lastName;
- string lastNameInput;
- bool isFound = false;
- Console.Write("\nВведите фамилию: ");
- lastNameInput = Console.ReadLine();
- for (int i = 0; i < fullNames.Length; i++)
- {
- lastName = fullNames[i].Split(' ');
- if (lastName[0].ToLower() == lastNameInput.ToLower())
- {
- Console.WriteLine($"\n| {fullNames[i]} - {posts[i]} |");
- isFound = true;
- }
- }
- if (isFound == false)
- {
- Console.WriteLine("\nТакой фамилии нет.");
- }
- }
- static string[] AddData(string[] array)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- array = tempArray;
- array[array.Length - 1] = Console.ReadLine();
- return array;
- }
- static string[] DeleteElement(string[] array, int index)
- {
- string[] tempArray = array;
- array = new string[tempArray.Length - 1];
- for (int i = 0; i < array.Length; i++)
- {
- if (i == index || index < i)
- {
- array[i] = tempArray[i + 1];
- }
- else
- {
- array[i] = tempArray[i];
- }
- }
- return array;
- }
- static int ReadInt()
- {
- int number = 0;
- while (int.TryParse(Console.ReadLine(), out number) == false)
- {
- Console.WriteLine("\nВведите число.\n");
- }
- return number;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement