Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Task1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.SetWindowSize(100, 55);
- string[] fullNames = new string[0];
- string[] posts = new string[0];
- string[] fullNamesStaff = new string[]
- {
- "Колесников Андрей Викторович",
- "Кондратьев Владимир Сергеевич",
- "Соловьёв Михаил Юрьевич",
- "Максимов Александр Константинович",
- "Петров Илья Валерьеви"
- };
- string[] postsStaff = new string[]
- {
- "CEO",
- "Project Manager",
- "Middle developer",
- "Junior developer",
- "QA tester"
- };
- int searchLastName = 0;
- int searchFirstName = 1;
- int searchMiddleName = 2;
- string command = "";
- while (command != "/exit")
- {
- Console.WriteLine("Меню. Выберите команду");
- Console.WriteLine("/add - добавить досье\n/addstaff - добавить штатных сотрудников" +
- "\n/remove - удалить досье\n/show - вывести все досье" +
- "\n/search - поиск досье по фамилии\n/exit - выход из программы");
- command = Console.ReadLine().ToLower();
- if (command == "/add")
- {
- Console.WriteLine("Введите ФИО:");
- string fullName = Console.ReadLine();
- Console.WriteLine($"Введите должность сотрудника: {fullName}");
- string post = Console.ReadLine();
- fullNames = Add(fullNames, fullName);
- posts = Add(posts, post);
- Console.Clear();
- ShowMessage("Досье успешно добавлено", ConsoleColor.Green);
- }
- else if (command == "/addstaff")
- {
- Console.Clear();
- ShowMessage("Штатные сотрудники добавленны", ConsoleColor.Green);
- fullNames = Add(fullNames, fullNamesStaff);
- posts = Add(posts, postsStaff);
- }
- else if (command == "/remove")
- {
- Console.WriteLine("Введите номер досье который хотите удалить");
- int removable = Convert.ToInt32(Console.ReadLine());
- fullNames = Remove(fullNames, removable);
- posts = Remove(posts, removable);
- Console.Clear();
- ShowMessage("Досье удалено", ConsoleColor.Green);
- }
- else if (command == "/show")
- {
- Console.Clear();
- if (fullNames.Length != 0)
- ShowAll(fullNames, posts);
- else
- ShowMessage("Список досье пуст", ConsoleColor.Red);
- }
- else if (command == "/search")
- {
- int foundIndex = -1;
- string element;
- Console.WriteLine("По какому критерию искать?");
- Console.WriteLine("/lastname - по фамилии\n/firstname - по имени\n/middlename - по отчеству");
- command = Console.ReadLine();
- if (command == "/lastname")
- {
- Console.WriteLine("Введите фамилию для поиска:");
- element = Console.ReadLine();
- foundIndex = Search(fullNames, element, searchLastName);
- }
- else if (command == "/firstname")
- {
- Console.WriteLine("Введите имя для поиска:");
- element = Console.ReadLine();
- foundIndex = Search(fullNames, element, searchFirstName);
- }
- else if (command == "/middlename")
- {
- Console.WriteLine("Введите отчество для поиска:");
- element = Console.ReadLine();
- foundIndex = Search(fullNames, element, searchMiddleName);
- }
- Console.Clear();
- if (foundIndex != -1)
- {
- ShowDocument(fullNames, posts, foundIndex);
- ShowMessage("Досье успешно найдено", ConsoleColor.Green);
- }
- else
- ShowMessage("Досье не найдено", ConsoleColor.Red);
- }
- else
- {
- Console.Clear();
- ShowMessage("Такой команды нет", ConsoleColor.Red);
- }
- }
- }
- //------------------------------------------------------------------------------------------------------
- static string[] Add(string[] array, string addedElement)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = addedElement;
- return tempArray;
- }
- static string[] Add(string[] array, string[] addedArray)
- {
- string[] tempArray = new string[array.Length + addedArray.Length];
- int tempIndex = 0;
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- tempIndex = i + 1;
- }
- for (int i = 0; i < addedArray.Length; i++)
- {
- tempArray[tempIndex + i] = addedArray[i];
- }
- return tempArray;
- }
- static string[] Remove(string[] array, int removable)
- {
- string[] tempArray = new string[array.Length - 1];
- int tempIndex = 0;
- for (int i = 0; i < array.Length - 1; i++)
- {
- if (i != removable - 1)
- {
- tempArray[i] = array[i];
- }
- else
- {
- tempIndex = i;
- break;
- }
- }
- for (int i = tempIndex; i < array.Length - 1; i++)
- {
- tempArray[i] = array[i + 1];
- }
- return tempArray;
- }
- static int Search(string[] array, string element, int criteria)
- {
- int index = -1;
- for (int i = 0; i < array.Length; i++)
- {
- string[] splitName = array[i].Split(' ');
- if (element == splitName[criteria])
- {
- index = i;
- }
- }
- return index;
- }
- static void ShowAll(string[] fullNames, string[] posts, int left = 0, int top = 16)
- {
- Console.SetCursorPosition(left, top);
- Console.ForegroundColor = ConsoleColor.Yellow;
- if (fullNames.Length == posts.Length)
- {
- for (int i = 0; i < fullNames.Length; i++)
- {
- Console.WriteLine($"{i + 1}. {fullNames[i]} - {posts[i]}");
- }
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Кол-во ФИО и должностей должны быть одинаковыми!");
- Console.ResetColor();
- }
- Console.ResetColor();
- Console.SetCursorPosition(0, 0);
- }
- static void ShowDocument(string[] fullNames, string[] posts, int index, int left = 0, int top = 16)
- {
- string[] fullNamesSplit = fullNames[index].Split();
- Console.SetCursorPosition(left, top);
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"Фамилия: {fullNamesSplit[0]}");
- Console.WriteLine($"Имя: {fullNamesSplit[1]}");
- Console.WriteLine($"Отчество: {fullNamesSplit[2]}");
- Console.WriteLine($"Должность: {posts[index]}");
- Console.ResetColor();
- Console.SetCursorPosition(0, 0);
- }
- static void ShowMessage(string message, ConsoleColor color, int left = 0, int top = 14)
- {
- Console.SetCursorPosition(left, top);
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ResetColor();
- Console.SetCursorPosition(0, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement