251 lines
6.2 KiB
C#
251 lines
6.2 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Stats.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Stats.Pages
|
|
{
|
|
public partial class Oee : ComponentBase, IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private MP.Data.DbModels.TurniOee currRecord = null;
|
|
|
|
private string fileName = "OEE.csv";
|
|
private List<MP.Data.DbModels.TurniOee> ListRecords;
|
|
|
|
private List<MP.Data.DbModels.TurniOee> SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _currPage { get; set; } = 1;
|
|
|
|
private int _numRecord { get; set; } = 10;
|
|
|
|
private SelectData currFilter
|
|
{
|
|
get
|
|
{
|
|
return MessageService.OEE_Filter;
|
|
}
|
|
set
|
|
{
|
|
MessageService.OEE_Filter = value;
|
|
}
|
|
}
|
|
|
|
private int currPage
|
|
{
|
|
get => _currPage;
|
|
set
|
|
{
|
|
if (_currPage != value)
|
|
{
|
|
_currPage = value;
|
|
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
|
|
{
|
|
get => _numRecord;
|
|
set
|
|
{
|
|
if (_numRecord != value)
|
|
{
|
|
_numRecord = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool ShowCharts { get; set; } = false;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; }
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; }
|
|
|
|
[Inject]
|
|
protected MpStatsService StatService { get; set; }
|
|
|
|
protected int totalCount
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
if (SearchRecords != null)
|
|
{
|
|
answ = SearchRecords.Count;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void clearFile()
|
|
{
|
|
await Task.Run(() => File.Delete(fullPath));
|
|
}
|
|
|
|
private async Task ExportCsv()
|
|
{
|
|
isLoading = true;
|
|
// calcolo nome file
|
|
// salvo davvero!
|
|
await Egw.Core.Utils.SaveToCsv(SearchRecords, fullPath, ';');
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await StatService.StatTurniOeeGetAllCached(currFilter, MessageService.SearchVal);
|
|
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task DoFilter(SelectData newFilter)
|
|
{
|
|
clearFile();
|
|
currRecord = null;
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
currFilter = newFilter;
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void ForceReload(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
}
|
|
|
|
protected void ForceReloadPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
clearFile();
|
|
numRecord = 10;
|
|
MessageService.ShowSearch = false;
|
|
MessageService.PageName = "TRS/OEE %";
|
|
MessageService.PageIcon = "fa fa-display";
|
|
MessageService.EA_SearchUpdated += OnSeachUpdated;
|
|
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();
|
|
}
|
|
|
|
protected void Select(MP.Data.DbModels.TurniOee selRecord)
|
|
{
|
|
// applico filtro da selezione
|
|
currRecord = selRecord;
|
|
}
|
|
|
|
protected async Task ToggleChart(bool doShow)
|
|
{
|
|
ShowCharts = !ShowCharts;
|
|
if (ShowCharts)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
currRecord = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
public string checkSelect(DateTime DataRif, string Turno, string IdxMacchina)
|
|
{
|
|
string answ = "";
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.IdxMacchina == IdxMacchina && currRecord.Turno == Turno && currRecord.DataRif == DataRif) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
MessageService.EA_SearchUpdated -= OnSeachUpdated;
|
|
}
|
|
|
|
// public void OnSeachUpdated()
|
|
// {
|
|
// InvokeAsync(() =>
|
|
// {
|
|
// UpdateData();
|
|
// StateHasChanged();
|
|
// });
|
|
// }
|
|
public async void OnSeachUpdated()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
Task task = UpdateData();
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |