Files
mapo-core/MP.SPEC/Components/SelectCodArt.razor.cs
Samuele Locatelli 62fb0e38b3 SPEC:
- Completo gestione Template KIT
2025-04-10 08:09:11 +02:00

143 lines
3.9 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.Data.Services;
using NLog;
namespace MP.SPEC.Components
{
public partial class SelectCodArt
{
#region Public Properties
[Parameter]
public EventCallback<string> E_CodArt { get; set; }
[Parameter]
public int SearchMinChar { get; set; }
#endregion Public Properties
#region Protected Properties
protected string CodArtSel
{
get => codArtSel;
set
{
if (codArtSel != value)
{
codArtSel = value;
E_CodArt.InvokeAsync(CodArtSel).ConfigureAwait(false);
}
}
}
protected int DisplayCount { get; set; } = 0;
protected bool ListArtDisabled { get => string.IsNullOrEmpty(SearchVal) || SearchVal.Length < SearchMinChar; }
protected Dictionary<string, string>? ListArticoli { get; set; } = null;
protected Dictionary<string, string> ListArticoliAll { get; set; } = new Dictionary<string, string>();
[Inject]
protected ListSelectDataSrv MDataService { get; set; } = null!;
protected int Num2Displ
{
get => num2Displ;
set
{
if (num2Displ != value)
{
num2Displ = value;
FiltArticoli();
}
}
}
protected string SearchVal
{
get => searchVal;
set
{
if (value.Length >= SearchMinChar || string.IsNullOrEmpty(value))
{
if (searchVal != value)
{
searchVal = value;
var pUpd = Task.Run(async () =>
{
await ReloadArticoli();
});
pUpd.Wait();
}
}
}
}
protected int TotalCount { get; set; } = 0;
#endregion Protected Properties
#region Protected Methods
protected void FiltArticoli()
{
bool done = false;
if (!ListArtDisabled)
{
if (ListArticoliAll != null)
{
TotalCount = ListArticoliAll.Count;
ListArticoli = ListArticoliAll.Take(Num2Displ).ToDictionary(x => x.Key, x => x.Value);
DisplayCount = ListArticoli.Count;
done = true;
}
}
if (!done)
{
TotalCount = 0;
ListArticoli = new Dictionary<string, string>();
DisplayCount = 0;
}
}
protected async Task GetArticoli()
{
if (!ListArtDisabled)
{
Log.Debug("START GetArticoli");
var rawData = await MDataService.ArticoliGetSearch(10000, "*", searchVal);
// trasformo!
if (rawData != null)
{
ListArticoliAll = rawData.ToDictionary(x => x.CodArticolo, x => $"{x.CodArticolo} | {x.DescArticolo} | {x.Disegno}");
}
Log.Debug("END GetArticoli");
}
}
protected async Task ReloadArticoli()
{
await GetArticoli();
FiltArticoli();
}
#endregion Protected Methods
#region Private Fields
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
#endregion Private Fields
#region Private Properties
private string codArtSel { get; set; } = "";
private int num2Displ { get; set; } = 20;
private string searchVal { get; set; } = "";
#endregion Private Properties
}
}