public override void ImportToDatabase() { DataTable dataTable = GetImportDataFromTempDatabase(null); if (dataTable.Rows.Count > 0) { ECommissionAchievementImportBatch batchDetail = new ECommissionAchievementImportBatch(); batchDetail.CAImportBatchDateTime = AppUtils.ServerDateTime(); //batchDetail.CAImportBatchOriginalFilename = OriginalBatchFilename; batchDetail.CAImportBatchRemark = Remark; batchDetail.CAImportBatchUploadedBy = m_UserID; ECommissionAchievementImportBatch.db.insert(dbConn, batchDetail); foreach (DataRow row in dataTable.Rows) { EUploadCommissionAchievement obj = new EUploadCommissionAchievement(); EUploadCommissionAchievement.db.toObject(row, obj); ECommissionAchievement CA = new ECommissionAchievement(); CA.CAPercent = obj.CAPercent; CA.CAEffDate = obj.CAEffDate; CA.EmpID = obj.EmpID; CA.CAImportBatchID = batchDetail.CAImportBatchID; ECommissionAchievement.db.insert(dbConn, CA); EUploadCommissionAchievement.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)) { EUploadCommissionAchievement CA = new EUploadCommissionAchievement(); CA.EmpID = EmpID; CA.CAPercent = HROne.CommonLib.GenericRoundingFunctions.RoundingTo(percent, 2, 2); CA.CAEffDate = effDate; CA.SessionID = m_SessionID; CA.TransactionDate = UploadDateTime; CA.ImportActionStatus = ImportDBObject.ImportActionEnum.UPDATE; db.insert(dbConn, CA); } 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)); }