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

315 lines
9.2 KiB
C#

using EgwCoreLib.Razor;
using MagMan.Core.Services;
using MagMan.Data.Tenant.DbModels;
using MagMan.Data.Tenant.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace MagMan.UI.Components
{
public partial class MovMag : IDisposable
{
#region Public Properties
[Parameter]
public int CustomerId { get; set; } = 0;
[Parameter]
public int KeyNum { get; set; } = 0;
[Parameter]
public RawItemModel RawItemSel { get; set; } = null!;
#endregion Public Properties
#region Public Methods
public void Dispose()
{
AppMService.EA_SearchUpdated -= AppMService_EA_SearchUpdated;
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected MessageService AppMService { get; set; } = null!;
[Inject]
protected IConfiguration Configuration { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected int totalCount { get; set; } = 0;
[Inject]
protected TenantService TService { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected string CheckSel(MovMagModel curItem)
{
string answ = "";
if (CurrItem != null)
{
answ = curItem.MovID == CurrItem.MovID ? "table-info" : "";
}
else
{
answ = curItem.MovID == MovId ? "table-info" : "";
}
return answ;
}
#if false
protected async Task CreateNew()
{
CurrItem = new RawItemModel()
{
MatId = MaterialSel.MatId,
Location = "nd",
Note = "...",
QtyAvail = 0,
IsActive = true,
IsRemn = false,
HMm = MaterialSel.HMm,
LMm = MaterialSel.LMm,
WMm = MaterialSel.WMm
};
await InvokeAsync(StateHasChanged);
}
protected async Task DeleteRecord(RawItemModel selItem)
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
return;
await TService.ItemDelete(KeyNum, selItem);
await ReloadData();
}
protected void DoEdit(RawItemModel? selItem)
{
CurrItem = selItem;
if (selItem == null)
{
DoSelect(null);
}
}
protected void DoSelect(RawItemModel? selItem)
{
if (selItem != null)
{
RawItemId = selItem.MatId;
}
else
{
RawItemId = 0;
}
E_RawItemSel.InvokeAsync(RawItemId);
}
#endif
protected async Task ForceReload(bool force)
{
CurrItem = null;
await ReloadData();
}
protected override async Task OnInitializedAsync()
{
currSearch = "";
AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated;
numRecord = await AppMService.NumRowGridGet(gridKey);
}
protected override async Task OnParametersSetAsync()
{
CurrItem = null;
await ReloadData();
}
protected async Task SetNumRec(int newNum)
{
numRecord = newNum;
currPage = 1;
await AppMService.NumRowGridSet(gridKey, newNum);
await InvokeAsync(ReloadData);
}
protected async Task SetPage(int newNum)
{
currPage = newNum;
await InvokeAsync(ReloadData);
}
protected async Task SortRequested(Sorter.SortCallBack e)
{
sortField = e.ParamName;
sortAsc = e.IsAscending;
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private MovMagModel? CurrItem = null;
private string currSearch = "";
private int filtType = 0;
private string gridKey = "MovMag";
private List<MovMagModel>? ListRecords = null;
private int MovId = 0;
private List<MovMagModel>? SearchRecords = null;
private bool sortAsc = true;
private string sortField = "";
#endregion Private Fields
#region Private Properties
private int currPage { get; set; } = 1;
private int FiltType
{
get => filtType;
set
{
if (filtType != value)
{
filtType = value;
InvokeAsync(ReloadData);
InvokeAsync(StateHasChanged);
}
}
}
private bool isLoading { get; set; } = false;
private int numRecord { get; set; } = 10;
#endregion Private Properties
#region Private Methods
private async void AppMService_EA_SearchUpdated()
{
currSearch = AppMService.SearchVal;
await ReloadData();
}
private async Task ReloadData()
{
isLoading = true;
await InvokeAsync(StateHasChanged);
ListRecords = null;
if (RawItemSel != null)
{
SearchRecords = await TService.MovMagGetFilt(KeyNum, RawItemSel.RawItemId, 1000);
// verifico filtro per ricerca
if (!string.IsNullOrEmpty(currSearch))
{
SearchRecords = SearchRecords.Where(x => x.Note.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList();
}
totalCount = SearchRecords.Count;
}
SortTable();
isLoading = false;
await InvokeAsync(StateHasChanged);
}
private void SortTable()
{
if (SearchRecords != null)
{
// se ho ordinamento riordino...
if (!string.IsNullOrEmpty(sortField))
{
switch (sortField)
{
case "MovId":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.RawItemId).ThenBy(x => x.Note).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.RawItemId).ThenByDescending(x => x.Note).ToList();
}
break;
case "DtRec":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.DtRec).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.DtRec).ToList();
}
break;
case "QtyRec":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.QtyRec).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.QtyRec).ToList();
}
break;
case "Note":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.Note).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.Note).ToList();
}
break;
case "UserId":
if (sortAsc)
{
SearchRecords = SearchRecords.OrderBy(x => x.UserId).ToList();
}
else
{
SearchRecords = SearchRecords.OrderByDescending(x => x.UserId).ToList();
}
break;
default:
break;
}
}
// filtro x display
ListRecords = SearchRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
}
else
{
ListRecords = new List<MovMagModel>();
}
}
private string textCss(bool isActive)
{
return isActive ? "text-dark" : "text-secondary text-decoration-line-through";
}
#endregion Private Methods
}
}