Files
2023-03-02 18:00:28 +01:00

398 lines
10 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.JSInterop;
using StockMan.CORE.Data;
using StockMan.Data.DbModels;
namespace StockMan.CORE.Components
{
public partial class ItemList : IDisposable
{
#region Public Properties
[Parameter]
public ItemSelectFilter actFilter { get; set; } = new ItemSelectFilter();
public List<ItemFamilyModel>? itemFamList { get; set; } = null;
public List<ItemModel>? ListRecord { get; set; } = null;
public List<ItemModel>? SearchRecords { get; set; } = null;
[Parameter]
public EventCallback<int> updateRecordCount { get; set; }
#endregion Public Properties
#region Public Methods
public void Dispose()
{
SearchRecords = null;
ListRecord = null;
GC.Collect();
}
#endregion Public Methods
#region Protected Fields
protected string _codArt = "";
protected string _codForn = "";
protected int? _currItem;
protected string _descArt = "";
protected string _descForn = "";
protected string _famArt = "";
protected int _lottoGiac = 0;
protected int _minGiac = 0;
protected string _searchFamily = "";
protected string _searchVal = "";
protected string _uM = "";
protected decimal _valoreUnit = 0;
protected bool isCodExtAscending = false;
protected bool isCodIntAscending = false;
protected bool isLoading = false;
protected bool isStockAscending = false;
protected orderTypeEnum orderType = orderTypeEnum.none;
#endregion Protected Fields
#region Protected Enums
protected enum orderTypeEnum
{
none = 1,
stockAscending,
stockDescending,
codExtAscending,
codExtDescending,
codIntAscending,
codIntDescending
}
#endregion Protected Enums
#region Protected Properties
protected string codArt
{
get => _codArt;
set { _codArt = value; }
}
protected string codForn
{
get => _codForn;
set { _codForn = value; }
}
protected int? currItem
{
get => _currItem;
set => _currItem = value;
}
protected string descArt
{
get => _descArt;
set { _descArt = value; }
}
protected string descForn
{
get => _descForn;
set { _descForn = value; }
}
protected string famArt
{
get => _famArt;
set { _famArt = value; }
}
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
protected int lottoGiac
{
get => _lottoGiac;
set { _lottoGiac = value; }
}
protected int minGiac
{
get => _minGiac;
set { _minGiac = value; }
}
[Inject]
protected NavigationManager NavManager { get; set; } = null!;
protected string rawCode
{
get
{
string answ = "";
answ = $"itemDetails?ItemID={currItem}";
return answ;
}
}
[Inject]
protected StockDataService SDService { get; set; } = null!;
//protected string searchFamily
//{
// get => _searchFamily;
// set
// {
// _searchFamily = value;
// currPage = 1;
// StateHasChanged();
// }
//}
//protected string searchVal
//{
// get => _searchVal;
// set
// {
// _searchVal = value;
// currPage = 1;
// StateHasChanged();
// }
//}
protected string uM
{
get => _uM;
set { _uM = value; }
}
protected decimal valoreUnit
{
get => _valoreUnit;
set { _valoreUnit = value; }
}
#endregion Protected Properties
#region Protected Methods
protected async Task addNewItem()
{
ItemModel newRec = new ItemModel()
{
Descr = descArt,
CodInt = codArt,
ItemFamilyId = famArt,
CodExt = codForn,
DescrExt = descForn,
QtaMin = minGiac,
QtaBatch = lottoGiac,
CurrValue = valoreUnit,
Um = uM
};
var done = await SDService.ItemAdd(newRec);
if (done)
{
NavManager.NavigateTo(NavManager.Uri, true);
}
}
protected void dupItem(ItemModel itemDup)
{
if (itemDup != null)
{
codArt = itemDup.CodInt;
descArt = itemDup.Descr;
famArt = itemDup.ItemFamilyId;
codForn = itemDup.CodExt;
descForn = itemDup.DescrExt;
minGiac = itemDup.QtaMin;
lottoGiac = itemDup.QtaBatch;
valoreUnit = itemDup.CurrValue;
uM = itemDup.Um;
}
}
protected override async Task OnInitializedAsync()
{
await Task.Delay(1);
var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("itemFamId", out var _itemFamID))
{
searchFamily = _itemFamID;
}
else
{
searchFamily = "*";
}
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
}
protected async Task orderByCodForn()
{
isCodExtAscending = !isCodExtAscending;
if (isCodExtAscending)
{
orderType = orderTypeEnum.codExtAscending;
}
else
{
orderType = orderTypeEnum.codExtDescending;
}
await ReloadData();
}
protected async Task orderByCodInt()
{
isCodIntAscending = !isCodIntAscending;
if (isCodIntAscending)
{
orderType = orderTypeEnum.codIntAscending;
}
else
{
orderType = orderTypeEnum.codIntDescending;
}
await ReloadData();
}
protected async Task orderByStock()
{
isStockAscending = !isStockAscending;
if (isStockAscending)
{
orderType = orderTypeEnum.stockAscending;
}
else
{
orderType = orderTypeEnum.stockDescending;
}
await ReloadData();
}
#endregion Protected Methods
#region Private Properties
private int _totalCount { get; set; } = 0;
[Inject]
private IConfiguration Configuration { get; set; } = null!;
private int currPage
{
get => actFilter.CurrPage;
set => actFilter.CurrPage = value;
}
private int numRecord
{
get => actFilter.NumRec;
set => actFilter.NumRec = value;
}
private string searchVal
{
get => actFilter.searchValue;
set => actFilter.searchValue = value;
}
private string searchFamily
{
get => actFilter.itemFamily;
set => actFilter.itemFamily = value;
}
private int totalCount
{
get => _totalCount;
set
{
if (_totalCount != value)
{
_totalCount = value;
updateRecordCount.InvokeAsync(value);
}
}
}
#endregion Private Properties
#region Private Methods
private async Task ReloadData()
{
isLoading = true;
if (searchVal != "" || searchFamily != "*")
{
SearchRecords = await SDService.ItemsGetSearch(searchVal, searchFamily);
}
else
{
SearchRecords = await SDService.ItemsGetAll();
}
totalCount = SearchRecords.Count;
if (orderType == orderTypeEnum.stockAscending)
{
SearchRecords = SearchRecords.OrderBy(x => x.QtaBatch).ToList();
}
else if (orderType == orderTypeEnum.stockDescending)
{
SearchRecords = SearchRecords.OrderByDescending(x => x.QtaBatch).ToList();
}
else if (orderType == orderTypeEnum.codExtAscending)
{
SearchRecords = SearchRecords.OrderBy(x => x.CodExt).ToList();
}
else if (orderType == orderTypeEnum.stockDescending)
{
SearchRecords = SearchRecords.OrderByDescending(x => x.CodExt).ToList();
}
else if (orderType == orderTypeEnum.codIntAscending)
{
SearchRecords = SearchRecords.OrderBy(x => x.CodInt).ToList();
}
else if (orderType == orderTypeEnum.codIntDescending)
{
SearchRecords = SearchRecords.OrderByDescending(x => x.CodInt).ToList();
}
ListRecord = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
//itemFamList = await SDService.ItemFamilyGetAll();
await Task.Delay(1);
await InvokeAsync(() => StateHasChanged());
isLoading = false;
}
private async void selItemToDet(int selItem)
{
currItem = selItem;
await JSRuntime.InvokeAsync<object>("open", rawCode, "_blank");
}
#endregion Private Methods
//protected StringBuilder uriNew
}
}