Files
lux/Lux.UI/Components/Compo/OfferRowMan.razor.cs
T
2025-09-16 19:16:21 +02:00

141 lines
4.0 KiB
C#

using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data;
using EgwCoreLib.Lux.Data.DbModel;
using EgwCoreLib.Lux.Data.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using static EgwCoreLib.Lux.Core.Enums;
namespace Lux.UI.Components.Compo
{
public partial class OfferRowMan
{
#region Public Properties
[Parameter]
public DisplayMode DisplayMode { get; set; } = DisplayMode.Standard;
[Parameter]
public int OfferID { get; set; } = 0;
#endregion Public Properties
#region Protected Properties
[Inject]
protected IConfiguration Config { get; set; } = null!;
[Inject]
protected DataLayerServices DLService { get; set; } = null!;
[Inject]
protected ImageCacheService ICService { get; set; } = null!;
[Inject]
protected IJSRuntime JSRuntime { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected void DoEdit(OfferRowModel curRec)
{
EditRecord = curRec;
}
protected string imgUrl(string imgUid, string env)
{
// cast string su env..
EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS envir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
Enum.TryParse(env, out envir);
return ICService.ImageUrl($"{apiUrl}/{imgBasePath}", false, imgUid, envir);
}
protected override void OnInitialized()
{
apiUrl = Config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "";
imgBasePath = Config.GetValue<string>("ServerConf:ImageBaseUrl") ?? "";
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
UpdateTable();
}
protected async Task RecalcOffer()
{
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler ricalcolare importi offerta?"))
return;
isLoading = true;
await DLService.OffertUpdateCost(OfferID);
await Task.Delay(50);
await ReloadData();
UpdateTable();
isLoading = false;
}
#endregion Protected Methods
protected void ClosePopup()
{
showChangeMat = false;
EditBomRecord = null;
}
protected void DoSwapMat(OfferRowModel currRow)
{
showChangeMat = true;
EditBomRecord = currRow;
CurrBomList = DLService.OffertGetBomList(EditBomRecord);
}
#region Private Fields
private bool showChangeMat = false;
private List<BomItemDTO>? CurrBomList = null;
private List<OfferRowModel> AllRecords = new List<OfferRowModel>();
private string apiUrl = "";
private int currPage = 1;
private OfferRowModel? EditRecord = null;
private OfferRowModel? EditBomRecord = null;
private string imgBasePath = "";
private bool isLoading = false;
private List<OfferRowModel> ListRecords = new List<OfferRowModel>();
private int numRecord = 10;
private int totalCount = 0;
#endregion Private Fields
#region Private Methods
/// <summary>
/// Legge i dati dei record completi
/// </summary>
private async Task ReloadData()
{
if (OfferID > 0)
{
AllRecords = await DLService.OfferRowGetByOffer(OfferID);
totalCount = AllRecords.Count();
}
}
/// <summary>
/// Filtro e paginazione
/// </summary>
private void UpdateTable()
{
// fix paginazione
ListRecords = AllRecords
.Skip(numRecord * (currPage - 1))
.Take(numRecord)
.ToList();
isLoading = false;
}
#endregion Private Methods
}
}