Files
Samuele Locatelli 627a9297f7 Update calcolo quantità
fix display cambio pagina
2024-07-04 15:17:46 +02:00

224 lines
6.6 KiB
C#

using EgwCoreLib.Razor;
using MagMan.Data.Admin.DbModels;
using MagMan.Data.Admin.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace MagMan.UI.Components
{
public partial class AuthKeyMan
{
#region Public Properties
[Parameter]
public int CustomerId { get; set; } = 0;
#endregion Public Properties
#region Protected Properties
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
[Inject]
protected MTAdminService MTService { get; set; } = null!;
protected int totalCount { get; set; } = 0;
#endregion Protected Properties
#region Protected Methods
protected string CheckSel(AuthKeyModel curItem)
{
string answ = "";
if (CurrItem != null)
{
answ = curItem.AuthKeyID == CurrItem.AuthKeyID ? "table-info" : "";
}
return answ;
}
protected async Task CreateNew()
{
CurrItem = new AuthKeyModel()
{
KeyNum = 0,
KeyValue = "S-Value",
Note = "...",
CustomerID = CustomerId
};
await InvokeAsync(StateHasChanged);
}
protected async Task DeleteRecord(AuthKeyModel selItem)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
return;
await MTService.AuthKeyDelete(selItem);
await ReloadData();
}
protected void DoEdit(AuthKeyModel? selItem)
{
CurrItem = selItem;
}
protected async Task ForceReload(bool force)
{
CurrItem = null;
await ReloadData();
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
protected async Task SetNumRec(int newNum)
{
numRecord = newNum;
await Task.Delay(1);
currPage = 1;
}
protected async Task SetPage(int newNum)
{
await Task.Delay(1);
currPage = newNum;
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private AuthKeyModel? CurrItem = null;
private List<AuthKeyModel>? ListRecords = null;
private List<AuthKeyModel>? SearchRecords = null;
private bool sortAsc = true;
private string sortField = "";
#endregion Private Fields
#region Private Properties
private int currPage { get; set; } = 1;
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 10;
#endregion Private Properties
#region Private Methods
private async Task ReloadData()
{
isLoading = true;
ListRecords = null;
SearchRecords = await MTService.AuthKeyByCustId(CustomerId);
totalCount = SearchRecords.Count;
SortTable();
isLoading = false;
}
private void SortTable()
{
if (SearchRecords != null)
{
// se ho ordinamento riordino...
if (!string.IsNullOrEmpty(sortField))
{
switch (sortField)
{
case "CustomerID":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.CustomerID).ThenBy(x => x.AuthKeyID).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.CustomerID).ThenByDescending(x => x.AuthKeyID).ToList();
}
break;
case "Note":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.Note).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.Note).ToList();
}
break;
case "DtActivation":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.DtActivation).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.DtActivation).ToList();
}
break;
case "KeyName":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.KeyNum).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.KeyNum).ToList();
}
break;
case "KeyValue":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.KeyValue).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.KeyValue).ToList();
}
break;
default:
break;
}
}
// filtro x display
ListRecords = SearchRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
else
{
ListRecords = new List<AuthKeyModel>();
}
}
private string textCss(bool isActive)
{
return isActive ? "text-dark" : "text-secondary text-decoration-line-through";
}
#endregion Private Methods
}
}