private void button1_Click(object sender, EventArgs e) { libros nuevo = new libros(); buscado = textBox2.Text; Conexion bd = new Conexion(); List<string> lista = bd.consulta("SELECT * FROM libros WHERE titulo LIKE '%" + buscado + "%';"); for (int i = 0; i < lista.Count; i = i + 10) { string id = lista[i]; string nombre = lista[i + 1]; nuevo.agregar(id, nombre); LISTA.Add(nuevo); } this.buscar(); }
private void button1_Click(object sender, EventArgs e) { libros nuevo = new libros(); buscado = buscador.Text; Conexion bd = new Conexion(); List<string> lista = bd.consulta("SELECT * FROM libros WHERE titulo LIKE'%" + buscado + "%';"); for (int i = 0; i < lista.Count; i = i + 10) { string id = lista[i]; string nombre = lista[i + 1]; string categoria = lista[i + 2]; string cant_hojas = lista[i + 3]; string editorial = lista[i + 5]; string precio = lista[i + 6]; string año = lista[i + 7]; string indice = lista[i + 8]; string stock = lista[i + 9]; nuevo.agregar(id, nombre, categoria, cant_hojas, editorial, precio, año, indice, stock); LISTA.Add(nuevo); } this.buscar(); }
private void mostrarLibros() { Conexion bd = new Conexion(); List<string> lista = bd.consulta("SELECT * FROM libros"); libros libro = new libros(); List<string> columnas = new List<string> { "id", "Nombre", "Categoria", "Cant Hojas", "Editorial", "Precio", "Año", "Stock" }; foreach (String columna in columnas) { DataGridViewColumn nueva = new DataGridViewTextBoxColumn(); nueva.Name = columna; nueva.DataPropertyName = columna; nueva.HeaderText = columna; dataGridView1.Columns.Add(nueva); } for (int i = 0; i < lista.Count; i = i + 10) { string id = lista[i]; string nombre = lista[i + 1]; string categoria = lista[i + 2]; string cant_hojas = lista[i + 3]; string editorial = lista[i + 5]; string precio = lista[i + 6]; string año = lista[i + 7]; string indice = lista[i + 8]; string stock = lista[i + 9]; libro.agregar(id, nombre, categoria, cant_hojas, editorial, precio, año, indice, stock); dataGridView1.Rows.Add(libro.getId(), libro.getNombre(), libro.getCategoria(), libro.getCantHojas(), libro.getEditorial(), libro.getPrecio(), libro.getAño(), libro.getStock()); } // Resize the master DataGridView columns to fit the newly loaded data. dataGridView1.AutoResizeColumns(); dataGridView1.AutoSize = false; // Configure the details DataGridView so that its columns automatically // adjust their widths when the data changes. dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; }