You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.4 KiB

using BlazorApp1.Modals;
using BlazorApp1.Sevices;
using Blazored.LocalStorage;
using Blazored.Modal;
using Blazored.Modal.Services;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
namespace BlazorApp1.Components
{
public partial class Inventory
{
[Parameter]
public List<Item> Items { get; set; }
public Item CurrentDragItem { get; set; }
public ItemDisplay CurrentEllement { get; set; }
[Inject]
public ILocalStorageService LocalStorage { get; set; }
public List<String> InventoryItems { get; set; } = new List<String>() { null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null
};
public List<int> InventoryNbElems { get; set; } = new List<int>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
public int CurrenttmpNbElem { get; set; }
public void StateChange()
{
StateHasChanged();
LocalStorage.SetItemAsync("dataInv", InventoryItems);
LocalStorage.SetItemAsync("dataNbInv", InventoryNbElems);
}
protected override async Task OnInitializedAsync()
{
try
{
var currentNumberData = await LocalStorage.GetItemAsync<List<int>>("dataNbInv");
var currentData = await LocalStorage.GetItemAsync<List<String>>("dataInv");
if (currentData != null)
{
InventoryItems = await LocalStorage.GetItemAsync<List<String>>("dataInv");
}
if (currentNumberData != null )
{
InventoryNbElems = await LocalStorage.GetItemAsync<List<int>>("dataNbInv");
}
}
catch (Exception)
{
throw;
}
StateHasChanged();
}
public Item getItem(String name)
{
int indice = 0;
foreach (Item i in Items)
{
if (i.Name == name)
{
return Items[indice];
}
indice++;
}
return null;
}
public String getNameCurrentItem()
{
if (CurrentDragItem != null) {
return CurrentDragItem.Name;
}
return null;
}
}
}