212 lines
5.8 KiB
C#
212 lines
5.8 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Data.DbModel;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace Lux.UI.Components.Compo
|
|
{
|
|
public partial class ItemMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public List<ItemGroupModel> ListItemGroup { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public FiltSelect SelFilt { get; set; } = null!;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Classes
|
|
|
|
/// <summary>
|
|
/// Filtro selezione items
|
|
/// </summary>
|
|
public class FiltSelect
|
|
{
|
|
#region Public Properties
|
|
|
|
public string SearchVal { get; set; } = "";
|
|
public string SelCodGroup { get; set; } = "";
|
|
public Enums.ItemClassType SelType { get; set; } = Enums.ItemClassType.ND;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj == null)
|
|
return false;
|
|
if (!(obj is FiltSelect item))
|
|
return false;
|
|
|
|
if (SelCodGroup != item.SelCodGroup)
|
|
return false;
|
|
|
|
if (SelType != item.SelType)
|
|
return false;
|
|
|
|
if (SearchVal != item.SearchVal)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
|
|
#endregion Public Classes
|
|
|
|
#region Protected Fields
|
|
|
|
protected List<ItemModel> AllRecords = new List<ItemModel>();
|
|
#if false
|
|
protected List<ItemGroupModel> ListItemGroup = new List<ItemGroupModel>();
|
|
#endif
|
|
protected List<ItemModel> ListRecords = new List<ItemModel>();
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected DataLayerServices DLService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// impossta record x eliminazione
|
|
/// </summary>
|
|
/// <param name="selRec"></param>
|
|
protected async Task DoDelete(ItemModel selRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler eliminare il record? Dettagli: {selRec.ItemID} | {selRec.CodGroup} | {selRec.ItemType} | {selRec.ExtItemCode}"))
|
|
return;
|
|
//// esegue eliminazione del record...
|
|
//await DLService.ItemDeleteAsync(selRec);
|
|
|
|
editRecord = null;
|
|
selRecord = null;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void DoEdit(ItemModel curRec)
|
|
{
|
|
editRecord = curRec;
|
|
}
|
|
|
|
protected void DoReset()
|
|
{
|
|
editRecord = null;
|
|
}
|
|
|
|
protected void DoSelect(ItemModel curRec)
|
|
{
|
|
selRecord = curRec;
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (!SelFilt.Equals(actFilt) || true)
|
|
{
|
|
actFilt = SelFilt;
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
protected void SaveNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
protected void SavePage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
UpdateTable();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private FiltSelect actFilt = new FiltSelect();
|
|
private int currPage = 1;
|
|
private ItemModel? editRecord = null;
|
|
private bool isLoading = false;
|
|
private int numRecord = 10;
|
|
private ItemModel? selRecord = null;
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private async Task DoCancel()
|
|
{
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
}
|
|
|
|
private async Task DoSave(ItemModel currRec)
|
|
{
|
|
// salvo
|
|
await DLService.ItemUpsertAsync(currRec);
|
|
await ResetEdit();
|
|
UpdateTable();
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
isLoading = true;
|
|
AllRecords = await DLService.ItemGetFiltAsync(actFilt.SelCodGroup, actFilt.SelType);
|
|
// se ho ricerca testuale faccio filtro ulteriore...
|
|
if (!string.IsNullOrEmpty(actFilt.SearchVal))
|
|
{
|
|
AllRecords = AllRecords
|
|
.Where(x =>
|
|
x.Description.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.ExtItemCode.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase) ||
|
|
x.SupplCode.Contains(actFilt.SearchVal, StringComparison.InvariantCultureIgnoreCase))
|
|
.ToList();
|
|
}
|
|
totalCount = AllRecords.Count;
|
|
}
|
|
|
|
private async Task ResetEdit()
|
|
{
|
|
// reset edit
|
|
editRecord = null;
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |