Exemplo n.º 1
0
        // Populate an initial set of Employees
        void InitialEmployees()
        {
            // Create Employees
            Executive     dan    = new Executive("Dan", "Brown", DateTime.Parse("3/20/1963"), 200000, "121-12-1211", 50000, ExecTitle.CEO);
            Executive     connie = new Executive("Connie", "Chung", DateTime.Parse("2/5/1972"), 150000, "229-67-7898", 40000, ExecTitle.CFO);
            Manager       chucky = new Manager("Chucky", "Jones", DateTime.Parse("4/23/1967"), 100000, "333-23-2322", 9000);
            Manager       mary   = new Manager("Mary", "Williams", DateTime.Parse("5/9/1963"), 200000, "121-12-1211", 9500);
            Engineer      bob    = new Engineer("Bob", "Roe", DateTime.Parse("6/30/1986"), 120000, "334-24-2422", DegreeName.MS);
            SalesPerson   fran   = new SalesPerson("Fran", "Smith", DateTime.Parse("7/5/1975"), 80000, "932-32-3232", 31);
            PTSalesPerson sam    = new PTSalesPerson("Sam", "Abbott", DateTime.Parse("8/11/1984"), 20000, "525-76-5030", 20);
            PTSalesPerson sally  = new PTSalesPerson("Sally", "McRae", DateTime.Parse("9/12/1979"), 30000, "913-43-4343", 10);
            SupportPerson mike   = new SupportPerson("Mike", "Roberts", DateTime.Parse("10/31/1975"), 15000, "229-67-7898", ShiftName.One);
            SupportPerson steve  = new SupportPerson("Steve", "Kinny", DateTime.Parse("11/21/1982"), 80000, "913-43-4343", ShiftName.Two);

            // Bonuses and promotions
            dan.GiveBonus(1000);
            bob.GiveBonus(500);
            sally.GiveBonus(400);
            dan.GivePromotion();
            chucky.GivePromotion();
            fran.GivePromotion();

            // Add reports - just report error and continue on exception
            try
            {
                dan.AddReport(chucky);
                dan.AddReport(mary);
                connie.AddReport(fran);
                connie.AddReport(sally);
                mary.AddReport(sam);
                mary.AddReport(mike);
                chucky.AddReport(bob);
                chucky.AddReport(steve);
            }
            catch (Exception e)
            {
                MessageBox.Show($"Error adding reports: {e.Message}");
            }

            // Add Expenses
            dan.Expenses.Add(new Expense(DateTime.Parse("1/25/2017"), ExpenseCategory.Travel, "Airline Tickets - San Diego", 300.55));
            dan.Expenses.Add(new Expense(DateTime.Parse("1/27/2017"), ExpenseCategory.Meals, "Breakfast at Hotel", 27.61));
            dan.Expenses.Add(new Expense(DateTime.Parse("1/29/2017"), ExpenseCategory.Lodging, "Conference Hotel - 5 nights", 423.15));

            // Add Employees to list
            List <Employee> emps = new List <Employee>()
            {
                dan, connie, chucky, mary, bob, fran, sam, sally, mike, steve
            };

            foreach (Employee e in emps)
            {
                Add(e);
            }
        }
