/// <summary> /// put the data from imports table to actual data after constraints check /// </summary> private bool ProcessFile(string fileName, ref ArrayList processedMessages) { int idImport = ApplicationConstants.INT_NULL_VALUE; int result = ApplicationConstants.INT_NULL_VALUE; int resultFileExist = ApplicationConstants.INT_NULL_VALUE; string duplicateError = string.Empty; string cleanFileName = ApplicationUtils.GetCleanFileName(fileName); AnnualUpload annualUpload = new AnnualUpload(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER)); annualUpload.IdAssociate = currentUser.IdAssociate; try { annualUpload.FileName = fileName; resultFileExist = annualUpload.CheckFileAlreadyUploaded(); } catch (Exception ex) { processedMessages.Add(ApplicationMessages.IMPORT_CHECK_FILE_CRASH); LogErrorToDataBase(ex.Message, fileName); return(false); } if (resultFileExist < 0) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ALREADY_UPLOADED, cleanFileName)); return(false); } try { idImport = annualUpload.WriteToAnnualImportTable(); } catch (Exception ex) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ERROR, cleanFileName)); LogErrorToDataBase(ex.Message, fileName); return(false); } if (idImport < 0) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ERROR, cleanFileName)); return(false); } try { annualUpload.IdImport = idImport; result = annualUpload.InsertIntoAnnualTable(); } catch (IndException ex) { result = -100; if (((IndException)ex).BaseException is SqlException) { SqlException sqlBaseException = ((SqlException)((IndException)ex).BaseException); if (sqlBaseException.Number == 2627) //The exception number for primary key violation { duplicateError = "At least one record from the file " + cleanFileName + " already exists in the database."; } } if (string.IsNullOrEmpty(duplicateError)) { LogProcessErrorToDataBase(idImport, ex.Message, fileName); } else { LogProcessErrorToDataBase(idImport, duplicateError, fileName); } } if (result >= 0) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_PROCESSED, cleanFileName)); return(true); } else { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ERROR, cleanFileName)); return(false); } }
/// <summary> /// put the data from imports table to actual data after constraints check /// </summary> private bool ProcessFile(string fileName, ref ArrayList processedMessages) { int idImport = ApplicationConstants.INT_NULL_VALUE; int result = ApplicationConstants.INT_NULL_VALUE; int resultFileExist = ApplicationConstants.INT_NULL_VALUE; string duplicateError = string.Empty; string cleanFileName = ApplicationUtils.GetCleanFileName(fileName); AnnualUpload annualUpload = new AnnualUpload(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER)); annualUpload.IdAssociate = currentUser.IdAssociate; try { annualUpload.FileName = fileName; resultFileExist = annualUpload.CheckFileAlreadyUploaded(); } catch (Exception ex) { processedMessages.Add(ApplicationMessages.IMPORT_CHECK_FILE_CRASH); LogErrorToDataBase(ex.Message, fileName); return(false); } if (resultFileExist < 0) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ALREADY_UPLOADED, cleanFileName)); return(false); } try { idImport = annualUpload.WriteToAnnualImportTable(); } catch (Exception ex) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ERROR, cleanFileName)); LogErrorToDataBase(ex.Message, fileName); return(false); } if (idImport < 0) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ERROR, cleanFileName)); return(false); } try { annualUpload.IdImport = idImport; bool skipStartEndPhaseErrorsHours = false; bool skipStartEndPhaseErrorsCosts = false; bool skipStartEndPhaseErrorsSales = false; if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Hours")) { skipStartEndPhaseErrorsHours = true; } if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Costs")) { skipStartEndPhaseErrorsCosts = true; } if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Sales")) { skipStartEndPhaseErrorsSales = true; } result = annualUpload.InsertIntoAnnualTable(skipStartEndPhaseErrorsHours, skipStartEndPhaseErrorsCosts, skipStartEndPhaseErrorsSales); } catch (IndException ex) { result = -100; if (((IndException)ex).BaseException is SqlException) { SqlException sqlBaseException = ((SqlException)((IndException)ex).BaseException); if (sqlBaseException.Number == 2627) //The exception number for primary key violation { duplicateError = "At least one record from the file " + cleanFileName + " already exists in the database."; } } if (string.IsNullOrEmpty(duplicateError)) { LogProcessErrorToDataBase(idImport, ex.Message, fileName); } else { LogProcessErrorToDataBase(idImport, duplicateError, fileName); } } if (result >= 0) { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_PROCESSED, cleanFileName)); //If file was in this collection and it has been successfully processed, then remove it if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Hours")) { FilesWithSkipStartEndPhaseErrors.Remove(cleanFileName + "_Hours"); } if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Costs")) { FilesWithSkipStartEndPhaseErrors.Remove(cleanFileName + "_Costs"); } if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Sales")) { FilesWithSkipStartEndPhaseErrors.Remove(cleanFileName + "_Sales"); } return(true); } else { processedMessages.Add(string.Format(ApplicationMessages.IMPORT_FILE_ERROR, cleanFileName)); if (result == ApplicationConstants.SKIP_START_END_PHASE_VALIDATION_HOURS) { if (!FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Hours")) { FilesWithSkipStartEndPhaseErrors.Add(cleanFileName + "_Hours"); } } else if (result == ApplicationConstants.SKIP_START_END_PHASE_VALIDATION_SALES) { if (!FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Sales")) { FilesWithSkipStartEndPhaseErrors.Add(cleanFileName + "_Sales"); } } else if (result == ApplicationConstants.SKIP_START_END_PHASE_VALIDATION_COSTS) { if (!FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Costs")) { FilesWithSkipStartEndPhaseErrors.Add(cleanFileName + "_Costs"); } } else { //if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Hours")) FilesWithSkipStartEndPhaseErrors.Remove(cleanFileName + "_Hours"); //if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Costs")) FilesWithSkipStartEndPhaseErrors.Remove(cleanFileName + "_Costs"); //if (FilesWithSkipStartEndPhaseErrors.Contains(cleanFileName + "_Sales")) FilesWithSkipStartEndPhaseErrors.Remove(cleanFileName + "_Sales"); } return(false); } }