public List <Carrito> obtenerTodos(String idCliente) { ///CREAR CONEXION, MODIFICARLA, USARLA List <Carrito> elcarrito = new List <Carrito>(); MySqlConnection cn = new MySqlConnection(); daoprod = new daoProducto(); try { cn.ConnectionString = conexion; cn.Open(); ///EJECUTAR COMANDO string strSQL = "SELECT * FROM CARRITO WHERE ID_CLIENTE=@ID_CLIENTE"; MySqlCommand comando = new MySqlCommand(strSQL, cn); comando.Parameters.AddWithValue("ID_CLIENTE", idCliente); MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { Carrito car = new Carrito ( dr.GetString("ID_CLIENTE"), dr.GetInt32("ID_PRODUCTO"), daoprod.obtenerUno(dr.GetInt32("ID_PRODUCTO")).nombre, dr.GetInt32("CANTIDAD"), dr.GetDouble("SUBTOTAL") ); elcarrito.Add(car); } comando.Dispose(); return(elcarrito); } catch (Exception e) { throw e; } finally { ///CERRAR CONEXION cn.Close(); cn.Dispose(); } }
public List <pedidoAdmin> obtenerTodosAdmin(String estado) { ///CREAR CONEXION, MODIFICARLA, USARLA List <pedidoAdmin> pendientes = new List <pedidoAdmin>(); MySqlConnection cn = new MySqlConnection(); daoprod = new daoProducto(); try { cn.ConnectionString = conexion; cn.Open(); ///EJECUTAR COMANDO string strSQL = "SELECT * FROM PEDIDOS_PENDIENTES WHERE ESTADO=@ESTADO"; MySqlCommand comando = new MySqlCommand(strSQL, cn); comando.Parameters.AddWithValue("ESTADO", estado); MySqlDataReader dr = comando.ExecuteReader(); while (dr.Read()) { pedidoAdmin ped = new pedidoAdmin(); ped.ID = dr.GetString("ID"); ped.ID_CLIENTE = dr.GetString("ID_CLIENTE"); ped.DIRECCION = dr.GetString("DIRECCION"); ped.PEDIDO = dr.GetString("PEDIDO"); ped.TOTAL = dr.GetDouble("TOTAL"); ped.ESTADO = dr.GetString("ESTADO"); pendientes.Add(ped); } comando.Dispose(); return(pendientes); } catch (Exception e) { throw e; } finally { ///CERRAR CONEXION cn.Close(); cn.Dispose(); } }
public Carrito obtenerUno(int idProducto) { ///CREAR CONEXION, MODIFICARLA, USARLA MySqlConnection cn = new MySqlConnection(); try { daoprod = new daoProducto(); Carrito carrito = null; cn.ConnectionString = conexion; cn.Open(); ///EJECUTAR COMANDO string strSQL = "SELECT * FROM CARRITO WHERE ID_PRODUCTO = @ID"; MySqlCommand comando = new MySqlCommand(strSQL, cn); comando.Parameters.AddWithValue("ID", idProducto); MySqlDataReader dr = comando.ExecuteReader(); if (dr.Read()) { carrito = new Carrito(); carrito.idCliente = dr.GetString("ID_CLIENTE"); carrito.idProducto = dr.GetInt32("ID_PRODUCTO"); carrito.nombreProducto = daoprod.obtenerUno(dr.GetInt32("ID_PRODUCTO")).nombre; carrito.cantidad = dr.GetInt32("CANTIDAD"); carrito.subtotal = (daoprod.obtenerUno(dr.GetInt32("ID_PRODUCTO")).precio) * dr.GetInt32("CANTIDAD"); } comando.Dispose(); return(carrito); } catch (Exception e) { throw e; } finally { ///CERRAR CONEXION cn.Close(); cn.Dispose(); } }