/* * private List<Autor> listaautor; * private List<Editorial> listaeditorial; * private List<int> lista_id_editoriales; * private List<Idioma> listaidioma; * private List<TipoLibro> listatipolibro; */ public void MostrarFormulario(int id) { // Si voy a cargar un libro nuevo (id = 0). if (id == 0) { this.Libro = new Libro(); this.cbAutor.SelectedIndex = -1; this.cbEditorialNombre.SelectedIndex = -1; this.cbIdiomaNombre.SelectedIndex = -1; this.cbTipoLibroNombre.SelectedIndex = -1; this.cbAnio.SelectedIndex = -1; this.tbDescripcionCorta.Text = ""; this.tbDescripcionLarga.Text = ""; this.tbTitulo.Text = ""; this.btnBorrar.Enabled = false; this.btnPrestamo.Enabled = false; // Si voy a cargar un libro existente. } else { this.Libro = BDLibro.BuscarPorId(id); this.Cargarlibro(); this.btnBorrar.Enabled = true; } // Establezco el tipo de borde de la ventana para que no se pueda cambiar de tamaño. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.ShowDialog(); }
private void CargarComboTitulo() { List <Libro> lista; lista = BDLibro.BuscarLibrosEnPrestamo(false); for (int i = 0; i < lista.Count; i++) { this.cbTitulo.Items.Add(lista [i]); } }
private void ListaLibro_Load(object sender, EventArgs e) { DataTable tabla; tabla = BDLibro.CargarLista(); this.dgListaLibro.DataSource = tabla; // No se muestra el valor de la celda en el dg. /*for (int i = 0; this.dgListaLibro.RowCount > i; i++) { * this.dgListaLibro.Rows [i].Cells [0].Value = "perro"; * }*/ }
private void btnBuscar_Click(object sender, EventArgs e) { DataTable tabla; if (this.tbApellidoAutor.Text.IndexOf("'") >= 0) { MessageBox.Show("El campo contiene elementos inválidos"); return; } else if (this.tbNombreAutor.Text.IndexOf("'") >= 0) { MessageBox.Show("El campo contiene elementos inválidos"); return; } else if (this.tbEditorial.Text.IndexOf("'") >= 0) { MessageBox.Show("El campo contiene elementos inválidos"); return; } else if (this.tbIdioma.Text.IndexOf("'") >= 0) { MessageBox.Show("El campo contiene elementos inválidos"); return; } else if (this.tbTipoLibro.Text.IndexOf("'") >= 0) { MessageBox.Show("El campo contiene elementos inválidos"); return; } else if (this.tbTitulo.Text.IndexOf("'") >= 0) { MessageBox.Show("El campo contiene elementos inválidos"); return; } tabla = BDLibro.Buscar(this.tbTitulo.Text, this.tbApellidoAutor.Text, this.tbNombreAutor.Text, this.tbTipoLibro.Text, this.tbIdioma.Text, this.tbEditorial.Text); this.dgListaLibro.DataSource = tabla; }
public static Prestamo BuscarPorId(int id) { SqlCommand cmd; SqlDataReader rd; string select; Prestamo prestamo; select = "select * from PrestamoLibro where iPrestamoLibroId =" + id; prestamo = new Prestamo(); cmd = new SqlCommand(select, BD.Con); rd = cmd.ExecuteReader(); rd.Read(); prestamo.Id = Convert.ToInt32(rd [0]); prestamo.Socio = BDSocio.BuscarPorId(Convert.ToInt32(rd [1])); prestamo.Libro = BDLibro.BuscarPorId(Convert.ToInt32(rd [2])); prestamo.FechaSalida = Convert.ToDateTime(rd [3]); prestamo.FechaDevolucion = Convert.ToDateTime(rd [4]); prestamo.Activo = Convert.ToBoolean(rd [5]); rd.Close(); return(prestamo); }
private void btnBorrar_Click(object sender, EventArgs e) { BDLibro.Borrar(this.Libro.LibroId); this.Close(); }
private void btnGuardar_Click(object sender, EventArgs e) { // Validaciones. if (this.tbTitulo.Text == "") { MessageBox.Show("Fatlan completar campos"); return; } else if (this.tbTitulo.Text.IndexOf("'") >= 0 || this.tbTitulo.Text.IndexOf(";") >= 0) { MessageBox.Show("No se pueden ingresar ', ;"); return; } else if (this.tbDescripcionCorta.Text.IndexOf("'") >= 0 || this.tbDescripcionCorta.Text.IndexOf(";") >= 0) { MessageBox.Show("No se pueden ingresar ', ;"); return; } else if (this.tbDescripcionLarga.Text.IndexOf("'") >= 0 || this.tbDescripcionLarga.Text.IndexOf(";") >= 0) { MessageBox.Show("No se pueden ingresar ', ;"); return; } if (this.cbEditorialNombre.SelectedIndex < 0) { MessageBox.Show("Fatlan completar campos"); return; } else if (this.cbAutor.SelectedIndex < 0) { MessageBox.Show("Fatlan completar campos"); return; } else if (this.cbTipoLibroNombre.SelectedIndex < 0) { MessageBox.Show("Fatlan completar campos"); return; } else if (this.cbIdiomaNombre.SelectedIndex < 0) { MessageBox.Show("Fatlan completar campos"); return; } else if (this.cbAnio.SelectedIndex < 0) { MessageBox.Show("Fatlan completar campos"); return; } // Creo los punteros. Editorial editorial; Autor autor; Idioma idioma; TipoLibro tipo; // Asigno al puntero a un objeto ya creado. // Asigno al objeto un item del cb. indico el indice seleccionado en el cb para traer al item. // Indico entre parentesis qué tipo de objeto es el que me devuelve ya que le cb no lo sabe. editorial = (Editorial)this.cbEditorialNombre.Items [this.cbEditorialNombre.SelectedIndex]; autor = (Autor)this.cbAutor.Items [this.cbAutor.SelectedIndex]; idioma = (Idioma)this.cbIdiomaNombre.Items [this.cbIdiomaNombre.SelectedIndex]; tipo = (TipoLibro)this.cbTipoLibroNombre.Items [this.cbTipoLibroNombre.SelectedIndex]; // Asigno los valores al objeto Libro de la clase. Libro.Autor = autor; Libro.Editorial = editorial; Libro.Idioma = idioma; Libro.Tipo = tipo; Libro.DescripcionCorta = this.tbDescripcionCorta.Text; Libro.DescripcionLarga = this.tbDescripcionLarga.Text; Libro.AnioEdicion = Convert.ToInt32(this.cbAnio.SelectedItem); Libro.Titulo = this.tbTitulo.Text; Libro.Activo = true; BDLibro.Guardar(Libro); this.Close(); /* * Forma básica de encontrar el objeto que se seleccionó en el CB. No es recomendable porque es una búsqueda indirecta. * * int i; * Idioma idioma; * * i = this.cbIdiomaNombre.SelectedIndex; * * idioma = lista [i]; * */ }