Files
Samuele Locatelli af7998273d fix sync method
2025-06-30 07:59:29 +02:00

331 lines
8.7 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MP.Data;
using MP.Data.DbModels;
using MP.SPEC.Data;
using MP.SPEC.Services;
using NLog;
namespace MP.SPEC.Components.ProdKit
{
public partial class KitPodlMan : IDisposable
{
#region Public Properties
[Parameter]
public EventCallback<PODLExpModel> EC_RecordSel { get; set; }
[Parameter]
public string PadCodXdl { get; set; } = "0000";
[Parameter]
public EventCallback<bool> PagerResetReq { get; set; }
[Parameter]
public EventCallback<int> UpdateRecordCount { get; set; }
[Parameter]
public SelectXdlParams ActFilter { get; set; } = new SelectXdlParams();
#endregion Public Properties
#region Public Methods
public string checkSelect(PODLExpModel record)
{
string answ = "";
if (currRecord != null)
{
try
{
answ = (currRecord.IdxPromessa == record.IdxPromessa) ? "table-info" : "";
}
catch
{ }
}
return answ;
}
public void Dispose()
{
currRecord = null;
SearchRecords = null;
ListRecords = null;
GC.Collect();
}
#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!;
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
protected string SearchVal
{
get => searchVal;
set
{
if (searchVal != value)
{
searchVal = value;
UpdateTable();
}
}
}
protected string sParentCss
{
get => string.IsNullOrEmpty(SearchVal) ? "btn-secondary" : "btn-primary";
}
#endregion Protected Properties
#region Protected Methods
protected override void OnInitialized()
{
DateTime oggi = DateTime.Today;
ActFilter = new SelectXdlParams()
{
DtEnd = oggi.AddDays(1),
DtStart = oggi.AddYears(-1),
HasOdl = false,
MaxRecord = 1000,
NumRec = 5
};
}
protected override async Task OnParametersSetAsync()
{
if (!lastFilter.Equals(ActFilter) || true)
{
lastFilter = ActFilter.clone();
await ReloadData();
}
}
protected async void OnSeachUpdated()
{
await InvokeAsync(() =>
{
PagerResetReq.InvokeAsync(true);
Task task = UpdateData();
StateHasChanged();
});
}
protected async Task ReloadData()
{
ListRecords = null;
isLoading = true;
SearchRecords = await MDService.POdlToKitListGetFiltAsync(hasOdl, StatoSel, macchina, reparto, selDtStart, selDtEnd);
// rivedere filtro FixMe ToDo!!!
// filtro tenendo SOLO se hanno keyRichiesta CodExt + ATTIVI + NON KIT | Hard Coded...
SearchRecords = SearchRecords
.Where(x => !string.IsNullOrEmpty(x.KeyRichiesta) && x.Attivabile && !x.KeyRichiesta.StartsWith("KIT"))
.ToList();
UpdateTable();
isLoading = false;
}
protected void ResetParent()
{
SearchVal = "";
UpdateTable();
}
protected async Task resetSel(bool forceUpdate)
{
currRecord = null;
currPage = 1;
if (forceUpdate)
{
await ReloadData();
}
}
protected async Task selRecord(PODLExpModel? selRec)
{
currRecord = selRec;
currPage = 1;
await EC_RecordSel.InvokeAsync(selRec);
}
protected void SetNumPage(int newNum)
{
currPage = newNum;
UpdateTable();
}
protected void SetNumRec(int newNum)
{
currPage = 1;
numRecord = newNum;
UpdateTable();
}
protected async Task UpdateData()
{
currRecord = null;
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private static Logger Log = LogManager.GetCurrentClassLogger();
private PODLExpModel? currRecord = null;
private List<PODLExpModel>? ListRecords;
/// <summary>
/// Elenco ODL correnti...
/// </summary>
private List<string> odlCurrList = new List<string>();
private List<PODLExpModel>? SearchRecords;
private string searchVal = "";
protected string sSearchtCss
{
get => string.IsNullOrEmpty(searchVal) ? "btn-secondary" : "btn-primary";
}
#endregion Private Fields
#region Private Properties
private int _totalCount { get; set; } = -1;
private int currPage
{
get => ActFilter.CurrPage;
set => ActFilter.CurrPage = value;
}
private bool hasOdl
{
get => ActFilter.HasOdl;
set => ActFilter.HasOdl = value;
}
private bool isLoading { get; set; } = false;
private SelectXdlParams lastFilter { get; set; } = new SelectXdlParams() { CurrPage = -1 };
private string macchina
{
get => ActFilter.IdxMacchina;
set => ActFilter.IdxMacchina = value;
}
private int numRecord
{
get => ActFilter.NumRec;
set => ActFilter.NumRec = value;
}
private string reparto
{
get => ActFilter.CodReparto;
set => ActFilter.CodReparto = value;
}
private DateTime selDtEnd
{
get => ActFilter.DtEnd;
set
{
if (!ActFilter.DtEnd.Equals(value))
{
ActFilter.DtEnd = value;
currPage = 1;
}
}
}
private DateTime selDtStart
{
get => ActFilter.DtStart;
set
{
if (!ActFilter.DtStart.Equals(value))
{
ActFilter.DtStart = value;
currPage = 1;
}
}
}
private string StatoSel
{
get => ActFilter.CodFase;
set => ActFilter.CodFase = value;
}
private int totalCount
{
get => _totalCount;
set
{
if (_totalCount != value)
{
_totalCount = value;
UpdateRecordCount.InvokeAsync(value);
}
}
}
#endregion Private Properties
#region Private Methods
private void UpdateTable()
{
totalCount = 0;
if (SearchRecords != null)
{
var filtRec = new List<PODLExpModel>(SearchRecords);
// se ho ricerca filtro!
if (!string.IsNullOrEmpty(searchVal))
{
int idxPodl = 0;
// SE la ricerca contiene PODL filtro e cerco...
if (searchVal.Contains("PODL"))
{
int.TryParse(searchVal.Replace("PODL", ""), out idxPodl);
}
filtRec = SearchRecords
.Where(x => (x.KeyRichiesta.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|| x.KeyBCode.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)
|| (x.IdxPromessa == idxPodl && idxPodl > 0))
|| (x.CodArticolo.Contains(searchVal, StringComparison.InvariantCultureIgnoreCase)))
.ToList();
}
// fix conteggi
totalCount = filtRec.Count;
ListRecords = filtRec
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
}
#endregion Private Methods
}
}