007e22785d
- Fix display forza update + selezione
451 lines
12 KiB
C#
451 lines
12 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using MP.Data.DatabaseModels;
|
|
using MP.SPEC.Data;
|
|
using MP.SPEC.Services;
|
|
using NLog;
|
|
|
|
namespace MP.SPEC.Components
|
|
{
|
|
public partial class ListODL : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public SelectXdlParams currFilter { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public string padCodXdl { get; set; } = "0000";
|
|
|
|
[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 void Dispose()
|
|
{
|
|
currRecord = null;
|
|
SearchRecords = null;
|
|
ListRecords = null;
|
|
ListStati = null;
|
|
ListOdlStats = null;
|
|
ListOdlStatsNetto = null;
|
|
statRecord = null;
|
|
GC.Collect();
|
|
}
|
|
|
|
public string formDurata(double durataMin)
|
|
{
|
|
return MP.Data.Utils.FormDurata(durataMin);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected MpDataService MDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IOApiService MpIoApiCall { 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);
|
|
Log.Info($"Effettuata chiusura ODL {currRecord.IdxOdl}");
|
|
// ricarica...
|
|
await selRecord(null);
|
|
}
|
|
await reloadData();
|
|
}
|
|
|
|
protected string colorChanger(string colorCSS)
|
|
{
|
|
string answ = "";
|
|
if (colorCSS == "yellow")
|
|
{
|
|
answ = "text-dark";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Richiesta invio sync all'IOB-WIN
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task forceSyncDb()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sei sicuro di voler (re)inviare i dati (Articoli, PODL) all'impianto?"))
|
|
return;
|
|
|
|
if (currRecord != null)
|
|
{
|
|
await callSyncDb(currRecord.IdxMacchina);
|
|
Log.Info($"Richiesto forceSyncDb per idxMacc {currRecord.IdxMacchina}");
|
|
// ricarica...
|
|
await selRecord(null);
|
|
}
|
|
await reloadData();
|
|
}
|
|
|
|
protected int getPodl(int idxOdl)
|
|
{
|
|
int answ = 0;
|
|
var pOdlData = MDService.POdlGetByOdl(idxOdl);
|
|
if (pOdlData != null)
|
|
{
|
|
answ = pOdlData.IdxPromessa;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ListStati = await MDService.AnagStatiComm();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await reloadData();
|
|
}
|
|
|
|
protected async void OnSeachUpdated()
|
|
{
|
|
await InvokeAsync(() =>
|
|
{
|
|
PagerResetReq.InvokeAsync(true);
|
|
Task task = UpdateData();
|
|
StateHasChanged();
|
|
});
|
|
}
|
|
|
|
protected async Task resetSel()
|
|
{
|
|
await selRecord(null);
|
|
await reloadData();
|
|
}
|
|
|
|
protected async Task selectStatRecord(ODLExpModel? currRec)
|
|
{
|
|
showStats = true;
|
|
await Task.Delay(1);
|
|
statRecord = currRec;
|
|
if (currRec != null)
|
|
{
|
|
await reloadStatsData(currRec);
|
|
}
|
|
else
|
|
{
|
|
showStats = false;
|
|
ListOdlStats = null;
|
|
}
|
|
}
|
|
|
|
protected async Task selRecord(ODLExpModel? currRec)
|
|
{
|
|
await Task.Delay(1);
|
|
selDtFine = DateTime.Now;
|
|
currRecord = currRec;
|
|
showStats = false;
|
|
ListOdlStats = null;
|
|
ListOdlStatsNetto = null;
|
|
}
|
|
|
|
protected async Task toggleSpenta()
|
|
{
|
|
hideSpenta = !hideSpenta;
|
|
await Task.Delay(1);
|
|
if (statRecord != null)
|
|
{
|
|
await reloadStatsData(statRecord);
|
|
}
|
|
}
|
|
|
|
protected async Task UpdateData()
|
|
{
|
|
await selRecord(null);
|
|
await reloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
private ODLExpModel? currRecord = null;
|
|
|
|
private List<StatODLModel>? ListOdlStats;
|
|
|
|
private List<StatODLModel>? ListOdlStatsNetto;
|
|
|
|
private List<ODLExpModel>? ListRecords;
|
|
|
|
private List<ListValues>? ListStati;
|
|
|
|
private List<ODLExpModel>? SearchRecords;
|
|
|
|
private ODLExpModel? statRecord = null;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int _totalCount { get; set; } = 0;
|
|
|
|
private int currPage
|
|
{
|
|
get => currFilter.CurrPage;
|
|
set => currFilter.CurrPage = value;
|
|
}
|
|
|
|
private string durataFilt
|
|
{
|
|
get
|
|
{
|
|
string answ = "ND";
|
|
if (statRecord != null)
|
|
{
|
|
if (hideSpenta)
|
|
{
|
|
if (ListOdlStatsNetto != null)
|
|
{
|
|
var tsDurata = TimeSpan.FromMinutes(ListOdlStatsNetto.Sum(x => x.TotDurata));
|
|
if (tsDurata.TotalDays < 1)
|
|
{
|
|
answ = $"{tsDurata.Hours:00}h {tsDurata.Minutes:00}'";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{tsDurata.Days}gg {tsDurata.Hours:00}h";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
answ = statRecord.DurataMinuti;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private bool hideSpenta { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Indica se si tratti di ODL correnti
|
|
/// </summary>
|
|
private bool isCurrOdl
|
|
{
|
|
get => currFilter.IsActive;
|
|
}
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
|
|
private string leftStringCSS
|
|
{
|
|
get => hideSpenta ? "text-secondary" : "text-dark fw-bold";
|
|
}
|
|
|
|
private List<StatODLModel>? ListOdlStatsAct
|
|
{
|
|
get
|
|
{
|
|
List<StatODLModel>? answ = new List<StatODLModel>();
|
|
if (hideSpenta)
|
|
{
|
|
answ = ListOdlStatsNetto;
|
|
}
|
|
else
|
|
{
|
|
answ = ListOdlStats;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private int numRecord
|
|
{
|
|
get => currFilter.NumRec;
|
|
set => currFilter.NumRec = value;
|
|
}
|
|
|
|
private string rightStringCSS
|
|
{
|
|
get => hideSpenta ? "text-dark fw-bold" : "text-secondary";
|
|
}
|
|
|
|
private DateTime selDtFine { get; set; } = DateTime.Now;
|
|
|
|
private bool showStats { get; set; } = false;
|
|
|
|
private int totalCount
|
|
{
|
|
get => _totalCount;
|
|
set
|
|
{
|
|
if (_totalCount != value)
|
|
{
|
|
_totalCount = value;
|
|
updateRecordCount.InvokeAsync(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Chiama metodo x chiedere sync DB
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
/// <returns></returns>
|
|
private async Task addTask2Exe(string idxMacc, string taskName, string taskVal)
|
|
{
|
|
// compongo URL e chiamo
|
|
string restUrl = $"IOB/addTask2Exe/{idxMacc}?taskName={taskName}&taskVal={taskVal}";
|
|
try
|
|
{
|
|
var response = await MpIoApiCall.callMpIoUrlGet(restUrl);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore durante chiamata: {Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
|
|
private double calcolaPerc(double durata)
|
|
{
|
|
double answ = 0;
|
|
|
|
double tot = 0;
|
|
if (ListOdlStatsAct != null)
|
|
{
|
|
tot = ListOdlStatsAct.Sum(x => x.TotDurata);
|
|
|
|
double perc = (durata / tot) * 100;
|
|
if (perc > 1)
|
|
{
|
|
answ = Math.Round(perc, 2);
|
|
}
|
|
else
|
|
{
|
|
answ = Math.Round(perc, 4);
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Chiama metodo x chiedere sync DB
|
|
/// </summary>
|
|
/// <param name="IdxMacc"></param>
|
|
/// <returns></returns>
|
|
private async Task callSyncDb(string IdxMacc)
|
|
{
|
|
// chiamo aggiunta task SyncDb...
|
|
await addTask2Exe(IdxMacc, "syncDbData", "");
|
|
}
|
|
|
|
private string pbStyle(string css)
|
|
{
|
|
string answ = "";
|
|
if (ListOdlStats != null)
|
|
{
|
|
if (css == "yellow")
|
|
{
|
|
answ = "orange";
|
|
}
|
|
else if (css == "blue")
|
|
{
|
|
answ = "#2874A6";
|
|
}
|
|
else
|
|
{
|
|
answ = css;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private async Task reloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await MDService.OdlListGetFilt(currFilter.IsActive, currFilter.SearchVal, currFilter.CodFase, currFilter.CodReparto, 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());
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task reloadStatsData(ODLExpModel? currRec)
|
|
{
|
|
showStats = true;
|
|
if (currRec != null)
|
|
{
|
|
ListOdlStats = await MDService.StatOdl(currRec.IdxOdl);
|
|
ListOdlStatsNetto = ListOdlStats.Where(x => x.Semaforo != "sGr").ToList();
|
|
}
|
|
else
|
|
{
|
|
ListOdlStats = null;
|
|
ListOdlStatsNetto = null;
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
} |