Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //menu with 1 employee
- 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 string eName;
- static int eID, eSalary;
- 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()
- {
- Console.WriteLine("Enter employee information.");
- Console.Write("ID: "); eID = int.Parse(Console.ReadLine());
- Console.Write("Name: "); eName = Console.ReadLine();
- Console.Write("Salary: "); eSalary = int.Parse(Console.ReadLine());
- }
- static void displayEmployee()
- {
- Console.WriteLine("Employee ID: {0}\nEmployee Name: {1}\nEmployee Salary: {2}\n", eID, eName, eSalary);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement