Ejemplo n.º 1
0
        /// <summary>
        /// this is actually the double click when selected in the employee view.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LVxEmployees_SelectedIndexChanged(object sender, EventArgs e)
        {
            ClearForm();
            ListView.SelectedListViewItemCollection mylist = LVxEmployees.SelectedItems;
            ListViewItem lvi          = mylist[0];
            Employee     thisEmployee = BusinessRules.EmpDictionary[uint.Parse(lvi.SubItems[0].Text)];

            CbxEmployeeType.Text = thisEmployee.EmpType;
            ToggleText();
            TxtEmpID.Text             = thisEmployee.EmpID.ToString();
            TxtLastName.Text          = thisEmployee.LastName;
            TxtFirstName.Text         = thisEmployee.FirstName;
            TxtMiddleName.Text        = thisEmployee.MiddleName;
            TxtMaritalStatus.Text     = thisEmployee.MaritalStatus;
            TxtDepartment.Text        = thisEmployee.Department;
            TxtTitle.Text             = thisEmployee.Title;
            TxtStartDate.Text         = thisEmployee.StartDate;
            CkbBenefits.Checked       = thisEmployee.Benefits;
            CkbActiveEmployee.Checked = thisEmployee.ActiveEmployee;
            if (thisEmployee.EmpType == EType.SALARY.ToString())
            {
                Salary thisEmp = new Salary();
                thisEmp           = (Salary)thisEmployee;
                TxtXtraProp1.Text = thisEmp.MonthlySalary.ToString();
            }
            if (thisEmployee.EmpType == EType.SALES.ToString())
            {
                Sales thisEmp = new Sales();
                thisEmp           = (Sales)thisEmployee;
                TxtXtraProp1.Text = thisEmp.Commission.ToString();
                TxtXtraProp2.Text = thisEmp.GrossSales.ToString();
            }
            if (thisEmployee.EmpType == EType.CONTRACT.ToString())
            {
                Contract thisEmp = new Contract();
                thisEmp           = (Contract)thisEmployee;
                TxtXtraProp1.Text = thisEmp.ContractWage.ToString();
            }
            if (thisEmployee.EmpType == EType.HOURLY.ToString())
            {
                Hourly thisEmp = new Hourly();
                thisEmp           = (Hourly)thisEmployee;
                TxtXtraProp1.Text = thisEmp.HourlyRate.ToString();
                TxtXtraProp2.Text = thisEmp.HoursWorked.ToString();
            }
            //update the education information.
            foreach (var item in thisEmployee.Education)
            {
                Course       myCourse  = item.Value;
                ListViewItem lviCourse = new ListViewItem(myCourse.CourseID);
                lviCourse.SubItems.Add(myCourse.Description);
                lviCourse.SubItems.Add(myCourse.Grade);
                lviCourse.SubItems.Add(myCourse.Date);
                lviCourse.SubItems.Add(myCourse.Credits);
                lviCourse.SubItems.Add(myCourse.Approved);
                LVxCourses.Items.Add(lviCourse);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// this will add the employee to the business rules dictionary so it can be saved for later.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnCreate_Click(object sender, EventArgs e)
        {
            EType selectedType;

            if (!Enum.TryParse(CbxEmployeeType.Text, out selectedType))
            {
                LblStatus.Text = "Invalid employee type given.";
                return;
            }
            else if (selectedType == EType.SALARY)
            {
                Salary creatingEmployee = new Salary();
                if (!CheckBaseValues(creatingEmployee))
                {
                    return;
                }

                if (double.TryParse(TxtXtraProp1.Text, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out tempDouble))
                {
                    creatingEmployee.MonthlySalary = tempDouble;
                }
                else
                {
                    LblStatus.Text = errorMessageDouble + errorMessageMonthlySalary;
                    TxtXtraProp1.Focus();
                    return;
                }

                //add employee education before creating employee
                AddEducation(creatingEmployee);

                if (employeeList.Add(creatingEmployee))
                {
                    AddEmployeeToView(creatingEmployee);

                    ClearForm();
                }
                else
                {
                    UpdateEmployee(creatingEmployee);
                }
            }
            else if (selectedType == EType.SALES)
            {
                Sales creatingEmployee = new Sales();
                if (!CheckBaseValues(creatingEmployee))
                {
                    return;
                }
                if (double.TryParse(TxtXtraProp1.Text, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out tempDouble))
                {
                    creatingEmployee.Commission = tempDouble;
                }
                else
                {
                    LblStatus.Text = errorMessageDouble + errorMessageCommision;
                    TxtXtraProp1.Focus();
                    return;
                }
                if (double.TryParse(TxtXtraProp2.Text, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out tempDouble))
                {
                    creatingEmployee.GrossSales = tempDouble;
                }
                else
                {
                    LblStatus.Text = errorMessageDouble + errorMessageGrossSales;
                    TxtXtraProp2.Focus();
                    return;
                }
                //add employee education before creating employee
                AddEducation(creatingEmployee);
                if (employeeList.Add(creatingEmployee))
                {
                    AddEmployeeToView(creatingEmployee);

                    ClearForm();
                }
                else
                {
                    UpdateEmployee(creatingEmployee);
                }
            }
            else if (selectedType == EType.HOURLY)
            {
                Hourly creatingEmployee = new Hourly();
                if (!CheckBaseValues(creatingEmployee))
                {
                    return;
                }
                if (double.TryParse(TxtXtraProp1.Text, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out tempDouble))
                {
                    creatingEmployee.HourlyRate = tempDouble;
                }
                else
                {
                    LblStatus.Text = errorMessageDouble + errorMessageHourlyRate;
                    TxtXtraProp1.Focus();
                    return;
                }
                if (double.TryParse(TxtXtraProp2.Text, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out tempDouble))
                {
                    creatingEmployee.HoursWorked = tempDouble;
                }
                else
                {
                    LblStatus.Text = errorMessageDouble + errorMessageHoursWorked;
                    TxtXtraProp2.Focus();
                    return;
                }
                //add employee education before creating employee
                AddEducation(creatingEmployee);
                if (employeeList.Add(creatingEmployee))
                {
                    AddEmployeeToView(creatingEmployee);

                    ClearForm();
                }
                else
                {
                    UpdateEmployee(creatingEmployee);
                }
            }
            else if (selectedType == EType.CONTRACT)
            {
                Contract creatingEmployee = new Contract();
                if (!CheckBaseValues(creatingEmployee))
                {
                    return;
                }
                if (double.TryParse(TxtXtraProp1.Text, System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.GetCultureInfo("en-US"), out tempDouble))
                {
                    creatingEmployee.ContractWage = tempDouble;
                }
                else
                {
                    LblStatus.Text = errorMessageDouble + errorMessageContractWage;
                    TxtXtraProp1.Focus();
                    return;
                }
                //add employee education before creating employee
                AddEducation(creatingEmployee);

                if (employeeList.Add(creatingEmployee))
                {
                    AddEmployeeToView(creatingEmployee);
                    ClearForm();
                }
                else
                {
                    UpdateEmployee(creatingEmployee);
                }
            }
        }