Example #1
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            VentasNegocio conexionV = new VentasNegocio();
            VENTAS        vta       = new VENTAS();

            foreach (CLIENTES cliente in listaC)
            {
                if (cliente.strNombre == cmbClientes.Text)
                {
                    vta.intIDCliente = cliente.intIDCliente;
                }
            }

            foreach (INGRESOS ing in listaI)
            {
                vta.decValor += ing.decValorIng;
            }


            try
            {
                conexionV.grabarVenta(vta);
                conexionV.grabarDetalleVta(listaI);
                conexionV.grabarPedido(dtpFechaEntrega.Value);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            MessageBox.Show("Venta generada correctamente");
        }
Example #2
0
        private void btnImprimir_Click(object sender, EventArgs e)
        {
            if (txtFacID.Text == "")
            {
                MessageBox.Show("INGRESE NUMERO DE FACTURA");
            }
            else
            {
                int newidventa = 0;

                VentasNegocio ventaacc = new VentasNegocio();
                newidventa = ventaacc.obtenerId();

                if (Convert.ToInt32(txtFacID.Text) > newidventa)
                {
                    MessageBox.Show("NUMERO DE FACTURA INVALIDO");
                }
                else
                {
                    int     fac  = Convert.ToInt32(txtFacID.Text);
                    Report1 form = new Report1(fac);
                    form.Show();
                }
            }
        }
Example #3
0
        private void btnReporte1_Click(object sender, EventArgs e)
        {
            txtId.Text           = "";
            txtApellido.Text     = "";
            dtpFechaFinal.Text   = "";
            dtpFechaInicial.Text = "";
            VentasNegocio v = new VentasNegocio();

            //DgvFacturacion.DataSource = v.listarVentas();
            //DgvFacturacion.Columns["Descripcion"].Visible = false;
            //DgvFacturacion.Columns["Cantidad"].Visible = false;
            //DgvFacturacion.Columns["Ventadet"].Visible = false;
            DgvFacturacion.DataSource = BD.Ejecutar("SELECT VE.IDVENTA AS FACTURA,VE.FECHA, CL.APELLIDO+' '+ CL.NOMBRE AS CLIENTE,US.APELLIDO+' '+ US.NOMBRE  AS VENDEDOR, SUM(AXV.PU*AXV.CANTIDAD) AS TOTAL_FACTURA FROM VENTAS AS VE INNER JOIN CLIENTES AS CL ON VE.IDCLIENTE = CL.IDCLIENTE INNER JOIN USUARIOS AS US ON VE.IDUSUARIO = US.IDUSUARIO INNER JOIN ARTICULOS_X_VENTA AS AXV ON VE.IDVENTA = AXV.IDVENTA INNER JOIN ARTICULOS AS AR ON AXV.IDARTICULO = AR.IDARTICULO GROUP BY VE.IDVENTA, CL.APELLIDO, US.APELLIDO,VE.FECHA,CL.NOMBRE, US.NOMBRE ORDER BY VE.IDVENTA DESC").Tables[0];
        }
Example #4
0
        private void txbBuscar_TextChanged(object sender, EventArgs e)
        {
            VentasNegocio        vent   = new VentasNegocio();
            List <ListadoVentas> listaV = new List <ListadoVentas>();

            listaV = (List <ListadoVentas>)vent.listar();

            if (txbBuscar.Text == "")
            {
                dgvListadoVentas.DataSource = listaV;
            }
            else
            {
                List <ListadoVentas> lista;
                lista = listaV.FindAll(venta => venta.strNombreC.Contains(txbBuscar.Text));
                dgvListadoVentas.DataSource = lista;
            }
        }
