private void btnBuscar_Click(object sender, EventArgs e) { Services.Libro oLibro = new Services.Libro(); BO.Libro oLibroBO = new BO.Libro(); if (txtISBN.Text.Trim().Length > 0) { oLibroBO.Isbn = txtISBN.Text.Trim(); } if (txtAutor.Text.Trim().Length > 0) { oLibroBO.Autor = txtAutor.Text.Trim(); } if (txtEditorial.Text.Trim().Length > 0) { oLibroBO.Editorial = txtEditorial.Text.Trim(); } if (txtNombre.Text.Trim().Length > 0) { oLibroBO.Titulo = txtNombre.Text.Trim(); } if (txtPrecio.Text.Trim().Length > 0) { oLibroBO.Precio = Convert.ToDecimal(txtISBN.Text.Trim()); } dgListado.DataSource = oLibro.ListarLibro(oLibroBO).Tables[0]; dsReporte = oLibro.ListarLibro(oLibroBO).Tables[0]; }
//-----insertar---- private void Insertar() { BO.Libro oLibroBO = new BO.Libro(); Services.Libro oLibroCTRL = new Services.Libro(); bool opc = false; if (txtAutor.Text.Trim().Length == 0) { opc = true; } if (txtISBN.Text.Trim().Length == 0) { opc = true; } if (txtEditorial.Text.Trim().Length == 0) { opc = true; } if (txtNombre.Text.Trim().Length == 0) { opc = true; } if (txtPrecio.Text.Trim().Length == 0) { opc = true; } if (opc == false) { oLibroBO.Isbn = txtISBN.Text.Trim(); oLibroBO.Autor = txtAutor.Text.Trim(); oLibroBO.Editorial = txtEditorial.Text.Trim(); oLibroBO.Precio = Convert.ToDecimal(txtPrecio.Text.Trim()); oLibroBO.Titulo = txtNombre.Text.Trim(); oLibroBO.Imagen = this.GuardarImagen(); int i = oLibroCTRL.creaLibro(oLibroBO); if (i > 0) { MessageBox.Show("EL Libro ha sido creado con exito "); this.Close(); } } else { MessageBox.Show("por fávor llénar todos los campos"); } }// ---- fin insertar
//---------------------Metodos------------------------ //-------cargarLibro----- private void Edit(BO.Libro obj) { Services.Libro oLibro = new Services.Libro(); DataTable dt = oLibro.ListarLibro(obj).Tables[0]; if (dt.Rows.Count != 0) { txtAutor.Text = dt.Rows[0]["Autor"].ToString(); txtEditorial.Text = dt.Rows[0]["Editorial"].ToString(); txtISBN.Text = dt.Rows[0]["ISBN"].ToString(); txtNombre.Text = dt.Rows[0]["Titulo"].ToString(); txtPrecio.Text = dt.Rows[0]["Precio"].ToString(); this.cargar(dt.Rows[0]["Imgen"].ToString()); } }
}// ---- fin insertar //----- Eliminar-------- private void Eliminar() { BO.Libro oLiroBO = new BO.Libro(); Services.Libro oLibroCtrl = new Services.Libro(); oLiroBO.Isbn = txtISBN.Text.Trim(); int i = oLibroCtrl.eliminaLibro(oLiroBO); if (i == 1) { MessageBox.Show("Los dátos se eliminaron correctamente"); } else { MessageBox.Show("Los datos no se eliminaron, intenta de nuevo"); } }