Пример #1
0
        public DataTable UploadToTempDatabase(DataTable rawDataTable, int UserID)
        {
            if (rawDataTable == null)
            {
                return(GetImportDataFromTempDatabase(null));
            }

            int rowCount = 1;

            foreach (DataRow row in rawDataTable.Rows)
            {
                rowCount++;

                EUploadEmpFinalPayment uploadEmpFinalPay = new EUploadEmpFinalPayment();
                //EEmpFinalPayment lastEmpFinalPay;

                string EmpNo = row[FIELD_EMP_NO].ToString().Trim();
                uploadEmpFinalPay.EmpID = Parse.GetEmpID(dbConn, EmpNo, UserID);
                if (uploadEmpFinalPay.EmpID < 0)
                {
                    errors.addError(ImportErrorMessage.ERROR_ACCESS_DENIED_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                }
                uploadEmpFinalPay.PayCodeID = Parse.GetPaymentCodeID(dbConn, row[FIELD_PAYMENT_CODE].ToString());

                if (uploadEmpFinalPay.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))
                {
                    uploadEmpFinalPay.EmpFinalPayAmount = amount;
                }
                else
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_AMOUNT + "=" + row[FIELD_AMOUNT].ToString(), EmpNo, rowCount.ToString() });
                }

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

                uploadEmpFinalPay.EmpFinalPayMethod = Parse.toPaymentMethodCode(row[FIELD_METHOD].ToString());

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

                //  Check if the bank account no does not exist in database
                if (uploadEmpFinalPay.EmpAccID == 0 && !BankCode.Trim().Equals(string.Empty))
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_ACCOUNT_NO + "=" + BankCode, EmpNo, rowCount.ToString() });
                }

                if (uploadEmpFinalPay.EmpAccID > 0 && !uploadEmpFinalPay.EmpFinalPayMethod.Equals("A"))
                {
                    errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_METHOD + "=" + row[FIELD_METHOD].ToString(), EmpNo, rowCount.ToString() });
                }

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

                    if (uploadBankAccount != null)
                    {
                        //if (uploadBankAccount.EmpBankAccountID > 0)
                        //    uploadEmpFinalPay.EmpAccID = uploadBankAccount.EmpBankAccountID;
                        //else
                        //    uploadEmpFinalPay.UploadEmpAccID = uploadBankAccount.UploadEmpBankAccountID;
                    }
                    else
                    if (uploadEmpFinalPay.EmpID > 0)
                    {
                        EEmpBankAccount bankAccount = EEmpBankAccount.GetDefaultBankAccount(dbConn, uploadEmpFinalPay.EmpID);
                        if (bankAccount != null)
                        {
                            //uploadEmpFinalPay.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_COST_CENTER))
                {
                    string CostCenter = row[FIELD_COST_CENTER].ToString();
                    if (!string.IsNullOrEmpty(CostCenter))
                    {
                        uploadEmpFinalPay.CostCenterID = HROne.Import.Parse.GetCostCenterID(dbConn, CostCenter, false, UserID);
                        if (uploadEmpFinalPay.CostCenterID <= 0)
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_COST_CENTER + "=" + CostCenter, EmpNo, rowCount.ToString() });
                        }
                    }
                    else
                    {
                        uploadEmpFinalPay.CostCenterID = 0;
                    }
                }

                uploadEmpFinalPay.EmpFinalPayRemark = row[FIELD_REMARK].ToString().Trim();

                double NumOfDayAdjust = 0;

                if (rawDataTable.Columns.Contains(FIELD_NUM_OF_DAY_ADJUST))
                {
                    string NumOfDayAdjustString = row[FIELD_NUM_OF_DAY_ADJUST].ToString();
                    if (!string.IsNullOrEmpty(NumOfDayAdjustString))
                    {
                        if (!double.TryParse(NumOfDayAdjustString, out NumOfDayAdjust))
                        {
                            errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_NUM_OF_DAY_ADJUST + "=" + NumOfDayAdjustString, EmpNo, rowCount.ToString() });
                        }
                        else
                        {
                            uploadEmpFinalPay.EmpFinalPayNumOfDayAdj = NumOfDayAdjust;
                        }
                    }
                    else
                    {
                        uploadEmpFinalPay.EmpFinalPayNumOfDayAdj = 0;
                    }
                }

                uploadEmpFinalPay.EmpFinalPayIsAutoGen = false;


                uploadEmpFinalPay.SessionID       = m_SessionID;
                uploadEmpFinalPay.TransactionDate = UploadDateTime;

                //  Final Payment do NOT have unique constraint, skip checking duplicate record
                //if (uploadEmpFinalPay.EmpID != 0)
                //{
                //    AND andTerms = new AND();
                //    andTerms.add(new Match("PayCodeID", uploadEmpFinalPay.PayCodeID));

                //    lastEmpFinalPay = (EEmpFinalPayment)AppUtils.GetLastObj(dbConn, uploadDB, "EmpFinalPayID", uploadEmpFinalPay.EmpID, andTerms);


                //    if (lastEmpFinalPay != null)
                //    {
                //        if (uploadEmpFinalPay.EmpAccID == lastEmpFinalPay.EmpAccID
                //            && Math.Abs(uploadEmpFinalPay.EmpFinalPayAmount - lastEmpFinalPay.EmpFinalPayAmount) < 0.01
                //            && uploadEmpFinalPay.EmpFinalPayMethod == lastEmpFinalPay.EmpFinalPayMethod
                //            && uploadEmpFinalPay.PayCodeID == lastEmpFinalPay.PayCodeID
                //            )
                //            continue;
                //        else
                //        {
                //            // add postion terms with new ID
                //                uploadEmpFinalPay.EmpFinalPayID = lastEmpFinalPay.EmpFinalPayID;
                //        }
                //    }
                //}
                //if (rawDataTable.Columns.Contains(FIELD_INTERNAL_ID))
                //{
                //    try
                //    {
                //        if (!row.IsNull(FIELD_INTERNAL_ID))
                //        {
                //            int tmpID = FromHexDecWithCheckDigit((string)row[FIELD_INTERNAL_ID]);
                //            EEmpFinalPayment tmpObj = new EEmpFinalPayment();
                //            tmpObj.EmpFinalPayID = tmpID;
                //            if (EEmpFinalPayment.db.select(dbConn, tmpObj))
                //                uploadEmpFinalPay.EmpFinalPayID = 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();
                        uploadEmpFinalPay.SynID = strSynID;
                        if (!string.IsNullOrEmpty(strSynID))
                        {
                            DBFilter synIDFilter = new DBFilter();
                            synIDFilter.add(new Match("SynID", strSynID));
                            ArrayList objSameSynIDList = EEmpFinalPayment.db.select(dbConn, synIDFilter);
                            if (objSameSynIDList.Count > 0)
                            {
                                uploadEmpFinalPay.EmpFinalPayID = ((EEmpFinalPayment)objSameSynIDList[0]).EmpFinalPayID;
                            }
                        }
                    }
                }

                if (uploadEmpFinalPay.EmpFinalPayID <= 0)
                {
                    uploadEmpFinalPay.ImportActionStatus = ImportDBObject.ImportActionEnum.INSERT;
                }
                else
                {
                    uploadEmpFinalPay.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE;
                }

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

                Hashtable values = new Hashtable();
                tempDB.populate(uploadEmpFinalPay, values);
                PageErrors pageErrors = new PageErrors(tempDB);
                tempDB.validate(pageErrors, values);
                if (pageErrors.errors.Count == 0)
                {
                    tempDB.insert(dbConn, uploadEmpFinalPay);
                }
                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));
        }
        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));
        }
