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 ConsoleApp1
- {
- class Program
- {
- /*Метод - ПОЛУЧИТЬ ТЕКУЩЕЕ ДОСЬЕ
- *Аргументов - нет.
- *Возвращает:
- *string [] dossier - одномерный массив строк
- *С индексами:
- * 0 - Фамилия
- * 1 - Имя Отчество
- * 2 - Номер должности
- */
- static string [] GetCurrentDossier()
- {
- string [] dossier = new string[3];
- Console.WriteLine("Введите фамилию: ");
- dossier[0] = Console.ReadLine().ToLower();
- Console.WriteLine("Введите имя: ");
- dossier[1] = " " + Console.ReadLine();
- Console.WriteLine("Введите отчество: ");
- dossier[1] += " " + Console.ReadLine();
- Console.WriteLine("Выберите должность из списка\n" +
- "и введите цифру:\n" +
- "1) Региональный менеджер\n" +
- "2) Менеджер персонала\n" +
- "3) Экономист\n" +
- "4) Маркетолог");
- dossier[2] = Console.ReadLine();
- return dossier;
- }
- /*Метод - ЗАПИСАТЬ ИМЯ В БД
- *Аргументы:
- *string [,] fullName - двумерный массив со всеми именами,
- *string [] dossier - одномерный массив с текущим введеным сотрудником
- *Возвращает:
- *string [,] fullName - двумерный динамически увеличенный массив
- */
- static string [,] WriteNameDatabase(string [,] fullName, string [] dossier)
- {
- string[,] tempFullName = new string[fullName.GetLength(0) + 1, 3];
- for (int i = 0; i < fullName.GetLength(0); i++)
- {
- for (int j = 0; j < fullName.GetLength(1); j++)
- {
- tempFullName[i, j] = fullName[i, j];
- }
- }
- fullName = tempFullName;
- fullName[fullName.GetLength(0) - 1, 0] = dossier[0];
- fullName[fullName.GetLength(0) - 1, 1] = dossier[1];
- fullName[fullName.GetLength(0) - 1, 2] = dossier[2];
- return fullName;
- }
- /*Метод - ЗАПИСАТЬ ДОЛЖНОСТЬ В БД
- *Аргументы:
- *string [,] position - двумерный массив со всеми должностями,
- *string [] dossier - одномерный массив с текущим введеным сотрудником
- *Возвращает:
- *string [,] position - двумерный динамически увеличенный массив
- */
- static string[,] WritePositionDatabase(string[,] position, string[] dossier)
- {
- string[,] tempPosition = new string[4, position.GetLength(1) + 1];
- for (int i = 0; i < position.GetLength(0); i++)
- {
- for (int j = 0; j < position.GetLength(1); j++)
- {
- tempPosition[i, j] = position[i, j];
- }
- }
- position = tempPosition;
- position[Convert.ToInt32(dossier[2])-1, position.GetLength(1) - 1] = dossier[0];
- return position;
- }
- /*Метод - ВЫВЕСТИ В КОНСОЛЬ ВСЕ ДОСЬЕ
- *Аргументы:
- *string [,] fullName - двумерный массив со всеми именами,
- *string [,] position - двумерный массив со всеми должностями,
- *Ничего не возвращает.
- */
- static void WriteAllDossier(string [,] fullName, string [,] position)
- {
- for (int i = 0; i < fullName.GetLength(0); i++)
- {
- Console.WriteLine($"Досье №{i + 1} ФИО - {CapitalizationSurname(fullName[i, 0]) + fullName[i, 1]} должность - {position[Convert.ToInt32(fullName[i, 2]) - 1, 0]}");
- }
- }
- /*Метод - УДАЛИТЬ ДОСЬЕ
- *Аргументы:
- *string [,] fullName - двумерный массив со всеми именами,
- *int numberDossier - номер пользователя которого нужно удалить,
- *Возвращает:
- *string [,] tempFullName - двумерный динамически уменьшенный массив
- */
- static string [,] DeleteDossier(string [,] fullName, int numberDossier)
- {
- string currentValue;
- fullName[numberDossier - 1, 0] = "";
- fullName[numberDossier - 1, 1] = "";
- fullName[numberDossier - 1, 2] = "";
- for (int i = 0; i < fullName.GetLength(0); i++)
- {
- for (int j = 0; j < fullName.GetLength(1); j++)
- {
- if (fullName[i, j] == "")
- {
- currentValue = fullName[i, j];
- if (i + 1 < fullName.GetLength(0))
- {
- fullName[i, j] = fullName[i + 1, j];
- fullName[i + 1, j] = currentValue;
- }
- }
- }
- }
- string[,] tempFullName = new string[fullName.GetLength(0) - 1, 3];
- for (int i = 0; i < fullName.GetLength(0) - 1; i++)
- {
- for (int j = 0; j < fullName.GetLength(1); j++)
- {
- tempFullName[i, j] = fullName[i, j];
- }
- }
- return tempFullName;
- }
- /*Метод - УДАЛИТЬ ИЗ СПИСКА ДОЛЖНОСТЕЙ
- *Аргументы:
- *string [,] position - двумерный массив со всеми именами,
- *int numberDossier - номер пользователя которого нужно удалить,
- *Возвращает:
- *string [,] tempPosition - двумерный динамически уменьшенный массив
- */
- static string[,] DeletePosition(string[,] position, int numberDossier)
- {
- for (int i = 0; i < position.GetLength(0); i++)
- {
- for (int j = 0; j < position.GetLength(1); j++)
- {
- if (position[i, j] == "")
- {
- if (j + 1 < position.GetLength(1))
- {
- position[i, j] = position[i, j + 1];
- position[i, j + 1] = "";
- }
- }
- }
- }
- string[,] tempPosition = new string[4, position.GetLength(1) - 1];
- for (int i = 0; i < position.GetLength(0); i++)
- {
- for (int j = 0; j < position.GetLength(1) - 1; j++)
- {
- tempPosition[i, j] = position[i, j];
- }
- }
- return tempPosition;
- }
- /*Метод - НАЙТИ ДОСЬЕ ПО ФАМИЛИИ
- *Аргументы:
- *string [,] fullName - двумерный массив со всеми именами,
- *string [,] position - двумерный массив со всеми должностями,
- *Ничего не возвращает.
- */
- static void SearchName(string [,] fullName, string [,] position)
- {
- string searchName;
- string name = "";
- Console.WriteLine("Введите фамилию которую нужно найти");
- searchName = Console.ReadLine().ToLower();
- for (int i = 0; i < fullName.GetLength(0); i++)
- {
- if (fullName[i, 0] == searchName)
- {
- Console.WriteLine($"Досье №{i + 1} ФИО - {CapitalizationSurname(fullName[i, 0]) + fullName[i, 1]} должность - {position[Convert.ToInt32(fullName[i, 2]) - 1, 0]}");
- }
- }
- }
- /*Метод - ВЫВОД ФАМИЛИИ С ЗАГЛАВНОЙ БУКВЫ
- *Аргументы:
- *string name - строка с фамилией,
- *Возвращает:
- *string tempName - строка с фамилией с заглавной буквой
- */
- static string CapitalizationSurname(string name)
- {
- string tempName = "";
- for (int j = 0; j < name.Length; j++)
- {
- if (j == 0)
- {
- tempName += Convert.ToString(name[0]).ToUpper();
- }
- else
- {
- tempName += Convert.ToString(name[j]);
- }
- }
- return tempName;
- }
- static void Main(string[] args)
- {
- bool finish = true;
- string command;
- string[] dossier;
- int numberDossier;
- string[,] fullName = new string[0,3];
- /*Индексы: fullName
- * 0 - номер по порядку
- * ...
- * 1 - Данные сотрудников: *
- 0 - Фамилия
- 1 - Имя Отчество
- 2 - Код должности
- */
- string[,] position = new string[4, 1];
- /*Индексы: position
- * 0 - Наименования должностей
- * 0 - Региональный менеджер
- * 1 - Менеджер персонала
- * 2 - Экономист
- * 3 - Маркетолог
- * 1 - Фамилии сотрудников
- * ...
- */
- position[0, 0] = "Региональный менеджер";
- position[1, 0] = "Менеджер персонала";
- position[2, 0] = "Экономист";
- position[3, 0] = "Маркетолог";
- while (finish)
- {
- Console.Clear();
- Console.WriteLine("1) Добавить досье.\n" +
- "2) Вывести все досье\n" +
- "3) Удалить досье\n" +
- "4) Поиск по фамилии \n" +
- "5) Выход");
- command = Console.ReadLine();
- switch (command)
- {
- case "1":
- dossier = GetCurrentDossier();
- fullName = WriteNameDatabase(fullName, dossier);
- position = WritePositionDatabase(position, dossier);
- break;
- case "2":
- WriteAllDossier(fullName, position);
- Console.ReadKey();
- break;
- case "3":
- WriteAllDossier(fullName, position);
- Console.WriteLine("Введите номер досье который хотите удалить:");
- numberDossier = Convert.ToInt32(Console.ReadLine());
- position[Convert.ToInt32(fullName[numberDossier - 1, 2]), numberDossier] = "";
- position = DeletePosition(position, numberDossier);
- fullName = DeleteDossier(fullName, numberDossier);
- break;
- case "4":
- SearchName(fullName, position);
- Console.ReadKey();
- break;
- case "5":
- finish = false;
- break;
- default:
- Console.WriteLine("Неверная комманда");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement