Michele: timbrature index - messo combo commesse, data da, data a.

timbrature controller - metodo per gestione combo commesse
modifica filtri ricerca  dopo modifica index
This commit is contained in:
michele 2024-05-21 11:53:25 +02:00
parent baaf87dec6
commit cc5a935a06
2 changed files with 89 additions and 22 deletions

View File

@ -1,6 +1,8 @@
using ClosedXML.Excel; using ClosedXML.Excel;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Diagnostics;
using VirtualTask.Models; using VirtualTask.Models;
using X.PagedList; using X.PagedList;
@ -29,7 +31,7 @@ namespace VirtualTask.Controllers
#region INDEX #region INDEX
public IActionResult Index(DateTime dataTimb, string commessa, string tecnico, int? page = 1) public IActionResult Index(DateTime dataIni, DateTime dataFin, string commessa, string tecnico, int? page = 1)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
@ -57,30 +59,33 @@ namespace VirtualTask.Controllers
string data = response.Content.ReadAsStringAsync().Result; string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<Timbratura>>(data); modelList = JsonConvert.DeserializeObject<List<Timbratura>>(data);
if (dataTimb.Date != DateTime.MinValue) ViewBag.Timbrature = GetCommesse();
if (dataIni.Date != DateTime.MinValue)
{ {
modelList = modelList.Where(x => x.data_timbratura.GetValueOrDefault().Date == dataTimb).ToList(); modelList = modelList.Where(x => x.data_timbratura.GetValueOrDefault().Date >= dataIni.Date).ToList();
}
if (dataFin.Date != DateTime.MinValue)
{
modelList = modelList.Where(x => x.data_timbratura.GetValueOrDefault().Date <= dataFin.Date).ToList();
} }
if (!string.IsNullOrEmpty(commessa)) if (!string.IsNullOrEmpty(commessa))
{ {
modelList = modelList.Where(s => s.commessa.ToLower().Contains(commessa.ToLower())).ToList(); modelList = modelList.Where(s => s.commessa.Contains(commessa)).ToList();
// ViewData["CurrentFilter"] = commessa;
//ViewBag.Timbrature = commessa;
} }
else
//ViewData["CurrentFilter"] = null;
if (!string.IsNullOrEmpty(tecnico)) if (!string.IsNullOrEmpty(tecnico))
{ {
modelList = modelList.Where(s => s.tecnico.ToLower().Contains(tecnico.ToLower())).ToList(); modelList = modelList.Where(s => s.tecnico.ToLower().Contains(tecnico.ToLower())).ToList();
} }
//if (id != 0)
//{
// modelList = modelList.Where(s => s.id == id).ToList();
// ViewData["CurrentFilter"] = id;
//}
//else
//{
// ViewData["CurrentFilter"] = null;
//}
if (page != null && page < 1) if (page != null && page < 1)
{ {
page = 1; page = 1;
@ -148,7 +153,53 @@ namespace VirtualTask.Controllers
#region metodi interni #region metodi interni
public IActionResult ExportExcel(DateTime dataTimb, string commessa, string tecnico) private List<SelectListItem> GetCommesse()
{
SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok");
apiUrl = helper.GetStringValue("apiUrl");
urlBase = apiUrl + "commesseList";
urlBase = urlBase + "?token=" + token;
Uri baseAddress = new Uri(urlBase);
client = new HttpClient();
client.BaseAddress = baseAddress;
List<SelectListItem> selectItems = new List<SelectListItem>();
List<CommesseVT> modelList = new List<CommesseVT>();
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
modelList = JsonConvert.DeserializeObject<List<CommesseVT>>(data);
//per gestire primo elemento tendina (deve essere vuoto)
SelectListItem listItemFirt = new SelectListItem();
listItemFirt.Value = string.Empty;
listItemFirt.Text = " - Commessa";
selectItems.Add(listItemFirt);
var appoggio = string.Empty;
foreach (var role in modelList)
{
if (!appoggio.Equals(role.lacodcom))
{
SelectListItem listItem = new SelectListItem();
string s = role.lacodcom;
listItem.Value = role.lacodcom;
listItem.Text = s;
selectItems.Add(listItem);
}
appoggio = role.lacodcom;
}
}
return selectItems;
}
public IActionResult ExportExcel(DateTime dataIni, DateTime dataFin, string commessa, string? tecnico)
{ {
SessionHelper helper = new SessionHelper(this); SessionHelper helper = new SessionHelper(this);
token = helper.GetStringValue("tok"); token = helper.GetStringValue("tok");
@ -176,9 +227,13 @@ namespace VirtualTask.Controllers
modelList = JsonConvert.DeserializeObject<List<Timbratura>>(data); modelList = JsonConvert.DeserializeObject<List<Timbratura>>(data);
if (dataTimb.Date != DateTime.MinValue) if (dataIni.Date != DateTime.MinValue)
{ {
modelList = modelList.Where(x => x.data_timbratura.GetValueOrDefault().Date == dataTimb).ToList(); modelList = modelList.Where(x => x.data_timbratura.GetValueOrDefault().Date >= dataIni.Date).ToList();
}
if (dataFin.Date != DateTime.MinValue)
{
modelList = modelList.Where(x => x.data_timbratura.GetValueOrDefault().Date <= dataFin.Date).ToList();
} }
if (!string.IsNullOrEmpty(commessa)) if (!string.IsNullOrEmpty(commessa))
@ -260,6 +315,14 @@ namespace VirtualTask.Controllers
} }
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
SessionHelper helper = new SessionHelper(this);
string e = helper.GetStringValue("errMsg");
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
}
#endregion metodi interni #endregion metodi interni
} }
} }

View File

@ -18,15 +18,18 @@
{ {
<div> <div>
<div style="float:left;width:40%;padding:0 20px;"> <div style="float:left;width:40%;padding:0 20px;">
<th><b>Data timbratura:</b></th> <th><b>Data da:</b></th>
@Html.TextBox("dataTimb", null, new { type = "date", @class = "agy-form-field require" }) @Html.TextBox("dataIni", null, new { type = "date", @class = "agy-form-field require" })
<th><b>Data a:</b></th>
@Html.TextBox("dataFin", null, new { type = "date", @class = "agy-form-field require" })
<th><b>Commessa:</b></th> <th><b>Commessa:</b></th>
@Html.TextBox("commessa", ViewBag.Timbrature, null, new { @class = "agy-form-field require" }) @Html.DropDownList("commessa", ViewBag.Timbrature, null, new { @class = "agy-form-field require" })
<th><b>Tecnico:</b></th> <th><b>Tecnico:</b></th>
@Html.TextBox("tecnico", ViewBag.Timbrature, null, new { @class = "agy-form-field require" }) @Html.TextBox("tecnico", null, new { placeholder = "", @class = "agy-form-field require" })
<div style="float:left;width:57%;"><input type="submit" value="Cerca" class="agy-btn submitForm" /></div> <div style="float:left;width:57%;"><input type="submit" value="Cerca" class="agy-btn submitForm" /></div>
</div> </div>
@ -44,7 +47,8 @@
@using (Html.BeginForm("ExportExcel", "Timbrature")) @using (Html.BeginForm("ExportExcel", "Timbrature"))
{ {
@Html.Hidden("dataTimb", ViewBag.Timbrature, null) @Html.Hidden("dataIni", ViewBag.Timbrature, null)
@Html.Hidden("dataFin", ViewBag.Timbrature, null)
@Html.Hidden("commessa", ViewBag.Timbrature, null) @Html.Hidden("commessa", ViewBag.Timbrature, null)
@Html.Hidden("tecnico", ViewBag.Timbrature, null) @Html.Hidden("tecnico", ViewBag.Timbrature, null)