//AGREGAR public bool AgregarPrestamo(Entities.DetallePrestamos prestamo) { SqlConnection c = null; SqlCommand comandAgregar = null; String sql = "INSERT INTO detallePrestamos (preUsuario, preLibro, preFechaInicio, preFechaFin, preDiasSancion, preCantidad) VALUES (@usuario, @libro, @inicio, @fin, @sancion, @cantidad)"; try { c = con.getConexion(); comandAgregar = new SqlCommand(sql, c); comandAgregar.Parameters.AddWithValue("@usuario", prestamo.Usuario); comandAgregar.Parameters.AddWithValue("@libro", prestamo.Libro); comandAgregar.Parameters.AddWithValue("@inicio", prestamo.FechaInicio); comandAgregar.Parameters.AddWithValue("@fin", prestamo.FechaFin); comandAgregar.Parameters.AddWithValue("@sancion", prestamo.DiasSancion); comandAgregar.Parameters.AddWithValue("@cantidad", prestamo.Cantidad); comandAgregar.ExecuteNonQuery(); return(true); }catch (Exception ex) { ex.ToString(); return(false); } finally { c.Close(); comandAgregar = null; } }
//ACTUALIZAR public bool ActualizarPrestamo(Entities.DetallePrestamos prestamo, String cod) { SqlConnection c = null; SqlCommand commandActualizar = null; String sql = "UPDATE detallePrestamos SET preUsuario = @usuario, preLibro = @libro, preFechaInicio = @fInicio, preFechaFin = @fFin, preDiasSancion = @dias, preCantidad = @cantidad WHERE preCodigo = @cod"; try { c = con.getConexion(); commandActualizar = new SqlCommand(sql, c); commandActualizar.Parameters.AddWithValue("@usuario", prestamo.Usuario); commandActualizar.Parameters.AddWithValue("@libro", prestamo.Libro); commandActualizar.Parameters.AddWithValue("@fInicio", prestamo.FechaInicio); commandActualizar.Parameters.AddWithValue("@fFin", prestamo.FechaFin); commandActualizar.Parameters.AddWithValue("@dias", prestamo.DiasSancion); commandActualizar.Parameters.AddWithValue("@cantidad", prestamo.Cantidad); commandActualizar.Parameters.AddWithValue("@cod", cod); commandActualizar.ExecuteNonQuery(); return(true); }catch (Exception ex) { ex.ToString(); return(false); } finally { c.Close(); commandActualizar = null; } }