Advertisement
illiden

Docs v2

Dec 12th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.27 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];
  14.             string[] posts = new string[0];
  15.             bool exit = false;
  16.  
  17.             while (!exit)
  18.             {
  19.                 Console.Clear();
  20.                 Console.WriteLine("Кадровый учет. Меню:\n\n" +
  21.                                 "1. Добавить досье\n\n" +
  22.                                 "2. Вывести все досье\n\n" +
  23.                                 "3. Удалить досье\n\n" +
  24.                                 "4. Поиск по фамилии\n\n" +
  25.                                 "5. Выход\n");
  26.                 Console.Write("Введите номер команды: ");
  27.  
  28.                 switch (Console.ReadLine())
  29.                 {
  30.                     case "1":
  31.                         Console.Write("\nВведите ФИО через пробел: ");
  32.                         string fio = Console.ReadLine() + " ";
  33.                         Console.Write("Введите должность: ");
  34.                         string post = Console.ReadLine();
  35.                         AddDoc(ref names, ref posts, fio, post);
  36.                         break;
  37.                     case "2":
  38.                         ShowDoc(names, posts);
  39.                         break;
  40.                     case "3":
  41.                         Console.Write("\nВведите номер удаляемого досье: ");
  42.                         int deleteNumber = Convert.ToInt32(Console.ReadLine()) - 1;
  43.                         DeleteDoc(ref names, ref posts, deleteNumber);
  44.                         break;
  45.                     case "4":
  46.                         Console.Write("\nВведите фамилиию: ");
  47.                         string surname = Console.ReadLine();
  48.                         Search(names, posts, surname);
  49.                         break;
  50.                     case "5":
  51.                         exit = true;
  52.                         break;
  53.                     default:
  54.                         Console.WriteLine("\nТакой команды не существует");
  55.                         Console.ReadKey();
  56.                         break;
  57.                 }
  58.             }
  59.  
  60.             static void AddDoc(ref string[] fio, ref string[] position, string newFio, string newPosition)
  61.             {
  62.                 string[] addFio = new string[fio.Length + 1];
  63.                 string[] addPosition = new string[position.Length + 1];
  64.                
  65.                 for (int i = 0; i < fio.GetLength(0); i++)
  66.                 {
  67.                     addFio[i] = fio[i];
  68.                     addPosition[i] = position[i];
  69.                 }
  70.  
  71.                 addFio[addFio.Length - 1] = newFio;
  72.                 addPosition[addPosition.Length - 1] = newPosition;
  73.                 fio = addFio;
  74.                 position = addPosition;
  75.             }
  76.  
  77.             static void ShowDoc(string[] fio, string[] position)
  78.             {
  79.                 for (int i = 0; i < position.Length; i++)
  80.                 {
  81.                     Console.WriteLine(Convert.ToString(i + 1) + ". " + fio[i] + "- " + position[i]);
  82.                 }
  83.                 Console.ReadKey();
  84.             }
  85.  
  86.             static void DeleteDoc(ref string[] fio, ref string[] position, int deleteDocIndex)
  87.             {
  88.                 if (fio.Length < deleteDocIndex)
  89.                 {
  90.                     Console.WriteLine("\nДосье под таким номером не существует");
  91.                     Console.ReadKey();
  92.                     return;
  93.                 }
  94.                 else
  95.                 {
  96.                     string[] newFio = new string[fio.Length - 1];
  97.                     string[] newPosts = new string[position.Length - 1];
  98.                     int index = 0;
  99.  
  100.                     for (int i = 0; i < newFio.Length; i++)
  101.                     {
  102.                         if (i == deleteDocIndex)
  103.                         {
  104.                             index++;
  105.                         }
  106.                         newFio[i] = fio[index];
  107.                         newPosts[i] = position[index];
  108.                         index++;
  109.                     }
  110.                     fio = newFio;
  111.                     position = newPosts;
  112.                 }
  113.             }
  114.  
  115.             static void Search(string[] fio, string[] position, string searchWord)
  116.             {
  117.                 string[] search = new string[3];
  118.                 for (int i = 0; i < fio.Length; i++)
  119.                 {
  120.                     search = fio[i].ToLower().Split();
  121.                     if (search[0] == searchWord.ToLower())
  122.                     {
  123.                         Console.WriteLine(Convert.ToString(i + 1) + ". " + fio[i] + "- " + position[i]);
  124.                         break;
  125.                     }
  126.                     if (search[0] != searchWord.ToLower() && i == fio.Length - 1)
  127.                     {
  128.                         Console.WriteLine("\nФамилия не найдена");
  129.                     }
  130.                 }
  131.                 Console.ReadKey();
  132.             }
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement