private void bindAccessorProcessor(GridViewRowEventArgs e, DropDownList selectDropDown, GridView selectGV)
    {

        //get processor and check name

        string[] splitter = new string[] { PageConstants.GREATER_GREATER_THAN };
        string[] VacancyInfoTosplit = (selectDropDown.SelectedValue).Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        currentVacancyNo = VacancyInfoTosplit[0].Trim();
        currentVacancyDate = VacancyInfoTosplit[1].Trim();
        resposibleHROfficer = VacancyInfoTosplit[3].Trim();
        Vacancy vacancy = new Vacancy();
        vacancy.VacancyNo = currentVacancyNo;
        vacancy.PostedDate = currentVacancyDate;


        VacancyRegistrationAndEvaluationManager vacancyRegEvaluationManager = new VacancyRegistrationAndEvaluationManager(vacancy);
        TransactionResponse response = new TransactionResponse();
        response = vacancyRegEvaluationManager.getVacancyDetail(vacancy);

        DataTable employeeData = (DataTable)response.Data;


        Employee employee = new Employee();
        //get list of Employee using Employee manager.
        if (employeeData != null && employeeData.Rows.Count > 0)
        {

            // Display processor and checker in the gridview footer
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                //get processor First name & Middle Name
                employee.EmpID = employeeData.Rows[0]["responsible_processor_EID"].ToString();

                EmployeeManager employeeManager = new EmployeeManager(employee);
                List<Employee> listOfEmployee = employeeManager.getEmployeeDetial();
                string fullName = null;

                foreach (Employee emply in listOfEmployee)
                {
                    fullName = emply.FName + " " + emply.MName;
                }

                e.Row.Cells[2].Text = "Processed by :";
                e.Row.Cells[2].Font.Bold = true;

                e.Row.Cells[3].Text = fullName;
                e.Row.Cells[3].Font.Bold = true;

                //get checkor First name & Middle Name
                employee.EmpID = employeeData.Rows[0]["reponsible_accessor_EID"].ToString();
                employeeManager = new EmployeeManager(employee);
                listOfEmployee = employeeManager.getEmployeeDetial();

                fullName = null;
                foreach (Employee emply in listOfEmployee)
                {
                    fullName = emply.FName + " " + emply.MName;
                }

                e.Row.Cells[7].Text = "Assessed by :";
                e.Row.Cells[7].Font.Bold = true;

                e.Row.Cells[8].Text = fullName;
                e.Row.Cells[8].Font.Bold = true;
            }
        }
        else
        {
            selectGV.ShowFooter = false;
        }
    }
    private void BindFirstPhaseReport(int isfromAll, DropDownList selectDropDown)
    {

        lblVacancyPhase1.Visible = false;

        lblVacancyPhase1.Visible = false;
        string[] splitter = new string[] { PageConstants.GREATER_GREATER_THAN };
        string[] VacancyInfoTosplit = (selectDropDown.SelectedValue).Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        currentVacancyNo = VacancyInfoTosplit[0].Trim();
        currentVacancyDate = VacancyInfoTosplit[1].Trim();
        resposibleHROfficer = VacancyInfoTosplit[3].Trim();
        Vacancy vacancy = new Vacancy();
        vacancy.VacancyNo = currentVacancyNo;
        vacancy.PostedDate = currentVacancyDate;

        //get recently selected employee
        getRecentlySelectedLateralPenalityEmployee(vacancy, isfromAll);

        //get and display the vacancy to user. 
        getVacancyReportAndDisplayToUser(vacancy, PageConstants.REPORT_PHASE1, isfromAll);


        VacancyRegistrationAndEvaluationManager manager = new VacancyRegistrationAndEvaluationManager();
        TransactionResponse response = new TransactionResponse();

        //get vacancy detail
        response = manager.getVacancyDetail(vacancy);
        DataTable dataTable = (DataTable)response.Data;
        string postDate = "";
        try
        {
            postDate = String.Format("{0:MMM d, yyyy}", Convert.ToDateTime(dataTable.Rows[0]["posted_date"]));
        }
        catch (Exception)
        {
        }
        VacDetailPanel.Visible = true;
        lblVacancyPost.Text = dataTable.Rows[0]["Vancay_title"].ToString() + "  ( JG - " +
                              dataTable.Rows[0]["vacancy_for_JobGrade"].ToString() + " )";
        lblVacancyNum.Text = dataTable.Rows[0]["vacancy_No"].ToString() + " dated " + postDate;

        //lblJobDes.Text = "Specification: ";

        lblJobReq.Text = dataTable.Rows[0]["JobDescription"].ToString() + " " + dataTable.Rows[0]["JobRequirement"].ToString() + ". ";


        VacDetailAllForstPhasePanel.Visible = true;
        lblAll1stVacancyPost.Text = dataTable.Rows[0]["Vancay_title"].ToString() + "  ( JG - " +
                              dataTable.Rows[0]["vacancy_for_JobGrade"].ToString() + " )";
        lblAll1stVacancyNum.Text = dataTable.Rows[0]["vacancy_No"].ToString() + " dated " + postDate;
        //lblJobDes.Text = "Specification: ";

        lblAll1stJobReq.Text = dataTable.Rows[0]["JobDescription"].ToString() + " " + dataTable.Rows[0]["JobRequirement"].ToString() + ". ";
   
    }
    protected void btnGenerateFinalReport_Click(object sender, EventArgs e)
    {
        if (DropDownListFinalResult.SelectedValue == "-1")
        {
            lblVacancyFinal.Visible = true;
            return;
        }
        lblVacancyFinal.Visible = false;

        string[] splitter = new string[] { PageConstants.GREATER_GREATER_THAN };
        VacancyInfoTosplit = (DropDownListFinalResult.SelectedValue).Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        currentVacancyNo = VacancyInfoTosplit[0].Trim();
        currentVacancyDate = VacancyInfoTosplit[1].Trim();
        Vacancy vacancy = new Vacancy();
        vacancy.VacancyNo = currentVacancyNo;
        vacancy.PostedDate = currentVacancyDate;

        //get and display the vacancy to user. 
        int isfromAll = 0;
        getVacancyReportAndDisplayToUser(vacancy, PageConstants.REPORT_PHASE2, isfromAll);


        VacancyRegistrationAndEvaluationManager manager = new VacancyRegistrationAndEvaluationManager();
        TransactionResponse response = new TransactionResponse();

        //get vacancy detail
        response = manager.getVacancyDetail(vacancy);
        DataTable dataTable = (DataTable)response.Data;
        string postDate = "";
        try
        {
            postDate = String.Format("{0:MMM d, yyyy}", Convert.ToDateTime(dataTable.Rows[0]["posted_date"]));
        }
        catch (Exception)
        {
        }
        VacDetailFinalPanel.Visible = true;
        lblfinalVacancyPost.Text = dataTable.Rows[0]["Vancay_title"].ToString() + "  ( JG - " +
                              dataTable.Rows[0]["vacancy_for_JobGrade"].ToString() + " )";
        lblfinalVacancyNum.Text = dataTable.Rows[0]["vacancy_No"].ToString() + " dated " + postDate;

        lblfinalJobReq.Text = dataTable.Rows[0]["JobDescription"].ToString() + " " + dataTable.Rows[0]["JobRequirement"].ToString() + ". ";
   
    }
    private string getDetailOfSelectedVacancy(Vacancy vacancy)
    {
        VacancyRegistrationAndEvaluationManager manager = new VacancyRegistrationAndEvaluationManager();
        TransactionResponse response = new TransactionResponse();

        //get vacancy detail
        response = manager.getVacancyDetail(vacancy);
        DataTable dataTable = (DataTable)response.Data;

        return (dataTable.Rows[0]["vacancy_evaluation_form"].ToString().Trim());
    }
    private void populateEmployeeData(Vacancy vacancy)
    {
        vacancy.ResponsibleProcessorEID = loggedInEmpID;
        VacancyRegistrationAndEvaluationManager vacancyRegEvaluationManager = new VacancyRegistrationAndEvaluationManager(vacancy);
        List<string> empID = vacancyRegEvaluationManager.getListEmpIDForProcessorSecondPhase(evalutedEmpID);
        if (empID.Count != 0 && empID != null)
        {
            Employee emply = new Employee();
            emply.EmpID = empID[0];
            EmployeeManager EmployeeManager = new EmployeeManager(emply);
            Employee employee = EmployeeManager.detailOfEmployeToBeEvaluated(vacancy.VacancyNo, VacancyDate);
            if (employee != null)
            {
                //Get the current vacancy detail
                //Check vacancy status [if status = 7 interview only else if status = 8 exam only, else if status = 9 exam & interview]
                TransactionResponse response = new TransactionResponse();
                response = vacancyRegEvaluationManager.getVacancyDetail(vacancy);
                DataTable vacancyDetail = (DataTable)response.Data;

                string formtype = vacancyDetail.Rows[0]["vacancy_evaluation_form"].ToString();
                vacancyStatus = vacancyDetail.Rows[0]["status"].ToString();

                if (formtype == "2")
                {
                    if (vacancyStatus == "7")
                    {
                        ExamPanelforForm2.Visible = false;
                        InterviewPanelforForm2.Visible = true;
                    }
                    else if (vacancyStatus == "8")
                    {
                        ExamPanelforForm2.Visible = true;
                        InterviewPanelforForm2.Visible = false;
                    }
                    else if (vacancyStatus == "9")
                    {
                        ExamPanelforForm2.Visible = true;
                        InterviewPanelforForm2.Visible = true;
                    }
                }

                if (checkAlreadyEvaluatedApplicantAndDisplayForUpdate(employee, vacancy))
                {
                    return;
                }
                displayApplcantDetailEvaluationForm(employee);
            }
            else
            {
                UserDetialPanel.Visible = false;
                PanelApplicantmsg.Visible = true;
                ApplErrorDiv.Visible = true;
                lblApplicantErrormsg.Text = DBOperationErrorConstants.M_NO_EMPLOYEE_REGISTERED_FOR_PROCESSOR_SECOND_PHASE;
            }
        }
        else
        {
            UserDetialPanel.Visible = false;
            PanelApplicantmsg.Visible = true;
            ApplErrorDiv.Visible = true;
            lblApplicantErrormsg.Text = DBOperationErrorConstants.M_NO_EMPLOYEE_REGISTERED_FOR_PROCESSOR_SECOND_PHASE;
        }
    }
    protected void btnConfirmComplete_Click(object sender, EventArgs e)
    {
        string temp = DropDownVacancyProfList.SelectedValue;

        if (temp == "-1")
        {
            lblDropVacancyList.Visible = true;
            return;
        }

        string[] splitter = new string[] { PageConstants.GREATER_GREATER_THAN };
        VacancyInfoTosplit = (temp).Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        vacancyNo = VacancyInfoTosplit[0].Trim();
        VacancyDate = VacancyInfoTosplit[1].Trim();

        //Update vacancy Profile arrived date. 
        Vacancy vacancy = new Vacancy();
        vacancy.VacancyNo = vacancyNo;
        vacancy.PostedDate = VacancyDate;

        TransactionResponse response = new TransactionResponse();

        VacancyRegistrationAndEvaluationManager manager = new VacancyRegistrationAndEvaluationManager(vacancy);
        response = manager.updateProfileArrivedDateAndVacancyStatus();

        PanelConfirmVacancyComplete.Visible = false;
        displayMessageToTheUser(response);

        if (response.isSuccessful())
        {
            //REGISTER NOTIFICATION for HR Manager
            //check the vacancy status whether its re-advertise or Normal

            response = manager.getVacancyDetail(vacancy);
            DataTable dataTable = (DataTable)response.Data;

            string vacStatus = null;
            string repHROfficerProcessor = null;
            string repHROfficerCheckor = null;
            
            NotificationManager notificationManager = new NotificationManager(vacancy);
            TransactionResponse notificationResponse = null;

            if (dataTable != null && dataTable.Rows.Count > 0)
            {
                vacStatus = dataTable.Rows[0]["status"].ToString();
                repHROfficerProcessor = dataTable.Rows[0]["responsible_processor_EID"].ToString();
                repHROfficerCheckor = dataTable.Rows[0]["reponsible_accessor_EID"].ToString();

                if (vacStatus.Trim() == "11")
                {
                    if (repHROfficerCheckor != null || repHROfficerProcessor != null)
                    {
                    }
                    else
                    {
                        notificationResponse = notificationManager.addNotification(Membership.GetUser(), "6");
                    }
                }
                else
                {
                    notificationResponse = notificationManager.addNotification(Membership.GetUser(), "6");
                }
            }


            if (!notificationResponse.isSuccessful())
            {
                WarnDIV.Visible = true;
                lblWarningMsg.Text = notificationResponse.getMessage() + notificationResponse.getErrorCode();
            }

            DropDownVacancyProfList.ClearSelection();
        }
        else
        {
            msgPanel.Visible = true;
            InfoDIV.Visible = true;
            lblInformationMsg.Text = response.getMessage();
            DropDownVacancyProfList.ClearSelection();
        }
    }
    protected void AssignedVacDV_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        int updateAccProc = 0;
        string oldProcessor = null;
        string oldAccessor = null;

        int ProcAccUpdateStatus = 0;

        try
        {
            string vacancyTitle = e.NewValues["[Vacancy Title]"].ToString().Trim();
            string branchID = e.NewValues["branch_id"].ToString().Trim();
            string deadLine = e.NewValues["[Vacancy Deadline]"].ToString().Trim();
            string jGrade = e.NewValues["[Job Grade]"].ToString().Trim();
            string vacancyStatus = e.NewValues["status"].ToString().Trim();
            string year4Gen = e.NewValues["[Year required for General]"].ToString().Trim();
            string year4Spec = e.NewValues["[Year required for Specific]"].ToString().Trim();
            string genPerc = e.NewValues["[General Work Exp Percentage]"].ToString().Trim();
            string specPerc = e.NewValues["[Specific Work Exp Percentage]"].ToString().Trim();
            string RelPer = e.NewValues["[Related Work Exp Percentage]"].ToString().Trim();
            string examPer = e.NewValues["[Examination Percentage]"].ToString().Trim();
            string mangRec = e.NewValues["[Manageral Rec Percentage]"].ToString().Trim();
            string interviewPer = e.NewValues["[Interview Percentage]"].ToString().Trim();
            string jobDes = e.NewValues["[Job Description]"].ToString().Trim();
            string jobReq = e.NewValues["[Job Requirement]"].ToString().Trim();
            string benefit = e.NewValues["[Job Benefit]"].ToString().Trim();
            string appCompDate = e.NewValues["[Applicant Registration Complete Date]"].ToString().Trim();
            string profArrive = e.NewValues["[Profile Arrived Date]"].ToString().Trim();
            string procSDate = e.NewValues["[Processor Start Date]"].ToString().Trim();
            string procEDate = e.NewValues["[Processor End Date]"].ToString().Trim();
            string accesSDate = e.NewValues["[Accessor Start Date]"].ToString().Trim();
            string accesEDate = e.NewValues["[Accessor End Date]"].ToString().Trim();
            string procID = e.NewValues["[Processor ID]"].ToString().Trim();
            string accesID = e.NewValues["[Accessor ID]"].ToString().Trim();

            if (vacStatusCanEditted == "Vacancy Checking Done" ||
                vacStatusCanEditted == "Vacancy Evalution1 Done" ||
                vacStatusCanEditted == "Vacancy Evalution2 Done")
            {
                updateAccProc = 0;
            }
            else
            {
                updateAccProc = 1;
            }

            Vacancy vacancy = new Vacancy();

            vacancy.VancayTitle = vacancyTitle;
            vacancy.BranchId = branchID;
            vacancy.VancyDeadline = deadLine;
            vacancy.VacancyforJobGrade = jGrade;
            vacancy.Status = vacancyStatus;
            vacancy.YearRequiredforGeneral = year4Gen;
            vacancy.YearRequiredforSpec = year4Spec;
            vacancy.GeneralWrkExprPercent = genPerc;
            vacancy.SpecificWrkExprPercent = specPerc;
            vacancy.RelatedWrkExprPercent = RelPer;
            vacancy.ExaminationPercent = examPer;
            vacancy.ManagerRecPercent = mangRec;
            vacancy.InterviewPercent = interviewPer;
            vacancy.ApplicantComplete = appCompDate;
            vacancy.ProfileArrivedDate = profArrive;
            vacancy.ProcessorStartDate = procSDate;
            vacancy.ProcessorEndDate = procEDate;
            vacancy.AccessorStartDate = accesSDate;
            vacancy.AccessorEndDate = accesEDate;
            vacancy.ResponsibleProcessorEID = procID;
            vacancy.ResponsibleAccessorEID = accesID;
            vacancy.JobDescription = jobDes;
            vacancy.JobRequirement = jobReq;
            vacancy.SalaryAndBenefit = benefit;

            vacancy.VacancyNo = vacancyNoforGV;
            vacancy.PostedDate = postDate;

            VacancyRegistrationAndEvaluationManager manager = new VacancyRegistrationAndEvaluationManager();
            TransactionResponse response = new TransactionResponse();

            //get the current Processor and Checker
            response = manager.getVacancyDetail(vacancy);
            DataTable dataTable = (DataTable)response.Data;
            


            if (dataTable != null && dataTable.Rows.Count > 0)
            {
                oldProcessor = dataTable.Rows[0]["responsible_processor_EID"].ToString().Trim();
                oldAccessor = dataTable.Rows[0]["reponsible_accessor_EID"].ToString().Trim();

                if (procID == oldProcessor && accesID == oldAccessor)
                {
                    ProcAccUpdateStatus = 1;
                }
                else if (procID != oldProcessor && accesID == oldAccessor)
                {
                    ProcAccUpdateStatus = 2;
                }
                else if (procID == oldProcessor && accesID != oldAccessor)
                {
                    ProcAccUpdateStatus = 3;
                }
                else if (procID != oldProcessor && accesID != oldAccessor)
                {
                    ProcAccUpdateStatus = 4;
                }
            }

            response = manager.updateVacancyDetailAssignedtoHROfficer(vacancy, updateAccProc, ProcAccUpdateStatus, 
                                                oldProcessor, oldAccessor);
            if (response.isSuccessful())
            {
                AssignedVacDV.ChangeMode(DetailsViewMode.ReadOnly);
                BindAssignedVacToDetailView();

                msgPanel.Visible = true;
                SucessDIV.Visible = true;
                lblSuccessMessage.Text = response.getMessage();
            }
            else
            {
                msgPanel.Visible = true;
                ErroroDIV.Visible = true;
                lblErrorMsg.Text = response.getMessage();
            }

        }
        catch (Exception ex)
        {
            msgPanel.Visible = true;
            lblErrorMsg.Text = ex.StackTrace.ToString();
        }
    }
    protected void btnConfirmComplete_Click(object sender, EventArgs e)
    {
        lblCompleteVacancy.Visible = false;

        string[] splitter = new string[] { PageConstants.GREATER_GREATER_THAN };
        string[] VacancyInfoTosplit = (DropDownListCompVacancy.SelectedItem.Text).Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        string vacancyNo = VacancyInfoTosplit[0].Trim();
        string VacancyDate = VacancyInfoTosplit[1].Trim();

        //Update vacancy Profile arrived date. 
        Vacancy vacancy = new Vacancy();
        vacancy.VacancyNo = vacancyNo;
        vacancy.PostedDate = VacancyDate;

        TransactionResponse response = new TransactionResponse();

        VacancyRegistrationAndEvaluationManager manager = new VacancyRegistrationAndEvaluationManager(vacancy);

        response = manager.getVacancyDetail(vacancy);
        DataTable dataTable = (DataTable)response.Data;
        string vacStatus = null;
        string respProcessor = null;
        string respAccessor = null;
        if (dataTable != null && dataTable.Rows.Count > 0)
        {
            vacStatus = dataTable.Rows[0]["status"].ToString().Trim();

            respProcessor = dataTable.Rows[0]["responsible_processor_EID"].ToString().Trim();
            respAccessor = dataTable.Rows[0]["reponsible_accessor_EID"].ToString().Trim();
        }

        vacancy.ResponsibleProcessorEID = respProcessor;
        vacancy.ResponsibleAccessorEID = respAccessor;

        if (vacStatus == "11" && respAccessor != null && respProcessor != null && respAccessor != "" && respProcessor != "")
        {
            //Change the status of the vacancy into 3 ==> assigned to HR Officer
            //notifiy Re-advertise vacancy re-assigned to HR Officer

            //update vacancy status to 'assigned for Evaluation' STAUS CODE = 3 . 
            vacancy.Status = VacancyConstants.VACANCY_ASSIGNED_TO_HR_OFFICERS;

            VacancyRegistrationAndEvaluationManager vacancyRegistrationManager = new VacancyRegistrationAndEvaluationManager(vacancy);
            response = vacancyRegistrationManager.updateVacancyStatusToAssgnedFromReAdvertise();

            //Notification for HR Officer goes here.
            NotificationManager notificationManager = new NotificationManager(vacancy);
            TransactionResponse notificationResponse = notificationManager.addNotificationForVacancyAssignement(Membership.GetUser(), true);
            if (notificationResponse.isSuccessful())
            {

            }
            else
            {
                WarnDIV.Visible = true;
                lblWarningMsg.Text = notificationResponse.getMessage() + notificationResponse.getErrorCode();
            }
        }
        else
        {

            response = manager.getApplicantRegistrationComplete();

            if (response.isSuccessful())
            {
                response = manager.updateApplicantRegisterationCompleteDate();
                if (response.isSuccessful())
                {
                    msgPanel.Visible = true;
                    SucessDIV.Visible = true;
                    lblSuccessMessage.Text = response.getMessage();

                    PanelCompleteApplicant.Visible = true;
                    btnCompAppReg.Visible = true;
                    DropDownListCompVacancy.ClearSelection();

                    //Register Notification here if its required
                }
                else
                {
                    msgPanel.Visible = true;
                    ErroroDIV.Visible = true;
                    lblErrorMsg.Text = response.getMessage() + response.getErrorCode();
                }
            }
            else
            {
                clearMsgPanel();
                msgPanel.Visible = true;
                InfoDIV.Visible = true;
                lblInformationMsg.Text = response.getMessage();
            }
        }
        populateVacancyList();
        populateVacancyForRegComplete();

        PanelConfirmVacancyComplete.Visible = false;
        DropDownListCompVacancy.ClearSelection();
    }