Example #5
0
        private void btnFacturar_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvNventas.RowCount > 0)
                {
                    // GENERO LA VENTA
                    VentasNegocio venta      = new VentasNegocio();
                    Ventas        nuevaventa = new Ventas();
                    Clientes      auxclie;

                    auxclie = (Clientes)cbxCliente.SelectedItem;

                    nuevaventa.IdUsuario = Login.Userlogin.idusuario;
                    nuevaventa.IdCliente = auxclie.IdCliente;
                    nuevaventa.Fecha     = dtpFechaFactura.Value;
                    venta.Generarventa(nuevaventa);


                    // DETALLE DE VENTA

                    VentaArticulos artxventa = new VentaArticulos();

                    foreach (VentaArticulos fila in listaDetalleVenta)
                    {
                        venta.GenerarArtxVenta(fila);
                        venta.ActualizarStock(fila);
                    }

                    MessageBox.Show("Venta Generada");
                    this.Close();
                }


                else
                {
                    MessageBox.Show("Seleccione un articulo y cantidad");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #6
0
        private void cargar()
        {
            VentasNegocio ventas = new VentasNegocio();

            try
            {
                dgvListadoVentas.DataSource = ventas.listar();
                dgvListadoVentas.AutoResizeColumns();
                dgvListadoVentas.Columns[0].HeaderText = "ID Venta";
                dgvListadoVentas.Columns[1].HeaderText = "Fecha Venta";
                dgvListadoVentas.Columns[2].HeaderText = "ID Cliente";
                dgvListadoVentas.Columns[3].HeaderText = "Nombre";
                dgvListadoVentas.Columns[4].HeaderText = "ID Pedido";
                dgvListadoVentas.Columns[5].HeaderText = "Fecha Entrega";
                dgvListadoVentas.Columns[6].HeaderText = "Valor";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #7
0
        private void Ventasss_Load(object sender, EventArgs e)
        {
            VentasNegocio v = new VentasNegocio();

            dgvNventas.DataSource = v.traerPorVenta(vent);
            lblAtiende.Text       = dgvNventas.CurrentRow.Cells["Vendedor"].Value.ToString();
            lblCliente.Text       = dgvNventas.CurrentRow.Cells["Cliente"].Value.ToString();
            dtpFechaFactura.Text  = dgvNventas.CurrentRow.Cells["Fecha"].Value.ToString();

            double total = 0;

            foreach (DataGridViewRow row in dgvNventas.Rows)
            {
                total += Convert.ToDouble(row.Cells["Total"].Value);
            }
            lblTotal.Text = Convert.ToString(total);

            dgvNventas.Columns["Fecha"].Visible    = false;
            dgvNventas.Columns["Cliente"].Visible  = false;
            dgvNventas.Columns["Vendedor"].Visible = false;
            dgvNventas.Columns["Ventadet"].Visible = false;
        }
Example #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    bandera = false;
                }

                carrito.listaItem = (List <ItemCarrito>)Session[Session.SessionID + "listaCarrito"];
                if (carrito.listaItem == null)
                {
                    carrito.listaItem = new List <ItemCarrito>();
                }

                var prodQuitar = Request.QueryString["idQuitar"];
                if (prodQuitar != null)
                {
                    ItemCarrito productoQuitar = carrito.listaItem.Find(J => J.Producto.ID == int.Parse(prodQuitar));

                    carrito.listaItem.Remove(productoQuitar);

                    Session[Session.SessionID + "listaCarrito"] = carrito.listaItem;
                    Response.Redirect("Carrito.aspx", false);
                }
                else if (Request.QueryString["idprod"] != null)
                {
                    //obtengo lista original (el listado completo)
                    List <Producto> listaOriginal = (List <Producto>)Session[Session.SessionID + "listaProducto"];

                    var      prodSeleccionado = Convert.ToInt32(Request.QueryString["idprod"]);
                    Producto producto         = listaOriginal.Find(J => J.ID == prodSeleccionado);

                    ItemCarrito auxCarrito = carrito.listaItem.Find(B => B.Producto.ID == producto.ID);

                    if (auxCarrito == null)
                    {
                        CarritoItem.Producto = producto;

                        CarritoItem.Cantidad++;

                        carrito.Total += CarritoItem.Producto.Precio;
                        carrito.listaItem.Add(CarritoItem);
                        Session[Session.SessionID + "listaCarrito"] = carrito.listaItem;
                    }
                    Response.Redirect("Carrito.aspx", false);
                }

                var CantRest = Request.QueryString["idCantRest"];
                if (CantRest != null)
                {
                    if (!bandera)
                    {
                    }

                    ItemCarrito productoRestar = carrito.listaItem.Find(J => J.Producto.ID == int.Parse(CantRest));

                    if (productoRestar.Cantidad != 0 && productoRestar.Cantidad != 1)
                    {
                        productoRestar.Cantidad--;
                    }
                    else
                    {
                    }

                    Session[Session.SessionID + "listaCarrito"] = carrito.listaItem;
                    Response.Redirect("Carrito.aspx", false);
                }

                var CantSum = Request.QueryString["idCantSum"];
                if (CantSum != null)
                {
                    ItemCarrito productoSumar = carrito.listaItem.Find(J => J.Producto.ID == int.Parse(CantSum));

                    if (productoSumar.Cantidad == productoSumar.Producto.Stock || productoSumar.Cantidad > productoSumar.Producto.Stock)
                    {
                    }
                    else
                    {
                        productoSumar.Cantidad++;
                    }

                    Session[Session.SessionID + "listaCarrito"] = carrito.listaItem;
                    Response.Redirect("Carrito.aspx", false);
                }

                var idCarrito = Request.QueryString["idComprar"];
                if (idCarrito != null)
                {
                    Usuario usuario = (Usuario)Session["usersession"];


                    if ((List <ItemCarrito>)Session[Session.SessionID + "listaCarrito"] == null)
                    {
                        Session["Error" + Session.SessionID] = "Error al realizar la compra.";
                        Response.Redirect("Error.aspx", false);
                    }
                    else if (usuario == null)
                    {
                        Response.Redirect("Login.aspx", false);
                    }
                    else
                    {
                        carrito.listaItem = (List <ItemCarrito>)Session[Session.SessionID + "listaCarrito"];

                        Producto_X_Venta productoXventa = new Producto_X_Venta();
                        List <Venta>     listaVenta     = new List <Venta>();
                        Producto         producto       = new Producto();


                        Venta    venta    = new Venta();
                        DateTime fechaHoy = DateTime.Now;


                        //decimal subtotal = 0;

                        //foreach (var item in listaItem)
                        //{
                        //    subtotal += item.PrecioItem();
                        //}
                        //Total = subtotal;

                        decimal total = carrito.SubTotal();
                        venta.usuario     = usuario;
                        venta.PrecioTotal = total;
                        venta.Fecha       = fechaHoy;
                        negocioVenta.Agregar(venta);

                        VentasNegocio negocioVentas = new VentasNegocio();
                        listaVenta = negocioVentas.Listar();

                        Int64 idVenta = 0;

                        foreach (var item in listaVenta)
                        {
                            if (item.usuario.ID_Usuario == usuario.ID_Usuario)
                            {
                                idVenta = item.ID;
                            }
                        }
                        venta.ID = idVenta;
                        foreach (var itemCarrito in carrito.listaItem)
                        {
                            productoXventa.venta    = venta;
                            productoXventa.producto = itemCarrito.Producto;
                            productoXventa.Cantidad = itemCarrito.Cantidad;
                            //productoXventa.Precio = itemCarrito.PrecioItem();
                            productoXventa.Precio = itemCarrito.Producto.Precio;

                            producto.ID    = itemCarrito.Producto.ID;
                            producto.Stock = itemCarrito.Producto.Stock - itemCarrito.Cantidad;

                            negocioProducto.ModificarStock(producto);
                            negocioVenta.AgregarItem(productoXventa);
                        }



                        Response.Redirect("CompraFinalizada.aspx", false);
                    }

                    //else
                    //{
                    //    Session["Error" + Session.SessionID] = "Error al realizar la compra.";
                    //    Response.Redirect("Error.aspx", false);
                    //}


                    //foreach (var item in listaCarrito)
                    //{
                    //    foreach (var item2 in item.listaItem)
                    //    {
                    //        item2.

                    //        negocioVenta.AgregarItem(item2);
                    //    }

                    //}
                }
            }
            catch (Exception ex)
            {
                Session["Error" + Session.SessionID] = "Error en el carrito.";
                //Session["Error" + Session.SessionID] = ex;
                Response.Redirect("Error.aspx");
            }
        }
