protected static List <T> GetDTOList <T>(ref SqlCommand sqlCmd) where T : DTOBase { List <T> dtoList = new List <T>(); try { sqlCmd.Connection.Open(); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); if (sqlReader.HasRows) { DTOParser baseParser = DTOParserFactory.GetParser(typeof(T)); baseParser.PopulateOrdinals(sqlReader); while (sqlReader.Read()) { T currentDTO = null; currentDTO = (T)baseParser.PopulateDTO(sqlReader); dtoList.Add(currentDTO); } sqlReader.Close(); } } catch (Exception e) { throw e; } finally { sqlCmd.Connection.Close(); sqlCmd.Connection.Dispose(); } return(dtoList); }
protected static T GetDTO <T>(ref SqlCommand sqlCmd) where T : DTOBase { T currentDTO = null; try { sqlCmd.Connection.Open(); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); if (sqlReader.HasRows) { sqlReader.Read(); DTOParser baseParser = DTOParserFactory.GetParser(typeof(T)); baseParser.PopulateOrdinals(sqlReader); currentDTO = (T)baseParser.PopulateDTO(sqlReader); sqlReader.Close(); } else { return(null); } } catch (Exception e) { throw e; } finally { sqlCmd.Connection.Close(); sqlCmd.Connection.Dispose(); } return(currentDTO); }
// GetSingleDTO protected static T GetSingleDTO <T>(ref SqlCommand command) where T : DTOBase { T dto = null; try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); dto = (T)parser.PopulateDTO(reader); reader.Close(); } else { // S'il n'y a pas de données, nous renvoyons null. dto = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } // Renvoie le DTO, rempli soit avec des données soit avec null. return(dto); }
protected static List <T> GetDTOListJSON <T>(ref SqlCommand command) where T : CommonBase { List <T> dtoList = new List <T>(); try { command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Get a parser for this DTO type and populate // the ordinals. DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); while (reader.Read()) { dtoList = parser.PopulateDTOList <T>(reader); } reader.Close(); } } catch (SqlException oEx) { throw oEx; } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }
// GetSingleDTO protected static T GetSingleDTO <T>(ref SqlCommand command) where T : CommonBase { T dto = null; try { SqlDataReader reader; DTOParser parser = DTOParserFactory.GetParser(typeof(T)); command.CommandTimeout = 3000; //tamaño time out para enviar en el config command.Connection.Open(); reader = command.ExecuteReader(); if (reader.Read()) { parser.PopulateOrdinals(reader); dto = (T)parser.PopulateDTO(reader); reader.Close(); } } catch (SqlException oEx) { throw oEx; } finally { command.Connection.Close(); command.Connection.Dispose(); } // return the DTO, it's either populated with data or null. return(dto); }
// GetDTOList protected static List <T> GetDTOList <T>(ref SqlCommand command) where T : DTOBase { List <T> dtoList = new List <T>(); try { command.Connection.Open(); command.CommandTimeout = 3600; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { // Obtenir un analyseur (parser) pour ce type de DTO et remplir les ordinaux. DTOParser parser = DTOParserFactory.GetParser(typeof(T)); parser.PopulateOrdinals(reader); // Utilise l'analyseur (parser) pour construire notre liste de DTO. while (reader.Read()) { T dto = null; dto = (T)parser.PopulateDTO(reader); dtoList.Add(dto); } reader.Close(); } else { // S'il n'y a pas de données, nous renvoyons null. dtoList = null; } } catch (Exception e) { throw new Exception("Error populating data", e); } finally { command.Connection.Close(); command.Connection.Dispose(); } return(dtoList); }