Files
lux/Lux.UI/Components/Compo/OfferCommonPar.razor.cs
T
2026-03-24 12:55:16 +01:00

246 lines
7.8 KiB
C#

using EgwCoreLib.Lux.Core;
using EgwCoreLib.Lux.Core.RestPayload;
using EgwCoreLib.Lux.Data.DbModel.Sales;
using EgwCoreLib.Lux.Data.Services;
using EgwCoreLib.Lux.Data.Services.Config;
using EgwCoreLib.Lux.Data.Services.General;
using EgwCoreLib.Lux.Data.Services.Utils;
using Microsoft.AspNetCore.Components;
namespace Lux.UI.Components.Compo
{
public partial class OfferCommonPar
{
#region Public Properties
[Parameter]
public OfferModel CurrRecord { get; set; } = null!;
[Parameter]
public EventCallback<bool> EC_Cancel { get; set; }
[Parameter]
public EventCallback<OfferModel> EC_Updated { get; set; }
#endregion Public Properties
#region Protected Methods
protected override void OnInitialized()
{
setOriginal();
ConfInit();
}
protected override async Task OnParametersSetAsync()
{
setOriginal();
isLoading = true;
// deserializzo se possibile dal record...
CurrSel = new ParamDict(CurrRecord.DictPresel);
// leggo dati di base
var AllColors = await GVService.GetFiltAsync("WoodCol");
var AllConfGlass = await CGService.GetAllAsync();
var AllConfProfile = await CDService.ProfileListAsync(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "Default");
// se fosse vuoto chiamo update...
if (AllConfProfile == null || AllConfProfile.Count == 0)
{
await callRefreshProfList();
// aspetto 200ms... e richiedo!
await Task.Delay(200);
AllConfProfile = await CDService.ProfileListAsync(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "Default");
}
var AllConfWood = await CWService.GetAllAsync();
// conversione tipi
ListColors = AllColors
.Select(x => x.ValString)
.ToList();
ListGlass = AllConfGlass
.Select(x => x.Description)
.ToList();
ListProfiles = AllConfProfile;
ListWood = AllConfWood
.Select(x => x.Description)
.ToList();
isLoading = false;
}
#endregion Protected Methods
#region Private Fields
private string apiUrl = "";
private string calcTag = "calc";
private EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS cEnvir = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
private ParamDict CurrSel = new ParamDict("");
private string genericBasePath = "";
private bool isLoading = false;
private List<string> ListColors = new List<string>();
private List<string> ListGlass = new List<string>();
private List<string> ListProfiles = new List<string>();
private List<string> ListWood = new List<string>();
private ParamDict? OrigSel = null;
#endregion Private Fields
#region Private Properties
[Inject]
private IConfigDataService CDService { get; set; } = null!;
[Inject]
private IConfiguration Config { get; set; } = null!;
[Inject]
private ICalcRuidService CRService { get; set; } = null!;
[Inject]
private ICalcRequestService CService { get; set; } = null!;
[Inject]
private IDataLayerServices DLService { get; set; } = null!;
[Inject]
private IConfGlassService CGService { get; set; } = null!;
[Inject]
private IConfWoodService CWService { get; set; } = null!;
[Inject]
private IGenValService GVService { get; set; } = null!;
/// <summary>
/// Gestione selezione Colore
/// </summary>
private string SelColor
{
get => CurrSel.GetVal("Color");
set => CurrSel.SetVal("Color", value);
}
/// <summary>
/// Gestione selezione Glass
/// </summary>
private string SelGlass
{
get => CurrSel.GetVal("Glass");
set => CurrSel.SetVal("Glass", value);
}
/// <summary>
/// Gestione selezione Profile
/// </summary>
private string SelProfile
{
get => CurrSel.GetVal("Profile");
set => CurrSel.SetVal("Profile", value);
}
/// <summary>
/// Gestione selezione Wood
/// </summary>
private string SelWood
{
get => CurrSel.GetVal("Wood");
set => CurrSel.SetVal("Wood", value);
}
#endregion Private Properties
#region Private Methods
/// <summary>
/// Effettua vera richiesta della BOM
/// </summary>
/// <returns></returns>
private async Task callRefreshProfList()
{
Dictionary<string, string> DictExec = new Dictionary<string, string>();
var cMode = Egw.Window.Data.Enums.QuestionModes.CONFIG;
var cSubMode = Egw.Window.Data.Enums.QuestionConfSubModes.PROFILELIST;
// compongo righiesta
string reqUid = "Default";
DictExec.Add("Mode", $"{(int)cMode}");
DictExec.Add("UID", reqUid);
// creo registrazione richiesta...
var ruid = await CRService.AddRequestAsync($"{cEnvir}", $"{cMode}-{cSubMode}", reqUid);
// aggiungo RUID effettivo
DictExec.Add("RUID", ruid);
DictExec.Add("SubMode", $"{(int)cSubMode}");
CalcRequestDTO req = new CalcRequestDTO()
{
EnvType = cEnvir,
DictExec = DictExec
};
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
await CService.CallRestPost($"{apiUrl}/{genericBasePath}", $"{calcTag}/{reqUid}", req);
}
private void ConfInit()
{
apiUrl = Config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "";
genericBasePath = Config.GetValue<string>("ServerConf:GenericBaseUrl") ?? "";
calcTag = Config.GetValue<string>("ServerConf:CalcTag") ?? "calc";
}
private bool HasChanged()
{
bool answ = false;
if (OrigSel != null && CurrRecord != null)
{
if (IsChanged(OrigSel.GetVal("Profile"), SelProfile))
return true;
if (IsChanged(OrigSel?.GetVal("Glass"), SelGlass))
return true;
if (IsChanged(OrigSel?.GetVal("Wood"), SelWood))
return true;
if (IsChanged(OrigSel?.GetVal("Color"), SelColor))
return true;
}
return answ;
}
/// <summary>
/// Verifica variazione tramite helper
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="original"></param>
/// <param name="edited"></param>
/// <returns></returns>
private bool IsChanged<T>(T original, T edited) => CloneExtensions.IsChanged(original, edited);
private void setOriginal()
{
if (CurrRecord != null && OrigSel == null)
{
// deserializzo se possibile dal record...
OrigSel = new ParamDict(CurrRecord.DictPresel);
}
}
private Task DoCancel()
{
return EC_Cancel.InvokeAsync(true);
}
private Task DoSave()
{
// aggiorno valore serializzato...
CurrRecord.DictPresel = CurrSel.Serialized;
// richiesta update con salvataggio record
return EC_Updated.InvokeAsync(CurrRecord);
}
#endregion Private Methods
}
}