From ff2114a1e3fa7aff38ed730190ed4a012c1c2c2e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 2 Jul 2021 18:23:18 +0200 Subject: [PATCH] Bozza export data in CSV funzionante (da rivedere) --- MP.Data/Utils.cs | 13 ++++ MP.Stats/Components/DataPager.razor | 94 ++++++++++++++------------ MP.Stats/Components/DataPager.razor.cs | 29 ++++++++ MP.Stats/MP.Stats.csproj | 5 +- MP.Stats/Pages/Download.cshtml | 5 ++ MP.Stats/Pages/Download.cshtml.cs | 42 ++++++++++++ MP.Stats/Pages/Oee.razor | 6 +- MP.Stats/Pages/Oee.razor.cs | 28 ++++++++ MP.Stats/temp/.placeholder | 1 + Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 12 files changed, 178 insertions(+), 51 deletions(-) create mode 100644 MP.Stats/Pages/Download.cshtml create mode 100644 MP.Stats/Pages/Download.cshtml.cs create mode 100644 MP.Stats/temp/.placeholder diff --git a/MP.Data/Utils.cs b/MP.Data/Utils.cs index d160e583..de9ca1a3 100644 --- a/MP.Data/Utils.cs +++ b/MP.Data/Utils.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -26,6 +28,17 @@ namespace MP.Data return answ; } + public static void SaveToCsv(List reportData, string path) + { + var lines = new List(); + IEnumerable props = TypeDescriptor.GetProperties(typeof(T)).OfType(); + var header = string.Join(";", props.ToList().Select(x => x.Name)); + lines.Add(header); + var valueLines = reportData.Select(row => string.Join(";", header.Split(';').Select(a => row.GetType().GetProperty(a).GetValue(row, null)))); + lines.AddRange(valueLines); + File.WriteAllLines(path, lines.ToArray()); + } + #endregion Public Methods } } \ No newline at end of file diff --git a/MP.Stats/Components/DataPager.razor b/MP.Stats/Components/DataPager.razor index 22928184..51d8e827 100644 --- a/MP.Stats/Components/DataPager.razor +++ b/MP.Stats/Components/DataPager.razor @@ -4,43 +4,51 @@
@if (totalCount > 0) { - - - - - - - - - - - - @for (int i = @startPage; i <= endPage; ++i) + + + + + + + + + + + + @for (int i = @startPage; i <= endPage; ++i) { var pageNum = i; - - - @pageNum - - + + + @pageNum + + } - - - - - - - - - - - + + + + + + + + + + + }
-
+
@if (!showLoading) { - @totalCount records +
@totalCount records
+ } + @if (!fileExist) + { + + } + else + { + Download Data }
@@ -48,9 +56,9 @@
@if (showLoading) { - - - + + + }
@@ -58,16 +66,16 @@
@if (totalCount > 0) { -
- row/pag:  - -
+
+ row/pag:  + +
}
\ No newline at end of file diff --git a/MP.Stats/Components/DataPager.razor.cs b/MP.Stats/Components/DataPager.razor.cs index ba72a2ff..3d5155b2 100644 --- a/MP.Stats/Components/DataPager.razor.cs +++ b/MP.Stats/Components/DataPager.razor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; @@ -14,6 +15,8 @@ namespace MP.Stats.Components protected bool _showLoading = false; + protected string exportDir = $"{Directory.GetCurrentDirectory()}/temp"; + #endregion Protected Fields #region Private Properties @@ -80,6 +83,19 @@ namespace MP.Stats.Components protected int _numRecord { get; set; } = 10; + protected bool fileExist + { + get + { + return File.Exists(fullPath); + } + } + + protected string fullPath + { + get => $"{exportDir}/{fileName}"; + } + protected int percLoading { get; set; } = 0; #endregion Protected Properties @@ -104,6 +120,12 @@ namespace MP.Stats.Components } } + [Parameter] + public EventCallback exportRequested { get; set; } + + [Parameter] + public string fileName { get; set; } + [Parameter] public EventCallback numPageChanged { get; set; } @@ -167,6 +189,13 @@ namespace MP.Stats.Components numPageChanged.InvokeAsync(currPage); } + private async Task requestSave() + { + showLoading = true; + await exportRequested.InvokeAsync(currPage); + showLoading = false; + } + #endregion Private Methods #region Protected Methods diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 28d61c51..d4ddbd4c 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net5.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 1.0.2107.0212 + 1.0.2107.0218 @@ -47,6 +47,9 @@ PreserveNewest + + Always + diff --git a/MP.Stats/Pages/Download.cshtml b/MP.Stats/Pages/Download.cshtml new file mode 100644 index 00000000..8e451870 --- /dev/null +++ b/MP.Stats/Pages/Download.cshtml @@ -0,0 +1,5 @@ +@page "/Download" + +@model MP.Stats.Pages.DownloadModel +@{ +} \ No newline at end of file diff --git a/MP.Stats/Pages/Download.cshtml.cs b/MP.Stats/Pages/Download.cshtml.cs new file mode 100644 index 00000000..436f95c1 --- /dev/null +++ b/MP.Stats/Pages/Download.cshtml.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace MP.Stats.Pages +{ + public class DownloadModel : PageModel + { + #region Private Fields + + private readonly IWebHostEnvironment _env; + + #endregion Private Fields + + #region Public Constructors + + public DownloadModel(IWebHostEnvironment env) + { + _env = env; + } + + #endregion Public Constructors + + #region Public Methods + + public IActionResult OnGet() + { + var filePath = Path.Combine(_env.WebRootPath, "../temp/", "OEE.csv"); + + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + + return File(fileBytes, "application/force-download", "OEE.csv"); + } + + #endregion Public Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Pages/Oee.razor b/MP.Stats/Pages/Oee.razor index 503c0fe6..9867d0c8 100644 --- a/MP.Stats/Pages/Oee.razor +++ b/MP.Stats/Pages/Oee.razor @@ -30,7 +30,6 @@ - @**@ @@ -44,8 +43,6 @@ @foreach (var record in ListRecords) { - - @**@
Data Turno Macchina
@record.DataRif.ToString("yyyy.MM.dd")
@record.DataRif.ToString("dddd")
@@ -70,11 +67,12 @@ }
+ } \ No newline at end of file diff --git a/MP.Stats/Pages/Oee.razor.cs b/MP.Stats/Pages/Oee.razor.cs index 364c4fae..19b6ff0f 100644 --- a/MP.Stats/Pages/Oee.razor.cs +++ b/MP.Stats/Pages/Oee.razor.cs @@ -6,6 +6,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using System.IO; +using System.Threading; +using System.Text; +using System.ComponentModel; + namespace MP.Stats.Pages { public partial class Oee : ComponentBase, IDisposable @@ -20,6 +25,12 @@ namespace MP.Stats.Pages #endregion Private Fields + #region Protected Fields + + protected string fileName = "OEE.csv"; + + #endregion Protected Fields + #region Private Properties private int _currPage { get; set; } = 1; @@ -103,6 +114,14 @@ namespace MP.Stats.Pages #region Private Methods + private async Task ExportCsv() + { + isLoading = true; + // salvo il file + await saveCsv(); + isLoading = false; + } + private async Task reloadData() { isLoading = true; @@ -111,6 +130,15 @@ namespace MP.Stats.Pages isLoading = false; } + private async Task saveCsv() + { + // calcolo nome file + string currDir = $"{Directory.GetCurrentDirectory()}/temp/"; + string fullPath = $"{currDir}/{fileName}"; + // salvo davvero! + MP.Data.Utils.SaveToCsv(SearchRecords, fullPath); + } + #endregion Private Methods #region Protected Methods diff --git a/MP.Stats/temp/.placeholder b/MP.Stats/temp/.placeholder new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/MP.Stats/temp/.placeholder @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 502d9bc5..d00f7df2 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 1.0.2107.0212

+

Versione: 1.0.2107.0218


Note di rilascio:
    diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 73506e0a..fdae5767 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2107.0212 +1.0.2107.0218 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index ba64ef5d..43d68414 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2107.0212 + 1.0.2107.0218 http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/MP.Stats.zip http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html false