Bueno combinados los forms de nacho y mios
This commit is contained in:
@@ -58,5 +58,11 @@ namespace Controladora
|
|||||||
.ToList()
|
.ToList()
|
||||||
.AsReadOnly();
|
.AsReadOnly();
|
||||||
}
|
}
|
||||||
|
public ReadOnlyCollection<Cliente> ListarTodos()
|
||||||
|
{
|
||||||
|
return repositorioClientes.Listar()
|
||||||
|
.ToList()
|
||||||
|
.AsReadOnly();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Conventions;
|
|||||||
using Modelo;
|
using Modelo;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@@ -18,20 +19,20 @@ namespace Controladora
|
|||||||
|
|
||||||
private RepositorioFactura repositorioFactura = new(new Context());
|
private RepositorioFactura repositorioFactura = new(new Context());
|
||||||
|
|
||||||
public List<Factura>? MostrarFacturasEnRangoDeFechas(DateTime FechaInicio, DateTime FechaFinal)
|
public ReadOnlyCollection<Factura>? MostrarFacturasEnRangoDeFechas(DateTime FechaInicio, DateTime FechaFinal)
|
||||||
{
|
{
|
||||||
if (FechaFinal < FechaInicio) return null;
|
if (FechaFinal < FechaInicio) return null;
|
||||||
|
|
||||||
List<Factura> list = repositorioFactura.ObtenerFacturasEnRangoFechas(FechaInicio, FechaFinal);
|
ReadOnlyCollection<Factura> list = repositorioFactura.ObtenerFacturasEnRangoFechas(FechaInicio, FechaFinal);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Factura>? MostrarFacturasDeClienteEnRangoDeFechas(Cliente cli, DateTime fecInicio, DateTime fecFin)
|
public ReadOnlyCollection<Factura>? MostrarFacturasDeClienteEnRangoDeFechas(Cliente cli, DateTime fecInicio, DateTime fecFin)
|
||||||
{
|
{
|
||||||
if (fecFin < fecInicio) return null;
|
if (fecFin < fecInicio) return null;
|
||||||
if (cli.Cuit <= 0) return null;
|
if (cli.Cuit <= 0) return null;
|
||||||
|
|
||||||
List<Factura> list = repositorioFactura.ObtenerFacturasDeClienteEnRangoFechas(cli, fecInicio, fecFin);
|
ReadOnlyCollection<Factura> list = repositorioFactura.ObtenerFacturasDeClienteEnRangoFechas(cli, fecInicio, fecFin);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,22 +68,25 @@ namespace Modelo
|
|||||||
return factura;
|
return factura;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Factura> ObtenerFacturasDeClienteEnRangoFechas(Cliente cli, DateTime fecInicio, DateTime fecFin)
|
public ReadOnlyCollection<Factura> ObtenerFacturasDeClienteEnRangoFechas(Cliente cli, DateTime fecInicio, DateTime fecFin)
|
||||||
{
|
{
|
||||||
return context.Facturas
|
return context.Facturas
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Include(x => x.Detalles)
|
.Include(x => x.Detalles)
|
||||||
|
.ThenInclude(x => x.Producto)
|
||||||
.Include(x => x.Cliente)
|
.Include(x => x.Cliente)
|
||||||
.Where(x => x.Fecha > fecInicio && x.Fecha < fecFin && x.Cliente.Cuit == cli.Cuit)
|
.Where(x => x.Fecha > fecInicio && x.Fecha < fecFin && x.Cliente.Cuit == cli.Cuit)
|
||||||
.ToList();
|
.ToList().AsReadOnly();
|
||||||
}
|
}
|
||||||
public List<Factura> ObtenerFacturasEnRangoFechas(DateTime fecInicio, DateTime fecFinal)
|
public ReadOnlyCollection<Factura> ObtenerFacturasEnRangoFechas(DateTime fecInicio, DateTime fecFinal)
|
||||||
{
|
{
|
||||||
return context.Facturas
|
return context.Facturas
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Include(x => x.Detalles)
|
.Include(x => x.Detalles)
|
||||||
|
.ThenInclude(x=>x.Producto)
|
||||||
|
.Include(x => x.Cliente)
|
||||||
.Where(x => (x.Fecha > fecInicio && x.Fecha < fecFinal))
|
.Where(x => (x.Fecha > fecInicio && x.Fecha < fecFinal))
|
||||||
.ToList();
|
.ToList().AsReadOnly();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
btnBuscar.TabIndex = 0;
|
btnBuscar.TabIndex = 0;
|
||||||
btnBuscar.Text = "Hacer Busqueda";
|
btnBuscar.Text = "Hacer Busqueda";
|
||||||
btnBuscar.UseVisualStyleBackColor = true;
|
btnBuscar.UseVisualStyleBackColor = true;
|
||||||
|
btnBuscar.Click += btnBuscar_Click;
|
||||||
//
|
//
|
||||||
// dateInicio
|
// dateInicio
|
||||||
//
|
//
|
||||||
@@ -69,6 +70,8 @@
|
|||||||
//
|
//
|
||||||
dgvFactura.AllowUserToAddRows = false;
|
dgvFactura.AllowUserToAddRows = false;
|
||||||
dgvFactura.AllowUserToDeleteRows = false;
|
dgvFactura.AllowUserToDeleteRows = false;
|
||||||
|
dgvFactura.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
|
dgvFactura.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
|
||||||
dgvFactura.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dgvFactura.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dgvFactura.EditMode = DataGridViewEditMode.EditProgrammatically;
|
dgvFactura.EditMode = DataGridViewEditMode.EditProgrammatically;
|
||||||
dgvFactura.Location = new Point(271, 24);
|
dgvFactura.Location = new Point(271, 24);
|
||||||
@@ -78,11 +81,13 @@
|
|||||||
dgvFactura.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dgvFactura.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dgvFactura.Size = new Size(475, 469);
|
dgvFactura.Size = new Size(475, 469);
|
||||||
dgvFactura.TabIndex = 3;
|
dgvFactura.TabIndex = 3;
|
||||||
|
dgvFactura.CellClick += dgvFactura_CellClick;
|
||||||
//
|
//
|
||||||
// dgvDetalles
|
// dgvDetalles
|
||||||
//
|
//
|
||||||
dgvDetalles.AllowUserToAddRows = false;
|
dgvDetalles.AllowUserToAddRows = false;
|
||||||
dgvDetalles.AllowUserToDeleteRows = false;
|
dgvDetalles.AllowUserToDeleteRows = false;
|
||||||
|
dgvDetalles.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
|
||||||
dgvDetalles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dgvDetalles.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dgvDetalles.EditMode = DataGridViewEditMode.EditProgrammatically;
|
dgvDetalles.EditMode = DataGridViewEditMode.EditProgrammatically;
|
||||||
dgvDetalles.Location = new Point(763, 24);
|
dgvDetalles.Location = new Point(763, 24);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using Controladora;
|
||||||
|
using Entidades;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@@ -12,9 +15,69 @@ namespace Vista.Informes
|
|||||||
{
|
{
|
||||||
public partial class FrmInformeFacturaPorFecha : Form
|
public partial class FrmInformeFacturaPorFecha : Form
|
||||||
{
|
{
|
||||||
|
private ReadOnlyCollection<Factura>? facturas;
|
||||||
public FrmInformeFacturaPorFecha()
|
public FrmInformeFacturaPorFecha()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnBuscar_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dateInicio.Value >= dateFin.Value)
|
||||||
|
{
|
||||||
|
MessageBox.Show("La fecha de inicio no puede ser mayor que la fecha final.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
facturas = ControladoraInformes.Instance.MostrarFacturasEnRangoDeFechas(dateInicio.Value, dateFin.Value);
|
||||||
|
|
||||||
|
|
||||||
|
if (facturas == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("No se encontraron facturas en el rango de fechas.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
RefrescarTablaFacturas(facturas);
|
||||||
|
|
||||||
|
}
|
||||||
|
private void RefrescarTablaFacturas(ReadOnlyCollection<Factura> list)
|
||||||
|
{
|
||||||
|
dgvDetalles.DataSource = null;
|
||||||
|
dgvFactura.DataSource = null;
|
||||||
|
dgvFactura.DataSource = list;
|
||||||
|
foreach (DataGridViewColumn column in dgvFactura.Columns)
|
||||||
|
{
|
||||||
|
column.Visible = column.Name == "Id" || column.Name == "Total" || column.Name == "Fecha" || column.Name == "NombreCliente";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dgvFactura_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (dgvFactura.SelectedRows.Count <= 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Falta seleccionar una linea");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Factura? fac = (Factura)dgvFactura.SelectedRows[0].DataBoundItem;
|
||||||
|
|
||||||
|
fac = facturas.FirstOrDefault(x => x.Id == fac.Id);
|
||||||
|
if (fac == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("No se logro encontrar la factura");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefrescarTablaDetalles(fac.Detalles);
|
||||||
|
}
|
||||||
|
private void RefrescarTablaDetalles(List<DetalleFactura> list)
|
||||||
|
{
|
||||||
|
dgvDetalles.DataSource = null;
|
||||||
|
dgvDetalles.DataSource = list;
|
||||||
|
foreach (DataGridViewColumn column in dgvDetalles.Columns)
|
||||||
|
{
|
||||||
|
column.Visible = column.Name == "Subtotal" || column.Name == "NombreProducto" || column.Name == "Cantidad";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
//
|
//
|
||||||
btnEnviarEmail.Location = new Point(20, 470);
|
btnEnviarEmail.Location = new Point(20, 470);
|
||||||
btnEnviarEmail.Name = "btnEnviarEmail";
|
btnEnviarEmail.Name = "btnEnviarEmail";
|
||||||
btnEnviarEmail.Size = new Size(200, 26);
|
btnEnviarEmail.Size = new Size(239, 26);
|
||||||
btnEnviarEmail.TabIndex = 19;
|
btnEnviarEmail.TabIndex = 19;
|
||||||
btnEnviarEmail.Text = "Enviar Informe Por Email";
|
btnEnviarEmail.Text = "Enviar Informe Por Email";
|
||||||
btnEnviarEmail.UseVisualStyleBackColor = true;
|
btnEnviarEmail.UseVisualStyleBackColor = true;
|
||||||
@@ -108,6 +108,8 @@
|
|||||||
//
|
//
|
||||||
dgvFactura.AllowUserToAddRows = false;
|
dgvFactura.AllowUserToAddRows = false;
|
||||||
dgvFactura.AllowUserToDeleteRows = false;
|
dgvFactura.AllowUserToDeleteRows = false;
|
||||||
|
dgvFactura.AllowUserToResizeColumns = false;
|
||||||
|
dgvFactura.AllowUserToResizeRows = false;
|
||||||
dgvFactura.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dgvFactura.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dgvFactura.EditMode = DataGridViewEditMode.EditProgrammatically;
|
dgvFactura.EditMode = DataGridViewEditMode.EditProgrammatically;
|
||||||
dgvFactura.Location = new Point(265, 29);
|
dgvFactura.Location = new Point(265, 29);
|
||||||
@@ -117,29 +119,31 @@
|
|||||||
dgvFactura.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dgvFactura.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dgvFactura.Size = new Size(475, 469);
|
dgvFactura.Size = new Size(475, 469);
|
||||||
dgvFactura.TabIndex = 13;
|
dgvFactura.TabIndex = 13;
|
||||||
|
dgvFactura.CellClick += dgvFactura_CellClick;
|
||||||
//
|
//
|
||||||
// dateFin
|
// dateFin
|
||||||
//
|
//
|
||||||
dateFin.Location = new Point(20, 77);
|
dateFin.Location = new Point(20, 77);
|
||||||
dateFin.Name = "dateFin";
|
dateFin.Name = "dateFin";
|
||||||
dateFin.Size = new Size(200, 23);
|
dateFin.Size = new Size(239, 23);
|
||||||
dateFin.TabIndex = 12;
|
dateFin.TabIndex = 12;
|
||||||
//
|
//
|
||||||
// dateInicio
|
// dateInicio
|
||||||
//
|
//
|
||||||
dateInicio.Location = new Point(20, 29);
|
dateInicio.Location = new Point(20, 29);
|
||||||
dateInicio.Name = "dateInicio";
|
dateInicio.Name = "dateInicio";
|
||||||
dateInicio.Size = new Size(200, 23);
|
dateInicio.Size = new Size(239, 23);
|
||||||
dateInicio.TabIndex = 11;
|
dateInicio.TabIndex = 11;
|
||||||
//
|
//
|
||||||
// btnBusqueda
|
// btnBusqueda
|
||||||
//
|
//
|
||||||
btnBusqueda.Location = new Point(20, 438);
|
btnBusqueda.Location = new Point(20, 438);
|
||||||
btnBusqueda.Name = "btnBusqueda";
|
btnBusqueda.Name = "btnBusqueda";
|
||||||
btnBusqueda.Size = new Size(200, 26);
|
btnBusqueda.Size = new Size(239, 26);
|
||||||
btnBusqueda.TabIndex = 10;
|
btnBusqueda.TabIndex = 10;
|
||||||
btnBusqueda.Text = "Hacer Busqueda";
|
btnBusqueda.Text = "Hacer Busqueda";
|
||||||
btnBusqueda.UseVisualStyleBackColor = true;
|
btnBusqueda.UseVisualStyleBackColor = true;
|
||||||
|
btnBusqueda.Click += btnBusqueda_Click;
|
||||||
//
|
//
|
||||||
// dgvCliente
|
// dgvCliente
|
||||||
//
|
//
|
||||||
@@ -152,7 +156,7 @@
|
|||||||
dgvCliente.Name = "dgvCliente";
|
dgvCliente.Name = "dgvCliente";
|
||||||
dgvCliente.RowHeadersVisible = false;
|
dgvCliente.RowHeadersVisible = false;
|
||||||
dgvCliente.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
dgvCliente.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
dgvCliente.Size = new Size(200, 306);
|
dgvCliente.Size = new Size(239, 306);
|
||||||
dgvCliente.TabIndex = 20;
|
dgvCliente.TabIndex = 20;
|
||||||
//
|
//
|
||||||
// label5
|
// label5
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
using System;
|
using Controladora;
|
||||||
|
using Entidades;
|
||||||
|
using Modelo;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
@@ -12,9 +16,93 @@ namespace Vista.Informes
|
|||||||
{
|
{
|
||||||
public partial class FrmInformeFacturasPorCliente : Form
|
public partial class FrmInformeFacturasPorCliente : Form
|
||||||
{
|
{
|
||||||
|
private ReadOnlyCollection<Factura> facturas;
|
||||||
public FrmInformeFacturasPorCliente()
|
public FrmInformeFacturasPorCliente()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
IniciarTablaClientes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void IniciarTablaClientes()
|
||||||
|
{
|
||||||
|
dgvCliente.DataSource = ControladoraClientes.Instance.ListarTodos();
|
||||||
|
foreach (DataGridViewColumn column in dgvCliente.Columns)
|
||||||
|
{
|
||||||
|
column.Visible = column.Name == "Cuit" || column.Name == "NombreCompleto";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnBusqueda_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (Check())
|
||||||
|
{
|
||||||
|
Cliente cli = (Cliente)dgvCliente.SelectedRows[0].DataBoundItem;
|
||||||
|
var lista = ControladoraInformes.Instance.MostrarFacturasDeClienteEnRangoDeFechas(cli, dateInicio.Value, dateFin.Value);
|
||||||
|
|
||||||
|
if (lista == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Hubo un error obteniendo la lista de Facturas para el cliente");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefrescarTablaFacturas(lista);
|
||||||
|
facturas = lista;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool Check()
|
||||||
|
{
|
||||||
|
bool ret = true;
|
||||||
|
string msg = "";
|
||||||
|
if (dateInicio.Value >= dateFin.Value) msg += "La fecha final no puede ser igual o mayor que la de inicio\n";
|
||||||
|
if (dgvCliente.SelectedRows.Count <= 0) msg += "Tenes que seleccionar un cliente primero\n";
|
||||||
|
|
||||||
|
if (msg != "")
|
||||||
|
{
|
||||||
|
MessageBox.Show(msg);
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefrescarTablaFacturas(ReadOnlyCollection<Factura> list)
|
||||||
|
{
|
||||||
|
dgvDetalle.DataSource = null;
|
||||||
|
dgvFactura.DataSource = null;
|
||||||
|
dgvFactura.DataSource = list;
|
||||||
|
foreach (DataGridViewColumn column in dgvFactura.Columns)
|
||||||
|
{
|
||||||
|
column.Visible = column.Name == "Id" || column.Name == "Total" || column.Name == "Fecha" || column.Name == "NombreCliente";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dgvFactura_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (dgvFactura.SelectedRows.Count <= 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Falta seleccionar una linea");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Factura? fac = (Factura)dgvFactura.SelectedRows[0].DataBoundItem;
|
||||||
|
|
||||||
|
fac = facturas.FirstOrDefault(x => x.Id == fac.Id);
|
||||||
|
if (fac == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("No se logro encontrar la factura");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefrescarTablaDetalles(fac.Detalles);
|
||||||
|
}
|
||||||
|
private void RefrescarTablaDetalles(List<DetalleFactura> list)
|
||||||
|
{
|
||||||
|
dgvDetalle.DataSource = null;
|
||||||
|
dgvDetalle.DataSource = list;
|
||||||
|
foreach (DataGridViewColumn column in dgvDetalle.Columns)
|
||||||
|
{
|
||||||
|
column.Visible = column.Name == "Subtotal" || column.Name == "NombreProducto" || column.Name == "Cantidad";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Vista/daslug.db
BIN
Vista/daslug.db
Binary file not shown.
Reference in New Issue
Block a user