198 lines
5.6 KiB
C#
198 lines
5.6 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using StockMan.CORE.Data;
|
|
using StockMan.Data.DbModels;
|
|
|
|
namespace StockMan.CORE.Components
|
|
{
|
|
public partial class ItemFamList
|
|
{
|
|
#region Public Properties
|
|
|
|
//[Parameter]
|
|
//public int NumRecord { get; set; } = 10;
|
|
//[Parameter]
|
|
//public int CurrPage { get; set; } = 1;
|
|
[Parameter]
|
|
public ItemFamSelectFilter actFilter { get; set; } = new ItemFamSelectFilter();
|
|
|
|
public List<ItemFamilyModel>? ListRecord { get; set; } = null;
|
|
|
|
public List<ItemFamilyModel>? SearchRecords { get; set; } = null;
|
|
|
|
[Parameter]
|
|
public EventCallback<ItemFamilyModel> selectedItemFam { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<int> updateRecordCount { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
protected ItemFamilyModel? _currModel = null;
|
|
protected string currRowSel = "";
|
|
protected bool editMode = false;
|
|
protected bool isLoading = false;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected string _descrizione { get; set; } = "";
|
|
protected string _idUnivoco { get; set; } = "";
|
|
|
|
protected ItemFamilyModel? currModel
|
|
{
|
|
get => _currModel;
|
|
set => _currModel = value;
|
|
}
|
|
|
|
protected string descrizione
|
|
{
|
|
get => _descrizione;
|
|
set => _descrizione = value;
|
|
}
|
|
|
|
protected string idUnivoco
|
|
{
|
|
get => _idUnivoco;
|
|
set => _idUnivoco = value;
|
|
}
|
|
|
|
protected ItemSelectFilter itemFilter { get; set; } = new ItemSelectFilter();
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected NavigationManager NavManager { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected StockDataService SDService { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task addNewItem()
|
|
{
|
|
ItemFamilyModel newRec = new ItemFamilyModel() { Id = idUnivoco, Descr = descrizione };
|
|
var done = await SDService.ItemFamilyAdd(newRec);
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
|
|
protected async Task deleteItemFam(ItemFamilyModel currRec)
|
|
{
|
|
var ok = await JSRuntime.InvokeAsync<bool>("confirm", $"Confermare di voler eliminare la famiglia articoli: {currRec.Id}");
|
|
|
|
if (ok)
|
|
{
|
|
var done = await SDService.ItemFamilyDeleteByID(currRec);
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
}
|
|
|
|
protected async Task editItemFam(ItemFamilyModel selRec)
|
|
{
|
|
await SDService.ItemFamilyMod(selRec);
|
|
NavManager.NavigateTo(NavManager.Uri, true);
|
|
}
|
|
|
|
//protected override async Task OnInitializedAsync()
|
|
//{
|
|
// //ListRecord = await SDService.ItemFamilyGetAll();
|
|
//}
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
//lastFilter = actFilter.clone();
|
|
await reloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
private int _totalCount { get; set; } = 0;
|
|
|
|
private int currPage
|
|
{
|
|
get => actFilter.CurrPage;
|
|
set => actFilter.CurrPage = value;
|
|
}
|
|
|
|
private int numRecord
|
|
{
|
|
get => actFilter.NumRec;
|
|
set => actFilter.NumRec = value;
|
|
}
|
|
|
|
private int totalCount
|
|
{
|
|
get => _totalCount;
|
|
set
|
|
{
|
|
if (_totalCount != value)
|
|
{
|
|
_totalCount = value;
|
|
updateRecordCount.InvokeAsync(value);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task disableEdit()
|
|
{
|
|
await Task.Delay(1);
|
|
editMode = false;
|
|
//await JSRuntime.InvokeVoidAsync("noEditing", currRowSel);
|
|
}
|
|
|
|
//protected void changeEditMode(bool isEditing)
|
|
//{
|
|
// editMode = isEditing;
|
|
//}
|
|
private async Task enableEdit(string id)
|
|
{
|
|
await Task.Delay(1);
|
|
editMode = true;
|
|
//await JSRuntime.InvokeVoidAsync("isEditing", id);
|
|
currRowSel = id;
|
|
}
|
|
|
|
private async Task reloadData()
|
|
{
|
|
isLoading = true;
|
|
SearchRecords = await SDService.ItemFamilyGetAll();
|
|
totalCount = SearchRecords.Count;
|
|
ListRecord = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
|
await Task.Delay(1);
|
|
await InvokeAsync(() => StateHasChanged());
|
|
isLoading = false;
|
|
}
|
|
|
|
private async Task selectItem(ItemFamilyModel item)
|
|
{
|
|
//if (currRowSel == "")
|
|
//{
|
|
// currRowSel = id;
|
|
//}
|
|
//await JSRuntime.InvokeVoidAsync("unSelectItem", currRowSel);
|
|
//editMode = false;
|
|
//currRowSel = "";
|
|
//if (currRowSel != id)
|
|
//{
|
|
// await JSRuntime.InvokeVoidAsync("selectItem", id);
|
|
//}
|
|
currRowSel = item.Id;
|
|
currModel = item;
|
|
await selectedItemFam.InvokeAsync(currModel);
|
|
NavManager.NavigateTo($"AnagraficaArticoli?itemFamId={item.Id}", true);
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |