627a9297f7
fix display cambio pagina
230 lines
6.8 KiB
C#
230 lines
6.8 KiB
C#
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this
|
|
// file to you under the MIT license.
|
|
using EgwCoreLib.Razor;
|
|
using MagMan.Data.Admin.DbModels;
|
|
using MagMan.Data.Admin.Services;
|
|
using MagMan.Data.Tenant.DbModels;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
|
|
namespace MagMan.UI.Components
|
|
{
|
|
public partial class MachineMan
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public int CustomerId { get; set; } = 0;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected IConfiguration Configuration { get; set; } = null!;
|
|
|
|
[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(MachineModel curItem)
|
|
{
|
|
string answ = "";
|
|
if (CurrItem != null)
|
|
{
|
|
answ = curItem.MachineID == CurrItem.MachineID ? "table-info" : "";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected async Task CreateNew()
|
|
{
|
|
CurrItem = new MachineModel()
|
|
{
|
|
Name = "Nuova Macchina",
|
|
Note = "...",
|
|
MainKey = 0,
|
|
CustomerID = CustomerId
|
|
};
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async Task DeleteRecord(MachineModel selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
await MTService.MachineDelete(selItem);
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void DoEdit(MachineModel? 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 MachineModel? CurrItem = null;
|
|
|
|
private List<MachineModel>? ListRecords = null;
|
|
|
|
private List<MachineModel>? 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.MachineGetByCustId(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.MachineID).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.CustomerID).ThenByDescending(x => x.MachineID).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 "Name":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.Name).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.Name).ToList();
|
|
}
|
|
break;
|
|
|
|
case "MainKey":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.MainKey).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.MainKey).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// filtro x display
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<MachineModel>();
|
|
}
|
|
}
|
|
|
|
private string textCss(bool isActive)
|
|
{
|
|
return isActive ? "text-dark" : "text-secondary text-decoration-line-through";
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |