} // end method BtnLogin_Click()

        /// <summary>
        /// To validate the credentials, if good, general employee form is generated with users data
        /// </summary>
        private void AuthEmp()
        {
            //Declare & init vars:
            Employee emp = null;

            //COMMENTED OUT B/C LOGIN SHOULD ONLY BE VALIDATED FOR AUTHENTICITY
            ////Validate empID
            //if (!Validator.EmpID(TxtID.Text))
            //{
            //    //Prompt user, EmpID was invalid
            //    MessageBox.Show(INVALID_ID_MSG, INVALID_ID_CAPTION);

            //    return;
            //} // end if
            //if (!Validator.Name(TxtLName.Text))
            //{
            //    //Prompt user, invalid last name
            //    MessageBox.Show(INVALID_LNAME_MSG, INVALID_LNAME_CAPTION);

            //    return;
            //} // end else if

            try
            {
                //Try to get employee using given empID (key)
                emp = BusinessRules.Instance[uint.Parse(TxtID.Text)];

                //If emp is NOT null - throws exception if null
                if (!emp.Equals(null))
                {
                    //If employee is a former one
                    if (emp.Status.Equals(FORMER))
                    {
                        //Prompt user, credentials are those of a former emp
                        MessageBox.Show(FORMER_EMPLOYEE_MSG, FORMER_EMPLOYEE_CAPTION);
                        return;
                    } // end if

                    //If the given last name did NOT match that of the ID
                    if (!emp.LastName.Equals(TxtLName.Text))
                    {
                        //Prompt user - provided employee credentials were invalid
                        MessageBox.Show(INVALID_EMPLOYEE_MSG, INVALID_EMPLOYEE_CAPTION);
                    }    // end if
                    else // ID & last name correspond
                    {
                        //Create new instance of FrmEmp_General form
                        FrmEmp_General form = new FrmEmp_General();

                        //Set values in form
                        form.CurrEmp             = emp;
                        form.TxtID.Text          = emp.EmpID;
                        form.TxtFirstName.Text   = emp.FirstName;
                        form.TxtMiddle.Text      = emp.MiddleInitial;
                        form.TxtLastName.Text    = emp.LastName;
                        form.CBxType.Text        = emp.EmpType.ToString();
                        form.CBxMarital.Text     = emp.MaritalStatus;
                        form.CBxFPTime.Text      = emp.FPTime;
                        form.TxtDepartment.Text  = emp.Department;
                        form.TxtTitle.Text       = emp.Title;
                        form.DTPStart.Value      = emp.StartDate;
                        form.CBxStatus.Text      = emp.Status;
                        form.TxtOvertime.Text    = (emp.OvertimeEligible == true) ? "Yes" : "No";
                        form.TxtCommission.Text  = (emp.CommissionEligible == true) ? "Yes" : "No";
                        form.TxtBenefits.Text    = (emp.BenefitsEligible == true) ? "Yes" : "No";
                        form.TxtEduBenefits.Text = (emp.EducationBenefitsEligible == true) ? "Yes" : "No";

                        //Set form emp compensation type
                        if (emp.EmpType.Equals(EType.HOURLY))
                        {
                            Hourly hourly = (Hourly)emp;
                            form.TxtComp1.Text    = hourly.HourlyRate.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                            form.LblComp1.Text    = LITERAL_HRY_RATE;
                            form.LblComp2.Visible = true;
                            form.TxtComp2.Visible = true;
                            form.LblComp2.Text    = LITERAL_HOURS_WORKED;
                            form.LblComp3.Visible = false;
                            form.TxtComp3.Visible = false;
                        } // end else if
                        else if (emp.EmpType.Equals(EType.SALARY))
                        {
                            Salary salary = (Salary)emp;
                            form.TxtComp1.Text    = salary.MonthlySalary.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                            form.LblComp1.Text    = LITERAL_SRY_RATE;
                            form.LblComp2.Visible = false;
                            form.TxtComp2.Visible = false;
                            form.LblComp3.Visible = false;
                            form.TxtComp3.Visible = false;
                        } // end else if
                        else if (emp.EmpType.Equals(EType.SALES))
                        {
                            Sales sales = (Sales)emp;
                            form.TxtComp1.Text    = sales.MonthlySalary.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                            form.TxtComp2.Text    = ((sales.CommissionRate * 100).ToString() + "%");
                            form.LblComp1.Text    = LITERAL_SAL_RATE;
                            form.LblComp2.Text    = LITERAL_SRY_RATE;
                            form.LblComp2.Visible = true;
                            form.TxtComp2.Visible = true;
                            form.LblComp3.Text    = LITERAL_SALES;
                            form.LblComp3.Visible = true;
                            form.TxtComp3.Visible = true;
                            form.TxtComp3.Text    = sales.GrossSales.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                        } // end else if
                        else if (emp.EmpType.Equals(EType.CONTRACT))
                        {
                            Contract contract = (Contract)emp;
                            form.TxtComp1.Text    = contract.ContractWage.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                            form.LblComp1.Text    = LITERAL_CON_RATE;
                            form.LblComp2.Visible = true;
                            form.TxtComp2.Visible = true;
                            form.LblComp2.Text    = LITERAL_AGENCY;
                            form.TxtComp2.Text    = contract.Agency;
                            form.LblComp3.Visible = false;
                            form.TxtComp3.Visible = false;
                        } // end else if

                        //If employee is eligible for benefits
                        if (emp.EducationBenefitsEligible)
                        {
                            //Show the approval request btn
                            form.BtnRequestApproval.Visible = true;

                            //If the employee is eligible, but has already obtained approval
                            if (emp.EducationBenefitsApproved)
                            {
                                //Hide BtnRequestApproval
                                form.BtnRequestApproval.Visible = false;
                                //Show BtnEmpBenefits
                                form.BtnEmpBenefits.Visible = true;
                            } // end if
                        }     // end if

                        //Show form
                        form.ShowDialog(this);
                        form.Activate();
                    } // end else
                }     // end if
            }         // end try
            catch // employee INVALID
            {
                //Prompt user - provided employee credentials were invalid
                MessageBox.Show(INVALID_EMPLOYEE_MSG, INVALID_EMPLOYEE_CAPTION);
            } // end catch
        }     // end method AuthEmp()
示例#2
0
        } // end method BtnClear_Click()

        /// <summary>
        /// To find the item that was clicked on, then show a general employee form with item's data
        /// </summary>
        /// <param name="sender">The object generating the event</param>
        /// <param name="e">The event args</param>
        private void ListAllEmp_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //Create new Employee
            Employee emp = null;

            //Cast sender object to ListView
            ListView list = (ListView)sender;

            //Use hit test to find coordinates and item of mouse double click
            ListViewItem item = list.HitTest(e.Location).Item;

            try
            {
                //Get the employee object of the selected item
                emp = BusinessRules.Instance[uint.Parse(item.Text)];

                //Create new instance of the form
                FrmEmp_General form = new FrmEmp_General();

                //Set form's CurrEmp
                form.CurrEmp = emp;

                //Set values in form
                form.CurrEmp             = emp;
                form.TxtID.Text          = emp.EmpID;
                form.TxtFirstName.Text   = emp.FirstName;
                form.TxtMiddle.Text      = emp.MiddleInitial;
                form.TxtLastName.Text    = emp.LastName;
                form.CBxType.Text        = emp.EmpType.ToString();
                form.CBxMarital.Text     = emp.MaritalStatus;
                form.CBxFPTime.Text      = emp.FPTime;
                form.TxtDepartment.Text  = emp.Department;
                form.TxtTitle.Text       = emp.Title;
                form.DTPStart.Value      = emp.StartDate;
                form.CBxStatus.Text      = emp.Status;
                form.TxtOvertime.Text    = (emp.OvertimeEligible == true) ? "Yes" : "No";
                form.TxtCommission.Text  = (emp.CommissionEligible == true) ? "Yes" : "No";
                form.TxtBenefits.Text    = (emp.BenefitsEligible == true) ? "Yes" : "No";
                form.TxtEduBenefits.Text = (emp.EducationBenefitsEligible == true) ? "Yes" : "No";

                //Set form emp compensation type
                if (emp.EmpType.Equals(EType.HOURLY))
                {
                    Hourly hourly = (Hourly)emp;
                    form.TxtComp1.Text    = hourly.HourlyRate.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                    form.LblComp1.Text    = LITERAL_HRY_RATE;
                    form.LblComp2.Visible = true;
                    form.TxtComp2.Visible = true;
                    form.TxtComp2.Text    = hourly.HoursWorked.ToString();
                    form.LblComp2.Text    = LITERAL_HOURS_WORKED;
                    form.LblComp3.Visible = false;
                    form.TxtComp3.Visible = false;
                } // end else if
                else if (emp.EmpType.Equals(EType.SALARY))
                {
                    Salary salary = (Salary)emp;
                    form.TxtComp1.Text    = salary.MonthlySalary.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                    form.LblComp1.Text    = LITERAL_SAL_RATE;
                    form.LblComp2.Visible = false;
                    form.TxtComp2.Visible = false;
                    form.LblComp3.Visible = false;
                    form.TxtComp3.Visible = false;
                } // end else if
                else if (emp.EmpType.Equals(EType.SALES))
                {
                    Sales sales = (Sales)emp;
                    form.TxtComp1.Text    = sales.MonthlySalary.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                    form.TxtComp2.Text    = ((sales.CommissionRate * 100).ToString() + "%");
                    form.LblComp1.Text    = LITERAL_SAL_RATE;
                    form.LblComp2.Text    = LITERAL_SRY_RATE;
                    form.LblComp2.Visible = true;
                    form.TxtComp2.Visible = true;
                    form.LblComp3.Text    = LITERAL_SALES;
                    form.LblComp3.Visible = true;
                    form.TxtComp3.Visible = true;
                    form.TxtComp3.Text    = sales.GrossSales.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                } // end else if
                else if (emp.EmpType.Equals(EType.CONTRACT))
                {
                    Contract contract = (Contract)emp;
                    form.TxtComp1.Text    = contract.ContractWage.ToString("c", CultureInfo.CreateSpecificCulture("en-US"));
                    form.LblComp1.Text    = LITERAL_CON_RATE;
                    form.LblComp2.Visible = true;
                    form.TxtComp2.Visible = true;
                    form.LblComp2.Text    = LITERAL_AGENCY;
                    form.TxtComp2.Text    = contract.Agency;
                    form.LblComp3.Visible = false;
                    form.TxtComp3.Visible = false;
                } // end else if

                //Show request approval btn based on eduBfts eligibility & prior approval
                if (emp.EducationBenefitsEligible && emp.EducationBenefitsApproved)
                {
                    form.BtnEmpBenefits.Visible = true;
                } // end if

                //Enable all controls for admin editing
                foreach (Control control in form.GBxGeneral.Controls)
                {
                    control.Enabled = true;
                } // end foreach
                foreach (Control control in form.GBxSpecific.Controls)
                {
                    control.Enabled = true;
                } // end foreach

                //Show save btn
                form.BtnSave.Visible = true;

                //Show form
                form.ShowDialog(this);
            } // end try
            catch (NullReferenceException)
            {
                //do nothing
            } // end catch
        }     // end method ListAllEmp_MouseDoubleClick()