public override void ImportToDatabase() { DataTable dataTable = GetImportDataFromTempDatabase(null); if (dataTable.Rows.Count > 0) { EIncentivePaymentImportBatch batchDetail = new EIncentivePaymentImportBatch(); batchDetail.IPImportBatchDateTime = AppUtils.ServerDateTime(); //batchDetail.IPImportBatchOriginalFilename = OriginalBatchFilename; batchDetail.IPImportBatchRemark = Remark; batchDetail.IPImportBatchUploadedBy = m_UserID; EIncentivePaymentImportBatch.db.insert(dbConn, batchDetail); foreach (DataRow row in dataTable.Rows) { EUploadIncentivePayment obj = new EUploadIncentivePayment(); EUploadIncentivePayment.db.toObject(row, obj); EIncentivePayment IP = new EIncentivePayment(); IP.IPPercent = obj.IPPercent; IP.IPEffDate = obj.IPEffDate; IP.EmpID = obj.EmpID; IP.IPImportBatchID = batchDetail.IPImportBatchID; EIncentivePayment.db.insert(dbConn, IP); EUploadIncentivePayment.db.delete(dbConn, obj); } } }
public DataTable UploadToTempDatabase(DataTable rawDataTable, int UserID) { if (rawDataTable == null) { return(GetImportDataFromTempDatabase(null)); } int rowCount = 1; //ArrayList results = new ArrayList(); try { foreach (DataRow row in rawDataTable.Rows) { rowCount++; string EmpNo = row[FIELD_EMP_NO].ToString(); int EmpID = HROne.Import.Parse.GetEmpID(dbConn, EmpNo, UserID); if (EmpID < 0) { errors.addError(ImportErrorMessage.ERROR_ACCESS_DENIED_EMP_NO, new string[] { EmpNo, rowCount.ToString() }); } //string EffDateString = row[FIELD_EFFECTIVE_DATE].ToString(); //DateTime EffDate = Import.Parse.toDateTimeObject(row[FIELD_EFFECTIVE_DATE]); string percentString = row[FIELD_PERCENT].ToString(); double percent = 0; string effDateString = row[FIELD_EFF_DATE].ToString(); DateTime effDate = new DateTime(); //if (EmpID > 0 && EffDate.Ticks != 0 && double.TryParse(percentString, out percent)) if (EmpID > 0 && double.TryParse(percentString, out percent) && DateTime.TryParse(effDateString, out effDate)) { EUploadIncentivePayment IP = new EUploadIncentivePayment(); IP.EmpID = EmpID; IP.IPPercent = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(percent, 2, 2); IP.IPEffDate = effDate; IP.SessionID = m_SessionID; IP.TransactionDate = UploadDateTime; IP.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE; db.insert(dbConn, IP); } else { if (EmpID == 0) { errors.addError(ImportErrorMessage.ERROR_INVALID_EMP_NO, new string[] { EmpNo, rowCount.ToString() }); } else if (effDate.Ticks == 0) { errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_EFF_DATE + "=" + effDateString, EmpNo, rowCount.ToString() }); } else if (!double.TryParse(percentString, out percent)) { errors.addError(ImportErrorMessage.ERROR_INVALID_FIELD_VALUE, new string[] { FIELD_PERCENT + "=" + percentString, EmpNo, rowCount.ToString() }); } } } } catch (Exception e) { errors.addError(e.Message, null); } if (errors.List.Count > 0) { ClearTempTable(); throw (new HRImportException(rawDataTable.TableName + "\r\n" + errors.Message())); } return(GetImportDataFromTempDatabase(null)); }