200 lines
5.5 KiB
C#
200 lines
5.5 KiB
C#
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Compo.Config
|
|
{
|
|
public partial class GlassMan
|
|
{
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IConfGlassService CGService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
if (searchVal != value)
|
|
{
|
|
searchVal = value;
|
|
UpdateTable();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
/// <summary>
|
|
/// imposta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
protected async Task DoDelete(GlassModel selRec)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Sicuro di voler eliminare il record?\n" +
|
|
$"Dettagli: {selRec.GlassID} | {selRec.Description} | {selRec.Thickness}";
|
|
mMode = BootstrapModal.ModalMode.Confirm;
|
|
modalOpt = new();
|
|
modalOpt.Add(true, "Si");
|
|
modalOpt.Add(false, "No");
|
|
if (!await Modal!.ShowAsync<bool>())
|
|
return;
|
|
|
|
// esegue eliminazione del record...
|
|
await CGService.DeleteAsync(selRec);
|
|
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoEdit(GlassModel curRec)
|
|
{
|
|
EditRecord = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
protected void DoReset()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
protected void DoSelect(GlassModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadDataAsync();
|
|
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<GlassModel> AllRecords = new();
|
|
private List<GlassModel> SearchRecords = new();
|
|
private int currPage = 1;
|
|
private GlassModel? EditRecord = null;
|
|
private bool isLoading = false;
|
|
private List<GlassModel> ListRecords = new();
|
|
private int numRecord = 5;
|
|
private GlassModel? SelRecord = null;
|
|
private int totalCount = 0;
|
|
|
|
private BootstrapModal Modal = new();
|
|
private string mTitle = "";
|
|
private string mMessage = "";
|
|
private BootstrapModal.ModalMode mMode = BootstrapModal.ModalMode.ND;
|
|
private Dictionary<bool, string> modalOpt = new Dictionary<bool, string>();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private string searchVal { get; set; } = string.Empty;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private Task DoAdd()
|
|
{
|
|
// aggiungo un nuovo record in coda...
|
|
EditRecord = new GlassModel()
|
|
{
|
|
Description = "New Glass",
|
|
Code = "",
|
|
Thickness = 30
|
|
};
|
|
return DoSave(EditRecord);
|
|
}
|
|
|
|
private async Task DoSave(GlassModel currRec)
|
|
{
|
|
// salvo
|
|
await CGService.UpsertAsync(currRec);
|
|
await ReloadDataAsync();
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
UpdateTable();
|
|
}
|
|
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await CGService.GetAllAsync();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (string.IsNullOrEmpty(SearchVal))
|
|
{
|
|
SearchRecords = AllRecords
|
|
.OrderBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = AllRecords
|
|
.Where(x =>
|
|
x.Description.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.Code.Contains(SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.OrderBy(x => x.Description)
|
|
.ToList();
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
// fix paginazione
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |