private void btnDevolver_Click(object sender, EventArgs e) { try { foreach (var item in biblioteca.tbLibroes) { if (listaLibros.SelectedItem.ToString() == item.nombre) { //cambiamos el estado a "disponible" tbLibro tbLibro = biblioteca.tbLibroes.Find(item.id); tbLibro.estado = true; foreach (var item2 in biblioteca.tbHistoricoes) { if (item.id == item2.idLibro) { //modificamos el historico agregando la fecha de devolucion tbHistorico tbHistorico = biblioteca.tbHistoricoes.Find(item2.id); tbHistorico.fechaDevolucion = DateTime.Now; } } } } MessageBox.Show("Devolucion agregada con exito, ya puede sacar otro libro", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); recursivo(); } catch (Exception) { MessageBox.Show("No selecciono ningun libro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnPrestar_Click(object sender, EventArgs e) { try { //Agregando el registro del alquiler de libro tbHistorico tbHistorico = new tbHistorico { idCliente = int.Parse(txtCodCli.Text), idLibro = int.Parse(txtCodLi.Text), fechaPrestamo = DateTime.Now }; biblioteca.tbHistoricoes.Add(tbHistorico); //Actualizando libro para ponerlo no disponible tbLibro tbLibro = biblioteca.tbLibroes.Find(int.Parse(txtCodLi.Text)); tbLibro.estado = false; //Guardando cambios en la base de datos biblioteca.SaveChanges(); //limpiar todos los campos LimpiarPrestarLibro(); recursivo(); MessageBox.Show("Se creo el prestamo, entregue el libro", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("Error en el codigo de libro", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }