public void GuardarFactura(Detalle_Factura detalle_) { using (var commando = _conection.CreateCommand()) { commando.CommandText = "Insert Into Detalle (Cantidad, Valor_Subtotal, CodigoProducto, NumeroFactura) " + "Values (@Cantidad, @Valor_Subtotal, @CodigoProducto, @NumeroFactura)"; commando.Parameters.AddWithValue("@Cantidad", detalle_.CantidadProductosFacturados); commando.Parameters.AddWithValue("@Valor_Subtotal", detalle_.ValorSubtotal); commando.Parameters.AddWithValue("@CodigoProducto", detalle_.Producto.CodigoProducto); commando.Parameters.AddWithValue("@NumeroFactura", detalle_.factura.NumeroFactura); commando.ExecuteNonQuery(); } }
private Detalle_Factura DataReaderMapToDetalle(SqlDataReader dataReader) { if (!dataReader.HasRows) { return(null); } Detalle_Factura detalle = new Detalle_Factura(); detalle.idDetalle = (int)dataReader["Id"]; detalle.CantidadProductosFacturados = (int)dataReader["Cantidad"]; detalle.ValorSubtotal = (decimal)dataReader["Valor_Subtotal"]; detalle.Producto.CodigoProducto = (string)dataReader["CodigoProducto"]; detalle.factura.NumeroFactura = (string)dataReader["NumeroFactura"]; return(detalle); }
public List <Detalle_Factura> ConsultarTodos() { List <Detalle_Factura> detalles = new List <Detalle_Factura>(); using (var command = _conection.CreateCommand()) { command.CommandText = "Select Id, Cantidad, Valor_Subtotal, CodigoProducto, NumeroFactura from Detalle "; var dataReader = command.ExecuteReader(); if (dataReader.HasRows) { while (dataReader.Read()) { Detalle_Factura detalle = DataReaderMapToDetalle(dataReader); detalles.Add(detalle); } } } return(detalles); }
private void btnComprar_Click(object sender, EventArgs e) { try { int idProducto = Convert.ToInt32(txtIdProducto.Text); var producto = prod.BuscarProductoId(idProducto); catidad = (int)nudCantidad.Value; if (producto != null) { if (catidad != 0) { if (producto.Cantidad_Stock > 0) { if (catidad <= producto.Cantidad_Stock) { precio = Convert.ToInt32(producto.PrecioDetalle); var factura = fact.ListarFacturas(); var factura2 = factura.Last(); Total = Total + (precio * catidad); var Detalle = new Detalle_Factura { Id_Factura = factura2.Id_Factura, Id_Producto = Convert.ToInt32(txtIdProducto.Text), Cantidad = (int)nudCantidad.Value, Precio = precio, }; fac.FacturarConjunto(Detalle); prod.comprarProducto(idProducto, catidad); listaDetalle = fac.ListarCompra(factura2.Id_Factura); dgvFactura.DataSource = listaDetalle.ToList(); dgvProductos.DataSource = null; dgvProductos.DataSource = prod.ListarProductosViewStock(); } else { MessageBox.Show("La cantidad solicitada no existe en nuestro stock. Tenemos disponibles " + catidad + " artículos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No existen en stock este producto", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("La cantidad a comprar no puede ser 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("El producto no existe", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } txtIdProducto.Clear(); nudCantidad.Value = 0; } catch (Exception ex) { MessageBox.Show("Ocurrió el siguiente error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void FacturarConjunto(Detalle_Factura factura) { db.Insert(factura); }