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 0000000..4147b65 Binary files /dev/null and b/yourExcel.xlsx differ