Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace CSLight
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = false;
- int menuBar = 0;
- string[] menu = { "1. Добавить досье.", "2. Вывести досье.", "3. Удалить досье.", "4. Поиск по фамилии.", "5. Выход." };
- string[] fullNames = { "Иванов Иван Иванович", "Шевцов Глеб Егорыч" };
- string[] positions = { "Директор", "Коллектор" };
- Console.CursorVisible = false;
- while (exit == false)
- {
- string selectMenuItems;
- DrawMenu(menuBar, menu);
- ChangeDirection(ref menuBar, menu, out selectMenuItems);
- Console.Clear();
- switch (selectMenuItems)
- {
- case "1. Добавить досье.":
- string newWorker, positonWorker;
- DrawLabels("Ведите ФИО нового сотрудника:", 0, 0);
- newWorker = Console.ReadLine();
- AddANewDossier(ref fullNames, newWorker);
- DrawLabels("Ведите должность сотрудника:", 1, 0);
- positonWorker = Console.ReadLine();
- AddANewDossier(ref positions, positonWorker);
- Console.Clear();
- break;
- case "2. Вывести досье.":
- DrawaAllDossier(fullNames, positions);
- break;
- case "3. Удалить досье.":
- int dossierNumber;
- Console.Clear();
- if (CheckDossierNumber(out dossierNumber, fullNames, positions))
- {
- RemoveADossierFromTheList(ref fullNames, dossierNumber);
- RemoveADossierFromTheList(ref positions, dossierNumber);
- }
- Console.SetCursorPosition(20, 20);
- break;
- case "4. Поиск по фамилии.":
- string command;
- DrawLabels("Введите фамилию:", 0, 0);
- command = Console.ReadLine();
- SearchSurname(fullNames, positions, command);
- break;
- case "5. Выход.":
- exit = true;
- break;
- }
- }
- }
- static bool CheckDossierNumber(out int dossierNumber, string [] fullNames, string[] positions)
- {
- dossierNumber = 0;
- if (fullNames.Length == 0)
- {
- DrawLabels("Нет досье в списке.");
- return false;
- }
- else
- {
- DrawaAllDossier(fullNames, positions);;
- DrawLabels("Досье для удаления:", 0, 0);
- dossierNumber = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- if (dossierNumber > fullNames.Length || dossierNumber <= 0)
- {
- DrawLabels("Нет досье с таким номером");
- return false;
- }
- else
- {
- return true;
- }
- }
- }
- static void DrawLabels(string text, int x = 0, int y = 30)
- {
- Console.SetCursorPosition(y, x);
- Console.Write(text);
- }
- static void SearchSurname(string[] fullNames, string[] positions, string command)
- {
- int hitCoincidence = 0;
- for (int i = 0; i < fullNames.Length; i++)
- {
- if (fullNames[i].StartsWith(command))
- {
- Console.SetCursorPosition(30, i);
- Console.WriteLine($"{i + 1}) {fullNames[i]} - {positions[i]}");
- hitCoincidence++;
- }
- }
- if (hitCoincidence == 0)
- {
- DrawLabels("Cовпадений нет.");
- }
- }
- static void AddANewDossier(ref string[] fullNames, string value)
- {
- string[] temp = new string[fullNames.Length + 1];
- for (int i = 0; i < fullNames.Length; i++)
- {
- temp[i] = fullNames[i];
- }
- temp[temp.Length - 1] = value;
- fullNames = temp;
- }
- static void RemoveADossierFromTheList(ref string[] fullNames, int value)
- {
- string[] temp = new string[fullNames.Length - 1];
- for(int i = 0; i < value - 1; i++)
- {
- temp[i] = fullNames[i];
- }
- for(int i = value - 1; i < temp.Length; i++)
- {
- temp[i] = fullNames[i];
- }
- fullNames = temp;
- }
- static void DrawaAllDossier(string[] fullNames, string[] positions)
- {
- if (fullNames.Length == 0)
- {
- DrawLabels("Нет досье в списке.");
- }
- else
- {
- for (int i = 0; i < fullNames.Length; i++)
- {
- Console.SetCursorPosition(30, i);
- Console.WriteLine($"{i + 1}) {fullNames[i]} - {positions[i]}");
- }
- }
- }
- static void DrawMenu(int menuBar, string[] items)
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < items.Length; i++)
- {
- if (i == menuBar)
- {
- Console.BackgroundColor = ConsoleColor.Gray;
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine(items[i]);
- }
- else
- {
- Console.WriteLine(items[i]);
- }
- Console.ResetColor();
- }
- }
- static string GetChoise(string[] items, int menuBar)
- {
- return items[menuBar];
- }
- static void ChangeDirection(ref int menuBar, string[] items, out string selectMenuItems)
- {
- selectMenuItems = "";
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- if (menuBar <= 0)
- {
- menuBar = items.Length - 1;
- DrawMenu(menuBar, items);
- }
- else
- {
- menuBar--;
- DrawMenu(menuBar, items);
- }
- break;
- case ConsoleKey.DownArrow:
- if (menuBar == items.Length - 1)
- {
- menuBar = 0;
- DrawMenu(menuBar, items);
- }
- else
- {
- menuBar++;
- DrawMenu(menuBar, items);
- }
- break;
- case ConsoleKey.Enter:
- {
- selectMenuItems = GetChoise(items, menuBar);
- }
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment