예제 #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Employee employeeView = new Employee();
            EmployeeController employeeController = new EmployeeController(employeeView);

            employeeController.LoadEmployeeView();
            Application.Run(employeeView);
        }
예제 #2
0
 private void AddEmployee()
 {
     Employee emp;
     Console.WriteLine("Type the employee's first name below:");
     string firstName = Console.ReadLine();
     Console.WriteLine("Type the employee's surname below:");
     string surname = Console.ReadLine();
     Console.WriteLine("Type the employee's position below:");
     string position = Console.ReadLine();
     if (employees.Count == 0)
     {
         emp = new Employee(firstName, surname, position, 1);
     }
     else
     {
         emp = new Employee(firstName, surname, position, employees.Last().ID + 1);
     }
     employees.Add(emp);
     Console.WriteLine("The employee wass successfully added to the database. Press <enter> to continue");
     Console.ReadLine();
 }
예제 #3
0
        private void addEmployeeButton_Click(object sender, EventArgs e)
        {
            int employeeCount = _employees.Count + 1;

            DateTime dateOfBirth;
            if (!DateTime.TryParse(dateOfBirthTextBox.Text, out dateOfBirth))
            {
                dateOfBirth = DateTime.MinValue;
            }

            Employee employee = new Employee()
            {
                Id = employeeCount,
                LastName = lastNameTextBox.Text,
                FirstName = firstNameTextBox.Text,
                DateOfBirth = dateOfBirth
            };

            _employees.Add(employee);

            employeeCountValueLabel.Text = employeeCount.ToString();
        }
예제 #4
0
        static void Main(string[] args)
        {
            var database = new EmployeeDatabase();

            DisplayGreeting();

            var keepGoing = true;

            while (keepGoing)
            {
                // Inert a blank line then prompt them and get their answer (force uppercase)
                // Console.Clear();
                Console.WriteLine();
                Console.Write("What do you want to do? (A)dd an employee or (S)how all the employees or (F)ind an employee or (D)elete an employee or (U)pdate an employee or (Q)uit: "); var choice = Console.ReadLine().ToUpper();

                switch (choice)
                {
                case "Q":
                    // They said quit, so set our keepGoing to false
                    keepGoing = false;
                    break;

                case "U":
                    var nameToUpdate = PromptForString("What name are you looking for: ");

                    // Make a new variable to store the found employee, initializing
                    // to null which will indicate no match found
                    Employee foundEmployeeToUpdate = database.FindEmployee(nameToUpdate);

                    if (foundEmployeeToUpdate == null)
                    {
                        Console.WriteLine("Nobody by that name to update!");
                    }
                    else
                    {
                        var newSalary = PromptForInteger($"What is {foundEmployeeToUpdate}'s new salary? ");

                        foundEmployeeToUpdate.Salary = newSalary;
                    }
                    break;

                case "D":
                    var nameToDelete = PromptForString("What name are you looking for: ");

                    // Make a new variable to store the found employee, initializing
                    // to null which will indicate no match found
                    Employee foundEmployeeToDelete = database.FindEmployee(nameToDelete);

                    if (foundEmployeeToDelete == null)
                    {
                        Console.WriteLine("Nobody by that name to delete!");
                    }
                    else
                    {
                        database.RemoveEmployee(foundEmployeeToDelete);
                        Console.WriteLine($"Goodbye {nameToDelete}");
                    }
                    break;

                case "F":
                    // Ask for the name of an employee
                    var nameToFind = PromptForString("What name are you looking for: ");

                    // Make a new variable to store the found employee, initializing
                    // to null which will indicate no match found
                    Employee foundEmployeeToFind = database.FindEmployee(nameToFind);

                    // If the foundEmployee is still null, nothing was found
                    if (foundEmployeeToFind == null)
                    {
                        Console.WriteLine("No match found");
                    }
                    else
                    {
                        // Otherwise print details of the found employee
                        Console.WriteLine($"{foundEmployeeToFind.Name} is in department {foundEmployeeToFind.Department} and makes ${foundEmployeeToFind.Salary}");
                    }
                    break;

                case "S":
                    // show all the employees

                    // Loop through each employee
                    var allTheEmployeeFromTheDatabase = database.GetAllEmployees();
                    foreach (var employeeToShow in allTheEmployeeFromTheDatabase)
                    {
                        // And print details
                        Console.WriteLine($"{employeeToShow.Name} is in department {employeeToShow.Department} and makes ${employeeToShow.Salary}");
                    }

                    // Console.WriteLine("Press any key to continue");
                    // Console.ReadKey();
                    break;

                case "A":
                    var employee = new Employee();

                    employee.Name       = PromptForString("What is your name? ");
                    employee.Department = PromptForInteger("What is your department number? ");
                    employee.Salary     = PromptForInteger("What is your yearly salary (in dollars)? ");

                    database.AddEmployee(employee);
                    break;
                }
            }
        }