Modifche, filtri su estrazione rapportini in excel, non funzionavano i filtri
This commit is contained in:
parent
3a322b1b03
commit
58b70978b0
@ -70,7 +70,7 @@ namespace VirtualTask.Controllers
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = response.Content.ReadAsStringAsync().Result;
|
||||
modelList = JsonConvert.DeserializeObject<List<Rapportini>>(data);
|
||||
modelList = JsonConvert.DeserializeObject<List<Rapportini>>(data) ?? new List<Rapportini>();
|
||||
|
||||
string urlImpianti = apiUrl + "impiantiListMngr?token=" + token;
|
||||
HttpResponseMessage responseImpianti = client.GetAsync(urlImpianti).Result;
|
||||
@ -80,11 +80,26 @@ namespace VirtualTask.Controllers
|
||||
if (responseImpianti.IsSuccessStatusCode)
|
||||
{
|
||||
string dataImpianti = responseImpianti.Content.ReadAsStringAsync().Result;
|
||||
impiantiList = JsonConvert.DeserializeObject<List<Impianto>>(dataImpianti);
|
||||
ViewBag.Impianti = impiantiList;
|
||||
impiantiList = JsonConvert.DeserializeObject<List<Impianto>>(dataImpianti) ?? new List<Impianto>(); ;
|
||||
//ViewBag.Impianti = impiantiList;
|
||||
|
||||
// 🔧 Crea SelectList codice + descrizione
|
||||
ViewBag.Impianti = new SelectList(
|
||||
impiantiList.Select(i => new
|
||||
{
|
||||
imcodimp = i.imcodimp,
|
||||
descrizioneCompleta = $"{i.imcodimp} - {i.imdescri}"
|
||||
}),
|
||||
"imcodimp",
|
||||
"descrizioneCompleta",
|
||||
impianto
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ViewBag.Rapportini = getImpianti(null);
|
||||
// --- Filtri ---
|
||||
|
||||
//ViewBag.Rapportini = getImpianti(null);
|
||||
|
||||
if (!string.IsNullOrEmpty(impianto))
|
||||
{
|
||||
@ -92,10 +107,10 @@ namespace VirtualTask.Controllers
|
||||
|
||||
ViewData["impianto"] = impianto;
|
||||
|
||||
ViewBag.Impianto = impianto;
|
||||
//ViewBag.Impianto = impianto;
|
||||
}
|
||||
else
|
||||
ViewData["impianto"] = null;
|
||||
//else
|
||||
// ViewData["impianto"] = null;
|
||||
|
||||
if (dataIni.Date != DateTime.MinValue)
|
||||
{
|
||||
@ -167,43 +182,62 @@ namespace VirtualTask.Controllers
|
||||
|
||||
modelList = JsonConvert.DeserializeObject<List<Rapportini>>(data);
|
||||
|
||||
if (string.IsNullOrEmpty(impianto))
|
||||
if (impianto != null)
|
||||
{
|
||||
impianto = "- Impianto";
|
||||
modelList = modelList.Where(x => x.codice_impianto.Equals(impianto)).ToList();
|
||||
}
|
||||
|
||||
if (impianto.Equals("System.Collections.Generic.List`1[Microsoft.AspNetCore.Mvc.Rendering.SelectListItem]") || impianto.Equals("- Impianto"))
|
||||
if (dataIni != DateTime.MinValue)
|
||||
{
|
||||
modelList = modelList;
|
||||
modelList = modelList
|
||||
.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date)
|
||||
.ToList();
|
||||
ViewData["dataIni"] = dataIni.ToString("yyyy-MM-dd");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (impianto != null)
|
||||
{
|
||||
modelList = modelList.Where(x => x.codice_impianto.Equals(impianto)).ToList();
|
||||
}
|
||||
|
||||
//if (!dataFin.ToString().Substring(0, 10).Equals("01/01/0001"))
|
||||
//{
|
||||
// modelList = modelList.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date
|
||||
// && x.data_rapportino.GetValueOrDefault().Date <= dataFin.Date).ToList();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// modelList = modelList.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date).ToList();
|
||||
//}
|
||||
|
||||
if (dataFin != DateTime.MinValue)
|
||||
{
|
||||
modelList = modelList.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date
|
||||
&& x.data_rapportino.GetValueOrDefault().Date <= dataFin.Date).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
modelList = modelList.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date).ToList();
|
||||
}
|
||||
ViewData["dataIni"] = "";
|
||||
}
|
||||
|
||||
if (dataFin != DateTime.MinValue)
|
||||
{
|
||||
modelList = modelList
|
||||
.Where(x => x.data_rapportino.GetValueOrDefault().Date <= dataFin.Date)
|
||||
.ToList();
|
||||
ViewData["dataFin"] = dataFin.ToString("yyyy-MM-dd");
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["dataFin"] = "";
|
||||
}
|
||||
|
||||
//if (string.IsNullOrEmpty(impianto))
|
||||
//{
|
||||
// impianto = "- Impianto";
|
||||
//}
|
||||
|
||||
//if (impianto.Equals("System.Collections.Generic.List`1[Microsoft.AspNetCore.Mvc.Rendering.SelectListItem]") || impianto.Equals("- Impianto"))
|
||||
//{
|
||||
// modelList = modelList;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (impianto != null)
|
||||
// {
|
||||
// modelList = modelList.Where(x => x.codice_impianto.Equals(impianto)).ToList();
|
||||
// }
|
||||
|
||||
// if (dataFin != DateTime.MinValue)
|
||||
// {
|
||||
// modelList = modelList.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date
|
||||
// && x.data_rapportino.GetValueOrDefault().Date <= dataFin.Date).ToList();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// modelList = modelList.Where(x => x.data_rapportino.GetValueOrDefault().Date >= dataIni.Date).ToList();
|
||||
// }
|
||||
//}
|
||||
|
||||
var workbook = new XLWorkbook();
|
||||
workbook.AddWorksheet("sheetName");
|
||||
var ws = workbook.Worksheet("sheetName");
|
||||
|
||||
@ -1,4 +1,138 @@
|
||||
@model IPagedList<VirtualTask.Models.Rapportini>
|
||||
@using X.PagedList
|
||||
@using X.PagedList.Mvc.Core
|
||||
@using X.PagedList.Web.Common
|
||||
|
||||
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Esporta buoni su Excel";
|
||||
Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml";
|
||||
}
|
||||
|
||||
<div class="agy-project-wrapper agy-project-page-wrapper">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<!-- 🔍 FORM DI RICERCA -->
|
||||
@using (Html.BeginForm("Index", "Rapportini", FormMethod.Get))
|
||||
{
|
||||
<div class="card mb-4">
|
||||
<h5 class="card-header">Ricerca</h5>
|
||||
<div class="card-body">
|
||||
<div class="row g-3 align-items-end">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label fw-bold">Impianto</label>
|
||||
@Html.DropDownList(
|
||||
"impianto",
|
||||
ViewBag.Impianti as SelectList,
|
||||
"- Impianto",
|
||||
new { @class = "form-select" }
|
||||
)
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-bold">Data da</label>
|
||||
<input type="date" name="dataIni" class="form-control"
|
||||
value="@(ViewData["dataIni"] as string ?? "")" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label fw-bold">Data a</label>
|
||||
<input type="date" name="dataFin" class="form-control"
|
||||
value="@(ViewData["dataFin"] as string ?? "")" />
|
||||
</div>
|
||||
<div class="col-md-2 text-end">
|
||||
@* <button type="submit" class="btn btn-primary mt-3 w-100">Cerca</button> *@
|
||||
<span class="fw-medium"><input type="submit" value="Cerca" class="agy-btn submitForm" /></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- 🧾 FORM DI ESPORTAZIONE -->
|
||||
@using (Html.BeginForm("ExportDataToExcel", "Rapportini", FormMethod.Post))
|
||||
{
|
||||
<div class="card mb-4">
|
||||
<h5 class="card-header">Estrai</h5>
|
||||
<div class="card-body text-end">
|
||||
@Html.Hidden("impianto", ViewData["impianto"])
|
||||
@Html.Hidden("dataIni", ViewData["dataIni"])
|
||||
@Html.Hidden("dataFin", ViewData["dataFin"])
|
||||
@* <button type="submit" class="btn btn-success">Esporta Excel</button> *@
|
||||
@* <span class="fw-medium"><input type="submit" value="Esporta excel"
|
||||
name="Esporta excel" class="agy-btn submitForm" /></span> *@
|
||||
<span class="fw-medium">
|
||||
<input type="submit" value="Esporta excel" name="Esporta excel" class="agy-btn success" />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- 📋 TABELLA RISULTATI -->
|
||||
<div class="card">
|
||||
<div class="table-responsive text-nowrap">
|
||||
<table class="table table-striped align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Codice Buono</th>
|
||||
<th>Data buono</th>
|
||||
<th>Cliente</th>
|
||||
<th>Codice impianto</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (Model != null && Model.Any())
|
||||
{
|
||||
foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>@item.ser_buono</td>
|
||||
<td>@item.data_rapportino?.ToString("dd/MM/yyyy")</td>
|
||||
<td>@item.ancodice - @item.andescri</td>
|
||||
<td>@item.codice_impianto</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<tr>
|
||||
<td colspan="4" class="text-center text-muted">Nessun risultato trovato.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 🔢 PAGINAZIONE -->
|
||||
<nav class="mt-3">
|
||||
@Html.PagedListPager(Model, page => Url.Action("Index", new
|
||||
{
|
||||
page,
|
||||
impianto = ViewData["impianto"],
|
||||
dataIni = ViewData["dataIni"],
|
||||
dataFin = ViewData["dataFin"]
|
||||
}),
|
||||
new PagedListRenderOptions
|
||||
{
|
||||
ActiveLiElementClass = "active",
|
||||
PageClasses = new[] { "page-link" },
|
||||
LiElementClasses = new[] { "page-item" },
|
||||
UlElementClasses = new[] { "pagination", "justify-content-center" },
|
||||
LinkToNextPageFormat = "Successiva",
|
||||
LinkToPreviousPageFormat = "Precedente",
|
||||
MaximumPageNumbersToDisplay = 5,
|
||||
DisplayLinkToPreviousPage = PagedListDisplayMode.Always,
|
||||
DisplayLinkToNextPage = PagedListDisplayMode.Always
|
||||
})
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@* @model IPagedList<VirtualTask.Models.Rapportini>
|
||||
@using X.PagedList;
|
||||
@using X.PagedList.Mvc.Core;
|
||||
@using X.PagedList.Web.Common;
|
||||
@ -84,22 +218,16 @@
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
@* <th>Seriale buono</th> *@
|
||||
<th>Codice Buono</th>
|
||||
<th>Data buono</th>
|
||||
<th>Cliente</th>
|
||||
<th>Codice impianto</th>
|
||||
@* <th>Seriale commessa</th>
|
||||
<th>Data buono</th> *@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
@* <td>
|
||||
@Html.DisplayFor(modelItem => item.seriale_rapportino)
|
||||
</td> *@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ser_buono)
|
||||
</td>
|
||||
@ -147,4 +275,4 @@
|
||||
}
|
||||
|
||||
</div>
|
||||
|
||||
*@
|
||||
|
||||
Loading…
Reference in New Issue
Block a user