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 ClosePopup() { showChangeMat = false; EditBomRecord = null; } protected void DoEdit(OfferRowModel curRec) { EditRecord = curRec; } protected void DoSwapMat(OfferRowModel currRow) { showChangeMat = true; EditBomRecord = currRow; CurrBomList = DLService.OffertGetBomList(EditBomRecord); } 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("ServerConf:Prog.ApiUrl") ?? ""; imgBasePath = Config.GetValue("ServerConf:ImageBaseUrl") ?? ""; } protected override async Task OnParametersSetAsync() { await ReloadData(); UpdateTable(); } protected async Task RecalcOffer() { if (!await JSRuntime.InvokeAsync("confirm", $"Confermi di voler ricalcolare importi offerta?")) return; await DoRecalcOffer(); } #endregion Protected Methods #region Private Fields private List AllRecords = new List(); private string apiUrl = ""; private List? CurrBomList = null; private int currPage = 1; private OfferRowModel? EditBomRecord = null; private OfferRowModel? EditRecord = null; private string imgBasePath = ""; private bool isLoading = false; private List ListRecords = new List(); private int numRecord = 10; private bool showChangeMat = false; private int totalCount = 0; #endregion Private Fields #region Private Methods private async Task DoRecalcOffer() { isLoading = true; await DLService.OffertUpdateCost(OfferID); await Task.Delay(50); await ReloadData(); UpdateTable(); isLoading = false; } /// /// Legge i dati dei record completi /// private async Task ReloadData() { if (OfferID > 0) { AllRecords = await DLService.OfferRowGetByOffer(OfferID); totalCount = AllRecords.Count(); } } /// /// salva nel record corrente la BOM aggiornata e poi ricalcola importo... /// /// /// private async void UpdateBom(List newBomList) { if (EditBomRecord != null) { // salvo BOM nel record corrente... bool fatto = await DLService.OffertRowUpdateBom(EditBomRecord.OfferRowID, newBomList); // ricalcolo offerta completa await ReloadData(); UpdateTable(); } } /// /// Filtro e paginazione /// private void UpdateTable() { // fix paginazione ListRecords = AllRecords .Skip(numRecord * (currPage - 1)) .Take(numRecord) .ToList(); isLoading = false; } #endregion Private Methods } }