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 Docs
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[,] names = new string[0, 3];
- string[] posts = new string[0];
- bool exit = false;
- string inputComand = "";
- while (!exit)
- {
- Console.Clear();
- Console.WriteLine("Кадровый учет. Меню:\n\n" +
- "1. Добавить досье\n\n" +
- "2. Вывести все досье\n\n" +
- "3. Удалить досье\n\n" +
- "4. Поиск по фамилии\n\n" +
- "5. Выход\n");
- Console.Write("Введите номер команды: ");
- switch (Console.ReadLine())
- {
- case "1":
- Console.Write("\nВведите ФИО через пробел: ");
- string fio = Console.ReadLine() + " ";
- Console.Write("Введите должность: ");
- string post = Console.ReadLine();
- AddDoc(ref names, ref posts, fio, post);
- break;
- case "2":
- ShowDoc(names, posts);
- break;
- case "3":
- Console.Write("\nВведите номер удаляемого досье: ");
- int deleteNumber = Convert.ToInt32(Console.ReadLine()) - 1;
- DeleteDoc(ref names, ref posts, deleteNumber);
- break;
- case "4":
- Console.Write("\nВведите фамилиию: ");
- string surname = Console.ReadLine();
- Search(ref names, ref posts, surname);
- break;
- case "5":
- exit = true;
- break;
- default:
- Console.WriteLine("\nТакой команды не существует");
- Console.ReadKey();
- break;
- }
- }
- static void AddDoc(ref string[,] fio, ref string[] position, string newFio, string newPosition)
- {
- string[,] addFio = new string[fio.GetLength(0) + 1, 3]; // новый массив имен на 1 место больший
- string[] addPosition = new string[position.GetLength(0) + 1]; // новый массив должностей на 1 больший
- string name = ""; // для записи разделенного ФИО
- string[] newFioArray = new string[3]; // для хранения одной пизиции ФИО (полученная при вводе)
- for (int i = 0; i < 2;) // цикл для разделения ФИО и запись в отдельный массив
- {
- for (int j = 0; j < newFio.Length; j++)
- {
- if (Convert.ToString(newFio[j]) == " " && j == 0)
- {
- continue;
- }
- if (Convert.ToString(newFio[j]) == " " && Convert.ToString(newFio[j - 1]) == " ")
- {
- continue;
- }
- if (Convert.ToString(newFio[j]) == " ")
- {
- newFioArray[i++] = name;
- name = "";
- }
- else
- {
- name += newFio[j];
- }
- }
- }
- for (int i = 0; i < fio.GetLength(0); i++) // цикл записи старых маленьких массивов в новые большие
- {
- for (int j = 0; j < 3; j++)
- {
- addFio[i, j] = fio[i, j];
- }
- addPosition[i] = position[i];
- }
- for (int i = 0; i < 3; i++) // цикл записи новой ячейки ФИО
- {
- addFio[addFio.GetLength(0) - 1, i] = newFioArray[i];
- }
- addPosition[addPosition.Length - 1] = newPosition; // запись новой ячейки должности
- fio = addFio; // вывод старого массива с сылкой на новый для ФИО
- position = addPosition; // вывод старого массива с сылкой на новый для должности
- }
- static void ShowDoc(string[,] fio, string[] position)
- {
- string output = "";
- for (int i = 0; i < position.Length; i++)
- {
- output += Convert.ToString(i + 1) + ". ";
- for (int j = 0; j < 3; j++)
- {
- output += fio[i, j] + " ";
- }
- output += "- " + position[i] + "\n";
- }
- Console.WriteLine(output);
- Console.ReadKey();
- }
- static void DeleteDoc(ref string[,] fio, ref string[] position, int deleteDocIndex)
- {
- if (fio.GetLength(0) < deleteDocIndex)
- {
- Console.WriteLine("\nДосье под таким номером не существует");
- Console.ReadKey();
- return;
- }
- else
- {
- string[,] newFio = new string[fio.GetLength(0) - 1, 3];
- string[] newPosts = new string[position.GetLength(0) - 1];
- int index = 0;
- for (int i = 0; i < newFio.GetLength(0); i++)
- {
- if (i == deleteDocIndex)
- {
- index++;
- }
- for (int j = 0; j < 3; j++)
- {
- newFio[i, j] = fio[index, j];
- }
- newPosts[i] = position[index];
- index++;
- }
- fio = newFio;
- position = newPosts;
- }
- }
- static void Search(ref string[,] fio, ref string[] position, string searchWord)
- {
- string output = "";
- for (int i = 0; i < position.Length; i++)
- {
- if (fio[i, 0].ToLower() == searchWord.ToLower())
- {
- output += Convert.ToString(i + 1) + ". ";
- for (int j = 0; j < 3; j++)
- {
- output += fio[i, j] + " ";
- }
- output += "- " + position[i];
- break;
- }
- if (fio[i, 0].ToLower() != searchWord.ToLower() && i == position.Length)
- {
- Console.WriteLine("\nФамилия не найдена");
- }
- }
- Console.WriteLine(output);
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement