private void storeService_OnImportBusinessVolumeComplete(object sender, OperationCompleteEventArgs e) { ImportBusinessValuesResult importBusinessValuesResult = (ImportBusinessValuesResult)e.Param; if (importBusinessValuesResult.BusinessVolumeType == _ImportType) { _CompleteResult = e.Success; if (_CompleteResult) { if (importBusinessValuesResult.FilesCount <= 0) { _CompleteResult = false; _Exception = new Exception(GetLocalized("NoFilesMatchSpec")); } } else { _Exception = (Exception)importBusinessValuesResult.Data; } _ImportRunning = false; } }
/* * public ImportBusinessValuesResult ImportBusinessVolume(BusinessVolumeType importType) * { * string folderName = ServerEnvironment.ImportSettings.SourceFolder; * string[] files = ImportUtil.GetBusinessVolumeFilesList(folderName, importType); * * ImportBusinessValuesResult result = new ImportBusinessValuesResult(); * if (files.Length > 0) * { * if(ImportBusinessVolumeMessageInfo != null) * { * ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(files)); * } * using (IDbCommand command = CreateCommand()) * { * command.CommandTimeout = 0; * command.CommandText = "spBusinessVolume_ImportData"; * command.CommandType = CommandType.StoredProcedure; * SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); * importResult.Direction = ParameterDirection.Output; * command.Parameters.Add(importResult); * * SqlParameter xmlDocument = new SqlParameter("@xmlDocument", SqlDbType.NText); * xmlDocument.Value = ImportUtil.GetFilesListInXml(files); * command.Parameters.Add(xmlDocument); * * SqlParameter formatFile = new SqlParameter("@formatFile", SqlDbType.NVarChar, 255); * formatFile.Value = ImportUtil.GetFormatFile(folderName, importType); * command.Parameters.Add(formatFile); * * SqlParameter tableName = new SqlParameter("@tableName", SqlDbType.NVarChar, 30); * tableName.Value = ImportUtil.GetTableName(importType); * command.Parameters.Add(tableName); * * command.ExecuteNonQuery(); * result.Success = ((int) importResult.Value > 0); * if (result.Success) * { * ImportUtil.MoveFilesInImportedFolder(ServerEnvironment.ImportSettings.ImportedFolder, files); * command.Parameters.Clear(); * command.CommandText = "spBusinessVolume_ConvertData"; * command.CommandType = CommandType.StoredProcedure; * command.Parameters.Add(tableName); * command.ExecuteNonQuery(); * result.Data = files.Length; * } * } * } * else * { * result.Success = true; * result.Data = 0; * } * return result; * } */ public ImportBusinessValuesResult ImportBusinessVolume(BusinessVolumeType importType) { int importSuccessCount = 0; string folderName = ServerEnvironment.ImportSettings.SourceFolder; string[] files = ImportUtil.GetBusinessVolumeFilesList(folderName, importType); ImportBusinessValuesResult result = new ImportBusinessValuesResult(); result.BusinessVolumeType = importType; if (files.Length > 0) { using (IDbCommand command = CreateCommand()) { command.CommandTimeout = 0; command.CommandType = CommandType.StoredProcedure; SqlParameter importResult = new SqlParameter("@result", SqlDbType.Int, 4); importResult.Direction = ParameterDirection.Output; SqlParameter importFile = new SqlParameter("@importFile", SqlDbType.NVarChar, 255); SqlParameter errorFile = new SqlParameter("@errorFile", SqlDbType.NVarChar, 255); SqlParameter formatFile = new SqlParameter("@formatFile", SqlDbType.NVarChar, 255); formatFile.Value = ImportUtil.GetFormatFile(folderName, importType); SqlParameter tableName = new SqlParameter("@tableName", SqlDbType.NVarChar, 30); tableName.Value = ImportUtil.GetTableName(importType); for (int i = 0; i < files.Length; i++) { if (ImportBusinessVolumeMessageInfo != null) { ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(new MessageStringInfo(importType, files[i]))); } command.CommandText = "spBusinessVolume_ImportData"; command.Parameters.Clear(); command.Parameters.Add(importResult); importFile.Value = files[i]; command.Parameters.Add(importFile); errorFile.Value = ImportUtil.GetErrorFileName(files[i]); command.Parameters.Add(errorFile); command.Parameters.Add(formatFile); command.Parameters.Add(tableName); command.ExecuteNonQuery(); result.Success = ((int)importResult.Value > 0); if (result.Success) { importSuccessCount++; ImportUtil.MoveFilesInFolder(ServerEnvironment.ImportSettings.ImportedFolder, new string[] { files[i] }); if (ImportBusinessVolumeMessageInfo != null) { ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(new MessageStringInfo(importType, "bvImportOK", false, true))); } } else { ImportUtil.MoveFilesInFolder(ServerEnvironment.ImportSettings.ImportErrorsFolder, ImportUtil.GetFilesWithErrorsForFile(files[i])); if (ImportBusinessVolumeMessageInfo != null) { ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(new MessageStringInfo(importType, "bvImportError", false, true))); } } } if (importSuccessCount != files.Length) { if (ImportBusinessVolumeMessageInfo != null) { MessageStringInfo messageStringInfo = new MessageStringInfo(importType, "bvAboutErrorFilesInfo"); messageStringInfo.LocalizeKey = true; messageStringInfo.MessageParams = new string[] { ServerEnvironment.ImportSettings.ImportErrorsFolder }; ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(messageStringInfo)); } } if (importSuccessCount > 0) { if (ImportBusinessVolumeMessageInfo != null) { ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(new MessageStringInfo(importType, ""))); MessageStringInfo messageStringInfo = new MessageStringInfo(importType, "bvDataConvertStart"); messageStringInfo.LocalizeKey = true; ImportBusinessVolumeMessageInfo(null, new MessageInfoEventArgs(messageStringInfo)); } command.Parameters.Clear(); command.CommandText = "spBusinessVolume_ConvertData"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(tableName); command.ExecuteNonQuery(); ReloadDataIntoCache(importType); } result.Success = importSuccessCount == files.Length; if (result.Success) { result.FilesCount = files.Length; } } } else { result.Success = true; result.FilesCount = 0; } return(result); }