From aacb8e04379544d7d1adfdb56dfb45a16e218a00 Mon Sep 17 00:00:00 2001 From: michele Date: Fri, 15 Dec 2023 17:57:29 +0100 Subject: [PATCH] Michele: estrazione excel --- Controllers/RapportiniController.cs | 164 ++++++++++++++++++++++ Models/Chiusure.cs | 2 +- Models/Rapportini.cs | 36 +++++ Views/Chiusure/Create.cshtml | 2 +- Views/Chiusure/Edit.cshtml | 2 +- Views/Chiusure/Index.cshtml | 2 +- Views/Rapportini/Index.cshtml | 165 +++++++++++++++++++++++ Views/Shared/_LayoutAreaRiservata.cshtml | 1 + VirtualTask.csproj | 2 + yourExcel.xlsx | Bin 0 -> 6230 bytes 10 files changed, 372 insertions(+), 4 deletions(-) create mode 100644 Controllers/RapportiniController.cs create mode 100644 Models/Rapportini.cs create mode 100644 Views/Rapportini/Index.cshtml create mode 100644 yourExcel.xlsx diff --git a/Controllers/RapportiniController.cs b/Controllers/RapportiniController.cs new file mode 100644 index 0000000..bdbabe1 --- /dev/null +++ b/Controllers/RapportiniController.cs @@ -0,0 +1,164 @@ +using ClosedXML.Excel; +using DocumentFormat.OpenXml.Spreadsheet; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using VirtualTask.Models; +using X.PagedList; + +namespace VirtualTask.Controllers +{ + public class RapportiniController : Controller + { + string apiUrl = string.Empty; + string urlBase = string.Empty; + string token = string.Empty; + string tenant = string.Empty; + string errMes = string.Empty; + string admin = string.Empty; + + HttpClient client; + + private readonly IConfiguration _configuration; + + public RapportiniController(IConfiguration configuration) + { + client = new HttpClient(); + _configuration = configuration; + var key = _configuration["ApplicationInsights:rootUrlApi"]; + apiUrl = key; + } + + + public IActionResult Index(string searchString, int? page = 1) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login2", "Login"); + } + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "rapportiniList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + List modelList = new List(); + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + + if (!string.IsNullOrEmpty(searchString)) + { + modelList = modelList.Where(s => s.seriale_rapportino.ToUpper().Contains(searchString.ToUpper())).ToList(); + + ViewData["CurrentFilter"] = searchString; + } + else + ViewData["CurrentFilter"] = null; + + if (page != null && page < 1) + { + page = 1; + } + + var pageSize = 10; + + var shortLinks = modelList + .OrderByDescending(s => s.seriale_rapportino) + .ToPagedList(page ?? 1, pageSize); + + return View(shortLinks); + } + else + { + errMes = response.Content.ReadAsStringAsync().Result; + helper.SetStringValue("errMsg", errMes); + return RedirectToAction("Error"); + } + } + + public IActionResult ExportDataToExcel(DateTime DataIni, DateTime DataFin) + { + SessionHelper helper = new SessionHelper(this); + token = helper.GetStringValue("tok"); + if (string.IsNullOrEmpty(token)) + { + return RedirectToAction("Login2", "Login"); + } + + apiUrl = helper.GetStringValue("apiUrl"); + admin = helper.GetStringValue("admin"); + ViewBag.Admin = admin; + urlBase = apiUrl + "rapportiniList"; + urlBase = urlBase + "?token=" + token; + Uri baseAddress = new Uri(urlBase); + client = new HttpClient(); + client.BaseAddress = baseAddress; + + List modelList = new List(); + + HttpResponseMessage response = client.GetAsync(baseAddress).Result; + + if (response.IsSuccessStatusCode) + { + string data = response.Content.ReadAsStringAsync().Result; + modelList = JsonConvert.DeserializeObject>(data); + + 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()) + { + ws.Cell(1, col).Style = ws.Cell(1, col).Style.Font.SetBold(); + ws.Cell(1, col).Value = item.Name.ToString().Replace("_"," ").ToUpper(); + + col++; + } + + var row = 0; + + foreach (var item in modelList) + { + var colonna = 1; + + //righe per ogni elemento nel modelList + foreach (var prop in item.GetType().GetProperties()) + { + ws.Cell(row + 2, colonna).Value = prop.GetValue(item).ToString(); + + colonna ++; + } + + row ++; + } + + //creo file Excel + workbook.SaveAs($"C:\\Users\\utente\\Desktop\\ExcelVT\\rapportini_{dataCreazioneFile}.xlsx"); + } + + return View(); + } + + } +} diff --git a/Models/Chiusure.cs b/Models/Chiusure.cs index 6d718da..abb14e7 100644 --- a/Models/Chiusure.cs +++ b/Models/Chiusure.cs @@ -17,7 +17,7 @@ namespace VirtualTask.Models [Display(Name = "Descrizione"), Required(ErrorMessage = "Inserire descrizione")] public string? ccdescr { get; set; } - [Display(Name = "Desc. Supplementare"), Required(ErrorMessage = "Inserire Desc. Supplementare")] + [Display(Name = "Testo del rapportino App (desc. sup.)"), Required(ErrorMessage = "Inserire Desc. Supplementare")] public string? ccdessup { get; set; } diff --git a/Models/Rapportini.cs b/Models/Rapportini.cs new file mode 100644 index 0000000..d7932ee --- /dev/null +++ b/Models/Rapportini.cs @@ -0,0 +1,36 @@ +namespace VirtualTask.Models +{ + public class Rapportini + { + /// + /// Seriale + /// + public string? seriale_rapportino { get; set; } + + /// + /// Azienda + /// + public string? azienda_impianto { get; set; } + + /// + /// Codice Impianto + /// + public string? codice_impianto { get; set; } + + + /// + /// Seriale chiamata + /// + public string? seriale_chiamata { get; set; } + + /// + /// Seriale chiamata + /// + public string? seriale_commessa { get; set; } + + /// + /// Data rapportino + /// + public DateTime? data_rapportino { get; set; } + } +} diff --git a/Views/Chiusure/Create.cshtml b/Views/Chiusure/Create.cshtml index d51eae4..c5273a2 100644 --- a/Views/Chiusure/Create.cshtml +++ b/Views/Chiusure/Create.cshtml @@ -27,7 +27,7 @@
 
- +
 
diff --git a/Views/Chiusure/Edit.cshtml b/Views/Chiusure/Edit.cshtml index 7e0664e..99238ee 100644 --- a/Views/Chiusure/Edit.cshtml +++ b/Views/Chiusure/Edit.cshtml @@ -35,7 +35,7 @@
@* *@ - +
 
diff --git a/Views/Chiusure/Index.cshtml b/Views/Chiusure/Index.cshtml index e7fa7f5..b8d7fe8 100644 --- a/Views/Chiusure/Index.cshtml +++ b/Views/Chiusure/Index.cshtml @@ -31,7 +31,7 @@ Azienda Codice Descrizione - Desc. Sup. + Testo del rapportino App (desc. sup.) diff --git a/Views/Rapportini/Index.cshtml b/Views/Rapportini/Index.cshtml new file mode 100644 index 0000000..6fcfb70 --- /dev/null +++ b/Views/Rapportini/Index.cshtml @@ -0,0 +1,165 @@ +@model IPagedList +@using X.PagedList; +@using X.PagedList.Mvc.Core; +@using X.PagedList.Web.Common; + + + +@{ + ViewData["Title"] = "Rapportini"; + Layout = "~/Views/Shared/_LayoutAreaRiservata.cshtml"; +} + + +
+
+
+ @using (Html.BeginForm()) + { +
+
@Html.TextBox("SearchString", null, new { placeholder = "Cerca rapportino", @class = "agy-form-field require" })
+
 
+
+
+
+
@Html.TextBox("DataIni", null, new { type="date", @class = "agy-form-field require" })
+
@Html.TextBox("DataFin", null, new { type="date", @class = "agy-form-field require" })
+ +
+ @Html.ActionLink("Crea Excel", "ExportDataToExcel", "Rapportini", new { DataIni = "DataIni", DataFin = "DataFin" }, null) +
+
+ + @*
@Html.ActionLink("Crea Excel", "ExportDataToExcel", "Rapportini", new { type = "submit" })
*@ + + } + + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + @* *@ + + } + +
Seriale RapportinoAzienda impiantoCodice impiantoSeriale chiamateSeriale commessaData rapportino
+ @Html.DisplayFor(modelItem => item.seriale_rapportino) + + @Html.DisplayFor(modelItem => item.azienda_impianto) + + @Html.DisplayFor(modelItem => item.codice_impianto) + + @Html.DisplayFor(modelItem => item.seriale_chiamata) + + @Html.DisplayFor(modelItem => item.seriale_commessa) + + @Html.DisplayFor(modelItem => item.data_rapportino) + + + Modifica + + | + + Dettaglio + + | + + Elimina + +
+
+ +
+
+
+ + +@*

+ Create New +

+ + + + + + + + + + + + + +@foreach (var item in Model) { + + + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.seriale_rapportino) + + @Html.DisplayNameFor(model => model.azienda_impianto) + + @Html.DisplayNameFor(model => model.codice_impianto) + + @Html.DisplayNameFor(model => model.seriale_chiamata) + + @Html.DisplayNameFor(model => model.seriale_commessa) + + @Html.DisplayNameFor(model => model.data_rapportino) +
+ @Html.DisplayFor(modelItem => item.seriale_rapportino) + + @Html.DisplayFor(modelItem => item.azienda_impianto) + + @Html.DisplayFor(modelItem => item.codice_impianto) + + @Html.DisplayFor(modelItem => item.seriale_chiamata) + + @Html.DisplayFor(modelItem => item.seriale_commessa) + + @Html.DisplayFor(modelItem => item.data_rapportino) + + @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | + @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | + @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) +
+ *@ \ No newline at end of file diff --git a/Views/Shared/_LayoutAreaRiservata.cshtml b/Views/Shared/_LayoutAreaRiservata.cshtml index dba691f..2301d77 100644 --- a/Views/Shared/_LayoutAreaRiservata.cshtml +++ b/Views/Shared/_LayoutAreaRiservata.cshtml @@ -160,6 +160,7 @@ Purchase:
  • Dati Azienda
  • Dati Azienda2
  • Commesse
  • +
  • Elenco rapportini
  • Logout
  • @{ diff --git a/VirtualTask.csproj b/VirtualTask.csproj index cda6a56..a472ff4 100644 --- a/VirtualTask.csproj +++ b/VirtualTask.csproj @@ -7,6 +7,8 @@ false + + diff --git a/yourExcel.xlsx b/yourExcel.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..4147b6502bbd7c57ce671bc95704775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