Example #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Usuario usuario = (Usuario)Session["usersession"];
                if (usuario == null)
                {
                    Session["Error" + Session.SessionID] = "El usuario no tiene permisos para ingresar a la pagina.";
                    Response.Redirect("Error.aspx", false);
                }
                else if (usuario.TipoUsuario.ID != 1)
                {
                    Session["Error" + Session.SessionID] = "El usuario " + usuario.Nombre_Usuario + " no tiene permisos para ingresar a la pagina.";
                    Response.Redirect("Error.aspx", false);
                }



                CategoriaNegocio negocioCat = new CategoriaNegocio();
                listaCategoria = negocioCat.Listar();
                ProductoNegocio negocio = new ProductoNegocio();
                listaProducto = negocio.Listar();
                VentasNegocio negocioVentas = new VentasNegocio();
                listaVenta = negocioVentas.Listar();

                listaProductosEliminados = negocio.ListarEliminados();

                //Session[Session.SessionID + "listaProducto"] = listaProducto;

                var id = Request.QueryString["idQuitar"];
                //Int64 id = Int64.Parse(Request.QueryString["idQuitar"]);
                if (id != null)
                {
                    //negocio.Eliminar(Int64.Parse(id));
                    negocio.Eliminar(Convert.ToInt64(id));
                    listaProducto = negocio.Listar();
                    Response.Redirect("Admin.aspx", false);
                }

                var idCat = Request.QueryString["idQuitarCat"];
                if (idCat != null)
                {
                    negocioCat.Eliminar(Int32.Parse(idCat));
                    listaCategoria = negocioCat.Listar();
                    ////negocio.Eliminar(Int64.Parse(id));
                    //negocio.Eliminar(Convert.ToInt64(id));
                    //listaProducto = negocio.Listar();
                    Response.Redirect("Admin.aspx", false);
                }

                var idQuitarV = Request.QueryString["idQuitarVenta"];
                if (idQuitarV != null)
                {
                    negocioVentas.Eliminar(Int32.Parse(idQuitarV));
                    listaVenta = negocioVentas.Listar();
                    Response.Redirect("Admin.aspx", false);
                }
            }
            catch (Exception ex)
            {
                Session["Error" + Session.SessionID] = ex;
                Response.Redirect("Error.aspx");
            }
        }
Example #10
0
        private void btnCargar_Click(object sender, EventArgs e)
        {
            cbxCliente.Enabled = false;

            bool existe = false;

            VentaArticulos nuevo = new VentaArticulos();

            int newidventa = 0;

            VentasNegocio ventaacc = new VentasNegocio();

            newidventa = ventaacc.obtenerId();

            int stockp;

            nuevo.Articulos  = (Articulos)cbxArticulos.SelectedItem;
            nuevo.IdArticulo = nuevo.Articulos.IdArticulo;

            stockp = ventaacc.ConsultarStock(nuevo.Articulos.IdArticulo);

            if (dgvNventas.RowCount == 0)
            {
                if (Convert.ToInt32(txtCantidad.Text) <= stockp)
                {
                    nuevo.IdArticulo = nuevo.Articulos.IdArticulo;
                    nuevo.IdVenta    = newidventa;
                    nuevo.Cantidad   = Convert.ToInt32(txtCantidad.Text);
                    nuevo.Pu         = nuevo.Articulos.Pu;
                    nuevo.PuSubtotal = nuevo.Cantidad * nuevo.Pu;

                    listaDetalleVenta.Add(nuevo);

                    TotalVenta    = TotalVenta + nuevo.PuSubtotal;
                    lblTotal.Text = TotalVenta.ToString();

                    dgvNventas.DataSource = null;
                    dgvNventas.DataSource = listaDetalleVenta;
                    dgvNventas.Columns["IDVENTA"].Visible    = false;
                    dgvNventas.Columns["IDARTICULO"].Visible = false;
                }
                else
                {
                    MessageBox.Show("El stock del producto no permite cargar el producto");
                }
            }
            else
            {
                nuevo.Articulos = (Articulos)cbxArticulos.SelectedItem;

                foreach (VentaArticulos fila in listaDetalleVenta)

                {
                    if (fila.IdArticulo == nuevo.Articulos.IdArticulo)
                    {
                        stockp = ventaacc.ConsultarStock(nuevo.Articulos.IdArticulo);
                        Decimal montoanterior;
                        montoanterior = fila.PuSubtotal;

                        if (fila.Cantidad + Convert.ToInt32(txtCantidad.Text) <= stockp)
                        {
                            fila.Pu         = nuevo.Articulos.Pu;
                            fila.Cantidad   = fila.Cantidad + Convert.ToInt32(txtCantidad.Text);
                            fila.PuSubtotal = fila.Cantidad * fila.Pu;


                            TotalVenta    = (TotalVenta + fila.PuSubtotal) - montoanterior;
                            lblTotal.Text = TotalVenta.ToString();



                            dgvNventas.DataSource = null;
                            dgvNventas.DataSource = listaDetalleVenta;
                            dgvNventas.Columns["IDVENTA"].Visible    = false;
                            dgvNventas.Columns["IDARTICULO"].Visible = false;
                        }
                        else
                        {
                            MessageBox.Show("No Existe Sufuciente stock");
                        }

                        existe = true;
                    }
                }

                if (existe == false)
                {
                    if (Convert.ToInt32(txtCantidad.Text) <= stockp)
                    {
                        dgvNventas.DataSource = listaDetalleVenta;
                        nuevo.IdVenta         = newidventa;
                        nuevo.Articulos       = (Articulos)cbxArticulos.SelectedItem;
                        nuevo.Cantidad        = Convert.ToInt32(txtCantidad.Text);
                        nuevo.Pu         = nuevo.Articulos.Pu;
                        nuevo.PuSubtotal = nuevo.Cantidad * nuevo.Pu;
                        listaDetalleVenta.Add(nuevo);

                        TotalVenta    = TotalVenta + nuevo.PuSubtotal;
                        lblTotal.Text = TotalVenta.ToString();

                        dgvNventas.DataSource = null;
                        dgvNventas.DataSource = listaDetalleVenta;
                        dgvNventas.Columns["IDVENTA"].Visible    = false;
                        dgvNventas.Columns["IDARTICULO"].Visible = false;
                    }
                    else
                    {
                        MessageBox.Show("El stock del producto no permite cargar el producto");
                    }
                }
            }
        }