private void Generate()
        {
            Page.Validate();

            if (Page.IsValid)
            {
                mReport1 master = (mReport1)this.Master;

                // Get Data
                string employeeType = (ddlEmployeeType.SelectedValue == "(All)") ? "%" : ddlEmployeeType.SelectedValue + "%";
                string projectTimeState = (ddlProjectTimeState.SelectedValue == "(All)") ? "%" : ddlProjectTimeState.SelectedValue;
                DateTime startDate = DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                DateTime endDate = DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString());
                int clientId = 0; if (ddlClient.SelectedValue != "-1") clientId = Int32.Parse(ddlClient.SelectedValue);
                int projectId = 0; if (ddlProject.SelectedValue != "-1") projectId = Int32.Parse(ddlProject.SelectedValue);
                bool includeAllHours = cbxIncludeAllHours.Checked;
                string personnelAgencySelected = "null";
                if (pnlPersonnelAgency.Visible)
                {
                    if (ddlPersonalAgency.SelectedIndex > 0)
                    {
                        personnelAgencySelected = ddlPersonalAgency.SelectedValue + "%";
                    }
                }

                PrintHoursForPayrollPeriodGateway printHoursForPayrollPeriodGateway = new PrintHoursForPayrollPeriodGateway();
                printHoursForPayrollPeriodGateway.ClearBeforeFill = false;

                foreach (ListItem lst in cbxlEmployee.Items)
                {
                    if (lst.Selected)
                    {
                        if (ddlCountry.SelectedValue == "-1")
                        {
                            if (ddlEmployeeType.SelectedValue != "Salaried")
                            {
                                if (ddlClient.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeState(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, true, personnelAgencySelected);
                                }
                                else
                                {
                                    if (ddlProject.SelectedValue == "-1")
                                    {
                                        printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeStateClientId(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, true, personnelAgencySelected);
                                    }
                                    else
                                    {
                                        if (!includeAllHours)
                                        {
                                            printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeStateClientIdProjectId(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, projectId, true, personnelAgencySelected);
                                        }
                                        else
                                        {
                                            printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeStateClientIdProjectIdIncludeAllHours(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, projectId, true);

                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (ddlClient.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeState(startDate, endDate, int.Parse(lst.Value), projectTimeState, true);
                                }
                                else
                                {
                                    if (ddlProject.SelectedValue == "-1")
                                    {
                                        printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeStateClientId(startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, true);
                                    }
                                    else
                                    {
                                        if (!includeAllHours)
                                        {
                                            printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeStateClientIdProjectId(startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, projectId, true);
                                        }
                                        else
                                        {
                                            printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeStateClientIdProjectIdIncludeAllHours(startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, projectId, true);

                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (ddlEmployeeType.SelectedValue != "Salaried")
                            {
                                if (ddlClient.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeState(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, true, personnelAgencySelected);
                                }
                                else
                                {
                                    if (ddlProject.SelectedValue == "-1")
                                    {
                                        printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientId(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, true, personnelAgencySelected);
                                    }
                                    else
                                    {
                                        if (!includeAllHours)
                                        {
                                            printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientIdProjectId(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, projectId, true, personnelAgencySelected);
                                        }
                                        else
                                        {
                                            printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientIdProjectIdIncludeAllHours(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, projectId, true);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (ddlClient.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeState(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, true);
                                }
                                else
                                {
                                    if (ddlProject.SelectedValue == "-1")
                                    {
                                        printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientId(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, true);
                                    }
                                    else
                                    {
                                        if (!includeAllHours)
                                        {
                                            printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientIdProjectId(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, projectId, true);
                                        }
                                        else
                                        {
                                            printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientIdProjectIdIncludeAllHours(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, projectId, true);

                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                printHoursForPayrollPeriodGateway.ClearBeforeFill = true;

                // ... set properties to master page
                master.Data = printHoursForPayrollPeriodGateway.Data;
                master.Table = printHoursForPayrollPeriodGateway.TableName;

                // Get report
                if (printHoursForPayrollPeriodGateway.Table.Rows.Count > 0)
                {
                    if (master.Format == "pdf")
                    {
                        if (ddlCountry.SelectedValue == "1")
                        {
                            master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintHoursForPayrollPeriodWithApprovalReport();
                        }
                        else
                        {
                            master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintHoursForPayrollPeriodWithApprovalUSAReport();
                        }
                    }
                    else
                    {
                        if (ddlCountry.SelectedValue == "1")
                        {
                            master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintHoursForPayrollPeriodWithApprovalReportExport();
                        }
                        else
                        {
                            master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintHoursForPayrollPeriodWithApprovalUSAReportExport();
                        }
                    }

                    // ... set parameters to report
                    if (master.Format == "pdf")
                    {
                        // ... For report
                        // ... ... country
                        if (ddlCountry.SelectedValue == "2")
                        {
                            master.SetParameter("Country", "USA");
                        }
                        else
                        {
                            if (ddlCountry.SelectedValue == "1")
                            {
                                master.SetParameter("Country", "Canada");
                            }
                            else
                            {
                                master.SetParameter("Country", "All");
                            }
                        }

                        // ... ... project time state
                        if (ddlProjectTimeState.SelectedValue == "(All)")
                        {
                            master.SetParameter("ProjectTimeState", "All");
                        }
                        else
                        {
                            master.SetParameter("ProjectTimeState", ddlProjectTimeState.SelectedItem.Text);
                        }

                        // ... ... team member
                        if (IsAllEmployeesSelected())
                        {
                            master.SetParameter("teamMember", "All");
                        }
                        else
                        {
                            string fullName = GetEmployeesSelected();

                            master.SetParameter("teamMember", fullName);
                        }

                        // ... ... team member type
                        if (ddlEmployeeType.SelectedValue == "(All)")
                        {
                            master.SetParameter("teamMemberType", "All");
                        }
                        else
                        {
                            if (ddlEmployeeType.SelectedValue == "LFSCA") master.SetParameter("teamMemberType", "LFS Canada");
                            if (ddlEmployeeType.SelectedValue == "LFSUS") master.SetParameter("teamMemberType", "LFS USA");
                            if (ddlEmployeeType.SelectedValue == "LFS") master.SetParameter("teamMemberType", "All LFS");
                            if (ddlEmployeeType.SelectedValue == "PAGCA")
                            {
                                master.SetParameter("teamMemberType", "PAG Canada");
                            }
                            if (ddlEmployeeType.SelectedValue == "PAGUS")
                            {
                                master.SetParameter("teamMemberType", "PAG USA");
                            }
                            if (ddlEmployeeType.SelectedValue == "PAG")
                            {
                                master.SetParameter("teamMemberType", "All PAG");
                            }
                            if (ddlEmployeeType.SelectedValue == "SOTA") master.SetParameter("teamMemberType", "SOTA");
                            if (ddlEmployeeType.SelectedValue == "Salaried") master.SetParameter("teamMemberType", "Salaried");
                            if (ddlEmployeeType.SelectedValue == "Subcontractor") master.SetParameter("teamMemberType", "Subcontractor");
                        }

                        string employeeTypeSelected = ddlEmployeeType.SelectedValue;
                        string employeeTypeSelectedFull = ddlEmployeeType.SelectedItem.Text;
                        string country = "";
                        if (ddlCountry.SelectedValue == "1")
                        {
                            country = "CANADA";
                        }
                        else
                        {
                            country = "USA";
                        }

                        if (employeeTypeSelected == "PAGCA" || employeeTypeSelected == "PAGUS" || employeeTypeSelected == "PAG")
                        {
                            master.SetParameter("name", "TEAM MEMBER HOURS FOR PAYROLL PERIOD - " + country + " - " + employeeTypeSelectedFull.ToUpper() + " -  (New Version With Approval)");
                        }
                        else
                        {
                            master.SetParameter("name", "TEAM MEMBER HOURS FOR PAYROLL PERIOD - " + country + " -  (New Version With Approval)");
                        }

                        // ... ...  user
                        int loginId = Convert.ToInt32(Session["loginID"]);
                        int companyId = Convert.ToInt32(Session["companyID"]);

                        LoginGateway loginGateway = new LoginGateway();
                        loginGateway.LoadByLoginId(loginId, companyId);
                        string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                        master.SetParameter("User", user.Trim());

                        // ... ... client
                        if (ddlClient.SelectedValue == "-1")
                        {
                            master.SetParameter("Client", "All");
                        }
                        else
                        {
                            int currentClientId = Int32.Parse(ddlClient.SelectedValue);

                            CompaniesGateway companiesGateway = new CompaniesGateway();
                            companiesGateway.LoadByCompaniesId(currentClientId, companyId);
                            master.SetParameter("Client", companiesGateway.GetName(currentClientId));
                        }

                        // ... ... project
                        if (ddlProject.SelectedValue == "-1")
                        {
                            master.SetParameter("Project", "All");
                        }
                        else
                        {
                            int projectId2 = Int32.Parse(ddlProject.SelectedValue);
                            ProjectGateway projectGateway = new ProjectGateway();
                            projectGateway.LoadByProjectId(projectId2);
                            string project = projectGateway.GetName(projectId2);
                            master.SetParameter("Project", project);
                        }

                        master.SetParameter("dateFrom", tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                        master.SetParameter("dateTo", tkrdpEndDate.SelectedDate.Value.ToShortDateString());

                        if (ddlPersonalAgency.SelectedIndex > 0)
                        {
                            master.SetParameter("personnelAgency", ddlPersonalAgency.SelectedItem.Text);
                        }
                        else
                        {
                            master.SetParameter("personnelAgency", "All");
                        }

                        // Report format
                        master.Report.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
                        master.Report.PrintOptions.PaperSize = PaperSize.PaperLetter;
                    }
                }
            }
            else
            {
                PrintHoursForPayrollPeriodGateway printHoursForPayrollPeriodGateway = new PrintHoursForPayrollPeriodGateway();

                mReport1 master = (mReport1)this.Master;
                master.Data = printHoursForPayrollPeriodGateway.Data;
                master.Table = printHoursForPayrollPeriodGateway.TableName;
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            string employeeType = (ddlEmployeeType.SelectedValue == "(All)") ? "%" : ddlEmployeeType.SelectedValue + "%";
            string projectTimeState = "%";
            DateTime startDate = DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString());
            DateTime endDate = DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString());
            int clientId = 0; if (ddlClient.SelectedValue != "-1") clientId = Int32.Parse(ddlClient.SelectedValue);
            int projectId = 0; if (ddlProject.SelectedValue != "-1") projectId = Int32.Parse(ddlProject.SelectedValue);
            string personnelAgencySelected = "%";
            if (pnlPersonnelAgency.Visible)
            {
                if (ddlPersonalAgency.SelectedIndex > 0)
                {
                    personnelAgencySelected = ddlPersonalAgency.SelectedValue + "%";
                }
            }

            PrintHoursForPayrollPeriodGateway printHoursForPayrollPeriodGateway = new PrintHoursForPayrollPeriodGateway();
            printHoursForPayrollPeriodGateway.ClearBeforeFill = false;

            foreach (ListItem lst in cbxlEmployee.Items)
            {
                if (lst.Selected)
                {
                    if (ddlCountry.SelectedValue == "-1")
                    {
                        if (ddlEmployeeType.SelectedValue != "Salaried")
                        {
                            if (ddlClient.SelectedValue == "-1")
                            {
                                printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeState(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, false, personnelAgencySelected);
                            }
                            else
                            {
                                if (ddlProject.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeStateClientId(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, false, personnelAgencySelected);
                                }
                                else
                                {
                                    printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeStateClientIdProjectId(employeeType, startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, projectId, false, personnelAgencySelected);
                                }
                            }
                        }
                        else
                        {
                            if (ddlClient.SelectedValue == "-1")
                            {
                                printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeState(startDate, endDate, int.Parse(lst.Value), projectTimeState, false);
                            }
                            else
                            {
                                if (ddlProject.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeStateClientId(startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, false);
                                }
                                else
                                {
                                    printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateEmployeeIdProjectTimeStateClientIdProjectId(startDate, endDate, int.Parse(lst.Value), projectTimeState, clientId, projectId, false);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (ddlEmployeeType.SelectedValue != "Salaried")
                        {
                            if (ddlClient.SelectedValue == "-1")
                            {
                                printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeState(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, false, personnelAgencySelected);
                            }
                            else
                            {
                                if (ddlProject.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientId(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, false, personnelAgencySelected);
                                }
                                else
                                {
                                    printHoursForPayrollPeriodGateway.LoadByEmployeeTypeStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientIdProjectId(employeeType, startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, projectId, false, personnelAgencySelected);
                                }
                            }
                        }
                        else
                        {
                            if (ddlClient.SelectedValue == "-1")
                            {
                                printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeState(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, false);
                            }
                            else
                            {
                                if (ddlProject.SelectedValue == "-1")
                                {
                                    printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientId(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, false);
                                }
                                else
                                {
                                    printHoursForPayrollPeriodGateway.LoadBySalariedStartDateEndDateCountryIdEmployeeIdProjectTimeStateClientIdProjectId(startDate, endDate, int.Parse(ddlCountry.SelectedValue), int.Parse(lst.Value), projectTimeState, clientId, projectId, false);
                                }
                            }
                        }
                    }
                }
            }

            printHoursForPayrollPeriodGateway.ClearBeforeFill = true;

            // ... set properties to master page
            master.Data = printHoursForPayrollPeriodGateway.Data;
            master.Table = printHoursForPayrollPeriodGateway.TableName;

            // Get report
            if (printHoursForPayrollPeriodGateway.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintHoursForPayrollPeriodReportOld();
                }
                else
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintHoursForPayrollPeriodReportExportOld();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    // ... For report
                    // ... ... country
                    if (ddlCountry.SelectedValue == "2")
                    {
                        master.SetParameter("Country", "USA");
                    }
                    else
                    {
                        if (ddlCountry.SelectedValue == "1")
                        {
                            master.SetParameter("Country", "Canada");
                        }
                        else
                        {
                            master.SetParameter("Country", "All");
                        }
                    }

                    // ... ... team member
                    if (IsAllEmployeesSelected())
                    {
                        master.SetParameter("teamMember", "All");
                    }
                    else
                    {
                        string fullName = GetEmployeesSelected();

                        master.SetParameter("teamMember", fullName);
                    }

                    // ... ... team member type
                    if (ddlEmployeeType.SelectedValue == "(All)")
                    {
                        master.SetParameter("teamMemberType", "All");
                    }
                    else
                    {
                        if (ddlEmployeeType.SelectedValue == "LFSCA") master.SetParameter("teamMemberType", "LFS Canada");
                        if (ddlEmployeeType.SelectedValue == "LFSUS") master.SetParameter("teamMemberType", "LFS USA");
                        if (ddlEmployeeType.SelectedValue == "LFS") master.SetParameter("teamMemberType", "All LFS");
                        if (ddlEmployeeType.SelectedValue == "PAGCA") master.SetParameter("teamMemberType", "PAG Canada");
                        if (ddlEmployeeType.SelectedValue == "PAGUS") master.SetParameter("teamMemberType", "PAG USA");
                        if (ddlEmployeeType.SelectedValue == "PAG") master.SetParameter("teamMemberType", "All PAG");
                        if (ddlEmployeeType.SelectedValue == "SOTA") master.SetParameter("teamMemberType", "SOTA");
                        if (ddlEmployeeType.SelectedValue == "Salaried") master.SetParameter("teamMemberType", "Salaried");
                        if (ddlEmployeeType.SelectedValue == "Subcontractor") master.SetParameter("teamMemberType", "Subcontractor");
                    }

                    // ... ...  user
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    int companyId = Convert.ToInt32(Session["companyID"]);

                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(loginId, companyId);
                    string user = loginGateway.GetLastName(loginId,companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                    master.SetParameter("User", user.Trim());

                    // ... ... client
                    if (ddlClient.SelectedValue == "-1")
                    {
                        master.SetParameter("Client", "All");
                    }
                    else
                    {
                        int currentClientId = Int32.Parse(ddlClient.SelectedValue);
                        CompaniesGateway companiesGateway = new CompaniesGateway();
                        companiesGateway.LoadByCompaniesId(currentClientId, companyId);
                        master.SetParameter("Client", companiesGateway.GetName(currentClientId));
                    }

                    // ... ... project
                    if (ddlProject.SelectedValue == "-1")
                    {
                        master.SetParameter("Project", "All");
                    }
                    else
                    {
                        int projectId2 = Int32.Parse(ddlProject.SelectedValue);
                        ProjectGateway projectGateway = new ProjectGateway();
                        projectGateway.LoadByProjectId(projectId2);
                        string project = projectGateway.GetName(projectId2);
                        master.SetParameter("Project", project);
                    }

                    master.SetParameter("dateFrom", tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                    master.SetParameter("dateTo", tkrdpEndDate.SelectedDate.Value.ToShortDateString());
                }
                else
                {
                    master.SetParameter("dateFrom", tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                    master.SetParameter("dateTo", tkrdpEndDate.SelectedDate.Value.ToShortDateString());
                }
            }
        }