Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //menu with more than one employee (struct)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Project_3
- {
- struct Employee
- {
- public string eName;
- public int eID, eSalary;
- public Employee(string name, int id, int salary)
- {
- eName = name;
- eID = id;
- eSalary = salary;
- }
- //public void displayInfo()
- //{
- // Console.WriteLine("Employee ID: {0}\nEmployee Name: {1}\nEmployee Salary: {2}", eID, eName, eSalary);
- //}
- }
- class Program
- {
- private static int index = 0;
- static List<Employee> employees = new List<Employee>();
- static void Main(string[] args)
- {
- List<string> menuItems = new List<string>() { "New", "Display", "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 == "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(name, id, 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.eID, employee.eName, employee.eSalary);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment