diff --git a/Ventas/vender.cs b/Ventas/vender.cs index aadb28c..85d214a 100644 --- a/Ventas/vender.cs +++ b/Ventas/vender.cs @@ -22,10 +22,7 @@ namespace compabetov2 { - private bool masBtnPresionado = false; - private bool menosBtnPresionado = false; private List productos; - private List cartas = new List(); private decimal total = 0; private LoginModel loginPrincipal; @@ -173,10 +170,7 @@ namespace compabetov2 carta.Controls.Add(pic, 0, 0); carta.Controls.Add(HUD, 0, 1); - cartas.Add(carta); flowLayoutPanel3.Controls.Add(carta); - - } } @@ -677,8 +671,16 @@ namespace compabetov2 private void txtbusqueda_TextChanged(object sender, EventArgs e) { - - + if (!txtbusqueda.Text.Equals("")) + { + productos = service.conseguirProductosFiltrados(txtbusqueda.Text); + llenarLayout(); + } + else + { + getData(); + llenarLayout(); + } } private List listaProductosEnvio() diff --git a/bin/Debug/compabetov2.exe b/bin/Debug/compabetov2.exe index 644c22a..ae4804b 100644 Binary files a/bin/Debug/compabetov2.exe and b/bin/Debug/compabetov2.exe differ diff --git a/bin/Debug/compabetov2.pdb b/bin/Debug/compabetov2.pdb index 6edea12..4b5c2f8 100644 Binary files a/bin/Debug/compabetov2.pdb and b/bin/Debug/compabetov2.pdb differ diff --git a/database/DAO.cs b/database/DAO.cs index 1d578fa..b048ae8 100644 --- a/database/DAO.cs +++ b/database/DAO.cs @@ -1483,6 +1483,31 @@ namespace compabetov2.database } } + public static SQLiteDataReader conseguirProductosFiltradosDAO(string nombreProducto) + { + SQLiteDataReader reader = null; + var db_conexion = new Conexion(); + try + { + SQLiteConnection conexion = db_conexion.get_connection(); + + conexion.Open(); + + string sql = "SELECT * FROM Producto WHERE nombre LIKE @nombre"; + SQLiteCommand command = new SQLiteCommand(sql, conexion); + command.Parameters.AddWithValue("@nombre", $"%{nombreProducto}%"); + reader = command.ExecuteReader(); + + return reader; + + } + catch (SQLiteException ex) + { + MessageBox.Show(ex.Message); + return reader; + } + } + private static void crearDB() { var db_conexion = new Conexion(); diff --git a/database/service.cs b/database/service.cs index 5da2b38..5d924d3 100644 --- a/database/service.cs +++ b/database/service.cs @@ -439,5 +439,26 @@ namespace compabetov2.database return resumen; } + + public static List conseguirProductosFiltrados(string nombreProducto) { + List productos = new List(); + SQLiteDataReader reader = DAO.conseguirProductosFiltradosDAO(nombreProducto); + + while (reader.Read()) + { + Producto producto = new Producto( + int.Parse(reader["idproducto"].ToString()), + reader["nombre"].ToString(), + reader["descripcion"].ToString(), + decimal.Parse(reader["precio"].ToString()), + reader["img"].ToString(), + int.Parse(reader["stock"].ToString()) + ); + + productos.Add(producto); + } + + return productos; + } } } diff --git a/obj/Debug/compabetov2.exe b/obj/Debug/compabetov2.exe index 644c22a..ae4804b 100644 Binary files a/obj/Debug/compabetov2.exe and b/obj/Debug/compabetov2.exe differ diff --git a/obj/Debug/compabetov2.pdb b/obj/Debug/compabetov2.pdb index 6edea12..4b5c2f8 100644 Binary files a/obj/Debug/compabetov2.pdb and b/obj/Debug/compabetov2.pdb differ