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