예제 #1
0
        protected void AgregarDetalle(object sender, EventArgs e)
        {
            Button          btn             = (Button)sender;
            Detalle         nuevoDetalle    = new Detalle();
            ProductoNegocio negocioProducto = new ProductoNegocio();
            List <Producto> listaProductos;

            if (Session["listaProductos"] != null)
            {
                listaProductos = (List <Producto>)Session["listaProductos"];
            }
            else
            {
                listaProductos = negocioProducto.listar();
            }
            List <Detalle> listaDetalle = new List <Detalle>();

            foreach (GridViewRow dgvItem in this.dgvProductos.Rows)
            {
                CheckBox Sel = ((CheckBox)dgvProductos.Rows[dgvItem.RowIndex].FindControl("cbxSeleccion"));
                if (Sel.Checked == true)
                {
                    nuevoDetalle          = new Detalle();
                    nuevoDetalle.Producto = listaProductos[dgvItem.RowIndex];
                    nuevoDetalle.Precio   = listaProductos[dgvItem.RowIndex].Precio;
                    nuevoDetalle.Cantidad = int.Parse(txtCantidad.Text);
                    nuevoDetalle.SubTotal = listaProductos[dgvItem.RowIndex].Precio * float.Parse(txtCantidad.Text);

                    if (Session["listaDetalle"] != null)
                    {
                        listaDetalle = (List <Detalle>)Session["listaDetalle"];
                    }
                    listaDetalle.Add(nuevoDetalle);

                    Session["listaDetalle"] = listaDetalle;


                    dgvDetalleVenta.DataSource = listaDetalle;
                    dgvDetalleVenta.DataBind();
                }
            }
            ActualizarTotal();
        }
        public void AgregarDetalle(object sender, EventArgs e)
        {
            Detalle         nuevoDetalle    = new Detalle();
            ProductoNegocio negocioProducto = new ProductoNegocio();

            nuevoDetalle.Producto = negocioProducto.traerProducto(ddlProductos.SelectedItem.Value);
            nuevoDetalle.Cantidad = int.Parse(txtCantidad.Text);
            nuevoDetalle.Precio   = float.Parse(txtPrecio.Text.Replace(".", ","));
            nuevoDetalle.SubTotal = (float.Parse(txtPrecio.Text.Replace(".", ",")) * int.Parse(txtCantidad.Text));

            if (Session["listaDetalle"] != null)
            {
                detalleCompra = (List <Detalle>)Session["listaDetalle"];
            }
            detalleCompra.Add(nuevoDetalle);

            Session["listaDetalle"] = detalleCompra;

            dgvDetalleCompra.DataSource = detalleCompra;
            dgvDetalleCompra.DataBind();
            ActualizarTotal();
        }