/** * Busca el primer registro que coincida con los datos enviados * @param Rolopcion obj * @return Retorna el mismo objeto pero con los datos consultados */ public Rolopcion buscarPrimeroRolopcion(Rolopcion obj) { List <Rolopcion> lista = null; try { RolopcionDao dao = new RolopcionDao(); conn = conexion.conectar(); lista = dao.searchMatching(conn, obj); if (lista != null && lista.Count > 0) { obj = (Rolopcion)lista[0]; } else { obj.ID_ROL_OPCION = -1; } } catch (Exception e) { obj.ID_ROL_OPCION = -1; } finally { if (conn != null && conn.State == System.Data.ConnectionState.Open) { conn.Close(); } } return(obj); }
/** * Inserta nuevo registro en la tabla * @param Rolopcion obj * @return Retorna el mismo objeto pero con la llave primaria configurada */ public Rolopcion crearRolopcion(Rolopcion obj) { List <Rolopcion> lista = null; Rolopcion obj_new = new Rolopcion(); try { RolopcionDao dao = new RolopcionDao(); conn = conexion.conectar(); int id = Funciones.obtenerId(conn, "ROL_OPCION"); obj.ID_ROL_OPCION = id; dao.create(conn, obj); //verificar existencia obj_new.ID_ROL_OPCION = obj.ID_ROL_OPCION; lista = dao.searchMatching(conn, obj_new); if (lista != null && lista.Count > 0) { obj_new = (Rolopcion)lista[0]; } else { obj_new.ID_ROL_OPCION = -1; } } catch (Exception e) { obj_new.ID_ROL_OPCION = -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 Rolopcion obj * @return Retorna la lista de los registros que coinciden */ public Rolopcion[] buscarRolopcion(Rolopcion obj, int pagina, int numRegPagina) { Rolopcion[] result = null; List <Rolopcion> lista = null; if (pagina > 0 && numRegPagina > 0) { pagina--; int limInf = 0; int limSup = 0; limInf = pagina * numRegPagina + 1; limSup = (pagina + 1) * numRegPagina; try { RolopcionDao dao = new RolopcionDao(); 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); }
private List <Rolopcion> listQuery(SqlCommand stmt) { List <Rolopcion> searchResults = new List <Rolopcion>(); SqlDataReader reader = null; try { int intt = 0; long longg = 0; double doublee = 0; DateTime datee; reader = stmt.ExecuteReader(); while (reader.Read()) { Rolopcion temp = createValueObject(); temp.ID_ROL_OPCION = reader["ID_ROL_OPCION"] != null && long.TryParse(reader["ID_ROL_OPCION"].ToString(), out longg) ? longg : 0; temp.ID_ROL = reader["ID_ROL"] != null && long.TryParse(reader["ID_ROL"].ToString(), out longg) ? longg : 0; temp.OPCION = reader["OPCION"] != null ? reader["OPCION"].ToString() : null; searchResults.Add(temp); } } finally { if (!reader.IsClosed) { reader.Close(); } if (stmt != null) { stmt.Dispose(); } } return(searchResults); }
public void delete(SqlConnection conn, Rolopcion valueObject) { SqlCommand stmt = null; String sql = ""; try { sql = "DELETE FROM ROL_OPCION WHERE (ID_ROL_OPCION = @ID_ROL_OPCION )"; stmt = new SqlCommand(sql, conn); stmt.Parameters.AddWithValue("@ID_ROL_OPCION", valueObject.ID_ROL_OPCION); 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(); } } }
public Rolopcion[] buscarPaginacionRolopcion(Rolopcion obj, int pag, int numReg) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRolopcion.buscarRolopcion(obj, pag, numReg)); } return(null); }
public Rolopcion[] buscarRolopcion(Rolopcion obj) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRolopcion.buscarRolopcion(obj)); } return(null); }
public bool editarRolopcion(Rolopcion obj) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRolopcion.editarRolopcion(obj)); } return(false); }
public int contarBusquedaRolopcion(Rolopcion obj) { if (autenticacion != null && autenticacion.esValido()) { return(gestionRolopcion.contarBusquedaRolopcion(obj)); } return(-1); }
public int countSearchMatching(SqlConnection conn, Rolopcion valueObject) { bool first = true; String sql = "SELECT COUNT(*) FROM ROL_OPCION WHERE 1=1 "; if (valueObject.ID_ROL_OPCION != null && valueObject.ID_ROL_OPCION != 0) { if (first) { first = false; } sql += "AND ID_ROL_OPCION= " + valueObject.ID_ROL_OPCION + " "; } if (valueObject.ID_ROL != null && valueObject.ID_ROL != 0) { if (first) { first = false; } sql += "AND ID_ROL= " + valueObject.ID_ROL + " "; } if (!String.IsNullOrEmpty(valueObject.OPCION)) { if (first) { first = false; } sql += "AND OPCION= '" + valueObject.OPCION + "' "; } 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 <Rolopcion> searchMatching(SqlConnection conn, Rolopcion valueObject, int limiteInf, int limiteSup) { List <Rolopcion> searchResults = new List <Rolopcion>(); bool first = true; String sql = "SELECT * FROM ROL_OPCION WHERE 1=1 "; if (valueObject.ID_ROL_OPCION != null && valueObject.ID_ROL_OPCION != 0) { if (first) { first = false; } sql += "AND ID_ROL_OPCION= " + valueObject.ID_ROL_OPCION + " "; } if (valueObject.ID_ROL != null && valueObject.ID_ROL != 0) { if (first) { first = false; } sql += "AND ID_ROL= " + valueObject.ID_ROL + " "; } if (!String.IsNullOrEmpty(valueObject.OPCION)) { if (first) { first = false; } sql += "AND OPCION= '" + valueObject.OPCION + "' "; } sql += ") AS CONSULTA WHERE RowNumber >=" + limiteInf + " AND RowNumber <=" + limiteSup; if (first) { searchResults = new List <Rolopcion>(); } else { searchResults = listQuery(new SqlCommand(sql, conn)); } return(searchResults); }
public int contarBusquedaRolopcion(Rolopcion obj) { int cantidad = -1; try { RolopcionDao dao = new RolopcionDao(); 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 Rolopcion obj * @return boolean indicando si se realizo o no la actualizacion */ public bool editarRolopcion(Rolopcion obj) { bool resultado; resultado = false; try { RolopcionDao dao = new RolopcionDao(); 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, Rolopcion valueObject) { SqlCommand stmt = null; String sql = ""; try { sql = "UPDATE ROL_OPCION SET ID_ROL = @ID_ROL , OPCION = @OPCION WHERE (ID_ROL_OPCION= @ID_ROL_OPCION)"; stmt = new SqlCommand(sql, conn); if (valueObject.ID_ROL != 0) { stmt.Parameters.AddWithValue("@ID_ROL", valueObject.ID_ROL); } else { stmt.Parameters.AddWithValue("@ID_ROL", DBNull.Value); } if (valueObject.OPCION != null && valueObject.OPCION.Length <= 50) { stmt.Parameters.AddWithValue("@OPCION", valueObject.OPCION); } else { stmt.Parameters.AddWithValue("@OPCION", DBNull.Value); } stmt.Parameters.AddWithValue("@ID_ROL_OPCION", valueObject.ID_ROL_OPCION); 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, Rolopcion valueObject) { String sql = ""; SqlCommand stmt = null; try { sql = "INSERT INTO ROL_OPCION ( ID_ROL_OPCION," + " ID_ROL, OPCION)" + "VALUES ( @ID_ROL_OPCION, @ID_ROL, @OPCION)"; stmt = new SqlCommand(sql, conn); stmt.Parameters.AddWithValue("@ID_ROL_OPCION", valueObject.ID_ROL_OPCION); if (valueObject.ID_ROL != 0) { stmt.Parameters.AddWithValue("@ID_ROL", valueObject.ID_ROL); } else { stmt.Parameters.AddWithValue("@ID_ROL", DBNull.Value); } if (valueObject.OPCION != null && valueObject.OPCION.Length <= 50) { stmt.Parameters.AddWithValue("@OPCION", valueObject.OPCION); } else { stmt.Parameters.AddWithValue("@OPCION", DBNull.Value); } databaseUpdate(stmt); } finally { if (stmt != null) { stmt.Dispose(); } } }
/** * Busca los registros que coincidan con los datos enviados * @param Rolopcion obj * @return Retorna la lista de los registros que coinciden */ public Rolopcion[] buscarRolopcion(Rolopcion obj) { Rolopcion[] result = null; List <Rolopcion> lista = null; try { RolopcionDao dao = new RolopcionDao(); 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); }