Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         /*Метод - ПОЛУЧИТЬ ТЕКУЩЕЕ ДОСЬЕ
  12.          *Аргументов - нет.
  13.          *Возвращает:
  14.          *string [] dossier - одномерный массив строк
  15.          *С индексами:
  16.          *          0 - Фамилия
  17.          *          1 - Имя Отчество
  18.          *          2 - Номер должности  
  19.          */
  20.         static string [] GetCurrentDossier()
  21.         {
  22.             string [] dossier = new string[3];        
  23.            
  24.             Console.WriteLine("Введите фамилию: ");
  25.             dossier[0] = Console.ReadLine().ToLower();
  26.             Console.WriteLine("Введите имя: ");
  27.             dossier[1] = " " + Console.ReadLine();
  28.             Console.WriteLine("Введите отчество: ");
  29.             dossier[1] += " " + Console.ReadLine();
  30.            
  31.             Console.WriteLine("Выберите должность из списка\n" +
  32.                 "и введите цифру:\n" +
  33.                 "1) Региональный менеджер\n" +
  34.                 "2) Менеджер персонала\n" +
  35.                 "3) Экономист\n" +
  36.                 "4) Маркетолог");
  37.             dossier[2] = Console.ReadLine();
  38.  
  39.             return dossier;
  40.         }
  41.  
  42.         /*Метод - ЗАПИСАТЬ ИМЯ В БД
  43.          *Аргументы:
  44.          *string [,] fullName - двумерный массив со всеми именами,
  45.          *string [] dossier   - одномерный массив с текущим введеным сотрудником
  46.          *Возвращает:
  47.          *string [,] fullName - двумерный динамически увеличенный массив
  48.          */
  49.         static string [,] WriteNameDatabase(string [,] fullName, string [] dossier)
  50.         {
  51.             string[,] tempFullName = new string[fullName.GetLength(0) + 1, 3];
  52.             for (int i = 0; i < fullName.GetLength(0); i++)
  53.             {
  54.                 for (int j = 0; j < fullName.GetLength(1); j++)
  55.                 {
  56.                     tempFullName[i, j] = fullName[i, j];
  57.                 }
  58.  
  59.             }
  60.  
  61.             fullName = tempFullName;
  62.  
  63.             fullName[fullName.GetLength(0) - 1, 0] = dossier[0];
  64.             fullName[fullName.GetLength(0) - 1, 1] = dossier[1];
  65.             fullName[fullName.GetLength(0) - 1, 2] = dossier[2];
  66.             return fullName;
  67.         }
  68.  
  69.         /*Метод - ЗАПИСАТЬ ДОЛЖНОСТЬ В БД
  70.          *Аргументы:
  71.          *string [,] position - двумерный массив со всеми должностями,
  72.          *string [] dossier   - одномерный массив с текущим введеным сотрудником
  73.          *Возвращает:
  74.          *string [,] position - двумерный динамически увеличенный массив
  75.          */
  76.         static string[,] WritePositionDatabase(string[,] position, string[] dossier)
  77.         {
  78.             string[,] tempPosition = new string[4, position.GetLength(1) + 1];
  79.  
  80.             for (int i = 0; i < position.GetLength(0); i++)
  81.             {
  82.                 for (int j = 0; j < position.GetLength(1); j++)
  83.                 {
  84.                     tempPosition[i, j] = position[i, j];
  85.                 }
  86.             }
  87.  
  88.             position = tempPosition;
  89.  
  90.             position[Convert.ToInt32(dossier[2])-1, position.GetLength(1) - 1] = dossier[0];
  91.             return position;
  92.         }
  93.  
  94.         /*Метод - ВЫВЕСТИ В КОНСОЛЬ ВСЕ ДОСЬЕ
  95.          *Аргументы:          
  96.          *string [,] fullName - двумерный массив со всеми именами,
  97.          *string [,] position - двумерный массив со всеми должностями,
  98.          *Ничего не возвращает.
  99.          */
  100.         static void WriteAllDossier(string [,] fullName, string [,] position)
  101.         {
  102.             for (int i = 0; i < fullName.GetLength(0); i++)
  103.             {
  104.                 Console.WriteLine($"Досье №{i + 1} ФИО - {CapitalizationSurname(fullName[i, 0]) + fullName[i, 1]} должность - {position[Convert.ToInt32(fullName[i, 2]) - 1, 0]}");
  105.                
  106.             }            
  107.         }
  108.  
  109.         /*Метод - УДАЛИТЬ ДОСЬЕ
  110.          *Аргументы:          
  111.          *string [,] fullName - двумерный массив со всеми именами,
  112.          *int numberDossier - номер пользователя которого нужно удалить,
  113.          *Возвращает:
  114.          *string [,] tempFullName - двумерный динамически уменьшенный массив
  115.          */
  116.         static string [,] DeleteDossier(string [,] fullName, int numberDossier)
  117.         {
  118.             string currentValue;
  119.            
  120.             fullName[numberDossier - 1, 0] = "";
  121.             fullName[numberDossier - 1, 1] = "";
  122.             fullName[numberDossier - 1, 2] = "";
  123.  
  124.             for (int i = 0; i < fullName.GetLength(0); i++)
  125.             {
  126.                 for (int j = 0; j < fullName.GetLength(1); j++)
  127.                 {
  128.                     if (fullName[i, j] == "")
  129.                     {
  130.                         currentValue = fullName[i, j];
  131.                         if (i + 1 < fullName.GetLength(0))
  132.                         {
  133.                             fullName[i, j] = fullName[i + 1, j];
  134.                             fullName[i + 1, j] = currentValue;
  135.                         }
  136.  
  137.                     }
  138.                 }
  139.             }
  140.  
  141.             string[,] tempFullName = new string[fullName.GetLength(0) - 1, 3];
  142.             for (int i = 0; i < fullName.GetLength(0) - 1; i++)
  143.             {
  144.                 for (int j = 0; j < fullName.GetLength(1); j++)
  145.                 {
  146.                     tempFullName[i, j] = fullName[i, j];
  147.                 }
  148.             }
  149.            
  150.             return tempFullName;
  151.         }
  152.  
  153.         /*Метод - УДАЛИТЬ ИЗ СПИСКА ДОЛЖНОСТЕЙ
  154.          *Аргументы:          
  155.          *string [,] position - двумерный массив со всеми именами,
  156.          *int numberDossier - номер пользователя которого нужно удалить,
  157.          *Возвращает:
  158.          *string [,] tempPosition - двумерный динамически уменьшенный массив
  159.          */
  160.         static string[,] DeletePosition(string[,] position, int numberDossier)
  161.         {
  162.             for (int i = 0; i < position.GetLength(0); i++)
  163.             {
  164.                 for (int j = 0; j < position.GetLength(1); j++)
  165.                 {
  166.                     if (position[i, j] == "")
  167.                     {
  168.                         if (j + 1 < position.GetLength(1))
  169.                         {
  170.                             position[i, j] = position[i, j + 1];
  171.                             position[i, j + 1] = "";
  172.                         }
  173.                     }
  174.                 }
  175.             }
  176.             string[,] tempPosition = new string[4, position.GetLength(1) - 1];
  177.             for (int i = 0; i < position.GetLength(0); i++)
  178.             {
  179.                 for (int j = 0; j < position.GetLength(1) - 1; j++)
  180.                 {
  181.  
  182.                     tempPosition[i, j] = position[i, j];
  183.  
  184.                 }
  185.             }
  186.             return tempPosition;
  187.         }
  188.  
  189.         /*Метод - НАЙТИ ДОСЬЕ ПО ФАМИЛИИ
  190.          *Аргументы:          
  191.          *string [,] fullName - двумерный массив со всеми именами,
  192.          *string [,] position - двумерный массив со всеми должностями,
  193.          *Ничего не возвращает.
  194.          */
  195.         static void SearchName(string [,] fullName, string [,] position)
  196.         {
  197.             string searchName;
  198.             string name = "";
  199.             Console.WriteLine("Введите фамилию которую нужно найти");
  200.             searchName = Console.ReadLine().ToLower();
  201.             for (int i = 0; i < fullName.GetLength(0); i++)
  202.             {
  203.                 if (fullName[i, 0] == searchName)
  204.                 {                    
  205.                     Console.WriteLine($"Досье №{i + 1} ФИО - {CapitalizationSurname(fullName[i, 0]) + fullName[i, 1]} должность - {position[Convert.ToInt32(fullName[i, 2]) - 1, 0]}");
  206.                 }
  207.             }
  208.         }
  209.  
  210.         /*Метод - ВЫВОД ФАМИЛИИ С ЗАГЛАВНОЙ БУКВЫ
  211.         *Аргументы:          
  212.         *string name - строка с фамилией,        
  213.         *Возвращает:
  214.         *string tempName - строка с фамилией с заглавной буквой
  215.         */
  216.         static string CapitalizationSurname(string name)
  217.         {
  218.             string tempName = "";
  219.             for (int j = 0; j < name.Length; j++)
  220.             {
  221.                 if (j == 0)
  222.                 {
  223.                     tempName += Convert.ToString(name[0]).ToUpper();
  224.                 }
  225.                 else
  226.                 {
  227.                     tempName += Convert.ToString(name[j]);
  228.                 }                
  229.             }
  230.             return tempName;
  231.         }
  232.  
  233.         static void Main(string[] args)
  234.         {
  235.             bool finish = true;
  236.             string command;
  237.             string[] dossier;
  238.             int numberDossier;
  239.  
  240.             string[,] fullName = new string[0,3];
  241.             /*Индексы: fullName
  242.              * 0 - номер по порядку
  243.              * ...
  244.              * 1 - Данные сотрудников:             *
  245.                     0 - Фамилия
  246.                     1 - Имя Отчество
  247.                     2 - Код должности                  
  248.  
  249.              */
  250.             string[,] position = new string[4, 1];
  251.             /*Индексы: position            
  252.              *   0 - Наименования должностей
  253.              *      0 - Региональный менеджер
  254.              *      1 - Менеджер персонала
  255.              *      2 - Экономист
  256.              *      3 - Маркетолог
  257.              *   1 - Фамилии сотрудников          
  258.              *   ...
  259.              */
  260.  
  261.             position[0, 0] = "Региональный менеджер";
  262.             position[1, 0] = "Менеджер персонала";
  263.             position[2, 0] = "Экономист";
  264.             position[3, 0] = "Маркетолог";          
  265.            
  266.             while (finish)
  267.             {
  268.                 Console.Clear();
  269.                 Console.WriteLine("1) Добавить досье.\n" +
  270.                 "2) Вывести все досье\n" +
  271.                 "3) Удалить досье\n" +
  272.                 "4) Поиск по фамилии \n" +
  273.                 "5) Выход");
  274.  
  275.                 command = Console.ReadLine();
  276.  
  277.                 switch (command)
  278.                 {
  279.                     case "1":
  280.                         dossier = GetCurrentDossier();
  281.                         fullName = WriteNameDatabase(fullName, dossier);
  282.                         position = WritePositionDatabase(position, dossier);                        
  283.                         break;
  284.  
  285.                     case "2":
  286.                         WriteAllDossier(fullName, position);
  287.                         Console.ReadKey();
  288.                         break;
  289.  
  290.                     case "3":                        
  291.                         WriteAllDossier(fullName, position);
  292.                         Console.WriteLine("Введите номер досье который хотите удалить:");                        
  293.                         numberDossier = Convert.ToInt32(Console.ReadLine());
  294.                         position[Convert.ToInt32(fullName[numberDossier - 1, 2]), numberDossier] = "";
  295.                         position = DeletePosition(position, numberDossier);
  296.                         fullName = DeleteDossier(fullName, numberDossier);
  297.                         break;
  298.  
  299.                     case "4":
  300.                         SearchName(fullName, position);
  301.                         Console.ReadKey();
  302.                         break;
  303.  
  304.                     case "5":
  305.                         finish = false;
  306.                         break;
  307.  
  308.                     default:
  309.                         Console.WriteLine("Неверная комманда");
  310.                         break;
  311.                 }
  312.             }          
  313.  
  314.         }
  315.     }
  316. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement