Skip to content

Instantly share code, notes, and snippets.

@kyzalex
Last active April 2, 2024 16:36
Show Gist options
  • Save kyzalex/fee2314bb244fb9cc9a44cb92565f6c3 to your computer and use it in GitHub Desktop.
Save kyzalex/fee2314bb244fb9cc9a44cb92565f6c3 to your computer and use it in GitHub Desktop.
Кадровый учет
internal class Program
{
static void Main(string[] args)
{
const string CommandAddDossier = "1";
const string CommandPrintDossier = "2";
const string CommandDelleteDossier = "3";
const string CommandSearchByFamily = "4";
const string CommandExitProgram = "5";
string selectedAction;
bool isOpen = true;
string[] names = new string[0];
string[] posts = new string[0];
while (isOpen)
{
Console.Clear();
Console.WriteLine($"Вас приветствует кадровый учет, выберете действие : ");
Console.WriteLine($"{CommandAddDossier} Добавить досье");
Console.WriteLine($"{CommandPrintDossier} Вывести досье");
Console.WriteLine($"{CommandDelleteDossier} Удалить досье");
Console.WriteLine($"{CommandSearchByFamily} Найти досье по фамилии");
Console.WriteLine($"{CommandExitProgram} Выход из программы");
Console.Write("Ваш выбор :");
selectedAction = Console.ReadLine();
switch (selectedAction)
{
case CommandAddDossier:
AddDossier(ref names, ref posts);
break;
case CommandPrintDossier:
PrintDossier(posts, names);
break;
case CommandDelleteDossier:
DeleteDossier(ref names, ref posts);
break;
case CommandSearchByFamily:
SearchDossier(names, posts);
break;
case CommandExitProgram:
isOpen = false;
break;
default:
Console.WriteLine("Вы нажали неведому кнопку!");
break;
}
Console.Write("Нажмите любую кнопку для того чтобы продолжить...");
Console.ReadKey();
}
}
static void AddDossier(ref string[] names, ref string[] post)
{
Console.WriteLine("Введите ФИО сотрудника");
string name = Console.ReadLine();
Console.WriteLine("Введите должность сотрудника");
string position = Console.ReadLine();
names = WriteToDossier(names, name);
post = WriteToDossier(post, position);
}
static string[] WriteToDossier(string[] array, string text)
{
string[] tempNumbers = new string[array.Length + 1];
for (int i = 0; i < array.Length; i++)
{
tempNumbers[i] = array[i];
}
tempNumbers[tempNumbers.Length - 1] = text;
array = tempNumbers;
return array;
}
static void PrintDossier(string[] post, string[] names)
{
int index = 1;
for (int i = 0; i < post.Length; i++)
{
Console.WriteLine($" Индекс [ {index} ] | ФИО : {names[i]} | должность : {post[i]}");
index++;
}
}
static void DeleteDossier(ref string[] fullNames, ref string[] post)
{
Console.Write("Введите номер досье :");
int number = int.Parse(Console.ReadLine());
if (number > 0 && number <= fullNames.Length)
{
int index = number - 1;
fullNames = DecreaseArray(fullNames, index);
post = DecreaseArray(post, index);
Console.WriteLine($"Досье с индексом [ {number} ] удалино!!!");
}
else
{
Console.WriteLine("Досье с таким номером не существует!!!");
}
}
static string[] DecreaseArray(string[] array, int index)
{
string[] temporaryArray = new string[array.Length - 1];
for (int i = 0; i < index; i++)
{
temporaryArray[i] = array[i];
}
for (int i = index; i < array.Length - 1; i++)
{
temporaryArray[i] = array[i + 1];
}
array = temporaryArray;
return array;
}
static void SearchDossier(string[] fullNames, string[] post)
{
Console.WriteLine("Введите фамилию для поиска досье");
string surname = Console.ReadLine();
bool isSuccessfulSearch = false;
for (int i = 0; i < fullNames.Length; i++)
{
if (fullNames[0].ToLower() == surname.ToLower())
{
Console.WriteLine($"Индекс [ {i + 1} ] | ФИО : {fullNames[i]} | должность : {post[i]}");
isSuccessfulSearch = true;
}
}
if (isSuccessfulSearch == false)
{
Console.WriteLine($"Досье сотрудников с фамилией '{surname}' не найдено!!!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment