605 lines
24 KiB
Plaintext
605 lines
24 KiB
Plaintext
@page "/Estadisticas"
|
|
|
|
@inject NavigationManager Navigation
|
|
@layout ConfiguracionLayout
|
|
@using Microsoft.AspNetCore.WebUtilities
|
|
|
|
@using BlazorBootstrap
|
|
@using System.Globalization
|
|
@using bdHerramientaCACOA.db
|
|
@rendermode InteractiveServer
|
|
@inject IJSRuntime JS
|
|
|
|
@using ClosedXML.Excel
|
|
@using Microsoft.EntityFrameworkCore
|
|
|
|
<Toasts class="p-3 font-weight-bold" Style="color:white;" AutoHide="true" Delay="4000" Messages="mensajes" Placement="ToastsPlacement.BottomCenter" />
|
|
|
|
|
|
<div class="row container-fluid mt-4" style="justify-content:space-between">
|
|
<div class="form-group mt-4 col-6">
|
|
<label>Fecha inicio:</label>
|
|
<InputDate TValue="DateTime?"
|
|
Value="fechaInicio"
|
|
ValueChanged="OnFechaInicioChanged"
|
|
ValueExpression="@(() => fechaInicio)" />
|
|
|
|
<label>Fecha final:</label>
|
|
<InputDate TValue="DateTime?"
|
|
Value="fechaFinal"
|
|
ValueChanged="OnFechaFinalChanged"
|
|
ValueExpression="@(() => fechaFinal)" />
|
|
|
|
</div>
|
|
|
|
<button @onclick="generarExcel" class="btnBlue col-1 " style="background-color: #65b7c3 !important;"> <i class="fas fa-print pe-2"></i>Generar Excel</button>
|
|
|
|
|
|
<div class="mt-2">
|
|
@if (!string.IsNullOrEmpty(mensajeError))
|
|
{
|
|
<label class="text-danger fw-semibold">
|
|
@mensajeError
|
|
</label>
|
|
}
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="container-fluid pt-3">
|
|
|
|
|
|
|
|
<Tabs>
|
|
<Tab Title="Estadisticas Herramienta CASA" Active>
|
|
<Content>
|
|
<div class="CajaTab p-2">
|
|
<HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaHerraCASATab ListadoHerraCASA="@listadoHerramientaEstadistica.Where(x=> x.idSimulacionNavigation.idTipoSimulacion == 31).ToList()"></HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaHerraCASATab>
|
|
</div>
|
|
</Content>
|
|
</Tab>
|
|
|
|
<Tab Title="Estadisticas Licitación CASA">
|
|
<Content>
|
|
<div class="CajaTab p-2">
|
|
<HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaLiciCASATab ListadoLiciCASA="@listadoHerramientaEstadistica.Where(x => x.idSimulacionNavigation.idTipoSimulacion == 32).ToList()"></HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaLiciCASATab>
|
|
</div>
|
|
</Content>
|
|
</Tab>
|
|
|
|
<Tab Title="Estadisticas Herramienta URBAN">
|
|
<Content>
|
|
<div class="CajaTab p-2">
|
|
<HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaHerraURBANTab ListadoHerraURBAN="@listadoHerramientaEstadisticaUrban.Where(x => x.idSimulacionNavigation.idTipoSimulacion == 34).ToList()"></HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaHerraURBANTab>
|
|
</div>
|
|
</Content>
|
|
</Tab>
|
|
|
|
<Tab Title="Estadisticas Licitación URBAN">
|
|
<Content>
|
|
<div class="CajaTab p-2">
|
|
<HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaLiciURBANTab ListadoLiciURBAN="@listadoHerramientaEstadisticaUrban.Where(x => x.idSimulacionNavigation.idTipoSimulacion == 35).ToList()"></HerramientaCASA.Components.Pages.ConfiguracionPages.EstadisticasTabs.EstadisticaLiciURBANTab>
|
|
</div>
|
|
</Content>
|
|
</Tab>
|
|
</Tabs>
|
|
</div>
|
|
|
|
|
|
@code {
|
|
|
|
public List<estadisticas> listadoHerramientaEstadistica { get; set; } = new List<estadisticas>();
|
|
public List<estadisticas> listadoHerramientaEstadisticaUrban { get; set; } = new List<estadisticas>();
|
|
public List<estadisticasusos> listadoHerramientaEstadisticaUsos { get; set; } = new List<estadisticasusos>();
|
|
public List<estadisticasfactores> listadoHerramientaEstadisticaFactores { get; set; } = new List<estadisticasfactores>();
|
|
|
|
public DateTime? fechaInicio { get; set; } = null;
|
|
public DateTime? fechaFinal { get; set; } = null;
|
|
|
|
public EstadistiaHerraCasaVM estadisticasTotales = new EstadistiaHerraCasaVM();
|
|
private int totalProyectosTipo = 0;
|
|
|
|
private string mensajeError = "";
|
|
List<ToastMessage> mensajes = new List<ToastMessage>();
|
|
|
|
public tsHerramientasCACOA bd;
|
|
|
|
|
|
private async Task OnFechaInicioChanged(DateTime? value)
|
|
{
|
|
fechaInicio = value;
|
|
|
|
if (UtilidadesCASA.comprobarFechasNulas(fechaInicio, fechaFinal))
|
|
{
|
|
if (UtilidadesCASA.comprobarFechas((DateTime)fechaInicio, (DateTime)fechaFinal))
|
|
{
|
|
inicializarListado();
|
|
mensajeError = "";
|
|
}
|
|
else
|
|
{
|
|
mensajeError = "La fecha final no puede ser menor que la fecha inicial.";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
inicializarListado();
|
|
mensajeError = "";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public bool IsVisible(bdHerramientaCACOA.db.estadisticas listado)
|
|
{
|
|
DateTime? ultimaFecha;
|
|
if (listado.idSimulacionNavigation.FechaModificacion != null)
|
|
{
|
|
ultimaFecha = listado.idSimulacionNavigation.FechaModificacion;
|
|
}
|
|
else
|
|
{
|
|
ultimaFecha = listado.idSimulacionNavigation.FechaCreacion;
|
|
}
|
|
|
|
if (fechaFinal != null && listado.idSimulacionNavigation.FechaCreacion.Date >= fechaInicio?.Date && ultimaFecha?.Date <= fechaFinal?.Date)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private async Task OnFechaFinalChanged(DateTime? value)
|
|
{
|
|
fechaFinal = value;
|
|
|
|
if (UtilidadesCASA.comprobarFechasNulas(fechaInicio, fechaFinal))
|
|
{
|
|
|
|
if (UtilidadesCASA.comprobarFechas((DateTime)fechaInicio, (DateTime)fechaFinal))
|
|
{
|
|
inicializarListado();
|
|
mensajeError = "";
|
|
}
|
|
else
|
|
{
|
|
mensajeError = "La fecha final no puede ser menor que la fecha inicial.";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
inicializarListado();
|
|
mensajeError = "";
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
bd = tsHerramientasCACOA.NuevoContexto(SoloLectura: false);
|
|
|
|
inicializarListado();
|
|
}
|
|
|
|
|
|
|
|
private async Task generarExcel()
|
|
{
|
|
try
|
|
{
|
|
bool fechaValida = false;
|
|
|
|
string nombreExcel = "";
|
|
|
|
|
|
if ((fechaInicio == null && fechaFinal == null) || (UtilidadesCASA.comprobarFechasNulas(fechaInicio, fechaFinal) && UtilidadesCASA.comprobarFechas((DateTime)fechaInicio, (DateTime)fechaFinal)))
|
|
{
|
|
fechaValida = true;
|
|
}
|
|
|
|
if (fechaValida)
|
|
{
|
|
|
|
if (UtilidadesCASA.comprobarFechasNulas(fechaInicio, fechaFinal))
|
|
{
|
|
nombreExcel = "Simulaciones_" + (fechaInicio ?? DateTime.Now).Date.ToString() + (fechaFinal ?? DateTime.Now).Date.ToString() + ".xlsx";
|
|
}
|
|
else
|
|
{
|
|
nombreExcel = "SimulacionesTotales_" + DateTime.Now.ToString() + ".xlsx";
|
|
}
|
|
var wb = new XLWorkbook();
|
|
wb.Properties.Author = "Tecnosis";
|
|
wb.Properties.Title = "Datos entre fechas";
|
|
wb.Properties.Subject = "";
|
|
|
|
var ws = wb.Worksheets.Add("Total datos");
|
|
|
|
// Generar tabla HERRAMIENTA/LICITACION CASA
|
|
var tablaPrincipal = generarTablaPrincipal(ws);
|
|
|
|
int filaSiguiente = tablaPrincipal.RangeAddress.LastAddress.RowNumber + 5;
|
|
|
|
// GENERAR TABLA USOS
|
|
int ultimaFilaUso = generarTablaUsos(bd, ws, filaSiguiente);
|
|
ultimaFilaUso = ultimaFilaUso + 5;
|
|
|
|
// GENERAR TABLA FACTORES
|
|
int ultimaFilaFactor = generarTablaFactores(bd, ws, ultimaFilaUso);
|
|
ultimaFilaFactor = ultimaFilaFactor + 5;
|
|
|
|
// GENERAR TABLA HERRAMIENTA/LICITACION URBAN
|
|
generarTablaUrban(bd, ws, ultimaFilaFactor);
|
|
|
|
using var ms = new MemoryStream();
|
|
wb.SaveAs(ms);
|
|
var bytes = ms.ToArray();
|
|
|
|
await JS.InvokeVoidAsync("descargarExcel", nombreExcel, Convert.ToBase64String(bytes));
|
|
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Primary,
|
|
Message = $"Descarga completada.",
|
|
});
|
|
}
|
|
else
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Warning,
|
|
Message = $"Fechas incorrectas.",
|
|
});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
mensajes.Add(new ToastMessage
|
|
{
|
|
Type = ToastType.Danger,
|
|
Message = $"Error al generar el excel.",
|
|
});
|
|
throw new Exception("Ocurrió un error en la descarga del excel -> " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private IXLTable? generarTablaPrincipal(IXLWorksheet? ws)
|
|
{
|
|
var datos = UtilidadesCASA.rellenarListadoCASA(listadoHerramientaEstadistica);
|
|
|
|
// INTRODUCIR DATOS PARA LA TABLA
|
|
var table = ws.Cell("B4").InsertTable(datos);
|
|
|
|
// OBTENER TAMAÑO DE LA TABLA
|
|
var firstCol = table.RangeAddress.FirstAddress.ColumnNumber;
|
|
var lastCol = table.RangeAddress.LastAddress.ColumnNumber;
|
|
var firstRow = table.RangeAddress.FirstAddress.RowNumber;
|
|
var lastRow = table.RangeAddress.LastAddress.RowNumber;
|
|
|
|
// AUMENTAMOS EL TAMAÑO DEL HEADER UN POCO
|
|
int filaHeader = table.HeadersRow().RowNumber();
|
|
ws.Row(filaHeader).Height += 20;
|
|
|
|
// OBTENER PRIMERA FILA DE LA TABLA PARA PONER EL TITULO ARRIBA
|
|
int filaTabla = table.FirstRow().RowNumber();
|
|
|
|
// PONER EL TITULO EN LA FILA DE ARRIBA
|
|
int filaTitulo = filaTabla - 1;
|
|
|
|
// SE ESCRIBE EL TITULO
|
|
ws.Cell(filaTitulo, 2).Value = "Herramienta CASA / Licitacion CASA";
|
|
|
|
// SE UNE LAS COLUMNAS
|
|
ws.Range(filaTitulo, 2, filaTitulo, table.ColumnCount()).Merge();
|
|
|
|
// SE LE PONE UN FORMATO
|
|
var rangoTitulo = ws.Range(filaTitulo, 2, filaTitulo, table.ColumnCount());
|
|
rangoTitulo.Merge();
|
|
rangoTitulo.Style.Font.Bold = true;
|
|
rangoTitulo.Style.Font.FontSize = 14;
|
|
rangoTitulo.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
ws.Row(filaTitulo).Height = 25;
|
|
|
|
|
|
// LE PONEMOS FORMATO AL HEADER
|
|
var headerRange = ws.Range(filaHeader, firstCol, filaHeader, lastCol);
|
|
headerRange.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
headerRange.Style.Font.Bold = true;
|
|
headerRange.Style.Font.FontColor = XLColor.White;
|
|
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#156082");
|
|
|
|
// CENTRAR LOS DATOS
|
|
var dataRange = ws.Range(firstRow, firstCol, lastRow, lastCol);
|
|
dataRange.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
|
|
// AJUSTAMOS LA TABLA
|
|
ws.Columns(firstCol, lastCol).AdjustToContents();
|
|
|
|
// SE PONE EL TITULO DE LOS HEADERS
|
|
table.Field(nameof(EstadistiaHerraCasaVM.idSimulacion)).Name = "Id Simulación";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.numeroTrabajadores)).Name = "Total trabajadores";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.costeAnualTotal)).Name = "Coste anual total";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.horasProduccion)).Name = "Horas de producción";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.costesDirectos)).Name = "Costes directos";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.costesIndirectos)).Name = "Coste indirectos";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.costesVariables)).Name = "Coste variables";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.costeDespacho)).Name = "Coste despacho";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.totalSuperficie)).Name = "Total superficie";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.porcentajeFases)).Name = "% fases";
|
|
|
|
table.Field(nameof(EstadistiaHerraCasaVM.horasDocumentacion)).Name = "Horas documentación";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.horasDireccionObra)).Name = "Horas dirección obra";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.horasTrabajo)).Name = "Horas trabajo";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.porcentajeExternalizacion)).Name = "% external.";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.plazoPresentacion)).Name = "Plazo presentación";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.costeProduccion)).Name = "Coste de producción";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.beneficio)).Name = "Beneficio";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.precioTrabajo)).Name = "Precio trabajo";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.totalOtrosTrabajos)).Name = "Total otros trabajos";
|
|
table.Field(nameof(EstadistiaHerraCasaVM.precioEncargo)).Name = "Precio encargo";
|
|
|
|
return table;
|
|
}
|
|
|
|
private int generarTablaUsos(tsHerramientasCACOA bd, IXLWorksheet ws, int filaValida)
|
|
{
|
|
var listaUsos = UtilidadesCASA.rellenarListadoUsos(bd, listadoHerramientaEstadisticaUsos);
|
|
|
|
// SE AGRUPA POR IDSIMULACION PARA SEPARAR LOS DATOS POR SIMULACION
|
|
var simulacion = listaUsos.GroupBy(x => x.idSimulacion);
|
|
|
|
int fila = filaValida;
|
|
|
|
ws.Cell(fila, 2).Value = "Id Simulación";
|
|
ws.Cell(fila, 3).Value = "Superficie";
|
|
ws.Cell(fila, 4).Value = "Uso";
|
|
ws.Cell(fila, 5).Value = "Tipología";
|
|
ws.Cell(fila, 6).Value = "Intervención";
|
|
|
|
|
|
// SE PONE EL FORMATO DEL HEADER
|
|
var headerRange = ws.Range(fila, 2, fila, 6);
|
|
|
|
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#156082");
|
|
headerRange.Style.Font.Bold = true;
|
|
headerRange.Style.Font.FontColor = XLColor.White;
|
|
|
|
headerRange.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
headerRange.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
|
|
ws.Row(fila).Height += 20;
|
|
|
|
|
|
|
|
// SE PONE EL TITULO ARRIBA DE LA TABLA
|
|
int filaTitulo = filaValida - 1;
|
|
|
|
ws.Cell(filaTitulo, 2).Value = "Usos";
|
|
var rangoTitulo = ws.Range(filaTitulo, 2, filaTitulo, 6);
|
|
rangoTitulo.Merge();
|
|
rangoTitulo.Style.Font.Bold = true;
|
|
rangoTitulo.Style.Font.FontSize = 14;
|
|
rangoTitulo.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
ws.Row(filaTitulo).Height = 25;
|
|
|
|
|
|
fila++;
|
|
|
|
// SE CREA LA TABLA RECORRIENDO EL LISTADO
|
|
foreach (var grupo in simulacion)
|
|
{
|
|
// SE PONE CADA COLUMNA
|
|
foreach (var item in grupo)
|
|
{
|
|
ws.Cell(fila, 2).Value = item.idSimulacion;
|
|
ws.Cell(fila, 3).Value = item.superficie;
|
|
ws.Cell(fila, 4).Value = item.uso;
|
|
ws.Cell(fila, 5).Value = item.tipologia;
|
|
ws.Cell(fila, 6).Value = item.intervencion;
|
|
|
|
// SE CENTRA LOS DATOS
|
|
ws.Range(fila, 2, fila, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
ws.Range(fila, 2, fila, 6).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
|
|
fila++;
|
|
}
|
|
|
|
// FILA DE TOTALES POR CADA SIMULACION
|
|
ws.Cell(fila, 2).Value = $"Total superficie de simulación: {grupo.Key}";
|
|
|
|
// SE SUMA EL TOTAL DE SUPERFICIE Y SE PONE UN FORMATO
|
|
ws.Cell(fila, 3).Value = grupo.Sum(x=> x.superficie);
|
|
ws.Range(fila, 2, fila, 6).Style.Font.Bold = true;
|
|
ws.Range(fila, 2, fila, 6).Style.Fill.BackgroundColor = XLColor.LightGray;
|
|
|
|
fila++;
|
|
}
|
|
|
|
// AJSUTAR COLUMNAS
|
|
ws.Columns().AdjustToContents();
|
|
|
|
return fila;
|
|
}
|
|
|
|
private int generarTablaFactores(tsHerramientasCACOA bd, IXLWorksheet ws, int filaValida)
|
|
{
|
|
var listaUsos = UtilidadesCASA.rellenarListadoFactores(bd, listadoHerramientaEstadisticaFactores);
|
|
|
|
// SE AGRUPA POR EL IDSIMULACION PARA DIVIDIR POR SIMULACION
|
|
var simulacion = listaUsos.GroupBy(x => x.idSimulacion);
|
|
|
|
int fila = filaValida;
|
|
|
|
ws.Cell(fila, 2).Value = "Id Simulación";
|
|
ws.Cell(fila, 3).Value = "Nombre";
|
|
ws.Cell(fila, 4).Value = "Coeficiente";
|
|
ws.Cell(fila, 5).Value = "Tipo";
|
|
|
|
|
|
// SE PONE UN FORMATO PARA EL HEADER
|
|
var headerRange = ws.Range(fila, 2, fila, 5);
|
|
|
|
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#156082");
|
|
headerRange.Style.Font.Bold = true;
|
|
headerRange.Style.Font.FontColor = XLColor.White;
|
|
|
|
headerRange.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
headerRange.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
|
|
ws.Row(fila).Height += 20;
|
|
|
|
|
|
// SE PONE EL TITULO
|
|
|
|
int filaTitulo = filaValida - 1;
|
|
|
|
ws.Cell(filaTitulo, 2).Value = "Factores";
|
|
var rangoTitulo = ws.Range(filaTitulo, 2, filaTitulo, 5);
|
|
rangoTitulo.Merge();
|
|
rangoTitulo.Style.Font.Bold = true;
|
|
rangoTitulo.Style.Font.FontSize = 14;
|
|
rangoTitulo.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
ws.Row(filaTitulo).Height = 25;
|
|
|
|
fila++;
|
|
|
|
// RECORREMOS EL LISTADO
|
|
foreach (var grupo in simulacion)
|
|
{
|
|
// SE AGREGA LAS COLUMNAS
|
|
foreach (var item in grupo)
|
|
{
|
|
ws.Cell(fila, 2).Value = item.idSimulacion;
|
|
ws.Cell(fila, 3).Value = item.nombre;
|
|
ws.Cell(fila, 4).Value = item.coeficiente;
|
|
ws.Cell(fila, 5).Value = item.tipo;
|
|
|
|
ws.Range(fila, 2, fila, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
ws.Range(fila, 2, fila, 5).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
|
|
fila++;
|
|
}
|
|
|
|
// FILA TOTAL PARA DIVIDIR
|
|
ws.Cell(fila, 2).Value = $"";
|
|
ws.Range(fila, 2, fila, 5).Style.Font.Bold = true;
|
|
ws.Range(fila, 2, fila, 5).Style.Fill.BackgroundColor = XLColor.LightGray;
|
|
|
|
fila++;
|
|
}
|
|
|
|
// AJUSTAMOS COLUMNAS
|
|
ws.Columns().AdjustToContents();
|
|
|
|
return fila;
|
|
}
|
|
|
|
private IXLTable? generarTablaUrban(tsHerramientasCACOA bd, IXLWorksheet? ws, int filaValida)
|
|
{
|
|
|
|
var datos = UtilidadesCASA.rellenarListadoURBAN(bd,listadoHerramientaEstadisticaUrban);
|
|
|
|
// AGREGAMOS LA TABLA
|
|
var table = ws.Cell(filaValida, 2).InsertTable(datos);
|
|
|
|
// SE OBTIENE LAS DIMENSIONES DE LA TABLA
|
|
var firstCol = table.RangeAddress.FirstAddress.ColumnNumber;
|
|
var lastCol = table.RangeAddress.LastAddress.ColumnNumber;
|
|
var firstRow = table.RangeAddress.FirstAddress.RowNumber;
|
|
var lastRow = table.RangeAddress.LastAddress.RowNumber;
|
|
|
|
// SE AGREGA MAS ALTURA AL HEADER
|
|
int filaHeader = table.HeadersRow().RowNumber();
|
|
ws.Row(filaHeader).Height += 20;
|
|
|
|
|
|
// OBTENEMOS LA PRIMERA FILA DE LA TABLA PARA PONER EL TITULO
|
|
int filaTabla = table.FirstRow().RowNumber();
|
|
|
|
int filaTitulo = filaTabla - 1;
|
|
|
|
// SE PONE EL TITULO Y SE CREA EL FORMATO
|
|
ws.Cell(filaTitulo, 2).Value = "Herramienta URBAN / Licitacion URBAN";
|
|
|
|
ws.Range(filaTitulo, 2, filaTitulo, table.ColumnCount()).Merge();
|
|
|
|
var rangoTitulo = ws.Range(filaTitulo, 2, filaTitulo, table.ColumnCount());
|
|
rangoTitulo.Merge();
|
|
rangoTitulo.Style.Font.Bold = true;
|
|
rangoTitulo.Style.Font.FontSize = 14;
|
|
rangoTitulo.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
ws.Row(filaTitulo).Height = 25;
|
|
|
|
|
|
// PONEMOS EL DISEÑO DEL HEADER
|
|
var headerRange = ws.Range(filaHeader, firstCol, filaHeader, lastCol);
|
|
headerRange.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
|
headerRange.Style.Font.Bold = true;
|
|
headerRange.Style.Font.FontColor = XLColor.White;
|
|
headerRange.Style.Fill.BackgroundColor = XLColor.FromHtml("#e97132");
|
|
|
|
// CENTRAMOS LOS DATOS
|
|
var dataRange = ws.Range(firstRow, firstCol, lastRow, lastCol);
|
|
dataRange.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
|
|
// AJUSTAMOS LAS COLUMNAS
|
|
ws.Columns(firstCol, lastCol).AdjustToContents();
|
|
|
|
// SE PONE EL NOMBRE AL HEADER
|
|
table.Field(nameof(EstadisticasUrbanVM.idSimulacion)).Name = "Id Simulación";
|
|
table.Field(nameof(EstadisticasUrbanVM.numeroTrabajadores)).Name = "Total trabajadores";
|
|
table.Field(nameof(EstadisticasUrbanVM.costeAnualTotal)).Name = "Coste anual total";
|
|
table.Field(nameof(EstadisticasUrbanVM.horasProduccion)).Name = "Horas de producción";
|
|
table.Field(nameof(EstadisticasUrbanVM.costesDirectos)).Name = "Costes directos";
|
|
table.Field(nameof(EstadisticasUrbanVM.costesIndirectos)).Name = "Coste indirectos";
|
|
table.Field(nameof(EstadisticasUrbanVM.costesVariables)).Name = "Coste variables";
|
|
table.Field(nameof(EstadisticasUrbanVM.costeDespacho)).Name = "Coste despacho";
|
|
table.Field(nameof(EstadisticasUrbanVM.tipoDocumento)).Name = "Tipo de documento";
|
|
table.Field(nameof(EstadisticasUrbanVM.documento)).Name = "Documento";
|
|
table.Field(nameof(EstadisticasUrbanVM.dato1)).Name = "Dato 1";
|
|
table.Field(nameof(EstadisticasUrbanVM.dato2)).Name = "Dato 2";
|
|
table.Field(nameof(EstadisticasUrbanVM.dato3)).Name = "Dato 3";
|
|
table.Field(nameof(EstadisticasUrbanVM.porcentajeFases)).Name = "Fases";
|
|
table.Field(nameof(EstadisticasUrbanVM.innovacion)).Name = "Innovación";
|
|
table.Field(nameof(EstadisticasUrbanVM.horasTrabajo)).Name = "Horas trabajo";
|
|
table.Field(nameof(EstadisticasUrbanVM.porcentajeExternalizacion)).Name = "% external.";
|
|
table.Field(nameof(EstadisticasUrbanVM.costeExternalizacion)).Name = "Coste externalización";
|
|
table.Field(nameof(EstadisticasUrbanVM.plazoPresentacion)).Name = "Plazo presentación";
|
|
table.Field(nameof(EstadisticasUrbanVM.costeProduccion)).Name = "Coste de producción";
|
|
table.Field(nameof(EstadisticasUrbanVM.beneficio)).Name = "Beneficio";
|
|
table.Field(nameof(EstadisticasUrbanVM.precioTrabajo)).Name = "Precio trabajo";
|
|
|
|
return table;
|
|
}
|
|
|
|
|
|
private void inicializarListado()
|
|
{
|
|
|
|
if (fechaInicio == null)
|
|
{
|
|
listadoHerramientaEstadistica = bd.estadisticas.Include(x => x.idSimulacionNavigation).Where(x => x.idSimulacionNavigation.idTipoSimulacion == 31 || x.idSimulacionNavigation.idTipoSimulacion == 32).ToList();
|
|
listadoHerramientaEstadisticaUrban = bd.estadisticas.Include(x => x.idSimulacionNavigation).Where(x => x.idSimulacionNavigation.idTipoSimulacion == 34 || x.idSimulacionNavigation.idTipoSimulacion == 35).ToList();
|
|
|
|
}
|
|
else
|
|
{
|
|
var listadoPorTipoCASA = bd.estadisticas.Include(x => x.idSimulacionNavigation).Where(x => x.idSimulacionNavigation.idTipoSimulacion == 31 || x.idSimulacionNavigation.idTipoSimulacion == 32).ToList();
|
|
|
|
listadoHerramientaEstadistica = listadoPorTipoCASA.Where(x => (x.idSimulacionNavigation.FechaCreacion >= fechaInicio) && (x.idSimulacionNavigation.FechaModificacion ?? x.idSimulacionNavigation.FechaCreacion).Date <= fechaFinal).ToList();
|
|
|
|
var listadoPorTipoURBAN = bd.estadisticas.Include(x => x.idSimulacionNavigation).Where(x => x.idSimulacionNavigation.idTipoSimulacion == 34 || x.idSimulacionNavigation.idTipoSimulacion == 35).ToList();
|
|
|
|
listadoHerramientaEstadisticaUrban = listadoPorTipoURBAN.Where(x => (x.idSimulacionNavigation.FechaCreacion >= fechaInicio) && (x.idSimulacionNavigation.FechaModificacion ?? x.idSimulacionNavigation.FechaCreacion).Date <= fechaFinal).ToList();
|
|
|
|
}
|
|
|
|
listadoHerramientaEstadisticaUsos = bd.estadisticasusos.AsEnumerable().Where(x => listadoHerramientaEstadistica.Any(y => y.idSimulacion == x.idSimulacion)).ToList();
|
|
|
|
|
|
listadoHerramientaEstadisticaFactores = bd.estadisticasfactores.AsEnumerable().Where(x => listadoHerramientaEstadistica.Any(y => y.idSimulacion == x.idsimulacion)).ToList();
|
|
}
|
|
}
|