public override ReportDocument GenerateReport()
        {
            string HierarchyLevel1 = string.Empty;
            string HierarchyLevel2 = string.Empty;
            string HierarchyLevel3 = string.Empty;
            string HierarchyLevel4 = string.Empty;

            if (values.Count > 0)
            {
                DataSet.EmployeeDetail ds = new DataSet.EmployeeDetail();

                DataSet.EmployeeDetail.HierarchyLevelDataTable HierarchyLevelTable = ds.HierarchyLevel;
                ArrayList HierarchyLevelList = EHierarchyLevel.db.select(dbConn, new DBFilter());
                foreach (EHierarchyLevel HierarchyLevel in HierarchyLevelList)
                {
                    DataSet.EmployeeDetail.HierarchyLevelRow row = HierarchyLevelTable.NewHierarchyLevelRow();
                    row.HLevelCode  = HierarchyLevel.HLevelCode;
                    row.HLevelDesc  = HierarchyLevel.HLevelDesc;
                    row.HLevelID    = HierarchyLevel.HLevelID;
                    row.HLevelSeqNo = HierarchyLevel.HLevelSeqNo;
                    HierarchyLevelTable.Rows.Add(row);
                }

                int currentDummyPosID       = 0;
                int currentDummyHierarchyID = 0;
                foreach (int EmpID in values)
                {
                    EmployeeDetailProcess.ImportEmployeeDetailRow(dbConn, ds.employeedetail, EmpID, AsOfDate);


                    DBFilter empBasicSalaryfilter = new DBFilter();
                    DBFilter paymentCodeFilter    = new DBFilter();
                    paymentCodeFilter.add(new Match("PaymentTypeID", EPaymentType.SystemPaymentType.BasicSalaryPaymentType(dbConn).PaymentTypeID));
                    //empBasicSalaryfilter.add(new MatchField("erp.PayCodeID", "pc.PaymentCodeID"));
                    empBasicSalaryfilter.add(new IN("PayCodeID", "Select PaymentCodeID from PaymentCode", paymentCodeFilter));
                    empBasicSalaryfilter.add(new Match("EmpRPEffFr", "<=", AsOfDate));
                    OR orEffToFilter = new OR();
                    orEffToFilter.add(new Match("EmpRPEffTo", ">=", AsOfDate));
                    orEffToFilter.add(new NullTerm("EmpRPEffTo"));
                    empBasicSalaryfilter.add(orEffToFilter);

                    empBasicSalaryfilter.add(new Match("EmpID", EmpID));

                    DataSet.EmployeeDetail.EmpRecurringPaymentDataTable empRPTable = ds.EmpRecurringPayment;
                    ArrayList empRecurringPaymentList = EEmpRecurringPayment.db.select(dbConn, empBasicSalaryfilter);
                    foreach (EEmpRecurringPayment empRP in empRecurringPaymentList)
                    {
                        DataSet.EmployeeDetail.EmpRecurringPaymentRow row = empRPTable.NewEmpRecurringPaymentRow();

                        row.CurrencyID  = empRP.CurrencyID;
                        row.EmpAccID    = empRP.EmpAccID;
                        row.EmpID       = empRP.EmpID;
                        row.EmpRPAmount = Convert.ToDecimal(empRP.EmpRPAmount);
                        row.EmpRPEffFr  = empRP.EmpRPEffFr;
                        row.EmpRPEffTo  = empRP.EmpRPEffTo;
                        row.EmpRPID     = empRP.EmpRPID;
                        row.EmpRPMethod = empRP.EmpRPMethod;
                        row.EmpRPRemark = empRP.EmpRPRemark;
                        row.EmpRPUnit   = empRP.EmpRPUnit;

                        EPaymentCode paymentCode = new EPaymentCode();
                        paymentCode.PaymentCodeID = empRP.PayCodeID;
                        if (EPaymentCode.db.select(dbConn, paymentCode))
                        {
                            row.PayCodeID       = paymentCode.PaymentCodeID;
                            row.PaymentCode     = paymentCode.PaymentCode;
                            row.PaymentCodeDesc = paymentCode.PaymentCodeDesc;
                            row.PaymentCodeID   = paymentCode.PaymentCodeID;
                            //                            row.p
                        }

                        empRPTable.AddEmpRecurringPaymentRow(row);
                    }

                    {
                        DataSet.EmployeeDetail.EmpPositionInfoDataTable empPosTable = ds.EmpPositionInfo;
                        EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, AsOfDate, EmpID);

                        if (empPos == null)
                        {
                            currentDummyPosID--;
                            DataSet.EmployeeDetail.EmpPositionInfoRow row = empPosTable.NewEmpPositionInfoRow();
                            row.EmpPosID = currentDummyPosID;
                            row.EmpID    = EmpID;

                            empPosTable.AddEmpPositionInfoRow(row);

                            DataSet.EmployeeDetail.EmpHierarchyDataTable empHierarchyTable = ds.EmpHierarchy;
                            foreach (EHierarchyLevel hLevel in HierarchyLevelList)
                            {
                                currentDummyHierarchyID--;
                                DataSet.EmployeeDetail.EmpHierarchyRow empHierarchyRow = empHierarchyTable.NewEmpHierarchyRow();

                                empHierarchyRow.EmpHierarchyID = currentDummyHierarchyID;
                                empHierarchyRow.EmpID          = EmpID;
                                empHierarchyRow.EmpPosID       = currentDummyPosID;
                                empHierarchyRow.HLevelID       = hLevel.HLevelID;
                                empHierarchyRow.HLevelSeqNo    = hLevel.HLevelSeqNo;

                                empHierarchyTable.AddEmpHierarchyRow(empHierarchyRow);
                            }
                        }
                        else
                        {
                            DataSet.EmployeeDetail.EmpPositionInfoRow row = empPosTable.NewEmpPositionInfoRow();

                            row.CompanyID   = empPos.CompanyID;
                            row.EmpID       = empPos.EmpID;
                            row.EmpPosEffFr = empPos.EmpPosEffFr;
                            row.EmpPosEffTo = empPos.EmpPosEffTo;
                            row.EmpPosID    = empPos.EmpPosID;
                            row.LeavePlanID = empPos.LeavePlanID;
                            row.PayGroupID  = empPos.PayGroupID;

                            EPosition position = new EPosition();
                            position.PositionID = empPos.PositionID;
                            if (EPosition.db.select(dbConn, position))
                            {
                                row.PositionCode = position.PositionCode;
                                row.PositionDesc = position.PositionDesc;
                                row.PositionID   = position.PositionID;
                            }

                            ERank rank = new ERank();
                            rank.RankID = empPos.RankID;
                            if (ERank.db.select(dbConn, rank))
                            {
                                row.RankCode = rank.RankCode;
                                row.RankDesc = rank.RankDesc;
                                row.RankID   = rank.RankID;
                            }

                            row.StaffTypeID = empPos.StaffTypeID;

                            empPosTable.AddEmpPositionInfoRow(row);

                            DataSet.EmployeeDetail.EmpHierarchyDataTable empHierarchyTable = ds.EmpHierarchy;
                            foreach (EHierarchyLevel hLevel in HierarchyLevelList)
                            {
                                if (hLevel.HLevelSeqNo.Equals(1))
                                {
                                    HierarchyLevel1 = hLevel.HLevelDesc;
                                }
                                else if (hLevel.HLevelSeqNo.Equals(2))
                                {
                                    HierarchyLevel2 = hLevel.HLevelDesc;
                                }
                                else if (hLevel.HLevelSeqNo.Equals(3))
                                {
                                    HierarchyLevel3 = hLevel.HLevelDesc;
                                }
                                else if (hLevel.HLevelSeqNo.Equals(4))
                                {
                                    HierarchyLevel4 = hLevel.HLevelDesc;
                                }


                                DBFilter empHierarchyFilter = new DBFilter();
                                empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                                empHierarchyFilter.add(new Match("HLevelID", hLevel.HLevelID));

                                ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);

                                DataSet.EmployeeDetail.EmpHierarchyRow empHierarchyRow = empHierarchyTable.NewEmpHierarchyRow();
                                empHierarchyRow.EmpID       = EmpID;
                                empHierarchyRow.EmpPosID    = empPos.EmpPosID;
                                empHierarchyRow.HLevelID    = hLevel.HLevelID;
                                empHierarchyRow.HLevelSeqNo = hLevel.HLevelSeqNo;

                                if (empHierarchyList.Count > 0)
                                {
                                    EEmpHierarchy empHierarchy = (EEmpHierarchy)empHierarchyList[0];
                                    empHierarchyRow.EmpHierarchyID = empHierarchy.EmpHierarchyID;

                                    EHierarchyElement hElement = new EHierarchyElement();
                                    hElement.HElementID = empHierarchy.HElementID;
                                    EHierarchyElement.db.select(dbConn, hElement);
                                    empHierarchyRow.HElementCode = hElement.HElementCode;
                                    empHierarchyRow.HElementDesc = hElement.HElementDesc;
                                    empHierarchyRow.HElementID   = hElement.HElementID;
                                }
                                else
                                {
                                    currentDummyHierarchyID--;
                                    empHierarchyRow.EmpHierarchyID = currentDummyHierarchyID;
                                }

                                empHierarchyTable.AddEmpHierarchyRow(empHierarchyRow);
                            }
                        }
                    }
                }

                DataSet.EmployeeDetail.PayrollGroupDataTable payrollGroupTable = ds.PayrollGroup;
                ArrayList payrollGroupList = EPayrollGroup.db.select(dbConn, new DBFilter());
                foreach (EPayrollGroup payrollGroup in payrollGroupList)
                {
                    DataSet.EmployeeDetail.PayrollGroupRow row = payrollGroupTable.NewPayrollGroupRow();
                    row.PayGroupCode = payrollGroup.PayGroupCode;
                    row.PayGroupDesc = payrollGroup.PayGroupDesc;
                    row.PayGroupID   = payrollGroup.PayGroupID;
                    payrollGroupTable.Rows.Add(row);
                }

                DataSet.EmployeeDetail.PositionDataTable PositionTable = ds.Position;
                ArrayList PositionList = EPosition.db.select(dbConn, new DBFilter());
                foreach (EPosition Position in PositionList)
                {
                    DataSet.EmployeeDetail.PositionRow row = PositionTable.NewPositionRow();
                    row.PositionCode = Position.PositionCode;
                    row.PositionDesc = Position.PositionDesc;
                    row.PositionID   = Position.PositionID;
                    PositionTable.Rows.Add(row);
                }

                DataSet.EmployeeDetail.BankListDataTable BankListTable = ds.BankList;
                ArrayList BankListList = EBankList.db.select(dbConn, new DBFilter());
                foreach (EBankList BankList in BankListList)
                {
                    DataSet.EmployeeDetail.BankListRow row = BankListTable.NewBankListRow();
                    row.BankCode = BankList.BankCode;
                    row.BankName = BankList.BankName;
                    BankListTable.Rows.Add(row);
                }


                //System.Data.DataSet ds = new System.Data.DataSet();

                //string select;
                //string from;
                //DBFilter filter;
                //OR or;

                //foreach (int EmpID in values)
                //{

                //from = "from EmpPersonalInfo e LEFT JOIN EmpTermination et ON et.EmpID=e.EmpID ";
                //select = " e.*, et.EmpTermLastDate";
                //filter = new DBFilter();
                //filter.add(new Match("e.EmpID", EmpID));
                //filter.loadData(ds, "employeedetail", null, select, from, null);

                //from = "from EmpPositionInfo ";//EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                //select = "* ";
                //filter = new DBFilter();
                //filter.add(new Match("EmpPosEffFr", "<=", AsOfDate));
                //OR orEffToFilter = new OR();
                //orEffToFilter.add(new Match("EmpPosEffTo", ">=", AsOfDate));
                //orEffToFilter.add(new NullTerm("EmpPosEffTo"));
                //filter.add(orEffToFilter);
                //filter.add(new Match("EmpID", EmpID));
                //filter.loadData(ds, "EmpPositionInfo", null, select, from, null);


                //from = "from EmpRecurringPayment erp, PaymentCode pc";//EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                //select = "* ";
                //filter = new DBFilter();
                //filter.add(new MatchField("erp.PayCodeID", "pc.PaymentCodeID"));
                //filter.add(new Match("pc.PaymentTypeID", EPaymentType.SystemPaymentType.BasicSalaryPaymentType(dbConn).PaymentTypeID));
                //filter.add(new Match("erp.EmpRPEffFr", "<=", AsOfDate));
                //orEffToFilter = new OR();
                //orEffToFilter.add(new Match("erp.EmpRPEffTo", ">=", AsOfDate));
                //orEffToFilter.add(new NullTerm("erp.EmpRPEffTo"));
                //filter.add(orEffToFilter);

                //filter.add(new Match("EmpID", EmpID));
                //filter.loadData(ds, "EmpRecurringPayment", null, select, from, null);
                //}
                //from = " from PayrollGroup ";//EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                //select = "* ";
                //filter = new DBFilter();
                //filter.loadData(ds, "PayrollGroup", null, select, from, null);

                //from = " from Position ";//EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                //select = "* ";
                //filter = new DBFilter();
                //filter.loadData(ds, "Position", null, select, from, null);

                //from = "from EmpHierarchy eh Left Join HierarchyElement he ON eh.HElementID=he.HElementID LEFT JOIN HierarchyLevel hl on hl.HLevelID=eh.HLevelID";//EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                //select = " eh.*, he.HElementCode, he.HElementDesc, hl.HLevelSeqNo";
                //filter = new DBFilter();
                //filter.add("HLevelSeqNo", true);
                //filter.loadData(ds, "EmpHierarchy", null, select, from, null);

                foreach (System.Data.DataRow row in ds.Tables["EmpHierarchy"].Rows)
                {
                    if (row.IsNull("HElementDesc"))
                    {
                        row["HElementDesc"] = "-";
                    }
                    if (string.IsNullOrEmpty(row["HElementDesc"].ToString()))
                    {
                        row["HElementDesc"] = "-";
                    }
                }

                //from = "from HierarchyLevel hl ";//EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                //select = " hl.* ";
                //filter = new DBFilter();
                //filter.add("HLevelSeqNo", true);
                //filter.loadData(ds, "HierarchyLevel", null, select, from, null);


                if (reportDocument == null)
                {
                    reportDocument = new ReportTemplate.Report_Employee_SalaryList();
                }
                else
                {
                }



                reportDocument.SetDataSource(ds);
                reportDocument.SetParameterValue("HierarchyLevel1", HierarchyLevel1);
                reportDocument.SetParameterValue("HierarchyLevel2", HierarchyLevel2);
                reportDocument.SetParameterValue("HierarchyLevel3", HierarchyLevel3);

                if (reportDocument.ParameterFields["HierarchyLevel4"] != null)
                {
                    reportDocument.SetParameterValue("HierarchyLevel4", HierarchyLevel4);
                }

                return(reportDocument);
            }
            else
            {
                return(null);
            }
        }
        public override ReportDocument GenerateReport()
        {
            if (EmpList.Count > 0)
            {
                string HierarchyLevel1 = " ";
                string HierarchyLevel2 = " ";
                string HierarchyLevel3 = " ";

                ArrayList HierarchyLevelList = EHierarchyLevel.db.select(dbConn, new DBFilter());
                foreach (EHierarchyLevel hLevel in HierarchyLevelList)
                {
                    if (hLevel.HLevelSeqNo.Equals(1))
                    {
                        HierarchyLevel1 = hLevel.HLevelDesc;
                    }
                    else if (hLevel.HLevelSeqNo.Equals(2))
                    {
                        HierarchyLevel2 = hLevel.HLevelDesc;
                    }
                    else if (hLevel.HLevelSeqNo.Equals(3))
                    {
                        HierarchyLevel3 = hLevel.HLevelDesc;
                    }
                }


                DataSet.EmployeeDetail ds = new DataSet.EmployeeDetail();

                ArrayList empExtraFieldList = EEmpExtraField.db.select(dbConn, new DBFilter());
                DataSet.EmployeeDetail.EmpExtraFieldDataTable empExtraFieldTable = ds.EmpExtraField;
                foreach (EEmpExtraField empExtraField in empExtraFieldList)
                {
                    DataSet.EmployeeDetail.EmpExtraFieldRow empExtraFieldRow = empExtraFieldTable.NewEmpExtraFieldRow();
                    empExtraFieldRow.EmpExtraFieldGroupName = empExtraField.EmpExtraFieldGroupName;
                    empExtraFieldRow.EmpExtraFieldID        = empExtraField.EmpExtraFieldID;
                    empExtraFieldRow.EmpExtraFieldName      = empExtraField.EmpExtraFieldName;

                    if (empExtraFieldRow.IsEmpExtraFieldGroupNameNull())
                    {
                        empExtraFieldRow.EmpExtraFieldGroupName = "Extra Information";
                    }
                    empExtraFieldTable.Rows.Add(empExtraFieldRow);
                }

                foreach (int EmpID in EmpList)
                {
                    DataSet.EmployeeDetail.employeedetailRow empRow = ImportEmployeeDetailRow(dbConn, ds.employeedetail, EmpID, AppUtils.ServerDateTime().Date);


                    EEmpDocument empDocument = EEmpDocument.GetProfilePhotoEmpDocument(dbConn, EmpID);
                    if (empDocument != null)
                    {
                        string documentFilePath = empDocument.GetDocumentPhysicalPath(dbConn);
                        string transferFilePath = documentFilePath;
                        string strTmpFolder     = string.Empty;
                        if (empDocument.EmpDocumentIsCompressed)
                        {
                            transferFilePath = empDocument.GetExtractedFilePath(dbConn);
                        }

                        empRow.PhotoByteArray = ThumbnailToByteArray(transferFilePath, 200, 200);

                        empDocument.RemoveExtractedFile();
                    }


                    DBFilter empFilter = new DBFilter();
                    empFilter.add(new Match("EmpID", EmpID));

                    DBFilter empPosFilter = new DBFilter();
                    empPosFilter.add(new Match("EmpID", EmpID));
                    empPosFilter.add("EmpPosEffFr", false);
                    ArrayList empPosList = EEmpPositionInfo.db.select(dbConn, empPosFilter);
                    DataSet.EmployeeDetail.EmpPositionInfoDataTable empPosTable = ds.EmpPositionInfo;
                    foreach (EEmpPositionInfo empPos in empPosList)
                    {
                        DataSet.EmployeeDetail.EmpPositionInfoRow row = empPosTable.NewEmpPositionInfoRow();

                        row.CompanyID   = empPos.CompanyID;
                        row.EmpID       = empPos.EmpID;
                        row.EmpPosEffFr = empPos.EmpPosEffFr;
                        if (!empPos.EmpPosEffTo.Ticks.Equals(0))
                        {
                            row.EmpPosEffTo = empPos.EmpPosEffTo;
                        }
                        row.EmpPosID    = empPos.EmpPosID;
                        row.LeavePlanID = empPos.LeavePlanID;
                        row.PayGroupID  = empPos.PayGroupID;

                        EPosition position = new EPosition();
                        position.PositionID = empPos.PositionID;
                        if (EPosition.db.select(dbConn, position))
                        {
                            row.PositionCode = position.PositionCode;
                            row.PositionDesc = position.PositionDesc;
                            row.PositionID   = position.PositionID;
                        }

                        ERank rank = new ERank();
                        rank.RankID = empPos.RankID;
                        if (ERank.db.select(dbConn, rank))
                        {
                            row.RankCode = rank.RankCode;
                            row.RankDesc = rank.RankDesc;
                            row.RankID   = rank.RankID;
                        }

                        row.StaffTypeID = empPos.StaffTypeID;

                        foreach (EHierarchyLevel hLevel in HierarchyLevelList)
                        {
                            if (hLevel.HLevelSeqNo < 4 && hLevel.HLevelSeqNo > 0)
                            {
                                DBFilter empHierarchyFilter = new DBFilter();
                                empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                                empHierarchyFilter.add(new Match("HLevelID", hLevel.HLevelID));

                                ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);

                                if (empHierarchyList.Count > 0)
                                {
                                    EEmpHierarchy empHierarchy = (EEmpHierarchy)empHierarchyList[0];

                                    EHierarchyElement hElement = new EHierarchyElement();
                                    hElement.HElementID = empHierarchy.HElementID;
                                    EHierarchyElement.db.select(dbConn, hElement);

                                    row["HierarchyCode" + hLevel.HLevelSeqNo] = hElement.HElementCode;
                                    row["HierarchyDesc" + hLevel.HLevelSeqNo] = hElement.HElementDesc;
                                }
                            }
                        }

                        empPosTable.AddEmpPositionInfoRow(row);
                    }

                    DBFilter empRPFilter = new DBFilter();
                    empRPFilter.add(new Match("EmpID", EmpID));
                    empRPFilter.add("empRPEffFr", false);

                    ArrayList empRPList = EEmpRecurringPayment.db.select(dbConn, empRPFilter);
                    DataSet.EmployeeDetail.EmpRecurringPaymentDataTable empRPTable = ds.EmpRecurringPayment;
                    foreach (EEmpRecurringPayment empRP in empRPList)
                    {
                        DataSet.EmployeeDetail.EmpRecurringPaymentRow row = empRPTable.NewEmpRecurringPaymentRow();

                        row.CurrencyID  = empRP.CurrencyID;
                        row.EmpAccID    = empRP.EmpAccID;
                        row.EmpID       = empRP.EmpID;
                        row.EmpRPAmount = Convert.ToDecimal(empRP.EmpRPAmount);
                        row.EmpRPEffFr  = empRP.EmpRPEffFr;
                        if (!empRP.EmpRPEffTo.Ticks.Equals(0))
                        {
                            row.EmpRPEffTo = empRP.EmpRPEffTo;
                        }
                        row.EmpRPID = empRP.EmpRPID;

                        if (empRP.EmpRPMethod.Equals("A"))
                        {
                            row.EmpRPMethod = HROne.Common.WebUtility.GetLocalizedString("Autopay");
                        }
                        else if (empRP.EmpRPMethod.Equals("Q"))
                        {
                            row.EmpRPMethod = HROne.Common.WebUtility.GetLocalizedString("Cheque");
                        }
                        else if (empRP.EmpRPMethod.Equals("C"))
                        {
                            row.EmpRPMethod = HROne.Common.WebUtility.GetLocalizedString("Cash");
                        }
                        else if (empRP.EmpRPMethod.Equals("O"))
                        {
                            row.EmpRPMethod = HROne.Common.WebUtility.GetLocalizedString("Others");
                        }


                        row.EmpRPRemark = empRP.EmpRPRemark;
                        row.EmpRPUnit   = empRP.EmpRPUnit;

                        EPaymentCode paymentCode = new EPaymentCode();
                        paymentCode.PaymentCodeID = empRP.PayCodeID;
                        if (EPaymentCode.db.select(dbConn, paymentCode))
                        {
                            row.PayCodeID       = paymentCode.PaymentCodeID;
                            row.PaymentCode     = paymentCode.PaymentCode;
                            row.PaymentCodeDesc = paymentCode.PaymentCodeDesc;
                            row.PaymentCodeID   = paymentCode.PaymentCodeID;
//                            row.p
                        }

                        empRPTable.AddEmpRecurringPaymentRow(row);
                    }

                    EmployeeBankAccountProcess.ImportEmpBankAccountRow(dbConn, ds.EmpBankAccount, EmpID);

                    ArrayList empSpouseList = EEmpSpouse.db.select(dbConn, empFilter);
                    DataSet.EmployeeDetail.EmpSpouseDataTable empSpouseTable = ds.EmpSpouse;
                    foreach (EEmpSpouse empSpouse in empSpouseList)
                    {
                        DataSet.EmployeeDetail.EmpSpouseRow row = empSpouseTable.NewEmpSpouseRow();

                        row.EmpID = empSpouse.EmpID;
                        row.EmpSpouseChineseName = empSpouse.EmpSpouseChineseName;
                        //empSpouse.EmpSpouseDateOfBirth;
                        row.EmpSpouseHKID                  = empSpouse.EmpSpouseHKID;
                        row.EmpSpouseID                    = empSpouse.EmpSpouseID;
                        row.EmpSpouseOtherName             = empSpouse.EmpSpouseOtherName;
                        row.EmpSpousePassportIssuedCountry = empSpouse.EmpSpousePassportIssuedCountry;
                        row.EmpSpousePassportNo            = empSpouse.EmpSpousePassportNo;
                        row.EmpSpouseSurname               = empSpouse.EmpSpouseSurname;
                        // Start 0000142, KuangWei, 2014-12-21
                        row.EmpGender = empSpouse.EmpGender;
                        if (empSpouse.EmpIsMedicalSchemaInsured)
                        {
                            row.EmpIsMedicalSchemaInsured = "Yes";
                        }
                        else
                        {
                            row.EmpIsMedicalSchemaInsured = "No";
                        }
                        row.EmpMedicalEffectiveDate = empSpouse.EmpMedicalEffectiveDate;
                        row.EmpMedicalExpiryDate    = empSpouse.EmpMedicalExpiryDate;
                        // End 0000142, KuangWei, 2014-12-21

                        empSpouseTable.AddEmpSpouseRow(row);
                    }

                    ArrayList empDependantList = EEmpDependant.db.select(dbConn, empFilter);
                    DataSet.EmployeeDetail.EmpDependantDataTable empDependantTable = ds.EmpDependant;
                    foreach (EEmpDependant empDependant in empDependantList)
                    {
                        DataSet.EmployeeDetail.EmpDependantRow row = empDependantTable.NewEmpDependantRow();

                        row.EmpID = empDependant.EmpID;
                        row.EmpDependantChineseName = empDependant.EmpDependantChineseName;
                        //empDependant.EmpDependantDateOfBirth;
                        row.EmpDependantGender                = empDependant.EmpDependantGender;
                        row.EmpDependantHKID                  = empDependant.EmpDependantHKID;
                        row.EmpDependantID                    = empDependant.EmpDependantID;
                        row.EmpDependantOtherName             = empDependant.EmpDependantOtherName;
                        row.EmpDependantPassportIssuedCountry = empDependant.EmpDependantPassportIssuedCountry;
                        row.EmpDependantPassportNo            = empDependant.EmpDependantPassportNo;
                        row.EmpDependantRelationship          = empDependant.EmpDependantRelationship;
                        row.EmpDependantSurname               = empDependant.EmpDependantSurname;

                        empDependantTable.AddEmpDependantRow(row);
                    }

                    DBFilter empQualificationFilter = new DBFilter();
                    empQualificationFilter.add(new Match("EmpID", EmpID));
                    empQualificationFilter.add("EmpQualificationFrom", false);

                    ArrayList empQualificationList = EEmpQualification.db.select(dbConn, empQualificationFilter);
                    DataSet.EmployeeDetail.EmpQualificationDataTable empQualificationTable = ds.EmpQualification;
                    foreach (EEmpQualification empQualification in empQualificationList)
                    {
                        DataSet.EmployeeDetail.EmpQualificationRow row = empQualificationTable.NewEmpQualificationRow();

                        row.EmpID = empQualification.EmpID;

                        if (!empQualification.EmpQualificationFrom.Ticks.Equals(0))
                        {
                            row.EmpQualificationFrom = empQualification.EmpQualificationFrom;
                        }
                        if (!empQualification.EmpQualificationTo.Ticks.Equals(0))
                        {
                            row.EmpQualificationTo = empQualification.EmpQualificationTo;
                        }
                        row.EmpQualificationID          = empQualification.EmpQualificationID;
                        row.EmpQualificationInstitution = empQualification.EmpQualificationInstitution;
                        row.EmpQualificationRemark      = empQualification.EmpQualificationRemark;

                        EQualification qualification = new EQualification();
                        qualification.QualificationID = empQualification.QualificationID;
                        if (EQualification.db.select(dbConn, qualification))
                        {
                            row.QualificationID   = qualification.QualificationID;
                            row.QualificationCode = qualification.QualificationCode;
                            row.QualificationDesc = qualification.QualificationDesc;
                        }

                        empQualificationTable.AddEmpQualificationRow(row);
                    }
                    ArrayList empSkillList = EEmpSkill.db.select(dbConn, empFilter);
                    DataSet.EmployeeDetail.EmpSkillDataTable empSkillTable = ds.EmpSkill;
                    foreach (EEmpSkill empSkill in empSkillList)
                    {
                        DataSet.EmployeeDetail.EmpSkillRow row = empSkillTable.NewEmpSkillRow();

                        row.EmpID = empSkill.EmpID;

                        row.EmpSkillID = empSkill.EmpSkillID;
                        ESkill skill = new ESkill();
                        skill.SkillID = empSkill.SkillID;
                        if (ESkill.db.select(dbConn, skill))
                        {
                            row.SkillID   = skill.SkillID;
                            row.SkillCode = skill.SkillCode;
                            row.SkillDesc = skill.SkillDesc;
                        }
                        ESkillLevel skillLevel = new ESkillLevel();
                        skillLevel.SkillLevelID = empSkill.SkillLevelID;
                        if (ESkillLevel.db.select(dbConn, skillLevel))
                        {
                            row.SkillLevelID   = skillLevel.SkillLevelID;
                            row.SkillLevelCode = skillLevel.SkillLevelCode;
                            row.SkillLevelDesc = skillLevel.SkillLevelDesc;
                        }
                        empSkillTable.AddEmpSkillRow(row);
                    }

                    ArrayList empWorkExpList = EEmpWorkExp.db.select(dbConn, empFilter);
                    DataSet.EmployeeDetail.EmpWorkExpDataTable empWorkExpTable = ds.EmpWorkExp;
                    foreach (EEmpWorkExp empWorkExp in empWorkExpList)
                    {
                        DataSet.EmployeeDetail.EmpWorkExpRow row = empWorkExpTable.NewEmpWorkExpRow();

                        row.EmpID = empWorkExp.EmpID;

                        row.EmpWorkExpID          = empWorkExp.EmpWorkExpID;
                        row.EmpWorkExpFromMonth   = empWorkExp.EmpWorkExpFromMonth;
                        row.EmpWorkExpFromYear    = empWorkExp.EmpWorkExpFromYear;
                        row.EmpWorkExpToYear      = empWorkExp.EmpWorkExpToYear;
                        row.EmpWorkExpToMonth     = empWorkExp.EmpWorkExpToMonth;
                        row.EmpWorkExpPosition    = empWorkExp.EmpWorkExpPosition;
                        row.EmpWorkExpCompanyName = empWorkExp.EmpWorkExpCompanyName;
                        row.EmpWorkExpRemark      = empWorkExp.EmpWorkExpRemark;

                        empWorkExpTable.AddEmpWorkExpRow(row);
                    }

                    ArrayList empExtraFieldValueList = EEmpExtraFieldValue.db.select(dbConn, empFilter);
                    DataSet.EmployeeDetail.EmpExtraFieldValueDataTable empExtraFieldValueTable = ds.EmpExtraFieldValue;
                    foreach (EEmpExtraFieldValue empExtraFieldValue in empExtraFieldValueList)
                    {
                        DataSet.EmployeeDetail.EmpExtraFieldValueRow row = empExtraFieldValueTable.NewEmpExtraFieldValueRow();

                        row.EmpID = empExtraFieldValue.EmpID;
                        row.EmpExtraFieldValueID = empExtraFieldValue.EmpExtraFieldValueID;
                        row.EmpExtraFieldID      = empExtraFieldValue.EmpExtraFieldID;
                        row.EmpExtraFieldValue   = empExtraFieldValue.EmpExtraFieldValue;

                        empExtraFieldValueTable.AddEmpExtraFieldValueRow(row);
                    }

                    //DBFilter filter = new DBFilter();
                    //filter.add(new Match("P.EmpID", EmpID));

                    //select = "P.*,EmpPos.*,Pos.*";
                    //from = "from EmpPersonalInfo P LEFT JOIN EmpPositionInfo EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID";
                    //filter.loadData(ds, "employeedetail", null, select, from, null);
                    //select = "P.*,Pos.PositionCode,Pos.PositionDesc,R.RankCode, R.RankDesc";
                    //from = "from EmpPositionInfo P LEFT JOIN Position Pos ON P.PositionID=Pos.PositionID LEFT JOIN Rank R ON P.RankID=R.RankID";
                    //filter.loadData(ds, "EmpPositionInfo", null, select, from, null);


                    //select = "P.*,C.*";
                    //from = "from EmpRecurringPayment P LEFT JOIN PaymentCode C ON P.PayCodeID=C.PaymentCodeID ";
                    //filter.loadData(ds, "EmpRecurringPayment", null, select, from, null);

                    //select = "P.*";
                    //from = "from EmpBankAccount P ";
                    //filter.loadData(ds, "EmpBankAccount", null, select, from, null);


                    //select = "P.*";
                    //from = "from EmpSpouse P ";
                    //filter.loadData(ds, "EmpSpouse", null, select, from, null);


                    //select = "P.*";
                    //from = "from EmpDependant P ";
                    //filter.loadData(ds, "EmpDependant", null, select, from, null);


                    //select = "P.*, Q.*";
                    //from = "from EmpQualification P LEFT JOIN Qualification Q on P.QualificationID=Q.QualificationID";
                    //filter.loadData(ds, "EmpQualification", null, select, from, null);


                    //select = "P.*, S.*,L.*";
                    //from = "from EmpSkill P LEFT JOIN Skill S ON P.SkillID=S.SkillID LEFT JOIN SkillLevel L on P.SkillLevelID=L.SkillLevelID";
                    //filter.loadData(ds, "EmpSkill", null, select, from, null);
                }
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["employeedetail"], "EmpHKID", true);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["employeedetail"], "EmpPassportNo", false);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["employeedetail"], "EmpResAddr", true);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["employeedetail"], "EmpCorAddr", true);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["EmpSpouse"], "EmpSpouseHKID", false);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["EmpSpouse"], "EmpSpousePassportNo", false);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["EmpDependant"], "EmpDependantHKID", false);
                //DBAESEncryptStringFieldAttribute.decode(ds.Tables["EmpDependant"], "EmpDependantPassportNo", false);


                if (reportDocument == null)
                {
                    reportDocument = new ReportTemplate.Report_Employee_Detail();
                }
                else
                {
                }

                reportDocument.SetDataSource(ds);
                reportDocument.SetParameterValue("HierarchyLevel1", HierarchyLevel1);
                reportDocument.SetParameterValue("HierarchyLevel2", HierarchyLevel2);
                reportDocument.SetParameterValue("HierarchyLevel3", HierarchyLevel3);

                reportDocument.SetParameterValue("HierarchyLevel1", HierarchyLevel1, "PositionInfo");
                reportDocument.SetParameterValue("HierarchyLevel2", HierarchyLevel2, "PositionInfo");
                reportDocument.SetParameterValue("HierarchyLevel3", HierarchyLevel3, "PositionInfo");

                return(reportDocument);
            }
            else
            {
                return(null);
            }
        }