85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using Controladora;
|
|
using Entidades;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Vista
|
|
{
|
|
public partial class FrmFacturas : Form
|
|
{
|
|
|
|
public FrmFacturas()
|
|
{
|
|
InitializeComponent();
|
|
ConfigurarDataGridViewDetalle();
|
|
ActualizarGrilla();
|
|
}
|
|
private void ActualizarGrilla()
|
|
{
|
|
dgvFacturas.DataSource = null;
|
|
dgvFacturas.DataSource = ControladoraFacturas.Instance.Listar();
|
|
}
|
|
private void BtnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var form = new FrmFactura();
|
|
form.ShowDialog();
|
|
ActualizarGrilla();
|
|
}
|
|
|
|
private void ConfigurarDataGridViewDetalle()
|
|
{
|
|
dgvDetalles.AutoGenerateColumns = false;
|
|
dgvDetalles.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "Producto",
|
|
HeaderText = "Producto",
|
|
Name = "Producto"
|
|
});
|
|
dgvDetalles.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "Cantidad",
|
|
HeaderText = "Cantidad",
|
|
Name = "Cantidad"
|
|
|
|
});
|
|
dgvDetalles.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "PrecioUnitario",
|
|
HeaderText = "PrecioUnitario",
|
|
Name = "PrecioUnitario"
|
|
});
|
|
dgvDetalles.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "Subtotal",
|
|
HeaderText = "Subtotal",
|
|
Name = "Subtotal"
|
|
});
|
|
}
|
|
private void ActualizarGrillaDetalles(ReadOnlyCollection<DetalleFactura> detalles)
|
|
{
|
|
dgvDetalles.DataSource = null;
|
|
if (detalles.Any())
|
|
{
|
|
var loteDatos = detalles.Select(detalle => new
|
|
{
|
|
Producto = detalle.Producto.Nombre,
|
|
Cantidad = detalle.Cantidad,
|
|
Subtotal = detalle.Subtotal,
|
|
PrecioUnitario = detalle.Producto.Precio,
|
|
}).ToList();
|
|
|
|
dgvDetalles.DataSource = loteDatos;
|
|
}
|
|
}
|
|
private void dgvFacturas_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex >= 0)
|
|
{
|
|
var selectedFactura = (Factura)dgvFacturas.Rows[e.RowIndex].DataBoundItem;
|
|
var detalles = ControladoraFacturas.Instance.ListarDetallesFactura(selectedFactura);
|
|
ActualizarGrillaDetalles(detalles);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|