Пример #3
0
        public DataTable UploadToTempDatabase(DataTable rawDataTable, int UserID)
        {
            if (rawDataTable == null)
            {
                return(GetImportDataFromTempDatabase(null));
            }

            int rowCount = 1;

            foreach (DataRow row in rawDataTable.Rows)
            {
                rowCount++;

                EUploadEmpBankAccount uploadEmpBankAcc = new EUploadEmpBankAccount();

                string EmpNo = row[FIELD_EMP_NO].ToString().Trim();
                uploadEmpBankAcc.EmpID = Parse.GetEmpID(dbConn, EmpNo, UserID);
                if (uploadEmpBankAcc.EmpID < 0)
                {
                    errors.addError(ImportErrorMessage.ERROR_ACCESS_DENIED_EMP_NO, new string[] { EmpNo, rowCount.ToString() });
                }
                uploadEmpBankAcc.EmpBankCode   = row[FIELD_BANK_CODE].ToString();
                uploadEmpBankAcc.EmpBranchCode = row[FIELD_BRANCH_CODE].ToString();
                uploadEmpBankAcc.EmpAccountNo  = row[FIELD_ACC_NO].ToString();

                uploadEmpBankAcc.EmpBankAccountHolderName = row[FIELD_HOLDER_NAME].ToString();
                uploadEmpBankAcc.EmpAccDefault            = row[FIELD_DEFAULTACCOUNT].ToString().Equals("Yes", StringComparison.CurrentCultureIgnoreCase) || row[FIELD_DEFAULTACCOUNT].ToString().Equals("Y", StringComparison.CurrentCultureIgnoreCase);

                uploadEmpBankAcc.EmpBankAccountID = Parse.GetEmpAccID(dbConn, uploadEmpBankAcc.EmpBankCode, uploadEmpBankAcc.EmpBranchCode, uploadEmpBankAcc.EmpAccountNo, uploadEmpBankAcc.EmpID);

                if (rawDataTable.Columns.Contains(FIELD_REMARK))
                {
                    uploadEmpBankAcc.EmpBankAccountRemark = row[FIELD_REMARK].ToString();
                }


                uploadEmpBankAcc.SessionID       = m_SessionID;
                uploadEmpBankAcc.TransactionDate = UploadDateTime;


                //if (rawDataTable.Columns.Contains(FIELD_INTERNAL_ID))
                //{
                //    try
                //    {
                //        if (!row.IsNull(FIELD_INTERNAL_ID))
                //        {
                //            int tmpID = FromHexDecWithCheckDigit((string)row[FIELD_INTERNAL_ID]);
                //            EEmpBankAccount tmpObj = new EEmpBankAccount();
                //            tmpObj.EmpBankAccountID = tmpID;
                //            if (EEmpBankAccount.db.select(dbConn, tmpObj))
                //                uploadEmpBankAcc.EmpBankAccountID = 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();
                        uploadEmpBankAcc.SynID = strSynID;
                        if (!string.IsNullOrEmpty(strSynID))
                        {
                            DBFilter synIDFilter = new DBFilter();
                            synIDFilter.add(new Match("SynID", strSynID));
                            ArrayList objSameSynIDList = EEmpBankAccount.db.select(dbConn, synIDFilter);
                            if (objSameSynIDList.Count > 0)
                            {
                                uploadEmpBankAcc.EmpBankAccountID = ((EEmpBankAccount)objSameSynIDList[0]).EmpBankAccountID;
                            }
                        }
                    }
                }

                if (uploadEmpBankAcc.EmpBankAccountID <= 0)
                {
                    uploadEmpBankAcc.ImportActionStatus = ImportDBObject.ImportActionEnum.INSERT;
                }
                else
                {
                    uploadEmpBankAcc.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE;
                }

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

                Hashtable values = new Hashtable();
                tempDB.populate(uploadEmpBankAcc, values);
                PageErrors pageErrors = new PageErrors(EUploadEmpPersonalInfo.db);
                tempDB.validate(pageErrors, values);
                if (pageErrors.errors.Count == 0)
                {
                    tempDB.insert(dbConn, uploadEmpBankAcc);
                }
                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));
        }