Example #1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     _HourlyEmployee = new HourlyPaidEmployee(txt_Id.Text, txt_Name.Text, txt_Address.Text,
                                              Convert.ToDouble(txt_HourlyRate.Text), Convert.ToInt16(txt_Hours.Text),
                                              Convert.ToDouble(txt_ORate.Text));
     MessageBox.Show("New Employee Object Created");
     this.Close();
 }
        static void Main(string[] args)
        {
            //create mapper instance
            EmployeeMapper em = new EmployeeMapper();

            // Get the same employee twice
            Employee emp1 = em.GetById(1);
            Employee emp2 = em.GetById(1);

            // check that the same object is returned by each call
            bool sameobject1 = emp1.Equals(emp2);

            // Get all hourly paid employees
            List<Employee> hpes = em.GetAllHourlyPaid();

            // Check that objects are not duplicated (may need to change these to match your data)
            // first hpe has empl1 as supervisor
            bool sameobject2 = emp1.Equals(hpes[0].Supervisor);         //  S/B TRUE
            // second hpe has first hpe as supervisor       NO DATA Has not been retrieved for this supervisor, although it's in the identity Map.
            bool sameobject3 = hpes[0].Equals(hpes[1].Supervisor);      //  S/B FALSE

            //  Get the supervisor for hpes[1], should have Id of 3
            Employee emp3 = em.GetById(3);
            bool sameobject4 = emp3.Equals(hpes[1].Supervisor);         //  S/B TRUE

            // Create a new hourly paid employee
            HourlyPaidEmployee newhpe = new HourlyPaidEmployee();
            Address newaddress = new Address("Entity Park", 100, new PostCode("KA1 1BX"));
            newhpe.Address = newaddress;
            newhpe.Name = "Michael";
            newhpe.Username = "******";
            newhpe.PhoneNumber = "2222";
            newhpe.Supervisor = emp1;

            // store and retrieve - object from database should have ID set
            int newID = em.StoreHourlyPaid(newhpe);
            Employee newEmp = em.GetById(newID);

            // set break point here and inspect objects with debugger
            Console.ReadLine();
        }
Example #3
0
        static void AddEmpl()
        {
            string   myType;
            string   myID;
            string   myName;
            string   myAddress;
            double   mySalary;
            double   mySalaryRate;
            int      myHours;
            double   myOvertimeRate;
            DateTime myStart;
            DateTime myEnd;

            Console.WriteLine("Add Employee");
            Console.WriteLine();
            Console.Write("Type M/W/H:");
            myType = Console.ReadLine();
            Console.Write("ID: ");
            myID = Console.ReadLine();
            Console.Write("Name: ");
            myName = Console.ReadLine();
            Console.Write("Address: ");
            myAddress = Console.ReadLine();
            //Console.Write("Salary: ");
            //mySalary = Convert.ToDouble(Console.ReadLine());


            if (myType == "M")
            {
                try
                {
                    Console.Write("Salary:");
                    mySalary = Convert.ToDouble(Console.ReadLine());
                    Posts myPostHistory = new Posts();

                    MonthlyPaidEmployee myEmployee = new MonthlyPaidEmployee(myID, myName, myAddress, mySalary);//, myPostHistory);
                    myBusiness.AddEmployee(myID, myEmployee);
                    //myEmployees.Add(myID, myEmployee);
                    Console.WriteLine();
                    Console.Write("Employee Entered; press any key to continue.");
                    Console.ReadLine();
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Salary is less than £20000");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine();
                    Console.WriteLine("Press Any Key to continue");
                    Console.ReadLine();
                }
            }
            else if (myType == "W")
            {
                try
                {
                    Console.Write("Salary:");
                    mySalary = Convert.ToDouble(Console.ReadLine());
                    Console.Write("Overtime Rate: ");
                    myOvertimeRate = Convert.ToDouble(Console.ReadLine());
                    Posts myPostHistory           = new Posts();
                    WeeklyPaidEmployee myEmployee = new WeeklyPaidEmployee(myID, myName, myAddress, mySalary, myOvertimeRate);//, myPostHistory);
                    myBusiness.AddEmployee(myID, myEmployee);
                    //myEmployees.Add(myID, myEmployee);
                    Console.WriteLine();
                    Console.Write("Employee Entered; press any key to continue.");
                    Console.ReadLine();
                }
                catch (WeeklyWageException ex)
                {
                    Console.WriteLine("Salary is greater than £1000");
                    Console.WriteLine(ex.Message);
                    Console.WriteLine();
                    Console.WriteLine("Press Any Key to continue");
                    Console.ReadLine();
                }
            }
            else if (myType == "H")
            {
                Console.Write("Temporary Y/N: ");
                myType = Console.ReadLine();
                Console.Write("Salary Rate: ");
                mySalaryRate = Convert.ToDouble(Console.ReadLine());
                Console.Write("Hours: ");
                myHours = Convert.ToInt16(Console.ReadLine());
                Console.Write("Overtime Rate: ");
                myOvertimeRate = Convert.ToDouble(Console.ReadLine());
                if (myType == "N")
                {
                    HourlyPaidEmployee myEmployee = new HourlyPaidEmployee(myID, myName, myAddress, mySalaryRate, myHours, myOvertimeRate);
                    myBusiness.AddEmployee(myID, myEmployee);
                    //myEmployees.Add(myID, myEmployee);
                }
                else if (myType == "Y")
                {
                    Console.Write("Start Date: ");
                    myStart = Convert.ToDateTime(Console.ReadLine());
                    Console.Write("End Date: ");
                    myEnd = Convert.ToDateTime(Console.ReadLine());

                    TemporaryHourlyPaidEmployee myEmployee = new TemporaryHourlyPaidEmployee(myID, myName, myAddress, mySalaryRate, myHours, myOvertimeRate, myStart, myEnd);
                    myBusiness.AddEmployee(myID, myEmployee);
                    //myEmployees.Add(myID, myEmployee);
                }
                Console.WriteLine();
                Console.Write("Employee Entered; press any key to continue.");
                Console.ReadLine();
            }

            // Employee myEmployee = new Employee(myID, myName, myAddress);//, mySalary);


            //Console.WriteLine(myEmployee.ToString());
        }