Advertisement
illiden

Docs

Dec 8th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.87 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 Docs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[,] names = new string[0, 3];
  14.             string[] posts = new string[0];
  15.             bool exit = false;
  16.             string inputComand = "";
  17.  
  18.             while (!exit)
  19.             {
  20.                 Console.Clear();
  21.                 Console.WriteLine("Кадровый учет. Меню:\n\n" +
  22.                                 "1. Добавить досье\n\n" +
  23.                                 "2. Вывести все досье\n\n" +
  24.                                 "3. Удалить досье\n\n" +
  25.                                 "4. Поиск по фамилии\n\n" +
  26.                                 "5. Выход\n");
  27.                 Console.Write("Введите номер команды: ");
  28.  
  29.                 switch (Console.ReadLine())
  30.                 {
  31.                     case "1":
  32.                         Console.Write("\nВведите ФИО через пробел: ");
  33.                         string fio = Console.ReadLine() + " ";
  34.                         Console.Write("Введите должность: ");
  35.                         string post = Console.ReadLine();
  36.                         AddDoc(ref names, ref posts, fio, post);
  37.                         break;
  38.                     case "2":
  39.                         ShowDoc(names, posts);
  40.                         break;
  41.                     case "3":
  42.                         Console.Write("\nВведите номер удаляемого досье: ");
  43.                         int deleteNumber = Convert.ToInt32(Console.ReadLine()) - 1;
  44.                         DeleteDoc(ref names, ref posts, deleteNumber);
  45.                         break;
  46.                     case "4":
  47.                         Console.Write("\nВведите фамилиию: ");
  48.                         string surname = Console.ReadLine();
  49.                         Search(ref names, ref posts, surname);
  50.                         break;
  51.                     case "5":
  52.                         exit = true;
  53.                         break;
  54.                     default:
  55.                         Console.WriteLine("\nТакой команды не существует");
  56.                         Console.ReadKey();
  57.                         break;
  58.                 }
  59.             }
  60.  
  61.             static void AddDoc(ref string[,] fio, ref string[] position, string newFio, string newPosition)
  62.             {
  63.                 string[,] addFio = new string[fio.GetLength(0) + 1, 3]; // новый массив имен на 1 место больший
  64.                 string[] addPosition = new string[position.GetLength(0) + 1]; // новый массив должностей на 1 больший
  65.                 string name = ""; // для записи разделенного ФИО
  66.                 string[] newFioArray = new string[3]; // для хранения одной пизиции  ФИО (полученная при вводе)
  67.                
  68.                 for (int i = 0; i < 2;) // цикл для разделения ФИО и запись в отдельный массив
  69.                 {
  70.                     for (int j = 0; j < newFio.Length; j++)
  71.                     {
  72.                         if (Convert.ToString(newFio[j]) == " " && j == 0)
  73.                         {
  74.                             continue;
  75.                         }
  76.                         if (Convert.ToString(newFio[j]) == " " && Convert.ToString(newFio[j - 1]) == " ")
  77.                         {
  78.                             continue;
  79.                         }
  80.                         if (Convert.ToString(newFio[j]) == " ")
  81.                         {
  82.                             newFioArray[i++] = name;
  83.                             name = "";
  84.                         }
  85.                         else
  86.                         {
  87.                             name += newFio[j];
  88.                         }
  89.                     }
  90.                 }
  91.                 for (int i = 0; i < fio.GetLength(0); i++) // цикл записи старых маленьких массивов в новые большие
  92.                 {
  93.                     for (int j = 0; j < 3; j++)
  94.                     {
  95.                         addFio[i, j] = fio[i, j];
  96.                     }
  97.                     addPosition[i] = position[i];
  98.                 }
  99.                 for (int i = 0; i < 3; i++) // цикл записи новой ячейки ФИО
  100.                 {
  101.                     addFio[addFio.GetLength(0) - 1, i] = newFioArray[i];
  102.                 }
  103.  
  104.                 addPosition[addPosition.Length - 1] = newPosition; // запись новой ячейки должности
  105.                 fio = addFio; // вывод старого массива с сылкой на новый для ФИО
  106.                 position = addPosition; // вывод старого массива с сылкой на новый для должности
  107.             }
  108.  
  109.             static void ShowDoc(string[,] fio, string[] position)
  110.             {
  111.                 string output = "";
  112.                 for (int i = 0; i < position.Length; i++)
  113.                 {
  114.                     output += Convert.ToString(i + 1) + ". ";
  115.                     for (int j = 0; j < 3; j++)
  116.                     {
  117.                         output += fio[i, j] + " ";
  118.                     }
  119.                     output += "- " + position[i] + "\n";
  120.                 }
  121.                 Console.WriteLine(output);
  122.                 Console.ReadKey();
  123.             }
  124.  
  125.             static void DeleteDoc(ref string[,] fio, ref string[] position, int deleteDocIndex)
  126.             {
  127.                 if (fio.GetLength(0) < deleteDocIndex)
  128.                 {
  129.                     Console.WriteLine("\nДосье под таким номером не существует");
  130.                     Console.ReadKey();
  131.                     return;
  132.                 }
  133.                 else
  134.                 {
  135.                     string[,] newFio = new string[fio.GetLength(0) - 1, 3];
  136.                     string[] newPosts = new string[position.GetLength(0) - 1];
  137.                     int index = 0;
  138.  
  139.                     for (int i = 0; i < newFio.GetLength(0); i++)
  140.                     {
  141.                         if (i == deleteDocIndex)
  142.                         {
  143.                             index++;
  144.                         }
  145.  
  146.                         for (int j = 0; j < 3; j++)
  147.                         {
  148.                             newFio[i, j] = fio[index, j];
  149.                         }
  150.                         newPosts[i] = position[index];
  151.                         index++;
  152.                     }
  153.                     fio = newFio;
  154.                     position = newPosts;
  155.                 }
  156.             }
  157.  
  158.             static void Search(ref string[,] fio, ref string[] position, string searchWord)
  159.             {
  160.                 string output = "";  
  161.                 for (int i = 0; i < position.Length; i++)
  162.                 {
  163.                     if (fio[i, 0].ToLower() == searchWord.ToLower())
  164.                     {
  165.                         output += Convert.ToString(i + 1) + ". ";
  166.                         for (int j = 0; j < 3; j++)
  167.                         {
  168.                             output += fio[i, j] + " ";
  169.                         }
  170.                         output += "- " + position[i];
  171.                         break;
  172.                     }
  173.                     if (fio[i, 0].ToLower() != searchWord.ToLower() && i == position.Length)
  174.                     {
  175.                         Console.WriteLine("\nФамилия не найдена");
  176.                     }
  177.                 }
  178.                 Console.WriteLine(output);
  179.                 Console.ReadKey();
  180.             }
  181.         }
  182.     }
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement