예제 #1
0
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            venta aux     = new venta();
            venta nueva   = new venta();
            int   bandera = 0;

            carro = (Carrito)Session[Session.SessionID + "articulo"];
            foreach (var item in carro.producto)
            {
                nueva.fechaventa = DateTime.Now.Date;
                nueva.producto   = item;
                nueva.Total      = Convert.ToDecimal(Session[Session.SessionID + "Total"]);
                if (bandera == 0)
                {
                    negocio1.AgregarVenta(nueva);
                    bandera++;
                }
                lista    = negocio1.listarTipo();
                aux      = lista[lista.Count - 1];
                nueva.Id = aux.Id;
                negocio1.AgregarVentaxProducto(nueva);
            }
            Usuario usua = new Usuario();

            usua = (Usuario)Session[Session.SessionID + "Usuario"];
            negocio1.AgregarVentaxUsuario(nueva, usua.Id);
            Response.Redirect("Listado.aspx");
        }
예제 #2
0
        protected void btnSeguir_Click(object sender, EventArgs e)
        {
            Venta        venta      = new Venta();
            VentaNegocio negocio    = new VentaNegocio();
            List <Venta> listaVenta = new List <Venta>();
            Venta        aux        = new Venta();
            int          contador   = 0;

            cliente = (Usuario)Session[Session.SessionID + "Usuario"];
            if (Session[Session.SessionID + "Usuario"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            if (cliente.direccion.Calle == "Sin datos")
            {
                Response.Redirect("AgregarDireccion.aspx");
            }
            else
            {
                venta.cliente = (Usuario)Session[Session.SessionID + "Usuario"];
                venta.carro   = (Carro)Session[Session.SessionID + "elemento"];
                venta.fecha   = DateTime.Now.Date;

                foreach (var item in venta.carro.Item)
                {
                    Articulo        producto        = new Articulo();
                    ArticuloNegocio negocioArticulo = new ArticuloNegocio();
                    producto = negocioArticulo.ListarArticulos().Find(k => k.Id == item.Id);
                    if (item.CantidadUnidades <= producto.Stock)
                    {
                        producto.Stock = producto.Stock - item.CantidadUnidades;
                        negocioArticulo.ModificarStockProducto(producto);
                        venta.producto = item;
                        if (contador == 0)
                        {
                            negocio.AgregarVenta(venta);
                            listaVenta = negocio.ListarVentas();

                            contador++;
                        }
                        aux      = listaVenta[listaVenta.Count - 1];
                        venta.Id = aux.Id;

                        negocio.AgregarProductos_Por_Ventas(venta);
                    }
                    else
                    {
                        Response.Redirect("Default.aspx");
                        break;
                    }
                }


                Response.Redirect("ClienteCompra.aspx");
            }
        }
예제 #3
0
        protected void btnRealizarCompra_Click(object sender, EventArgs e)
        {
            Usuario usuario = (Usuario)Session["userSession"];

            if ((List <ItemCarrito>)Session["carrito"] == null)
            {
                Session["error"] = "Error al intentar realizar la compra";
                Response.Redirect("Error.aspx");
            }
            else if (usuario == null)
            {
                Response.Redirect("IngresoUser.aspx", false);
            }
            else
            {
                carrito.listaItem = (List <ItemCarrito>)Session["carrito"];
                List <Venta> listaVentas  = new List <Venta>();
                Detalle      detalle      = new Detalle();
                Venta        venta        = new Venta();
                Produ        producto     = new Produ();
                VentaNegocio ventaNegocio = new VentaNegocio();
                venta.usuario      = new Usuario();
                detalle.idProducto = new Produ();
                detalle.idVenta    = new Venta();

                decimal totalCompra = carrito.SubTotal();
                venta.usuario.idUser = usuario.idUser;
                DateTime fechaCompra = DateTime.Now;
                venta.fecha     = fechaCompra;
                venta.formaPago = "1";
                ventaNegocio.AgregarVenta(venta);

                listaVentas = ventaNegocio.Listar();
                int idVenta = 0;

                foreach (var item in listaVentas)
                {
                    if (item.usuario.idUser == usuario.idUser)
                    {
                        idVenta = item.id;
                    }
                }
                venta.id = idVenta;

                foreach (var item in carrito.listaItem)
                {
                    detalle.precioUnitario     = item.producto.precio;
                    detalle.cantidad           = item.cantidad;
                    detalle.idProducto.idProdu = item.producto.idProdu;
                    detalle.idVenta.id         = idVenta;

                    ventaNegocio.AgregarDetalleVenta(detalle);
                }
                Response.Redirect("FinCompra.aspx");
            }
        }