Answer the question
In order to leave comments, you need to log in
Review code required. How to make menu logic correctly?
Hello, I just started learning programming and C# language. I would like to hear the opinion of more experienced people about the code below.
Got a job
Define the class Employee (employee), containing the fields:
Full name . employee, position, date of birth, salary, department, length of service, status.
Create methods that allow you to:
A) transfer an employee to a new position;
B) transfer an employee to another department;
B) change the experience;
D) to change the salary;
E) dismiss an employee, send him on a business trip, vacation,
sick leave, take him off sick leave, while changing the status of the employee. By
default, the status is "Working";
E) display information about a specific employee.
Answer the question
In order to leave comments, you need to log in
From the obvious in my opinion:
1. There is no validation, but it is better not to let it be filled with arbitrary data at all. It is better to replace it with a dictionary where in the console instead of "Enter a position" it will be "Choose from the proposed options" and opposite each position its own number.
public void SetNewPos()
{
Console.Write($"Введите должность для {Fullname}\nТекущая: {Position}\nНовая: ");
this.Position = Console.ReadLine();
}
private BirthdateFormat Birthdate { get; set; } //Дата рождения
private FullnameRules Fullname { get; set; } //ФИО
private Department DepartmentCode { get; set; } //Отдел
private CompanyPosition Position { get; set; } // Должность
private int Salary { get; set; } //Зарплата
private int Expirience { get; set; } //Стаж
private StatusDict Status { get; set; } //Состояние
public class A {
public StatusDict StatusCode {get; set;}
public enum StatusDict
{
Open = 1,
Close
}
public A(int code)
{
StatusCode = (StatusDict)code;
}
}
public Employee()
{
this.Fullname = "0";
this.Department = "0";
this.Salary = 0;
this.Expirience = 0;
this.Position = "0";
this.Birthdate = "0";
}
//Бесконечный цикл для работы меню
for (; ; )
Repeat:
var key = Console.ReadKey();
if (key.KeyChar == '1' || key.KeyChar == '3')
{
return;
}
else
{
goto Repeat;
}
Convert.ToInt32(Console.ReadLine());
Repeat:
Console.Clear(); //Очищает консоль после отработки функции
string input;
string currentLevel;
Console.WriteLine("Выберите функцию");
Console.WriteLine("1 Получить информацию");
Console.WriteLine("2 Изменить должность");
Console.WriteLine("3 Измеить отдел");
Console.WriteLine("4 Изменить стаж");
Console.WriteLine("5 Изменить зарплату");
Console.WriteLine("6 Изменить статус");
Console.WriteLine("0 Выход");
//Двух уровневое меню реализованное c помощью линейного switch
currentLevel = "";
Command:
//input = Console.ReadLine();
currentLevel += Console.ReadLine();
Console.WriteLine(currentLevel);
switch (currentLevel)
{
case "1":
Console.WriteLine("Выберите количество \n1 Все \n2 Один \n3 Несколько");
goto Command;
case "11":
for (int i = 0; i < Employers.Length; i++)
{
Employers[i].PrintInfo();
Console.WriteLine("___________________________");
}
Console.ReadKey(); //Костыль который не позволяет моментально очистить вывод
break;
case "12":
int c12input;
for (int i = 0; i < Employers.Length; i++)
{
Console.Write(i + 1 + " ");
Employers[i].PrintName();
}
Console.WriteLine("Выберите сотрудника");
c12input = Convert.ToInt32(Console.ReadLine());
Employers[c12input - 1].PrintInfo();
Console.WriteLine("___________________________");
break;
case "13":
Console.WriteLine("Выберите сотрудника");
Console.WriteLine("0 для возврата в предыдущее меню\n-------");
for (int i = 0; i < Employers.Length; i++)
{
Console.Write(i + 1 + " ");
Employers[i].PrintName();
}
Console.WriteLine("___________________________");
int c13input;
while ((c13input = Convert.ToInt32(Console.ReadLine())) != 0) //пока не введен 0, можно вводить индексы сотрудников
{
Employers[c13input - 1].PrintInfo();
Console.WriteLine("___________________________");
}
break;
}
goto Repeat;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question