michele: filtri per data estrazione excel
This commit is contained in:
parent
f293697536
commit
64f3622371
@ -2,6 +2,7 @@
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using VirtualTask.Models;
|
||||
using X.PagedList;
|
||||
|
||||
@ -85,7 +86,7 @@ namespace VirtualTask.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult ExportDataToExcel(DateTime DataIni, DateTime DataFin)
|
||||
public IActionResult ExportDataToExcel(DateTime dataIni, DateTime dataFin)
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
token = helper.GetStringValue("tok");
|
||||
@ -110,23 +111,24 @@ namespace VirtualTask.Controllers
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
modelList = JsonConvert.DeserializeObject<List<Rapportini>>(data);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
var workbook = new XLWorkbook();
|
||||
workbook.AddWorksheet("sheetName");
|
||||
var ws = workbook.Worksheet("sheetName");
|
||||
|
||||
int col = 1;
|
||||
|
||||
var anno = DateTime.Now.Year.ToString();
|
||||
var mese = DateTime.Now.Month.ToString();
|
||||
var giorno = DateTime.Now.Day.ToString();
|
||||
var ore = DateTime.Now.Hour.ToString();
|
||||
var minuti = DateTime.Now.Minute.ToString();
|
||||
var secondi = DateTime.Now.Second.ToString();
|
||||
|
||||
var dataCreazioneFile = anno + mese + giorno + ore + minuti + secondi;
|
||||
|
||||
|
||||
//Scrivo intestazioni colonne
|
||||
foreach (var item in modelList[0].GetType().GetProperties())
|
||||
{
|
||||
@ -153,12 +155,36 @@ namespace VirtualTask.Controllers
|
||||
row ++;
|
||||
}
|
||||
|
||||
//creo file Excel
|
||||
workbook.SaveAs($"C:\\Users\\utente\\Desktop\\ExcelVT\\rapportini_{dataCreazioneFile}.xlsx");
|
||||
}
|
||||
//Salvo il file Excel
|
||||
|
||||
return View();
|
||||
var anno = DateTime.Now.Year.ToString();
|
||||
var mese = DateTime.Now.Month.ToString();
|
||||
var giorno = DateTime.Now.Day.ToString();
|
||||
var ore = DateTime.Now.Hour.ToString();
|
||||
var minuti = DateTime.Now.Minute.ToString();
|
||||
var secondi = DateTime.Now.Second.ToString();
|
||||
|
||||
var dateFile = anno + mese + giorno + ore + minuti + secondi;
|
||||
|
||||
workbook.SaveAs($"C:\\Users\\utente\\Desktop\\ExcelVT\\rapportini_{dateFile}.xlsx");
|
||||
|
||||
return RedirectToAction("Index");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
errMes = response.Content.ReadAsStringAsync().Result;
|
||||
helper.SetStringValue("errMsg", errMes);
|
||||
return RedirectToAction("Error");
|
||||
}
|
||||
}
|
||||
|
||||
[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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,17 +20,17 @@
|
||||
<div style="float:left;width:40%;padding:0 20px;">@Html.TextBox("SearchString", null, new { placeholder = "Cerca rapportino", @class = "agy-form-field require" })</div>
|
||||
<div style="float:left;width:2%;"> </div>
|
||||
<div style="float:left;width:57%;"><input type="submit" value="Cerca" class="agy-btn submitForm" /></div>
|
||||
<hr/>
|
||||
<hr/>
|
||||
<div style="float:left;width:40%;padding:0 20px;">@Html.TextBox("DataIni", null, new { type="date", @class = "agy-form-field require" })</div>
|
||||
<div style="float:left;width:40%;padding:0 20px;">@Html.TextBox("DataFin", null, new { type="date", @class = "agy-form-field require" })</div>
|
||||
|
||||
<div style="float:left;width:40%;padding:0 20px;">
|
||||
@Html.ActionLink("Crea Excel", "ExportDataToExcel", "Rapportini", new { DataIni = "DataIni", DataFin = "DataFin" }, null)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<br>
|
||||
@using (Html.BeginForm("ExportDataToExcel", "Rapportini"))
|
||||
{
|
||||
<div style="float:left;width:40%;padding:0 20px;">@Html.TextBox("dataIni", null, new { type = "date", @class = "agy-form-field require" })</div>
|
||||
<div style="float:left;width:40%;padding:0 20px;">@Html.TextBox("dataFin", null, new { type = "date", @class = "agy-form-field require" })</div>
|
||||
|
||||
@* <div style="float:left;width:40%;padding:0 20px;">@Html.ActionLink("Crea Excel", "ExportDataToExcel", "Rapportini", new { type = "submit" })</div> *@
|
||||
<div style="float:left;width:40%;padding:0 20px;">
|
||||
<input type="submit" name="estrai" class="agy-btn submitForm" />
|
||||
</div>
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user