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 Project_1
- {
- class Program
- {
- private static int index = 0;
- static List<Employee> employees = new List<Employee>();
- static EmployeeSort employeeSort = new EmployeeSort();
- static void Main(string[] args)
- {
- //Employee[] arr = new Employee[]
- //{
- // new Employee{ID = 1, Salary = 50 },
- // new Employee{ID = 2, Salary = 10 },
- // new Employee{ID = 3, Salary = 30}
- //};
- //int result = arr[1].CompareTo(arr[2]);
- //Array.Sort(arr);
- List<string> menuItems = new List<string>() { "New", "Display", "Sort", "Exit" };
- Console.CursorVisible = false;
- while (true)
- {
- string selectedMenuItem = drawMenu(menuItems);
- if (selectedMenuItem == "New")
- {
- Console.Clear();
- newEmployee();
- }
- else if (selectedMenuItem == "Display")
- {
- Console.Clear();
- displayEmployee();
- }
- else if (selectedMenuItem == "Sort")
- {
- Console.Clear();
- Console.WriteLine("Choose sorting type:\n1. ID\n2. Name\n3. Salary");
- int choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- employeeSort.sortChoice = EmployeeSort.sortBy.ID;
- break;
- case 2:
- employeeSort.sortChoice = EmployeeSort.sortBy.name;
- break;
- case 3:
- employeeSort.sortChoice = EmployeeSort.sortBy.salary;
- break;
- default:
- Console.WriteLine("Error, invalid choice");
- break;
- }
- employees.Sort(employeeSort);
- }
- else if (selectedMenuItem == "Exit")
- {
- Environment.Exit(0);
- }
- }
- }
- private static string drawMenu(List<string> items)
- {
- for (int i = 0; i < items.Count; i++)
- {
- if (i == index)
- {
- Console.BackgroundColor = ConsoleColor.Gray;
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine(items[i]);
- }
- else
- {
- Console.WriteLine(items[i]);
- }
- Console.ResetColor();
- }
- ConsoleKeyInfo ckey = Console.ReadKey();
- if (ckey.Key == ConsoleKey.DownArrow)
- {
- if (index == items.Count - 1)
- {
- //index = 0;
- }
- else
- {
- index++;
- }
- }
- else if (ckey.Key == ConsoleKey.UpArrow)
- {
- if (index <= 0)
- {
- //index = menuItems.count - 1;
- }
- else
- {
- index--;
- }
- }
- else if (ckey.Key == ConsoleKey.Enter)
- {
- return items[index];
- }
- else
- {
- return "";
- }
- Console.Clear();
- return "";
- }
- static void newEmployee()
- {
- string name;
- int id, salary;
- Console.WriteLine("Enter employee information.");
- Console.Write("ID: "); id = int.Parse(Console.ReadLine());
- Console.Write("Name: "); name = Console.ReadLine();
- Console.Write("Salary: "); salary = int.Parse(Console.ReadLine());
- Employee e = new Employee(id, name, salary);
- employees.Add(e);
- }
- static void displayEmployee()
- {
- foreach(var employee in employees)
- {
- Console.WriteLine("Employee ID: {0}\nEmployee Name: {1}\nEmployee Salary: {2}\n", employee.ID, employee.name, employee.salary);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment