using System; using System.Collections.Generic; using System.Data.SQLite; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using compabetov2.database; using compabetov2.database.modelos; namespace compabetov2.database { internal class service { public static bool iniciarSesion(Usuario usuario) { return DAO.iniciarSesionDAO(usuario.nombreUsuario, usuario.contra); } public static List conseguirProductos() { List productos = new List(); SQLiteDataReader reader = DAO.conseguirProductosDAO(); while (reader.Read()) { Categoria categoria = new Categoria( (int)reader["idcategoria"], reader["nombre"].ToString(), reader["descripcion"].ToString()); Producto producto = new Producto( (int)reader["idproducto"], reader["nombre"].ToString(), reader["descripcion"].ToString(), (decimal)reader["precio"], reader["img"].ToString(), (int)reader["stock"], categoria); productos.Add(producto); } return productos; } public static bool insertarProducto(Producto producto) { return DAO.insertarProductoDAO(producto); } public static bool insertarCategoriaDAO(Categoria categoria) { return DAO.insertarCategoriaDAO(categoria); } public static bool insertarCliente(Cliente cliente) { return DAO.insertarClienteDAO(cliente); } public static bool eliminarCliente(Cliente cliente) { return DAO.eliminarClienteDAO(cliente); } public static List conseguirCliente() { List clientes = new List(); SQLiteDataReader reader = DAO.conseguirClientesDAO(); while (reader.Read()) { Cliente cliente = new Cliente( (int)reader["idCliente"], reader["nombres"].ToString(), reader["apellidos"].ToString(), reader["calle"].ToString(), reader["colonia"].ToString(), reader["cp"].ToString(), reader["no_ext"].ToString(), reader["no_int"].ToString(), reader["referencia"].ToString(), reader["telefono"].ToString(), reader["telefono_extra"].ToString() ); clientes.Add(cliente); } return clientes; } public static bool insertarEmpleado(Empleado empleado) { return DAO.insertarEmpleadoDAO(empleado); } public static List conseguirEmpleados() { List empleados = new List(); using (SQLiteDataReader reader = DAO.conseguirEmpleadosDAO()) { if(reader == null) { MessageBox.Show("null"); return empleados; } else { while (reader.Read()) { Empleado empleado = new Empleado( (int)reader["idempleado"], (string)reader["nombre"].ToString(), (string)reader["apellidos"].ToString(), (string)reader["calle"].ToString(), (string)reader["fecha_contratacion"].ToString(), (string)reader["estado"].ToString(), (string)reader["colonia"].ToString(), (string)reader["cp"].ToString(), (string)reader["no_ext"].ToString(), (string)reader["no_int"].ToString(), (string)reader["referencia"].ToString(), (string)reader["fecha_nac"].ToString(), (string)reader["telefono"].ToString() ); empleados.Add(empleado); } return empleados; } } } } }