Advertisement
dmitryEfremov

Untitled

Apr 18th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.69 KB | None | 0 0
  1. using System;
  2. namespace ConsoleApp5
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             string[] personalData = new string[0];
  9.             string[] numberToFami = new string[0];
  10.             bool exit = true;
  11.             while (exit)
  12.             {
  13.                 Console.SetCursorPosition(30, 0);
  14.                 Console.WriteLine("Базза данных");
  15.                 Console.WriteLine("Список комманд:\n");
  16.                 Console.WriteLine(" 1)Добавить досье");
  17.                 Console.WriteLine(" 2)Вывести досье");
  18.                 Console.WriteLine(" 3)Удалить досье");
  19.                 Console.WriteLine(" 4)Поиск по фамилии");
  20.                 Console.WriteLine(" 5)Выйти");
  21.                 Console.Write("Введите номер комманды:");
  22.                 int numberCommand = Convert.ToInt32(Console.ReadLine());
  23.                 switch (numberCommand)
  24.                 {
  25.                     case 1:
  26.                         Console.Write("Введите имя\nИмя:");
  27.                         string name = Console.ReadLine();
  28.                         Console.Write("Введите фамилию\nФамилия:");
  29.                         string fami = Console.ReadLine();
  30.                         Console.Write("Введите отчество\nОтчество:");
  31.                         string patronymic = Console.ReadLine();
  32.                         Console.Write("Введите должность\nДолжность:");
  33.                         string post = Console.ReadLine();
  34.                         addDossier(ref personalData, ref numberToFami, name, fami, patronymic, post);
  35.                         break;
  36.                     case 2:
  37.                         for (int i = 0; i < personalData.Length; i++)
  38.                         {
  39.                             Console.WriteLine("#" + (i + 1) + " " + personalData[i]);
  40.                         }
  41.                         break;
  42.                     case 3:
  43.                         Console.Write("Введите номер досье:");
  44.                         int numberDpssierDelete = Convert.ToInt32(Console.ReadLine()) - 1;
  45.                         deleteDossier(ref personalData, ref numberToFami, numberDpssierDelete);
  46.                         break;
  47.                     case 4:
  48.                         Console.Write("Введите фамилию\n Фамилия:");
  49.                         string searchByFami = Console.ReadLine();
  50.                         for (int i = 0; i < numberToFami.Length; i++)
  51.                         {
  52.                             if (numberToFami[i] == searchByFami)
  53.                             {
  54.                                 Console.WriteLine(personalData[i]);
  55.                                 break;
  56.                             }
  57.                             if (i == numberToFami.Length - 1)
  58.                             {
  59.                                 Console.WriteLine("Нет досье с введённой фамилией...");
  60.                             }
  61.                         }
  62.                         break;
  63.                     case 5:
  64.                         exit = false;
  65.                         break;
  66.                     default:
  67.                         Console.Write("Вы ввели неправильный номер комманды...");
  68.                         break;                      
  69.                 }
  70.                 Console.ReadLine();
  71.                 Console.Clear();
  72.             }
  73.         }
  74.         static void addDossier(ref string[] personalData, ref string[] numberToFami, string name, string fami, string patronymic, string post)
  75.         {
  76.  
  77.             string[] array = new string[personalData.Length + 1];
  78.             string[] addArrayNumberToFami = new string[personalData.Length + 1];
  79.             for (int i = 0; i < personalData.Length; i++)
  80.             {
  81.                 array[i] = personalData[i];
  82.             }
  83.             for (int i = 0; i < numberToFami.Length; i++)
  84.             {
  85.                 addArrayNumberToFami[i] = numberToFami[i];
  86.             }
  87.             addArrayNumberToFami[numberToFami.Length] = fami;
  88.             array[personalData.Length ] = ($"{fami} {name} {patronymic} - Должность {post}");
  89.             numberToFami = addArrayNumberToFami;
  90.             personalData = array;
  91.         }
  92.         static void deleteDossier(ref string[] personalData,ref string[] numberToFami, int numberDpssierDelete)
  93.         {
  94.             string[] arrayNumberToFamiEditor = numberToFami;
  95.             string[] arrayNumberToFamiDeleteIndex = new string[numberToFami.Length - 1];
  96.             for (int i = numberDpssierDelete; i < arrayNumberToFamiEditor.Length - 1; i++)
  97.             {
  98.                 arrayNumberToFamiEditor[i] = arrayNumberToFamiEditor[i + 1];
  99.             }
  100.             for (int i = 0; i < arrayNumberToFamiDeleteIndex.Length; i++)
  101.             {
  102.                 arrayNumberToFamiDeleteIndex[i] = arrayNumberToFamiEditor[i];
  103.             }
  104.             numberToFami = arrayNumberToFamiDeleteIndex;
  105.             string[] arrayPersonalDataEditor = personalData;          
  106.             string[] arrayPersonalDateDeleteIndex = new string[personalData.Length - 1];
  107.             for (int i = numberDpssierDelete; i < arrayPersonalDataEditor.Length - 1; i++)
  108.             {
  109.                 arrayPersonalDataEditor[i] = arrayPersonalDataEditor[i+1] ;
  110.             }
  111.             for (int i = 0; i < arrayPersonalDateDeleteIndex.Length; i++)
  112.             {
  113.                 arrayPersonalDateDeleteIndex[i] = arrayPersonalDataEditor[i];
  114.             }
  115.             personalData = arrayPersonalDateDeleteIndex;
  116.         }  
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement