protected void btnPedir_Click(object sender, EventArgs e) { Pedido p; Medicamento m = (Medicamento)Session["medicamento"]; Cliente c = (Cliente)Session["usuario"]; try { p = new Pedido(0, c, m, Convert.ToInt32(lblCantidad.Text), ""); LogicaPedido.Agregar(p); } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void btnPedir_Click(object sender, EventArgs e) { Pedido p; Medicamento m = (Medicamento)Session["medicamento"]; Cliente c = (Cliente)Session["usuario"]; if (m != null) { try { p = new Pedido(0, c, m, Convert.ToInt32(lblCantidad.Text), "GENERADO"); LogicaPedido.Agregar(p); } catch (Exception ex) { lblError.Text = ex.Message; } } else { lblError.Text = "Debe seleccionar un medicamento"; } }
// Realizar Venta protected void btVender_Click(object sender, EventArgs e) { try { List <Plato> lineaCarrito = (List <Plato>)Session["Carrito"]; List <Linea> lineaVenta = (List <Linea>)Session["LineaVenta"]; // Obtener cliente que queda guardado desde el login Cliente cliente = new Cliente(); cliente = (Cliente)Session["Usuario"]; // Creo venta double totalVenta = 0; bool estado = false; if (lineaVenta.Count < 1) { lbError.Text = "Debes agregar al menos un producto al carrito.."; } else { Pedido nuevaVenta = new Pedido(1, Convert.ToDateTime(DateTime.Now), Convert.ToDateTime("1990-01-01"), totalVenta, cliente, lineaVenta, estado); int resultado = LogicaPedido.Agregar(nuevaVenta, cliente); int resultado2 = 0; foreach (Linea lineaAgregar in lineaVenta) { // Total de ventas totalVenta = totalVenta + (lineaAgregar.Cantidad * lineaAgregar.UnPlato.Precio); resultado2 = LogicaLinea.Agregar(lineaAgregar, totalVenta, cliente); } if (resultado == 1 || resultado2 == 2) { lbError.Text = "Venta exitosa, total facturado: " + Convert.ToString(totalVenta); List <Linea> lineaVenta2 = new List <Linea>(); Session["LineaVenta"] = lineaVenta2; List <Plato> linea = new List <Plato>(); Session["Carrito"] = linea; listadoCarrito.DataSource = linea; listadoCarrito.DataBind(); List <Plato> listarPlatos = new List <Plato>(LogicaPlato.ListarPedido(Convert.ToInt32(ddlEspecializacion.SelectedValue), Convert.ToInt64(ddlCasas.SelectedValue))); Session["Platos"] = listarPlatos; if (listarPlatos.Count > 0) { listadoPlatos.DataSource = listarPlatos; listadoPlatos.DataBind(); } // Redirigir a un ticket a futuro si da el tiempo } } } catch (Exception ex) { lbError.Text = ex.Message; } }