public virtual DataTable UploadToTempDatabase(DataTable rawDataTable, int UserID)
        {
            if (rawDataTable == null)
            {
                return(GetImportDataFromTempDatabase(null));
            }

            int rowCount = 1;

            foreach (DataRow row in rawDataTable.Rows)
            {
                if (rawDataTable == null)
                {
                    return(GetImportDataFromTempDatabase(null));
                }

                rowCount++;

                EUploadEmpRecurringPayment uploadEmpPay = new EUploadEmpRecurringPayment();
                EEmpRecurringPayment       lastEmpPay   = null;

                string EmpNo = row[FIELD_EMP_NO].ToString().Trim();
                uploadEmpPay.EmpID = Parse.GetEmpID(dbConn, EmpNo, UserID);
                if (uploadEmpPay.EmpID < 0)
                {
                    errors.addError(ImportErrorMessage.ERROR_ACCESS_DENIED_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                }
                try
                {
                    uploadEmpPay.EmpRPEffFr = Parse.toDateTimeObject(row[FIELD_FROM]);
                }
                catch
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_FROM + "=" + row[FIELD_FROM].ToString(), EmpNo, rowCount.ToString() });
                }
                try
                {
                    uploadEmpPay.EmpRPEffTo = Parse.toDateTimeObject(row[FIELD_TO]);
                }
                catch
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_TO + "=" + row[FIELD_TO].ToString(), EmpNo, rowCount.ToString() });
                }
                uploadEmpPay.PayCodeID = Parse.GetPaymentCodeID(dbConn, row[FIELD_PAYMENT_CODE].ToString());

                if (uploadEmpPay.PayCodeID == 0)
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_PAYMENT_CODE + "=" + row[FIELD_PAYMENT_CODE].ToString(), EmpNo, rowCount.ToString() });
                }

                double amount = 0;
                if (double.TryParse(row[FIELD_AMOUNT].ToString(), out amount))
                {
                    uploadEmpPay.EmpRPAmount = amount;
                }
                else
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_AMOUNT + "=" + row[FIELD_AMOUNT].ToString(), EmpNo, rowCount.ToString() });
                }

                if (ESystemParameter.getParameter(dbConn, ESystemParameter.PARAM_CODE_PAYSCALE_POINT_SYSTEM) == "Y")
                {
                    if (amount > 0)
                    {
                        decimal m_point = 0;
                        if (decimal.TryParse(row[FIELD_POINT].ToString(), out m_point))
                        {
                            uploadEmpPay.Point = m_point;
                        }
                        else
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_POINT + "=" + row[FIELD_POINT].ToString(), EmpNo, rowCount.ToString() });
                        }

                        uploadEmpPay.SchemeCode = row[FIELD_SCHEME_CODE].ToString().Trim();
                        if (uploadEmpPay.SchemeCode == "")
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_SCHEME_CODE + "=" + row[FIELD_SCHEME_CODE].ToString(), EmpNo, rowCount.ToString() });
                        }

                        uploadEmpPay.Capacity = row[FIELD_CAPACITY].ToString().Trim();
                        if (uploadEmpPay.Capacity == "")
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_CAPACITY + "=" + row[FIELD_CAPACITY].ToString(), EmpNo, rowCount.ToString() });
                        }
                    }
                }

                if (ESystemParameter.getParameter(dbConn, ESystemParameter.PARAM_CODE_MONTHLY_ACHIEVEMENT_COMMISSION) == "Y")       // for F&V
                {
                    decimal m_fps;
                    decimal m_basicSalary;

                    if (decimal.TryParse(row[FIELD_FPS].ToString(), out m_fps))
                    {
                        uploadEmpPay.EmpRPFPS = System.Convert.ToDouble(m_fps);
                    }
                    else
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_FPS + "=" + row[FIELD_FPS].ToString(), EmpNo, rowCount.ToString() });
                    }

                    if (decimal.TryParse(row[FIELD_BASIC_SALARY].ToString(), out m_basicSalary))
                    {
                        uploadEmpPay.EmpRPBasicSalary = System.Convert.ToDouble(m_basicSalary);
                    }
                    else
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_BASIC_SALARY + "=" + row[FIELD_BASIC_SALARY].ToString(), EmpNo, rowCount.ToString() });
                    }
                }

                uploadEmpPay.CurrencyID = HROne.Lib.ExchangeCurrency.DefaultCurrency();

                uploadEmpPay.EmpRPUnit   = Parse.toRecurringPaymentUnit(row[FIELD_UNIT].ToString());
                uploadEmpPay.EmpRPMethod = Parse.toPaymentMethodCode(row[FIELD_METHOD].ToString());

                string BankCode = row[FIELD_ACCOUNT_NO].ToString();
                uploadEmpPay.EmpAccID = HROne.Import.Parse.GetEmpAccID(dbConn, BankCode, uploadEmpPay.EmpID);

                uploadEmpPay.UploadEmpID = ParseTemp.GetUploadEmpID(dbConn, EmpNo, m_SessionID);
                if (uploadEmpPay.UploadEmpID == 0)
                {
                    if (uploadEmpPay.EmpID == 0)
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                    }
                    else
                    {
                        uploadEmpPay.UploadEmpID = ImportEmpPersonalInfoProcess.CreateDummyUploadEmployeeInfo(dbConn, uploadEmpPay.EmpID, m_SessionID, UploadDateTime);
                    }
                }


                //  Check if the bank account no does not exist in database
                if (uploadEmpPay.EmpAccID == 0 && !BankCode.Trim().Equals(string.Empty))
                {
                    uploadEmpPay.UploadEmpAccID = ParseTemp.GetUploadEmpAccID(dbConn, BankCode, uploadEmpPay.UploadEmpID);
                    if (uploadEmpPay.UploadEmpAccID == 0)
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                    }
                }
                if ((uploadEmpPay.EmpAccID > 0 || uploadEmpPay.UploadEmpAccID > 0) && !uploadEmpPay.EmpRPMethod.Equals("A"))
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_METHOD + "=" + row[FIELD_METHOD].ToString(), EmpNo, rowCount.ToString() });
                }

                if (uploadEmpPay.EmpRPMethod.Equals("A") && uploadEmpPay.EmpAccID == 0 && uploadEmpPay.UploadEmpAccID == 0)
                {
                    EUploadEmpBankAccount uploadBankAccount = EUploadEmpBankAccount.GetDefaultBankAccount(dbConn, uploadEmpPay.EmpID, ParseTemp.GetUploadEmpID(dbConn, EmpNo, m_SessionID), m_SessionID);

                    if (uploadBankAccount != null)
                    {
                        //if (uploadBankAccount.EmpBankAccountID > 0)
                        //    uploadEmpPay.EmpAccID = uploadBankAccount.EmpBankAccountID;
                        //else
                        //    uploadEmpPay.UploadEmpAccID = uploadBankAccount.UploadEmpBankAccountID;
                    }
                    else
                    if (uploadEmpPay.EmpID > 0)
                    {
                        EEmpBankAccount bankAccount = EEmpBankAccount.GetDefaultBankAccount(dbConn, uploadEmpPay.EmpID);
                        if (bankAccount != null)
                        {
                            //uploadEmpPay.EmpAccID = bankAccount.EmpBankAccountID;
                        }
                        else
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                        }
                    }
                    else
                    {
                        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                    }
                }

                if (rawDataTable.Columns.Contains(FIELD_IS_NON_PAYROLL_ITEM))
                {
                    uploadEmpPay.EmpRPIsNonPayrollItem = row[FIELD_IS_NON_PAYROLL_ITEM].ToString().Equals("Yes", StringComparison.CurrentCultureIgnoreCase) || row[FIELD_IS_NON_PAYROLL_ITEM].ToString().Equals("Y", StringComparison.CurrentCultureIgnoreCase);
                }

                if (rawDataTable.Columns.Contains(FIELD_COST_CENTER))
                {
                    string CostCenter = row[FIELD_COST_CENTER].ToString();
                    if (!string.IsNullOrEmpty(CostCenter))
                    {
                        uploadEmpPay.CostCenterID = HROne.Import.Parse.GetCostCenterID(dbConn, CostCenter, false, UserID);
                        if (uploadEmpPay.CostCenterID <= 0)
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_COST_CENTER + "=" + CostCenter, EmpNo, rowCount.ToString() });
                        }
                    }
                    else
                    {
                        uploadEmpPay.CostCenterID = 0;
                    }
                }

                uploadEmpPay.EmpRPRemark = row[FIELD_REMARK].ToString().Trim();



                uploadEmpPay.SessionID       = m_SessionID;
                uploadEmpPay.TransactionDate = UploadDateTime;


                if (uploadEmpPay.EmpID != 0 && errors.List.Count <= 0)
                {
                    //if (rawDataTable.Columns.Contains(FIELD_INTERNAL_ID))
                    //{
                    //    try
                    //    {
                    //        if (!row.IsNull(FIELD_INTERNAL_ID))
                    //        {
                    //            int tmpID = FromHexDecWithCheckDigit((string)row[FIELD_INTERNAL_ID]);
                    //            EEmpRecurringPayment tmpObj = new EEmpRecurringPayment();
                    //            tmpObj.EmpRPID = tmpID;
                    //            if (EEmpRecurringPayment.db.select(dbConn, tmpObj))
                    //                uploadEmpPay.EmpRPID = tmpID;
                    //            else
                    //            {
                    //                errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_INTERNAL_ID + "=" + row[FIELD_INTERNAL_ID].ToString(), EmpNo, rowCount.ToString() });
                    //                continue;
                    //            }
                    //        }
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_INTERNAL_ID + "=" + row[FIELD_INTERNAL_ID].ToString(), EmpNo, rowCount.ToString() });
                    //        continue;
                    //    }
                    //}
                    if (rawDataTable.Columns.Contains(FIELD_SYNC_ID))
                    {
                        if (!row.IsNull(FIELD_SYNC_ID))
                        {
                            string strSynID = row[FIELD_SYNC_ID].ToString();
                            uploadEmpPay.SynID = strSynID;
                            if (!string.IsNullOrEmpty(strSynID))
                            {
                                DBFilter synIDFilter = new DBFilter();
                                synIDFilter.add(new Match("SynID", strSynID));
                                ArrayList objSameSynIDList = EEmpRecurringPayment.db.select(dbConn, synIDFilter);
                                if (objSameSynIDList.Count > 0)
                                {
                                    uploadEmpPay.EmpRPID = ((EEmpRecurringPayment)objSameSynIDList[0]).EmpRPID;
                                }
                            }
                        }
                    }

                    if (uploadEmpPay.EmpRPID == 0)
                    {
                        AND andTerms = new AND();
                        andTerms.add(new Match("EmpRPEffFr", "<=", uploadEmpPay.EmpRPEffFr));
                        andTerms.add(new Match("PayCodeID", uploadEmpPay.PayCodeID));

                        lastEmpPay = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpRPEffFr", uploadEmpPay.EmpID, andTerms);


                        if (lastEmpPay != null)
                        {
                            if (uploadEmpPay.EmpAccID == lastEmpPay.EmpAccID &&
                                Math.Abs(uploadEmpPay.EmpRPAmount - lastEmpPay.EmpRPAmount) < 0.01 &&
                                uploadEmpPay.EmpRPMethod == lastEmpPay.EmpRPMethod &&
                                uploadEmpPay.EmpRPUnit == lastEmpPay.EmpRPUnit &&
                                uploadEmpPay.PayCodeID == lastEmpPay.PayCodeID &&
                                uploadEmpPay.EmpRPEffFr == lastEmpPay.EmpRPEffFr &&
                                uploadEmpPay.EmpRPEffTo == lastEmpPay.EmpRPEffTo &&
                                uploadEmpPay.SchemeCode == lastEmpPay.SchemeCode &&
                                uploadEmpPay.Capacity == lastEmpPay.Capacity &&
                                uploadEmpPay.Point == lastEmpPay.Point &&
                                uploadEmpPay.CostCenterID == lastEmpPay.CostCenterID &&
                                uploadEmpPay.EmpRPRemark == lastEmpPay.EmpRPRemark &&
                                uploadEmpPay.EmpRPIsNonPayrollItem == lastEmpPay.EmpRPIsNonPayrollItem
                                )
                            {
                                continue;
                            }
                            else
                            {
                                // add postion terms with new ID
                                if (lastEmpPay.EmpRPEffFr.Equals(uploadEmpPay.EmpRPEffFr))
                                {
                                    uploadEmpPay.EmpRPID = lastEmpPay.EmpRPID;
                                    if (uploadEmpPay.EmpRPEffTo.Ticks == 0 && lastEmpPay.EmpRPEffTo.Ticks != 0)
                                    {
                                        AND andNextTerms = new AND();
                                        andNextTerms.add(new Match("EmpRPEffFr", ">", lastEmpPay.EmpRPEffTo));
                                        andNextTerms.add(new Match("PayCodeID", uploadEmpPay.PayCodeID));

                                        EEmpRecurringPayment afterEmpRP = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpRPEffFr", uploadEmpPay.EmpID, andNextTerms);
                                        if (afterEmpRP != null)
                                        {
                                            uploadEmpPay.EmpRPEffTo = afterEmpRP.EmpRPEffFr.AddDays(-1);
                                        }
                                    }
                                }
                                else
                                {
                                    AND lastObjAndTerms = new AND();
                                    lastObjAndTerms.add(new Match("EmpRPEffFr", ">", uploadEmpPay.EmpRPEffFr));
                                    if (!uploadEmpPay.EmpRPEffTo.Ticks.Equals(0))
                                    {
                                        lastObjAndTerms.add(new Match("EmpRPEffFr", "<=", uploadEmpPay.EmpRPEffTo));
                                    }
                                    lastObjAndTerms.add(new Match("PayCodeID", uploadEmpPay.PayCodeID));
                                    EEmpRecurringPayment lastObj = (EEmpRecurringPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpRPEffFr", uploadEmpPay.EmpID, lastObjAndTerms);
                                    if (lastObj != null)
                                    {
                                        if (!lastObj.EmpRPEffTo.Ticks.Equals(0))
                                        {
                                            errors.addError(ImportErrorMessage.ERROR_DATE_FROM_OVERLAP, new string[] { uploadEmpPay.EmpRPEffFr.ToString("yyyy-MM-dd"), rowCount.ToString() });
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (uploadEmpPay.EmpRPID <= 0)
                {
                    uploadEmpPay.ImportActionStatus = ImportDBObject.ImportActionEnum.INSERT;
                }
                else
                {
                    uploadEmpPay.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE;
                }


                Hashtable values = new Hashtable();
                tempDB.populate(uploadEmpPay, values);
                PageErrors pageErrors = new PageErrors(tempDB);
                tempDB.validate(pageErrors, values);
                if (pageErrors.errors.Count == 0)
                {
                    tempDB.insert(dbConn, uploadEmpPay);
                }
                else
                {
                    pageErrors.addError(rawDataTable.TableName);
                    throw new HRImportException(pageErrors.getPrompt() + "(line " + rowCount.ToString() + ")");
                }
            }
            if (errors.List.Count > 0)
            {
                ClearTempTable();
                throw (new HRImportException(rawDataTable.TableName + "\r\n" + errors.Message()));
            }
            return(GetImportDataFromTempDatabase(null));
        }