Exemplo n.º 2
0
        static List <Employee> InitialEmployees()
        {
            Executive     dan    = new Executive("Dan", "Doe", DateTime.Parse("3/20/1963"), 200000, "121-12-1211", 50000, ExecTitle.CEO);
            Executive     connie = new Executive("Connie", "Chung", DateTime.Parse("2/5/1972"), 150000, "229-67-7898", 40000, ExecTitle.CFO);
            Manager       chucky = new Manager("Chucky", "Kirkland", DateTime.Parse("4/23/1967"), 100000, "333-23-2322", 9000);
            Manager       mary   = new Manager("Mary", "Tompson", DateTime.Parse("5/9/1963"), 200000, "121-12-1211", 9500);
            Engineer      bob    = new Engineer("Bob", "Pirs", DateTime.Parse("6/30/1986"), 120000, "334-24-2422", DegreeName.MS);
            SalesPerson   fran   = new SalesPerson("Fran", "Smith", DateTime.Parse("7/5/1975"), 80000, "932-32-3232", 31);
            PTSalesPerson sam    = new PTSalesPerson("Sam", "Abbot", DateTime.Parse("8/11/1984"), 20000, "525-76-5030", 20);
            PTSalesPerson sally  = new PTSalesPerson("Sally", "McRae", DateTime.Parse("9/12/1979"), 30000, "913-43-4343", 10);
            SupportPerson mike   = new SupportPerson("Mike", "Roberts", DateTime.Parse("10/31/1975"), 15000, "229-67-7898", ShiftName.One);
            SupportPerson steve  = new SupportPerson("Steve", "Kinny", DateTime.Parse("11/21/1982"), 80000, "913-43-4343", ShiftName.Two);


            // Bonuses and promotions
            dan.GiveBonus(1000);
            bob.GiveBonus(500);
            sally.GiveBonus(400);
            dan.GivePromotion();
            chucky.GivePromotion();
            fran.GivePromotion();


            // Add reports - just report error and continue on exception
            try
            {
                dan.AddReport(chucky);
                dan.AddReport(mary);
                connie.AddReport(fran);
                connie.AddReport(sally);
                mary.AddReport(sam);
                mary.AddReport(mike);
                chucky.AddReport(bob);
                chucky.AddReport(steve);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error when adding reports: {e.Message}");
            }

            return(new List <Employee>()
            {
                dan, connie, chucky, mary, bob, fran, sam, sally, mike, steve
            });
            //return new List<Employee>() { dan, connie, chucky };
        }
Exemplo n.º 3
0
        static void Main()
        {
            Console.WriteLine("***** Assignment 4: Employee Reports *****\n");

            // Create Employees
            Manager       chucky = new Manager("Chucky", 50, 92, 100000, "333-23-2322", 9000);
            Manager       mary   = new Manager("Mary", 54, 90, 200000, "121-12-1211", 9500);
            SalesPerson   fran   = new SalesPerson("Fran", 43, 93, 80000, "932-32-3232", 31);
            SalesPerson   bob    = new SalesPerson("Bob", 31, 94, 120000, "334-24-2422", 30);
            PTSalesPerson sally  = new PTSalesPerson("Sally", 32, 95, 30000, "913-43-4343", 10);
            PTSalesPerson sam    = new PTSalesPerson("Sam", 33, 96, 20000, "525-76-5030", 20);
            PTSalesPerson mike   = new PTSalesPerson("Mike", 45, 91, 15000, "229-67-7898", 30);

            // Employee list
            Employee[] emps = { chucky, mary, fran, bob, sally, sam, mike };

            // Add reports
            try
            {
                mary.AddReport(fran);
                mary.AddReport(mike);
                chucky.AddReport(bob);
                chucky.AddReport(sally);
                chucky.AddReport(sam);
                mary.RemoveReport(fran);
                mary.RemoveReport(chucky);
                chucky.AddReport(fran);
                chucky.AddReport(mike);
                chucky.AddReport(mary);
            }
            catch (Manager.TooManyReportsException e)
            {
                Console.WriteLine("*** Error! ***");
                Console.WriteLine("Source: {0}", e.Source);
                Console.WriteLine("Method: {0}", e.TargetSite);
                Console.WriteLine("Message: {0}", e.Message);
                Console.WriteLine("Custom Data:");
                foreach (DictionaryEntry de in e.Data)
                {
                    Console.WriteLine("-> {0}: {1}", de.Key, de.Value);
                }
            }

            Console.WriteLine("\nDisplay Managers\n");
            mary.DisplayStats();
            Console.WriteLine();
            chucky.RemoveReport(sam); // Remove a report for testing
            chucky.DisplayStats();
            Console.Write("Reports by Name: ");
            foreach (Employee emp in chucky.ReportsByName())
            {
                Console.Write("{0} ", emp.Name);
            }
            Console.Write("\nReports by Age: ");
            foreach (Employee emp in chucky.ReportsByAge())
            {
                Console.Write("{0}-{1} ", emp.Age, emp.Name);
            }
            Console.Write("\nReports by Pay: ");
            foreach (Employee emp in chucky.ReportsByPay())
            {
                Console.Write("{0:C}-{1} ", emp.Pay, emp.Name);
            }
            Console.WriteLine();

            Console.ReadLine();
        }