Bozza export data in CSV funzionante (da rivedere)

This commit is contained in:
Samuele Locatelli
2021-07-02 18:23:18 +02:00
parent e7c831d9a2
commit ff2114a1e3
12 changed files with 178 additions and 51 deletions
+13
View File
@@ -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<T>(List<T> reportData, string path)
{
var lines = new List<string>();
IEnumerable<PropertyDescriptor> props = TypeDescriptor.GetProperties(typeof(T)).OfType<PropertyDescriptor>();
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
}
}
+51 -43
View File
@@ -4,43 +4,51 @@
<div class="col-9 small">
@if (totalCount > 0)
{
<Pagination>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="1">
<i class="fas fa-angle-double-left"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@prevBlock.ToString()">
<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>
</PaginationLink>
</PaginationItem>
@for (int i = @startPage; i <= endPage; ++i)
<Pagination>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="1">
<i class="fas fa-angle-double-left"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@prevBlock.ToString()">
<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>
</PaginationLink>
</PaginationItem>
@for (int i = @startPage; i <= endPage; ++i)
{
var pageNum = i;
<PaginationItem Active="@(currPage.Equals(pageNum))">
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@pageNum.ToString()">
@pageNum
</PaginationLink>
</PaginationItem>
<PaginationItem Active="@(currPage.Equals(pageNum))">
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@pageNum.ToString()">
@pageNum
</PaginationLink>
</PaginationItem>
}
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@nextBlock.ToString()">
<i class="fas fa-angle-right"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@LastPage.ToString()">
<i class="fas fa-angle-double-right"></i>
</PaginationLink>
</PaginationItem>
</Pagination>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@nextBlock.ToString()">
<i class="fas fa-angle-right"></i>
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink Clicked="@HandlePaginationItemClick" Page="@LastPage.ToString()">
<i class="fas fa-angle-double-right"></i>
</PaginationLink>
</PaginationItem>
</Pagination>
}
</div>
<div class="col-3">
<div class="col-3 text-center">
@if (!showLoading)
{
<span>@totalCount records</span>
<div>@totalCount records</div>
}
@if (!fileExist)
{
<button class="btn btn-block btn-sm btn-primary" @onclick="() => requestSave()"><span class="oi oi-wrench"></span> Prepare Data</button>
}
else
{
<a target="_blank" href="/Download?fileName=@fileName" class="btn btn-block btn-sm btn-success"><span class="oi oi-cloud-download"></span> Download Data</a>
}
</div>
</div>
@@ -48,9 +56,9 @@
<div class="col-12 small">
@if (showLoading)
{
<Progress>
<ProgressBar Value="@percLoading" Striped="true" Animated="true" />
</Progress>
<Progress>
<ProgressBar Value="@percLoading" Striped="true" Animated="true" />
</Progress>
}
</div>
</div>
@@ -58,16 +66,16 @@
<div class="col-6 col-lg-2 text-right">
@if (totalCount > 0)
{
<div class="input-group input-group-sm">
row/pag:&nbsp;
<select @bind="@PageSize" class="form-control form-control-sm">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
<div class="input-group input-group-sm">
row/pag:&nbsp;
<select @bind="@PageSize" class="form-control form-control-sm">
<option value="5">5</option>
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</div>
}
</div>
</div>
+29
View File
@@ -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<int> exportRequested { get; set; }
[Parameter]
public string fileName { get; set; }
[Parameter]
public EventCallback<int> 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
+4 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>1.0.2107.0212</Version>
<Version>1.0.2107.0218</Version>
</PropertyGroup>
<ItemGroup>
@@ -47,6 +47,9 @@
<None Update="logs\.placeholder">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="temp\.placeholder">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File $(ProjectDir)\post-build.ps1 -ProjectDir $(ProjectDir) -ProjectPath $(ProjectPath)" />
+5
View File
@@ -0,0 +1,5 @@
@page "/Download"
@model MP.Stats.Pages.DownloadModel
@{
}
+42
View File
@@ -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
}
}
+2 -4
View File
@@ -30,7 +30,6 @@
<table class="table table-sm table-striped">
<thead>
<tr>
@*<th><button class="btn btn-sm btn-primary" @onclick="() => ResetData()"><span class="oi oi-loop-circular"></span></button></th>*@
<th>Data</th>
<th>Turno</th>
<th>Macchina</th>
@@ -44,8 +43,6 @@
@foreach (var record in ListRecords)
{
<tr class="@checkSelect(record.DataRif, record.Turno, @record.IdxMacchina)">
@*<td><button class="btn btn-sm btn-primary" @onclick="() => Select(record)"><span class="oi oi-magnifying-glass"></span></button></td>*@
<td>
<div>@record.DataRif.ToString("yyyy.MM.dd")</div>
<div class="small">@record.DataRif.ToString("dddd")</div>
@@ -70,11 +67,12 @@
}
</tbody>
</table>
<button class="btn btn-sm btn-primary" @onclick="() => saveCsv()"><span class="oi oi-cloud-download"></span> SAVE</button>
</div>
</div>
}
</div>
<div class="card-footer py-1">
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" totalCount="totalCount" showLoading="isLoading" />
<DataPager PageSize="numRecord" currPage="currPage" numRecordChanged="ForceReload" numPageChanged="ForceReloadPage" exportRequested="ExportCsv" fileName="@fileName" totalCount="totalCount" showLoading="isLoading" />
</div>
</div>
+28
View File
@@ -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
+1
View File
@@ -0,0 +1 @@

+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 1.0.2107.0212</h4>
<h4>Versione: 1.0.2107.0218</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
1.0.2107.0212
1.0.2107.0218
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.0.2107.0212</version>
<version>1.0.2107.0218</version>
<url>http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/MP.Stats.zip</url>
<changelog>http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html</changelog>
<mandatory>false</mandatory>