Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "4.1 Кадровый учет";
- //string[,] arrFIO = new string[0, 3]; // Массив будет двумерным для отдельного хранения фамилии, имени и отчества
- // // это облегчит поиск по фамилии
- //string[] arrPositions = new string[0];
- string[,] arrFIO = { {"Иванов", "Иван", "Иванович" },
- {"Петров", "Петр", "Петрович" },
- {"Маск", "Илон", null },
- {"Герасим", null, null }}; // Массив будет двумерным для отдельного хранения фамилии, имени и отчества
- // это облегчит поиск по фамилии
- string[] arrPositions = {"Менеджер по уборке территории", "Управляющий хозяйственным инвентарём", "Главный инженер", "Разнорабочий"};
- int iCommandNumber = -1;
- while (true)
- {
- Console.Clear();
- Console.WriteLine("1. Добавить досье.");
- Console.WriteLine("2. Вывести все досье.");
- Console.WriteLine("3. Удалить досье.");
- Console.WriteLine("4. Поиск по фамилии.");
- Console.WriteLine("---------------------");
- Console.WriteLine("9. Выход.");
- Console.WriteLine();
- iCommandNumber = Convert.ToInt32(GetUserInput("Введите команду: ", 0, 7, true));
- //Console.WriteLine("Введите команду: ");
- //Console.SetCursorPosition(17, 7);
- //while (!int.TryParse(Console.ReadLine(), out iCommandNumber))
- //{
- // Console.SetCursorPosition(17, 7);
- // Console.Write(" << Введены некорректные данные, повторите");
- // Console.SetCursorPosition(17, 7);
- //}
- //Console.SetCursorPosition(18, 7);
- //Console.WriteLine(" ");
- if (iCommandNumber == 9)
- break;
- switch (iCommandNumber)
- {
- case 1:
- Console.WriteLine();
- Console.WriteLine("Добавление досье");
- string sFIO = GetUserInput("Введите фамилию имя отчество\n(например, Иванов Иван Иванович): ");
- string sPositions = GetUserInput("Введите должность: ");
- AddRecord(ref arrFIO, ref arrPositions, sFIO, sPositions);
- break;
- case 2:
- Console.WriteLine();
- Console.WriteLine("Список всех досье");
- ShowAllRecords(ref arrFIO, ref arrPositions);
- PressAnyKey();
- break;
- case 3:
- Console.WriteLine();
- Console.WriteLine("Удаление досье");
- int i = Convert.ToInt32(GetUserInput("Введите номер досье для удаления: ", 0, 10, true));
- if (i <= 0 || i > arrFIO.GetLength(0))
- {
- Console.WriteLine($"Досье с номером {i} не найдено.");
- PressAnyKey();
- }
- else
- {
- if (GetUserInput($"Удалить досье № {i}? (Y-да): ").ToLower() == "y")
- {
- DelRecord(ref arrFIO, ref arrPositions, i - 1);
- Console.WriteLine($"Досье № {i} удалено.");
- PressAnyKey();
- }
- }
- break;
- case 4:
- Console.WriteLine();
- Console.WriteLine("Поиск по фамилии");
- string sLastName = GetUserInput("Введите фамилию для поиска досье: ");
- int iRecorNamber = FindRecord(ref arrFIO, sLastName.ToLower());
- if(iRecorNamber == -1)
- {
- Console.WriteLine("Не найдено досье для фамилии " + sLastName);
- }
- else
- {
- Console.WriteLine($"Досье для фамилии {sLastName} найдено. Номер досье: {iRecorNamber + 1}");
- }
- PressAnyKey();
- break;
- }
- }
- }
- static void PressAnyKey()
- {
- Console.WriteLine();
- Console.WriteLine("Нажмите любую клавишу...");
- Console.ReadKey();
- }
- static string GetUserInput(string message, int coordX = -1, int coordY = -1, bool isInteger = false)
- {
- if(coordX >= 0 || coordY >= 0)
- Console.SetCursorPosition(Math.Max(coordX, 0), Math.Max(coordY, 0));
- Console.Write(message);
- string result = "";
- if (isInteger)
- {
- int i;
- while (!int.TryParse(Console.ReadLine(), out i))
- {
- if (coordX >= 0 || coordY >= 0)
- Console.SetCursorPosition(Math.Max(coordX, 0) + message.Length, Math.Max(coordY, 0));
- Console.Write(" << Введены некорректные данные, повторите");
- if (coordX >= 0 || coordY >= 0)
- Console.SetCursorPosition(Math.Max(coordX, 0) + message.Length, Math.Max(coordY, 0));
- }
- result = i.ToString();
- }
- else
- {
- result = Console.ReadLine();
- }
- return result;
- }
- static void NewSize(ref string[,] arrFIO, ref string[] arrPositions, int size)
- {
- string[,] arrTmp = new string[size, arrFIO.GetLength(1)];
- for (int i = 0; i < Math.Min(arrFIO.GetLength(0), size); i++)
- {
- for (int j = 0; j < arrFIO.GetLength(1); j++)
- {
- arrTmp[i, j] = arrFIO[i, j];
- }
- }
- arrFIO = arrTmp;
- string[] arrTmp1 = new string[size];
- for (int i = 0; i < Math.Min(arrPositions.Length, size); i++)
- {
- arrTmp1[i] = arrPositions[i];
- }
- arrPositions = arrTmp1;
- }
- static void AddRecord(ref string[,] arrFIO, ref string[] arrPositions, string sFIO, string sPositions)
- {
- string[] arrStr = sFIO.Split(' ');
- NewSize(ref arrFIO, ref arrPositions, arrFIO.GetLength(0) + 1);
- for(int i = 0; i < Math.Min(arrFIO.GetLength(1), arrStr.Length); i++)
- {
- arrFIO[arrFIO.GetLength(0) - 1, i] = arrStr[i];
- }
- arrPositions[arrPositions.Length - 1] = sPositions;
- }
- static void ShowAllRecords(ref string[,] arrFIO, ref string[] arrPositions)
- {
- for(int i = 0; i < arrFIO.GetLength(0); i++)
- {
- Console.Write(i + 1 + ". ");
- for (int j = 0; j < arrFIO.GetLength(1); j++)
- {
- Console.Write(arrFIO[i, j] + " ");
- }
- Console.WriteLine(" - " + arrPositions[i]);
- }
- }
- static void DelRecord(ref string[,] arrFIO, ref string[] arrPositions, int recNumber)
- {
- for (int i = recNumber; i < arrFIO.GetLength(0) - 1; i++)
- {
- for(int j = 0; j < arrFIO.GetLength(1); j++)
- {
- arrFIO[i, j] = arrFIO[i + 1, j];
- }
- arrPositions[i] = arrPositions[i + 1];
- }
- NewSize(ref arrFIO, ref arrPositions, arrFIO.GetLength(0) - 1);
- }
- static int FindRecord(ref string[,] arrFIO, string findString)
- {
- int result = -1;
- for(int i = 0; i < arrFIO.GetLength(0); i++)
- {
- if((arrFIO[i, 0]).ToLower() == findString)
- {
- result = i;
- break;
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement