Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string codVenta = Request.QueryString["ven"];
                N_PlataformaXProducto negPxP  = new N_PlataformaXProducto();
                N_Producto            negP    = new N_Producto();
                N_Plataforma          negPlat = new N_Plataforma();
                N_DetalleVenta        negDV   = new N_DetalleVenta();

                DataTable tabla  = negPxP.getImagenDetalleVenta(codVenta);
                DataTable nombre = negP.getNombreProductoDetalleVenta(codVenta);
                DataTable plat   = negPlat.getPlataformaDetalleVenta(codVenta);
                DataTable cp     = negDV.getCantPrecioDetalleVenta(codVenta);

                tabla.Columns.Add("Nombre", typeof(string));
                tabla.Columns.Add("Plataforma", typeof(string));
                tabla.Columns.Add("Cantidad", typeof(int));
                tabla.Columns.Add("PrecioTotal", typeof(int));

                for (int i = 0; i < tabla.Rows.Count; i++)
                {
                    tabla.Rows[i]["Nombre"]      = nombre.Rows[i]["Nombre_Producto_PR"];
                    tabla.Rows[i]["Plataforma"]  = plat.Rows[i]["Nombre_Plataforma_P"];
                    tabla.Rows[i]["Cantidad"]    = cp.Rows[i]["Cantidad_Producto_DV"];
                    tabla.Rows[i]["PrecioTotal"] = cp.Rows[i]["PrecioTotal"];
                }

                grdDetalle.DataSource = tabla;
                grdDetalle.DataBind();
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (this.Session["username"] != null)
                {
                    N_Usuario      negU  = new N_Usuario();
                    N_Venta        negV  = new N_Venta();
                    N_DetalleVenta negDV = new N_DetalleVenta();

                    string codUsuario = negU.getIDporUsername(this.Session["username"].ToString());

                    DataTable tabla  = negV.getTablaVentasPorUsuario(codUsuario);
                    DataTable tabla2 = negDV.getTablaDetalleVentasPrecioTotalPorCodUsuario(codUsuario);
                    tabla.Columns.Add("PrecioTotal", typeof(string));
                    for (int i = 0; i < tabla.Rows.Count; i++)
                    {
                        decimal precio = Convert.ToDecimal(tabla2.Rows[i]["PrecioTotal"].ToString());

                        tabla.Rows[i]["PrecioTotal"] = precio.ToString("N2");
                    }
                    grdVentas.DataSource = tabla;
                    grdVentas.DataBind();
                }
            }
        }
Ejemplo n.º 3
0
        protected void grdVentas_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdVentas.PageIndex = e.NewPageIndex;
            N_Usuario      negU  = new N_Usuario();
            N_Venta        negV  = new N_Venta();
            N_DetalleVenta negDV = new N_DetalleVenta();

            string codUsuario = negU.getIDporUsername(this.Session["username"].ToString());

            DataTable tabla  = negV.getTablaVentasPorUsuario(codUsuario);
            DataTable tabla2 = negDV.getTablaDetalleVentasPrecioTotalPorCodUsuario(codUsuario);

            tabla.Columns.Add("PrecioTotal", typeof(string));
            for (int i = 0; i < tabla.Rows.Count; i++)
            {
                decimal precio = Convert.ToDecimal(tabla2.Rows[i]["PrecioTotal"].ToString());

                tabla.Rows[i]["PrecioTotal"] = precio.ToString("N2");
            }
            grdVentas.DataSource = tabla;
            grdVentas.DataBind();
        }
Ejemplo n.º 4
0
        protected void btnComprar_Click(object sender, EventArgs e)
        {
            int          filasventa = 0;
            int          filasdet   = 0;
            Venta        venta      = new Venta();
            Usuario      usr        = new Usuario();
            TipoDePago   tp         = new TipoDePago();
            TipoUsuario  tu         = new TipoUsuario();
            N_Usuario    negu       = new N_Usuario();
            N_Venta      negv       = new N_Venta();
            N_Producto   negp       = new N_Producto();
            N_Plataforma negpl      = new N_Plataforma();

            string codUsuario  = negu.getIDporUsername(this.Session["username"].ToString().Trim());
            string tipoUsuario = this.Session["usertype"].ToString();
            string tipoPago    = ddlTipoPago.SelectedValue.ToString();

            tu.setCodigoTipoUsuario(tipoUsuario);
            usr.setCodigoUsuario(codUsuario);
            usr.setIdTipoUsuario(tu);
            venta.setIdCodigoUsuario(usr);
            venta.setFechaVenta(DateTime.Now);
            tp.setcodigoTipo(tipoPago);
            venta.setIdTipoPago(tp);
            filasventa = negv.GuardarVenta(venta);


            DataTable dt         = (DataTable)Session["carrito"];
            int       stockTotal = 0;

            ///COMPROBAR QUE TODOS LOS PRODUCTOS TENGAN STOCK
            for (int c = 0; c < dt.Rows.Count; c++)
            {
                N_PlataformaXProducto negPXP = new N_PlataformaXProducto();
                string codProd    = negp.getCodigoProductoConNombre(dt.Rows[c]["Nombre"].ToString());
                string stockProd  = negPXP.getStockProducto(codProd);
                int    stockFinal = Convert.ToInt32(stockProd) - Convert.ToInt32(dt.Rows[c]["Cantidad"].ToString());
                if (stockFinal >= 0)
                {
                    stockTotal++;
                }
            }

            if (stockTotal == dt.Rows.Count)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    N_DetalleVenta        negd    = new N_DetalleVenta();
                    N_PlataformaXProducto pxp     = new N_PlataformaXProducto();
                    DetalleVenta          detalle = new DetalleVenta();
                    Venta              v          = new Venta();
                    ENTIDAD.Producto   p          = new ENTIDAD.Producto();
                    ENTIDAD.Plataforma pl         = new Plataforma();
                    string             codProd    = negp.getCodigoProductoConNombre(dt.Rows[i]["Nombre"].ToString());
                    string             codPlat    = negpl.getCodigoPlataformaConNombre(dt.Rows[i]["Plataforma"].ToString());
                    int    cant        = Convert.ToInt32(dt.Rows[i]["Cantidad"].ToString());
                    float  preciototal = float.Parse(dt.Rows[i]["PrecioUnitario"].ToString());
                    string stockProd   = pxp.getStockProducto(codProd);
                    int    nuevostock  = Convert.ToInt32(stockProd) - Convert.ToInt32(dt.Rows[i]["Cantidad"].ToString());
                    int    codVenta    = negv.getCodVenta();

                    v.setCodigoVenta(codVenta);
                    detalle.setIdCodigoVenta(v);
                    p.setCodigoProducto(codProd);
                    detalle.setIdCodigoProducto(p);
                    pl.setCodigoPlataforma(codPlat);
                    detalle.setIdCodigoPlataforma(pl);
                    detalle.setCantidadVendida(cant);
                    detalle.setPrecioUnitario(preciototal / cant);

                    filasdet = negd.GuardarDetalleVenta(detalle);

                    pxp.modificarStockProducto(codProd, nuevostock.ToString());
                }

                if (filasventa > 0 && filasdet > 0)
                {
                    this.Session["carrito"] = null;
                    Response.Redirect("CarritoCheckout.aspx");
                }
                else
                {
                    this.Session["carrito"] = null;
                    Response.Redirect("CarritoError.aspx");
                }
            }
            else
            {
                this.Session["carrito"] = null;
                Response.Redirect("CarritoStock.aspx");
            }
        }