/** * Busca el primer registro que coincida con los datos enviados * @param Redessociales obj * @return Retorna el mismo objeto pero con los datos consultados */ public Redessociales buscarPrimeroRedessociales(Redessociales obj) { List <Redessociales> lista = null; try { RedessocialesDao dao = new RedessocialesDao(); conn = conexion.conectar(); lista = dao.searchMatching(conn, obj); if (lista != null && lista.Count > 0) { obj = (Redessociales)lista[0]; } else { obj.ID_REDES_SOCIALES = -1; } } catch (Exception e) { obj.ID_REDES_SOCIALES = -1; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(obj); }
private List <Redessociales> listQuery(SqlCommand stmt) { List <Redessociales> searchResults = new List <Redessociales>(); SqlDataReader reader = null; try { int intt = 0; long longg = 0; double doublee = 0; DateTime datee; reader = stmt.ExecuteReader(); while (reader.Read()) { Redessociales temp = createValueObject(); temp.ID_REDES_SOCIALES = reader["ID_REDES_SOCIALES"] != null && long.TryParse(reader["ID_REDES_SOCIALES"].ToString(), out longg) ? longg : 0; temp.ID_TIPO_RED_SOCIAL = reader["ID_TIPO_RED_SOCIAL"] != null && long.TryParse(reader["ID_TIPO_RED_SOCIAL"].ToString(), out longg) ? longg : 0; temp.URL = reader["URL"] != null ? reader["URL"].ToString() : null; searchResults.Add(temp); } } finally { if (!reader.IsClosed) { reader.Close(); } if (stmt != null) { stmt.Dispose(); } } return(searchResults); }
public void delete(SqlConnection conn, Redessociales valueObject) { SqlCommand stmt = null; String sql = ""; try { sql = "DELETE FROM REDES_SOCIALES WHERE (ID_REDES_SOCIALES = @ID_REDES_SOCIALES )"; stmt = new SqlCommand(sql, conn); stmt.Parameters.AddWithValue("@ID_REDES_SOCIALES", valueObject.ID_REDES_SOCIALES); int rowcount = databaseUpdate(stmt); if (rowcount == 0) { throw new Exception("Object could not be deleted! (PrimaryKey not found)"); } if (rowcount > 1) { throw new Exception("PrimaryKey Error when updating DB! (Many objects were deleted!)"); } } finally { if (stmt != null) { stmt.Dispose(); } } }
/** * Inserta nuevo registro en la tabla * @param Redessociales obj * @return Retorna el mismo objeto pero con la llave primaria configurada */ public Redessociales crearRedessociales(Redessociales obj) { List <Redessociales> lista = null; Redessociales obj_new = new Redessociales(); try { RedessocialesDao dao = new RedessocialesDao(); conn = conexion.conectar(); int id = Funciones.obtenerId(conn, "REDES_SOCIALES"); obj.ID_REDES_SOCIALES = id; dao.create(conn, obj); //verificar existencia obj_new.ID_REDES_SOCIALES = obj.ID_REDES_SOCIALES; lista = dao.searchMatching(conn, obj_new); if (lista != null && lista.Count > 0) { obj_new = (Redessociales)lista[0]; } else { obj_new.ID_REDES_SOCIALES = -1; } } catch (Exception e) { obj_new.ID_REDES_SOCIALES = -1; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(obj_new); }
/** * Busca los registros que coincidan con los datos enviados * @param Redessociales obj * @return Retorna la lista de los registros que coinciden */ public Redessociales[] buscarRedessociales(Redessociales obj, int pagina, int numRegPagina) { Redessociales[] result = null; List <Redessociales> lista = null; if (pagina > 0 && numRegPagina > 0) { pagina--; int limInf = 0; int limSup = 0; limInf = pagina * numRegPagina + 1; limSup = (pagina + 1) * numRegPagina; try { RedessocialesDao dao = new RedessocialesDao(); conn = conexion.conectar(); lista = dao.searchMatching(conn, obj, limInf, limSup); if (lista != null && lista.Count > 0) { result = lista.ToArray(); } } catch (Exception e) { result = null; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } } return(result); }
public Redessociales[] buscarPaginacionRedessociales(Redessociales obj, int pag, int numReg) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRedessociales.buscarRedessociales(obj, pag, numReg)); } return(null); }
public Redessociales[] buscarRedessociales(Redessociales obj) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRedessociales.buscarRedessociales(obj)); } return(null); }
public bool editarRedessociales(Redessociales obj) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRedessociales.editarRedessociales(obj)); } return(false); }
public int contarBusquedaRedessociales(Redessociales obj) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRedessociales.contarBusquedaRedessociales(obj)); } return(-1); }
public int countSearchMatching(SqlConnection conn, Redessociales valueObject) { bool first = true; String sql = "SELECT COUNT(*) FROM REDES_SOCIALES WHERE 1=1 "; if (valueObject.ID_REDES_SOCIALES != null && valueObject.ID_REDES_SOCIALES != 0) { if (first) { first = false; } sql += "AND ID_REDES_SOCIALES= " + valueObject.ID_REDES_SOCIALES + " "; } if (valueObject.ID_TIPO_RED_SOCIAL != null && valueObject.ID_TIPO_RED_SOCIAL != 0) { if (first) { first = false; } sql += "AND ID_TIPO_RED_SOCIAL= " + valueObject.ID_TIPO_RED_SOCIAL + " "; } if (!String.IsNullOrEmpty(valueObject.URL)) { if (first) { first = false; } sql += "AND URL= '" + valueObject.URL + "' "; } SqlCommand stmt = null; SqlDataReader result = null; int allRows = 0; try { stmt = new SqlCommand(sql, conn); result = stmt.ExecuteReader(); if (result.Read()) { allRows = int.Parse(result[0].ToString()); } } finally { if (!result.IsClosed) { result.Close(); } if (stmt != null) { stmt.Dispose(); } } return(allRows); }
public List <Redessociales> searchMatching(SqlConnection conn, Redessociales valueObject, int limiteInf, int limiteSup) { List <Redessociales> searchResults = new List <Redessociales>(); bool first = true; String sql = "SELECT * FROM REDES_SOCIALES WHERE 1=1 "; if (valueObject.ID_REDES_SOCIALES != null && valueObject.ID_REDES_SOCIALES != 0) { if (first) { first = false; } sql += "AND ID_REDES_SOCIALES= " + valueObject.ID_REDES_SOCIALES + " "; } if (valueObject.ID_TIPO_RED_SOCIAL != null && valueObject.ID_TIPO_RED_SOCIAL != 0) { if (first) { first = false; } sql += "AND ID_TIPO_RED_SOCIAL= " + valueObject.ID_TIPO_RED_SOCIAL + " "; } if (!String.IsNullOrEmpty(valueObject.URL)) { if (first) { first = false; } sql += "AND URL= '" + valueObject.URL + "' "; } sql += ") AS CONSULTA WHERE RowNumber >=" + limiteInf + " AND RowNumber <=" + limiteSup; if (first) { searchResults = new List <Redessociales>(); } else { searchResults = listQuery(new SqlCommand(sql, conn)); } return(searchResults); }
public int contarBusquedaRedessociales(Redessociales obj) { int cantidad = -1; try { RedessocialesDao dao = new RedessocialesDao(); conn = conexion.conectar(); cantidad = dao.countSearchMatching(conn, obj); } catch (Exception e) { cantidad = -1; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(cantidad); }
/** * Edita un registro en la tabla * @param Redessociales obj * @return boolean indicando si se realizo o no la actualizacion */ public bool editarRedessociales(Redessociales obj) { bool resultado; resultado = false; try { RedessocialesDao dao = new RedessocialesDao(); conn = conexion.conectar(); dao.save(conn, obj); resultado = true; } catch (Exception e) { resultado = false; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(resultado); }
public void save(SqlConnection conn, Redessociales valueObject) { SqlCommand stmt = null; String sql = ""; try { sql = "UPDATE REDES_SOCIALES SET ID_TIPO_RED_SOCIAL = @ID_TIPO_RED_SOCIAL , URL = @URL WHERE (ID_REDES_SOCIALES= @ID_REDES_SOCIALES)"; stmt = new SqlCommand(sql, conn); if (valueObject.ID_TIPO_RED_SOCIAL != 0) { stmt.Parameters.AddWithValue("@ID_TIPO_RED_SOCIAL", valueObject.ID_TIPO_RED_SOCIAL); } else { stmt.Parameters.AddWithValue("@ID_TIPO_RED_SOCIAL", DBNull.Value); } if (valueObject.URL != null && valueObject.URL.Length <= 500) { stmt.Parameters.AddWithValue("@URL", valueObject.URL); } else { stmt.Parameters.AddWithValue("@URL", DBNull.Value); } stmt.Parameters.AddWithValue("@ID_REDES_SOCIALES", valueObject.ID_REDES_SOCIALES); int rowcount = databaseUpdate(stmt); if (rowcount == 0) { throw new Exception("Object could not be saved! (PrimaryKey not found)"); } } finally { if (stmt != null) { stmt.Dispose(); } } }
public void create(SqlConnection conn, Redessociales valueObject) { String sql = ""; SqlCommand stmt = null; try { sql = "INSERT INTO REDES_SOCIALES ( ID_REDES_SOCIALES," + " ID_TIPO_RED_SOCIAL, URL)" + "VALUES ( @ID_REDES_SOCIALES, @ID_TIPO_RED_SOCIAL, @URL)"; stmt = new SqlCommand(sql, conn); stmt.Parameters.AddWithValue("@ID_REDES_SOCIALES", valueObject.ID_REDES_SOCIALES); if (valueObject.ID_TIPO_RED_SOCIAL != 0) { stmt.Parameters.AddWithValue("@ID_TIPO_RED_SOCIAL", valueObject.ID_TIPO_RED_SOCIAL); } else { stmt.Parameters.AddWithValue("@ID_TIPO_RED_SOCIAL", DBNull.Value); } if (valueObject.URL != null && valueObject.URL.Length <= 500) { stmt.Parameters.AddWithValue("@URL", valueObject.URL); } else { stmt.Parameters.AddWithValue("@URL", DBNull.Value); } databaseUpdate(stmt); } finally { if (stmt != null) { stmt.Dispose(); } } }
/** * Busca los registros que coincidan con los datos enviados * @param Redessociales obj * @return Retorna la lista de los registros que coinciden */ public Redessociales[] buscarRedessociales(Redessociales obj) { Redessociales[] result = null; List <Redessociales> lista = null; try { RedessocialesDao dao = new RedessocialesDao(); conn = conexion.conectar(); lista = dao.searchMatching(conn, obj); if (lista != null && lista.Count > 0) { result = lista.ToArray(); } } catch (Exception e) { result = null; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(result); }