diff --git a/.gitignore b/.gitignore index 146064f6..53ab3379 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,12 @@ *.pdb .vs/* +#-------------------------------- +# area MP.Stats +#-------------------------------- +/Mp.Stats/temp/*.csv + + #-------------------------------- # Area VersGen #-------------------------------- diff --git a/MP.Data/Utils.cs b/MP.Data/Utils.cs index d160e583..48f7c3b4 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 async Task 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); + await Task.Run(() => File.WriteAllLines(path, lines.ToArray())); + } + #endregion Public Methods } } \ No newline at end of file diff --git a/MP.Stats/Components/ChartOEE.razor b/MP.Stats/Components/ChartOEE.razor index 977b55c0..91670d2c 100644 --- a/MP.Stats/Components/ChartOEE.razor +++ b/MP.Stats/Components/ChartOEE.razor @@ -13,7 +13,7 @@ {
  • @item.label - @item.value.ToString("P1") + @item.value.ToString("N2")%
  • } diff --git a/MP.Stats/Components/ChartOEE.razor.cs b/MP.Stats/Components/ChartOEE.razor.cs index d6175aea..b241e6df 100644 --- a/MP.Stats/Components/ChartOEE.razor.cs +++ b/MP.Stats/Components/ChartOEE.razor.cs @@ -62,10 +62,11 @@ namespace MP.Stats.Components new { Display = true, ticks= new { - suggestedMin = 0 + min = 0, + max = 100 } + } } - } }, Tooltips = new { @@ -177,13 +178,13 @@ namespace MP.Stats.Components { ParetoData = RawData .GroupBy(x => x.IdxMacchina) - .Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Average(c => c.OEE) }) + .Select(y => new ChartKV() { label = y.First().CodMacchina, value = Math.Round(y.Average(c => c.OEE) * 100, 2) }) .OrderByDescending(x => x.value) .ToList(); TSData = RawData .GroupBy(x => x.DataRif.Date) - .Select(y => new ChartTS() { TLabel = y.First().DataRif.Date, Value = y.Average(c => c.OEE) }) + .Select(y => new ChartTS() { TLabel = y.First().DataRif.Date, Value = Math.Round(y.Average(c => c.OEE) * 100, 2) }) .OrderBy(x => x.TLabel) .ToList(); } diff --git a/MP.Stats/Components/DataPager.razor b/MP.Stats/Components/DataPager.razor index 22928184..bf75fb07 100644 --- a/MP.Stats/Components/DataPager.razor +++ b/MP.Stats/Components/DataPager.razor @@ -4,43 +4,54 @@
    @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 (totalCount > 0) + { + if (!fileExist) + { + + } + else + { + Download Data + } }
    @@ -48,9 +59,9 @@
    @if (showLoading) { - - - + + + }
    @@ -58,16 +69,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 65376227..1e09e88d 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.2106.2814 + 1.0.2107.0219 @@ -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..ae4167a9 --- /dev/null +++ b/MP.Stats/Pages/Download.cshtml.cs @@ -0,0 +1,52 @@ +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 +{ + /// + /// Gestione donwnload file csv + /// + /// da valutare eventualmente xlsx con https://github.com/closedxml/closedxml + /// + 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() + { + string fileName = "OUT.csv"; + if (Request.Query.ContainsKey("fileName")) + { + fileName = Request.Query["fileName"]; + } + var filePath = Path.Combine(_env.WebRootPath, "..\\temp\\", fileName); + + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + + return File(fileBytes, "application/force-download", fileName); + } + + #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..35b7c9e9 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) { - - @**@ - + } @@ -61,6 +61,6 @@ } \ No newline at end of file diff --git a/MP.Stats/Pages/ReportODL.razor.cs b/MP.Stats/Pages/ReportODL.razor.cs index e4477774..22cf93b5 100644 --- a/MP.Stats/Pages/ReportODL.razor.cs +++ b/MP.Stats/Pages/ReportODL.razor.cs @@ -3,6 +3,7 @@ using Microsoft.JSInterop; using MP.Stats.Data; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; @@ -19,6 +20,12 @@ namespace MP.Stats.Pages #endregion Private Fields + #region Protected Fields + + protected string fileName = "ODL.csv"; + + #endregion Protected Fields + #region Private Properties private SelectData currFilter @@ -34,6 +41,13 @@ namespace MP.Stats.Pages } private int currPage { get; set; } = 1; + + private string fullPath + { + get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}"; + } + + private bool isLoading { get; set; } = false; private int numRecord { get; set; } = 10; #endregion Private Properties @@ -69,7 +83,20 @@ namespace MP.Stats.Pages #region Private Methods - private async Task reloadData() + private async void clearFile() + { + await Task.Run(() => File.Delete(fullPath)); + } + + private async Task ExportCsv() + { + isLoading = true; + // salvo davvero! + await MP.Data.Utils.SaveToCsv(SearchRecords, fullPath); + isLoading = false; + } + + private async Task ReloadData() { SearchRecords = await StatService.StatOdlGetAll(currFilter, MessageService.SearchVal); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); @@ -81,53 +108,57 @@ namespace MP.Stats.Pages protected async Task DoFilter(SelectData newFilter) { + clearFile(); SearchRecords = null; ListRecords = null; currFilter = newFilter; - await reloadData(); + await ReloadData(); } protected async Task ForceReload(int newNum) { numRecord = newNum; - await reloadData(); + await ReloadData(); } protected async Task ForceReloadPage(int newNum) { currPage = newNum; - await reloadData(); + await ReloadData(); } protected override async Task OnInitializedAsync() { + clearFile(); numRecord = 10; MessageService.ShowSearch = false; MessageService.PageName = "Report ODL/Comm."; MessageService.PageIcon = "oi oi-book"; MessageService.EA_SearchUpdated += OnSeachUpdated; - await reloadData(); + await ReloadData(); } protected void ResetData() { + clearFile(); StatService.rollBackEdit(currRecord); currRecord = null; } protected async Task ResetFilter(SelectData newFilter) { + clearFile(); currRecord = null; SearchRecords = null; ListRecords = null; currFilter = SelectData.Init(5, 7); - await reloadData(); + await ReloadData(); } protected async Task UpdateData() { currRecord = null; - await reloadData(); + await ReloadData(); } #endregion 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 41a146db..b37506b8 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

    Versione: 1.0.2106.2814

    +

    Versione: 1.0.2107.0219


    Note di rilascio:
      diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 20adef80..07dfd325 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2106.2814 +1.0.2107.0219 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 34d7cd7a..5367571c 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2106.2814 + 1.0.2107.0219 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
    Data Turno Macchina
    @record.DataRif.ToString("yyyy.MM.dd")
    @record.DataRif.ToString("dddd")
    @@ -75,6 +72,6 @@ } \ No newline at end of file diff --git a/MP.Stats/Pages/Oee.razor.cs b/MP.Stats/Pages/Oee.razor.cs index 364c4fae..1de7694d 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 @@ -14,6 +19,7 @@ namespace MP.Stats.Pages private MP.Data.DatabaseModels.TurniOee currRecord = null; + private string fileName = "OEE.csv"; private List ListRecords; private List SearchRecords; @@ -46,12 +52,17 @@ namespace MP.Stats.Pages if (_currPage != value) { _currPage = value; - var pUpd = Task.Run(async () => await reloadData()); + var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } } + private string fullPath + { + get => $"{Directory.GetCurrentDirectory()}\\temp\\{fileName}"; + } + private bool isLoading { get; set; } = false; private int numRecord @@ -62,7 +73,7 @@ namespace MP.Stats.Pages if (_numRecord != value) { _numRecord = value; - var pUpd = Task.Run(async () => await reloadData()); + var pUpd = Task.Run(async () => await ReloadData()); pUpd.Wait(); } } @@ -103,7 +114,21 @@ namespace MP.Stats.Pages #region Private Methods - private async Task reloadData() + private async void clearFile() + { + await Task.Run(() => File.Delete(fullPath)); + } + + private async Task ExportCsv() + { + isLoading = true; + // calcolo nome file + // salvo davvero! + await MP.Data.Utils.SaveToCsv(SearchRecords, fullPath); + isLoading = false; + } + + private async Task ReloadData() { isLoading = true; SearchRecords = await StatService.StatTurniOeeGetAllCached(currFilter, MessageService.SearchVal); @@ -117,11 +142,12 @@ namespace MP.Stats.Pages protected async Task DoFilter(SelectData newFilter) { + clearFile(); currRecord = null; SearchRecords = null; ListRecords = null; currFilter = newFilter; - await reloadData(); + await ReloadData(); } protected void ForceReload(int newNum) @@ -136,27 +162,30 @@ namespace MP.Stats.Pages protected override async Task OnInitializedAsync() { + clearFile(); numRecord = 10; MessageService.ShowSearch = false; MessageService.PageName = "TRS/OEE %"; MessageService.PageIcon = "oi oi-monitor"; MessageService.EA_SearchUpdated += OnSeachUpdated; - await reloadData(); + await ReloadData(); } protected void ResetData() { + clearFile(); StatService.rollBackEdit(currRecord); currRecord = null; } protected async Task ResetFilter(SelectData newFilter) { + clearFile(); currRecord = null; SearchRecords = null; ListRecords = null; currFilter = SelectData.Init(5, 7); - await reloadData(); + await ReloadData(); } protected void Select(MP.Data.DatabaseModels.TurniOee selRecord) @@ -170,14 +199,14 @@ namespace MP.Stats.Pages ShowCharts = !ShowCharts; if (ShowCharts) { - await reloadData(); + await ReloadData(); } } protected async Task UpdateData() { currRecord = null; - await reloadData(); + await ReloadData(); } #endregion Protected Methods diff --git a/MP.Stats/Pages/ReportODL.razor b/MP.Stats/Pages/ReportODL.razor index 6671bc66..df8a84d2 100644 --- a/MP.Stats/Pages/ReportODL.razor +++ b/MP.Stats/Pages/ReportODL.razor @@ -50,8 +50,8 @@
    @record.DataFine @record.NumPezzi @record.NumPezziEv@record.NumPezziRil @record.NumPezziSca@record.NumPezziRil