コード例 #1
0
        public CompDetails(Object data) : this()
        {
            this.DataContext = data;

            if (data is Employee)
            {
                string name  = "";
                string value = "";

                if (data is Manager)
                {
                    Manager man = (Manager)data;

                    name = "Reports";
                    string options = "Stock Options";

                    // Set spare prop name and value
                    man.GetSpareProp1(ref name, ref value);
                    this.SpareProp1Name.Content  = name;
                    this.SpareProp1Value.Content = man.ReportsByName();

                    this.SpareProp2Name.Content  = options;
                    this.SpareProp2Value.Content = man.StockOptions;

                    // Make visible after setting values
                    this.SpareProp1Name.Visibility  = Visibility.Visible;
                    this.SpareProp1Value.Visibility = Visibility.Visible;

                    this.SpareProp2Name.Visibility  = Visibility.Visible;
                    this.SpareProp2Value.Visibility = Visibility.Visible;
                }
                if (data is Executive)
                {
                    Executive exe = (Executive)data;

                    name = "Reports";
                    string options = "Stock Options ";

                    // Set spare prop name and value
                    exe.GetSpareProp1(ref name, ref value);
                    this.SpareProp1Name.Content  = name;
                    this.SpareProp1Value.Content = exe.ReportsByName();

                    this.SpareProp2Name.Content  = options;
                    this.SpareProp2Value.Content = exe.StockOptions;

                    // Make visible after setting values
                    this.SpareProp1Name.Visibility  = Visibility.Visible;
                    this.SpareProp1Value.Visibility = Visibility.Visible;

                    this.SpareProp2Name.Visibility  = Visibility.Visible;
                    this.SpareProp2Value.Visibility = Visibility.Visible;
                }
                if (data is Engineer)
                {
                    Engineer eng = (Engineer)data;
                    name = "Highest Degree";

                    // Set spare prop name and value
                    eng.GetSpareProp1(ref name, ref value);
                    this.SpareProp1Name.Content  = name;
                    this.SpareProp1Value.Content = eng.HighestDegree;

                    // Make visible after setting values
                    this.SpareProp1Name.Visibility  = Visibility.Visible;
                    this.SpareProp1Value.Visibility = Visibility.Visible;
                }
                if (data is SalesPerson)
                {
                    SalesPerson sales = (SalesPerson)data;
                    name = "Number of Sales";

                    // Set spare prop name and value
                    sales.GetSpareProp1(ref name, ref value);
                    this.SpareProp1Name.Content  = name;
                    this.SpareProp1Value.Content = sales.SalesNumber;

                    // Make visible after setting values
                    this.SpareProp1Name.Visibility  = Visibility.Visible;
                    this.SpareProp1Value.Visibility = Visibility.Visible;
                }
                if (data is PTSalesPerson)
                {
                    PTSalesPerson pTSales = (PTSalesPerson)data;
                    name = "Number of Sales";

                    // Set spare prop name and value
                    pTSales.GetSpareProp1(ref name, ref value);
                    this.SpareProp1Name.Content  = name;
                    this.SpareProp1Value.Content = pTSales.SalesNumber;

                    // Make visible after setting values
                    this.SpareProp1Name.Visibility  = Visibility.Visible;
                    this.SpareProp1Value.Visibility = Visibility.Visible;
                }
                if (data is SupportPerson)
                {
                    SupportPerson support = (SupportPerson)data;
                    name = "Shift: ";

                    // Set spare prop name and value
                    support.GetSpareProp1(ref name, ref value);
                    this.SpareProp1Name.Content  = name;
                    this.SpareProp1Value.Content = support.Shift;

                    // Make visible after setting values
                    this.SpareProp1Name.Visibility  = Visibility.Visible;
                    this.SpareProp1Value.Visibility = Visibility.Visible;
                }
            }
        }
コード例 #2
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();
        }