199 lines
5.3 KiB
C#
199 lines
5.3 KiB
C#
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace Lux.UI.Components.Compo.Config
|
|
{
|
|
public partial class HardwareMan
|
|
{
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected ConfigDataService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
if (searchVal != value)
|
|
{
|
|
searchVal = value;
|
|
ReloadData();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
protected void DoReset()
|
|
{
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoSelect(HardwareModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void ResetSearch()
|
|
{
|
|
SearchVal = "";
|
|
}
|
|
|
|
protected void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<HardwareModel> AllRecords = new();
|
|
private int currPage = 1;
|
|
private HardwareModel? EditRecord = null;
|
|
private bool isLoading = false;
|
|
private List<HardwareModel> ListRecords = new();
|
|
private int numRecord = 5;
|
|
private HardwareModel? SelRecord = null;
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string searchVal { get; set; } = string.Empty;
|
|
|
|
#endregion Private Properties
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
protected async Task DoDelete(HardwareModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.HardwareID} | {selRec.Description} | {selRec.Thickness}"))
|
|
return;
|
|
|
|
// esegue eliminazione del record...
|
|
await CDService.ConfHardwareDeleteAsync(selRec);
|
|
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoEdit(HardwareModel curRec)
|
|
{
|
|
EditRecord = curRec;
|
|
}
|
|
#endif
|
|
#if false
|
|
private async Task DoAdd()
|
|
{
|
|
// aggiungo un nuovo record in coda...
|
|
EditRecord = new HardwareModel()
|
|
{
|
|
Description = "New Glass",
|
|
Code = "",
|
|
Thickness = 30
|
|
};
|
|
await DoSave(EditRecord);
|
|
}
|
|
|
|
private async Task DoSave(HardwareModel currRec)
|
|
{
|
|
// salvo
|
|
await CDService.ConfHardwareUpsertAsync(currRec);
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
}
|
|
#endif
|
|
|
|
#region Private Methods
|
|
|
|
private void ReloadData()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = CDService.ElencoHw(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "HW.AGB");
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (string.IsNullOrEmpty(SearchVal))
|
|
{
|
|
AllRecords = AllRecords
|
|
.OrderBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
AllRecords = AllRecords
|
|
.Where(x =>
|
|
x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.FamilyName.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.OrderBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
totalCount = AllRecords.Count;
|
|
}
|
|
|
|
#if false
|
|
private void ResetEdit()
|
|
{
|
|
// reset edit
|
|
EditRecord = null;
|
|
ReloadData();
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |