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]; }
public int modificaLibro(object obj) { BO.Libro data = (BO.Libro)obj; cmd = new SQLiteCommand(); ds = new DataSet(); da = new SQLiteDataAdapter(); conn = new Conexion(); cmd.Connection = conn.Establecer(); conn.Abrir(); sql = "UPDATE Libro SET Titulo ='" + data.Titulo.Trim() + "',Autor = '" + data.Autor.Trim() + "',Editorial = '" + data.Editorial.Trim() + "',Precio = '" + data.Precio + "',Imagen = '" + data.Imagen + "' WHERE ISBN='" + data.Isbn + "'"; cmd.CommandText = sql; int i = cmd.ExecuteNonQuery(); if (i <= 0) { return(0); } return(1); }
//-----Crear------ public int creaLibro(object obj) { BO.Libro data = new BO.Libro(); data = (BO.Libro)obj; cmd = new SQLiteCommand(); ds = new DataSet(); da = new SQLiteDataAdapter(); conn = new Conexion(); cmd.Connection = conn.Establecer(); conn.Abrir(); sql = "INSERT INTO Libro " + "VALUES('" + data.Isbn + "','" + data.Titulo + "','" + data.Autor.Trim() + "','" + data.Editorial + "','" + data.Precio.ToString() + "','" + data.Imagen + "')"; cmd.CommandText = sql; int i = cmd.ExecuteNonQuery(); if (i <= 0) { return(0); } return(1); }
//---Sobrecarga constructor--- public Editar(BO.Libro dt) { InitializeComponent(); this.Edit(dt); btnGuardar.Visible = false; btnModificar.Location = new Point(260, 87); btnEliminar.Location = new Point(260, 134); }
private void repositoryItemButtonEdit1_Click(object sender, EventArgs e) { BO.Libro olibroBO = new BO.Libro(); string id = gridView1.GetFocusedRowCellValue("ISBN").ToString(); olibroBO.Isbn = id; Editar frmEditar = new Editar(olibroBO); frmEditar.ShowDialog(); this.Ruta = frmEditar.Ruta; // dgListado.DataSource = this.Listar(); }
//-----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"); } }
public int eliminaLibro(object obj) { BO.Libro data = (BO.Libro)obj; cmd = new SQLiteCommand(); ds = new DataSet(); da = new SQLiteDataAdapter(); conn = new Conexion(); cmd.Connection = conn.Establecer(); conn.Abrir(); sql = "DELETE FROM Libro WHERE ISBN = '" + data.Isbn.ToString() + "'"; cmd.CommandText = sql; int i = cmd.ExecuteNonQuery(); if (i <= 0) { return(0); } return(1); }
//-----------Metodos---------------- //-----Listar------ public DataSet Listar(object obj) { BO.Libro LibroBO = (BO.Libro)obj; bool busqueda = false; string cadenaWhere = ""; ds = new DataSet(); conn = new Conexion(); cmd = new SQLiteCommand(); da = new SQLiteDataAdapter(); if (LibroBO.Isbn != null) { cadenaWhere += " ISBN = '" + LibroBO.Isbn + "' and"; busqueda = true; } if (LibroBO.Autor != null) { cadenaWhere += " Autor = '" + LibroBO.Autor + "' and"; busqueda = true; } if (LibroBO.Editorial != null) { cadenaWhere += " Editorial = '" + LibroBO.Editorial + "' and"; busqueda = true; } if (LibroBO.Precio > 0) { cadenaWhere += "Precio = '" + LibroBO.Precio + "' and"; busqueda = true; } if (LibroBO.Imagen != null) { cadenaWhere += "Imagen = '" + LibroBO.Imagen + "' and"; busqueda = true; } if (busqueda == true) { cadenaWhere = " WHERE " + cadenaWhere.Remove(cadenaWhere.Length - 3, 3); } try { sql = "SELECT * FROM Libro" + cadenaWhere; cmd.CommandText = sql; cmd.Connection = conn.Establecer(); conn.Abrir(); da.SelectCommand = cmd; da.Fill(ds); } catch (SQLiteException ex) { MessageBox.Show(ex.Message); } finally { conn.Cerrar(); } return(ds); }