90 lines
2.8 KiB
C#
90 lines
2.8 KiB
C#
using Controladora;
|
|
using Entidades;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace Vista
|
|
{
|
|
public partial class FrmFacturas : Form
|
|
{
|
|
|
|
public FrmFacturas()
|
|
{
|
|
InitializeComponent();
|
|
ActualizarGrilla();
|
|
dataGridView1.CellClick += dataGridView1_CellClick;
|
|
ConfigurarDataGridView2();
|
|
}
|
|
private void ActualizarGrilla()
|
|
{
|
|
dataGridView1.DataSource = null;
|
|
dataGridView1.DataSource = ControladoraFacturas.Instance.Listar();
|
|
}
|
|
private void BtnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var form = new FrmFactura();
|
|
form.ShowDialog();
|
|
ActualizarGrilla();
|
|
}
|
|
|
|
private void dataGridView1_CellBorderStyleChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
|
|
}
|
|
private void ConfigurarDataGridView2()
|
|
{
|
|
dataGridView2.AutoGenerateColumns = false;
|
|
dataGridView2.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "Producto",
|
|
HeaderText = "Producto"
|
|
});
|
|
dataGridView2.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "Cantidad",
|
|
HeaderText = "Cantidad"
|
|
});
|
|
|
|
dataGridView2.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "PrecioUnitario",
|
|
HeaderText = "PrecioUnitariod"
|
|
});
|
|
dataGridView2.Columns.Add(new DataGridViewTextBoxColumn
|
|
{
|
|
DataPropertyName = "Subtotal",
|
|
HeaderText = "Subtotal"
|
|
});
|
|
}
|
|
private void ActualizarGrillaLotes(ReadOnlyCollection<Lote> lotes)
|
|
{
|
|
dataGridView2.DataSource = null;
|
|
if (lotes.Any())
|
|
{
|
|
var loteDatos = lotes.Select(lote => new
|
|
{
|
|
Producto = lote.NombreProducto,
|
|
Cantidad = lote.CantidadDeProductos,
|
|
Subtotal = lote.Subtotal,
|
|
PrecioUnitario = lote.PrecioUnitario,
|
|
}).ToList();
|
|
|
|
dataGridView2.DataSource = loteDatos;
|
|
}
|
|
}
|
|
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex >= 0)
|
|
{
|
|
var selectedFactura = (Factura)dataGridView1.Rows[e.RowIndex].DataBoundItem;
|
|
var lotes = ControladoraLotes.Instance.ListarPorFacturaId(selectedFactura.Id);
|
|
ActualizarGrillaLotes(lotes);
|
|
}
|
|
}
|
|
}
|
|
}
|