314 lines
8.3 KiB
C#
314 lines
8.3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.SPEC.Data;
|
|
using MP.SPEC.Pages;
|
|
using System.Xml.Linq;
|
|
|
|
namespace MP.SPEC.Components
|
|
{
|
|
public partial class ListODL
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public SelectOdlParams currFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> PagerResetReq { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> updateRecordCount { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public string checkSelect(int IdxOdl)
|
|
{
|
|
string answ = "";
|
|
if (currRecord != null)
|
|
{
|
|
try
|
|
{
|
|
answ = (currRecord.IdxOdl == IdxOdl) ? "table-info" : "";
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public string formDurata(double durataMin)
|
|
{
|
|
return MP.Data.Utils.FormDurata(durataMin);
|
|
}
|
|
|
|
//oggetto contenente le funzioni del code behind che sono jsInvokable
|
|
private DotNetObjectReference<ListODL>? objRef;
|
|
|
|
#if false //FUNZIONA SE IL METODO TriggerDotNetInstanceMethod() E' IN ONCLICK BOTTONE
|
|
|
|
[JSInvokable]
|
|
public void setHelper()
|
|
{
|
|
objRef = DotNetObjectReference.Create(this);
|
|
}
|
|
[JSInvokable]
|
|
public void svuotaRecord()
|
|
{
|
|
currRecord = null;
|
|
|
|
}
|
|
public async Task TriggerDotNetInstanceMethod()
|
|
{
|
|
await JSRuntime.InvokeVoidAsync("recordDeselect", objRef);
|
|
}
|
|
#endif
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MessageService MessageService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Registra chiusura ODL alla data indicata
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task chiudiOdl()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sei sicuro di voler chiudere l'ODL corrente?"))
|
|
return;
|
|
|
|
if (currRecord != null)
|
|
{
|
|
// effettua chiusura sul DB
|
|
await MDService.ODLClose(currRecord.IdxOdl, currRecord.IdxMacchina, 0, true);
|
|
// ricarica...
|
|
await selectRecord(null);
|
|
}
|
|
await reloadData();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ListStati = await MDService.AnagStatiComm();
|
|
objRef = DotNetObjectReference.Create(this);
|
|
//await JSRuntime.InvokeVoidAsync("setHelper", objRef);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await reloadData();
|
|
}
|
|
|
|
protected string colorChanger(string colorCSS)
|
|
{
|
|
string answ = "";
|
|
if (colorCSS == "yellow")
|
|
{
|
|
answ = "text-dark";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
//protected double durataMin(DateTime? DataInizio, DateTime? DataFine)
|
|
//{
|
|
// DateTime end = DataInizio != null ? (DateTime)DataFine : DateTime.Now;
|
|
// var tsDurata = (end).Subtract((DateTime)DataInizio);
|
|
|
|
// return tsDurata.TotalMinutes;
|
|
//}
|
|
|
|
protected async void OnSeachUpdated()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
PagerResetReq.InvokeAsync(true);
|
|
Task task = UpdateData();
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
protected async Task resetSel()
|
|
{
|
|
await selectRecord(null);
|
|
await reloadData();
|
|
}
|
|
|
|
protected async Task selectRecord(ODLModel? currRec)
|
|
{
|
|
showStats = true;
|
|
await Task.Delay(1);
|
|
currRecord = currRec;
|
|
if (currRec != null)
|
|
{
|
|
showStats = true;
|
|
ListOdlStats = await MDService.StatOdl(currRec.IdxOdl);
|
|
}
|
|
else
|
|
{
|
|
showStats = false;
|
|
ListOdlStats = null;
|
|
}
|
|
}
|
|
protected async Task selectStatRecord(ODLModel? currRec)
|
|
{
|
|
showStats = true;
|
|
await Task.Delay(1);
|
|
statRecord = currRec;
|
|
if (currRec != null)
|
|
{
|
|
showStats = true;
|
|
ListOdlStats = await MDService.StatOdl(currRec.IdxOdl);
|
|
}
|
|
else
|
|
{
|
|
showStats = false;
|
|
ListOdlStats = null;
|
|
}
|
|
}
|
|
|
|
protected async Task selRecord(ODLModel? currRec)
|
|
{
|
|
await Task.Delay(1);
|
|
selDtFine = DateTime.Now;
|
|
currRecord = currRec;
|
|
showStats = false;
|
|
ListOdlStats = null;
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
await selectRecord(null);
|
|
await reloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private ODLModel? currRecord = null;
|
|
|
|
private ODLModel? statRecord = null;
|
|
|
|
private List<StatODLModel>? ListOdlStats;
|
|
|
|
private List<ODLModel>? ListRecords;
|
|
|
|
private List<ListValues>? ListStati;
|
|
|
|
private List<ODLModel>? SearchRecords;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage
|
|
{
|
|
get => MessageService.currPage;
|
|
set => MessageService.currPage = value;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indica se si tratti di ODL correnti
|
|
/// </summary>
|
|
private bool isCurrOdl
|
|
{
|
|
get => currFilter.IsActive;
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private int numRecord
|
|
{
|
|
get => MessageService.numRecord;
|
|
set => MessageService.numRecord = value;
|
|
}
|
|
|
|
private DateTime selDtFine { get; set; } = DateTime.Now;
|
|
private bool showStats { get; set; } = false;
|
|
#if false
|
|
private List<double>? ListOdlStatsData = new List<double>();
|
|
private List<string>? ListOdlStatsLabels = new List<string>();
|
|
#endif
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private double calcolaPerc(double durata)
|
|
{
|
|
double answ = 0;
|
|
|
|
double tot = 0;
|
|
if (ListOdlStats != null)
|
|
{
|
|
foreach (var item in ListOdlStats)
|
|
{
|
|
tot += item.TotDurata;
|
|
}
|
|
|
|
double perc = (durata / tot) * 100;
|
|
if (perc > 1)
|
|
{
|
|
answ = Math.Round(perc, 2);
|
|
}
|
|
else
|
|
{
|
|
answ = Math.Round(perc, 4);
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async void MessageService_EA_PageUpdated()
|
|
{
|
|
await reloadData();
|
|
}
|
|
|
|
private async Task reloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await MDService.ListODLFilt(currFilter.IsActive, currFilter.SearchVal, currFilter.CodStato, currFilter.IdxMacchina, currFilter.DtStart, currFilter.DtEnd);
|
|
totalCount = SearchRecords.Count;
|
|
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
await Task.Delay(1);
|
|
await InvokeAsync(() => StateHasChanged());
|
|
await updateRecordCount.InvokeAsync(totalCount);
|
|
isLoading = false;
|
|
}
|
|
|
|
private string tradFase(string codFase)
|
|
{
|
|
string answ = codFase;
|
|
if (ListStati != null && ListStati.Count > 0)
|
|
{
|
|
var recSel = ListStati.FirstOrDefault(x => x.value == codFase);
|
|
if (recSel != null)
|
|
{
|
|
answ = recSel.label;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |