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