Esempio n. 1
0
        public void agregarVenta(int idCliente)
        {
            DataTable         dtdt            = new DataTable();
            Productos_BLL     productoBLL     = new Productos_BLL();
            Ventas_BLL        ventaBLL        = new Ventas_BLL();
            VentasDetalle_BLL ventaDetalleBLL = new VentasDetalle_BLL();
            Existencias_BLL   existenciasBLL  = new Existencias_BLL();

            DateTime fechaVenta       = DateTime.Now;
            string   codigoProducto   = ddlCodigo.SelectedValue;
            int      cantidadProducto = int.Parse(txtCantidad.Text);

            dtdt = productoBLL.cargarProductos();
            double aux        = double.Parse(dtdt.Rows[0]["precioUnitario"].ToString());
            double subtotal   = (aux) * (int.Parse(txtCantidad.Text));
            double IVA        = ((aux) * (int.Parse(txtCantidad.Text))) * 0.16;
            double totalVenta = subtotal + IVA;

            lblSubtotal.Text = Convert.ToString(subtotal);
            lblIVA.Text      = Convert.ToString(IVA);
            lblTotal.Text    = Convert.ToString(totalVenta);



            int idProducto = int.Parse(dtdt.Rows[0]["idProducto"].ToString());

            idProducto = ddlCodigo.SelectedIndex;

            ventaBLL.agregarVenta(idCliente, fechaVenta, totalVenta);
            dtdt = ventaBLL.cargarVenta(idCliente);

            int idVenta = int.Parse(dtdt.Rows[0]["idVenta"].ToString());

            ventaDetalleBLL.agregarVentaDetalle(idVenta, idProducto, cantidadProducto);

            ClientScript.RegisterStartupScript(this.Page.GetType(), "alerta", "alert('Venta agregada exitosamente')", true);

            existenciasBLL.restarExistencia(cantidadProducto, idProducto);

            //DataTable dt = new DataTable();
            //dt = (DataTable)ViewState["dtVentaCliente"];
            //dt.Rows.Add(fechaVenta, codigoProducto, cantidadProducto, totalVenta);
            //grdVentaCliente.DataSource = dt;
            //grdVentaCliente.DataBind();
        }
 protected void ddlProducto_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ddlProducto.SelectedIndex != 0)
     {
         Existencias_BLL existenciasBLL = new Existencias_BLL();
         grdProductos.DataSource = existenciasBLL.cargarExistenciasPorID(int.Parse(ddlProducto.SelectedValue));
         grdProductos.DataBind();
     }
     else
     {
         DataTable dt = new DataTable();
         dt.Columns.Add("codigoProducto");
         dt.Columns.Add("nombreProducto");
         dt.Columns.Add("cantidad");
         grdProductos.DataSource = dt;
         grdProductos.DataBind();
     }
 }