private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (cbProducto.SelectedIndex == -1)
            {
                MessageBox.Show("Debe seleccionar un producto");
                return;
            }

            if (string.IsNullOrWhiteSpace(txtCantidad.Text))
            {
                MessageBox.Show("Porfavor ingrese la cantidad");
                return;
            }

            ProductoFacturaEntidad productoFacturaEntidad = new ProductoFacturaEntidad();

            productoFacturaEntidad.Cantidad = Convert.ToInt32(txtCantidad.Text);
            productoFacturaEntidad.Valor    = Convert.ToDecimal(txtTotal.Text);
            productoFacturaEntidad.Producto = new ProductoEntidad
            {
                CodigoProducto = cbProducto.SelectedValue.ToString()
            };
            productoFacturaEntidad.Factura = new FacturaEntidad
            {
                NumeroFactura = this.numeroFactura.ToString()
            };

            DetalleFacturaReglaNegocio detalleFacturaReglaNegocio = new DetalleFacturaReglaNegocio();

            if (detalleFacturaReglaNegocio.CrearDetalleFactura(productoFacturaEntidad))
            {
                this.Close();
            }
        }
Ejemplo n.º 2
0
        private void CargarProductosFactura()
        {
            if (string.IsNullOrWhiteSpace(txtNumeroFactura.Text))
            {
                return;
            }

            int numeroFactura = Convert.ToInt32(txtNumeroFactura.Text);

            dgvListarProductos.AutoGenerateColumns = false;
            DetalleFacturaReglaNegocio    detalleFacturaReglaNegocio = new DetalleFacturaReglaNegocio();
            List <ProductoFacturaEntidad> listaProductosFactura      = detalleFacturaReglaNegocio.ObtenerProductosFactura(numeroFactura);

            dgvListarProductos.DataSource = listaProductosFactura;

            decimal valorTotal = (from p in listaProductosFactura
                                  select p.Valor).Sum();

            txtValorTotal.Text = valorTotal.ToString();
        }