204 lines
5.6 KiB
C#
204 lines
5.6 KiB
C#
using EgwCoreLib.Razor;
|
|
|
|
namespace Lux.UI.Components.Compo.Config
|
|
{
|
|
public partial class WoodMan
|
|
{
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<WoodModel> AllRecords = new();
|
|
private int currPage = 1;
|
|
private WoodModel? EditRecord = null;
|
|
private bool isLoading = false;
|
|
private List<WoodModel> ListRecords = new();
|
|
private int numRecord = 5;
|
|
private List<WoodModel> SearchRecords = new();
|
|
private WoodModel? 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
|
|
|
|
[Inject]
|
|
private IConfWoodService CWService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IDataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
private string searchVal { get; set; } = string.Empty;
|
|
|
|
private string SearchVal
|
|
{
|
|
get => searchVal;
|
|
set
|
|
{
|
|
if (searchVal != value)
|
|
{
|
|
searchVal = value;
|
|
UpdateTable();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private Task DoAdd()
|
|
{
|
|
// aggiungo un nuovo record in coda...
|
|
EditRecord = new WoodModel()
|
|
{
|
|
Description = "New Wood",
|
|
Code = "",
|
|
Type = 1
|
|
};
|
|
return DoSave(EditRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
private async Task DoDelete(WoodModel selRec)
|
|
{
|
|
mTitle = "Attenzione";
|
|
mMessage = "Sicuro di voler eliminare il record?\n" +
|
|
$"Dettagli: {selRec.WoodID} | {selRec.Description} | Tipo: {selRec.Type}";
|
|
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 CWService.DeleteAsync(selRec);
|
|
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
await ReloadDataAsync();
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Edit articolo selezionato
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private void DoEdit(WoodModel curRec)
|
|
{
|
|
EditRecord = curRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset selezione
|
|
/// </summary>
|
|
private void DoReset()
|
|
{
|
|
EditRecord = null;
|
|
}
|
|
|
|
private async Task DoSave(WoodModel currRec)
|
|
{
|
|
// salvo
|
|
await CWService.UpsertAsync(currRec);
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
EditRecord = null;
|
|
SelRecord = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Selezione articolo x display info
|
|
/// </summary>
|
|
/// <param name="curRec"></param>
|
|
private void DoSelect(WoodModel curRec)
|
|
{
|
|
SelRecord = curRec;
|
|
}
|
|
|
|
private async Task ReloadDataAsync()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await CWService.GetAllAsync();
|
|
}
|
|
|
|
private Task ResetEdit()
|
|
{
|
|
// reset edit
|
|
EditRecord = null;
|
|
return ReloadDataAsync();
|
|
}
|
|
|
|
private void ResetSearch()
|
|
{
|
|
SearchVal = "";
|
|
}
|
|
|
|
private void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
private void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
/// <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
|
|
}
|
|
} |