Advertisement
holllowknight

Кадровый учёт

Apr 13th, 2023 (edited)
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Kadr
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             const string CommandAdd = "add";
  11.             const string CommandPrint = "print";
  12.             const string CommandDelete = "delete";
  13.             const string CommandExit = "exit";
  14.  
  15.             List<string> fullNames = new List<string>();
  16.             List<string> positions = new List<string>();
  17.             string userInput;
  18.             bool isRunning = true;
  19.  
  20.             while (isRunning)
  21.             {
  22.                 Console.Clear();
  23.                 Console.WriteLine($"{CommandAdd} - добавить досье\n{CommandPrint} - распечатать досье\n{CommandDelete} - удалить досье");
  24.                 Console.WriteLine($"{CommandExit} - выйти из программы");
  25.                 Console.WriteLine();
  26.                 userInput = Console.ReadLine();
  27.  
  28.                 switch (userInput)
  29.                 {
  30.                     case CommandAdd:
  31.                         AddFile(fullNames, positions);
  32.                         break;
  33.  
  34.                     case CommandPrint:
  35.                         PrintFiles(fullNames, positions);
  36.                         break;
  37.  
  38.                     case CommandDelete:
  39.                         DeleteFile(fullNames, positions);
  40.                         break;
  41.  
  42.                     case CommandExit:
  43.                         isRunning = false;
  44.                         break;
  45.                 }
  46.             }
  47.         }
  48.  
  49.         static void AddFile(List<string> fullNames, List<string> positions)
  50.         {
  51.             Console.WriteLine("Введите ФИО");
  52.             fullNames.Add(Console.ReadLine());
  53.             Console.WriteLine("Введите должность");
  54.             positions.Add(Console.ReadLine());
  55.             Console.WriteLine("Количество досье в архиве: " + fullNames.Count);
  56.             Console.ReadKey();
  57.         }
  58.  
  59.         static void PrintFiles(List<string> fullNames, List<string> positions)
  60.         {
  61.             if (fullNames.Count == 0)
  62.             {
  63.                 Console.WriteLine("В досье отсутствуют записи");
  64.             }
  65.             else
  66.             {
  67.                 for (int i = 0; i < fullNames.Count; i++)
  68.                     Console.WriteLine($"{i + 1} - {fullNames[i]} - {positions[i]}");
  69.             }
  70.  
  71.             Console.ReadKey();
  72.         }
  73.  
  74.         static void DeleteFile(List<string> fullNames, List<string> positions)
  75.         {
  76.             int fileIndex;
  77.             Console.Write("Введите номер удаляемой записи ");
  78.             string userInput = Console.ReadLine();
  79.  
  80.             if (int.TryParse(userInput, out fileIndex) == false)
  81.             {
  82.                 Console.WriteLine("Ошибка ввода номера");
  83.             }
  84.             else
  85.             {
  86.                 fileIndex = fileIndex - 1;
  87.  
  88.                 if ((fileIndex >= fullNames.Count) || (fileIndex < 0))
  89.                 {
  90.                     Console.WriteLine("Досье с данным номером отсутствует");
  91.                 }
  92.                 else
  93.                 {
  94.                     fullNames.RemoveAt(fileIndex);
  95.                     positions.RemoveAt(fileIndex);
  96.                 }
  97.             }
  98.  
  99.             Console.WriteLine("Количество досье в архиве: " + fullNames.Count);
  100.             Console.ReadKey();
  101.         }
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement