namespace Lux.UI.Components.Compo.Offer { public partial class OfferCommonPar { #region Public Properties [Parameter] public OfferModel CurrRecord { get; set; } = null!; [Parameter] public bool ForceMode { get; set; } = false; [Parameter] public EventCallback EC_Cancel { get; set; } [Parameter] public EventCallback EC_Updated { get; set; } [Parameter] public EventCallback> EC_Overwrite { 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 ParamDictFlex CurrForced = new ParamDictFlex(""); private string genericBasePath = ""; private bool isLoading = false; private List ListColors = new List(); private List ListGlass = new List(); private List ListProfiles = new List(); private List ListWood = new List(); 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!; private bool ForceColor { get => CurrForced.GetVal("Color"); set => CurrForced.SetVal("Color", value); } private bool ForceProfile { get => CurrForced.GetVal("Profile"); set => CurrForced.SetVal("Profile", value); } private bool ForceGlass { get => CurrForced.GetVal("Glass"); set => CurrForced.SetVal("Glass", value); } private bool ForceWood { get => CurrForced.GetVal("Wood"); set => CurrForced.SetVal("Wood", value); } /// /// Gestione selezione Colore /// private string SelColor { get => CurrSel.GetVal("Color"); set => CurrSel.SetVal("Color", value); } /// /// Gestione selezione Glass /// private string SelGlass { get => CurrSel.GetVal("Glass"); set => CurrSel.SetVal("Glass", value); } /// /// Gestione selezione Profile /// private string SelProfile { get => CurrSel.GetVal("Profile"); set => CurrSel.SetVal("Profile", value); } /// /// Gestione selezione Wood /// private string SelWood { get => CurrSel.GetVal("Wood"); set => CurrSel.SetVal("Wood", value); } #endregion Private Properties #region Private Methods /// /// Effettua vera richiesta della BOM /// /// private async Task callRefreshProfList() { Dictionary DictExec = new Dictionary(); 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("ServerConf:Prog.ApiUrl") ?? ""; genericBasePath = Config.GetValue("ServerConf:GenericBaseUrl") ?? ""; calcTag = Config.GetValue("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; } /// /// Verifica variazione tramite helper /// /// /// /// /// private bool IsChanged(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 async Task DoSave() { // aggiorno valore serializzato... CurrRecord.DictPresel = CurrSel.Serialized; // richiesta update con salvataggio record await EC_Updated.InvokeAsync(CurrRecord); // invio l'oggetto della selezione forzata... var readOnly = CurrForced.AsReadOnly(); if (readOnly != null && readOnly.Count > 0) { Dictionary forcedDict = new Dictionary(readOnly); await EC_Overwrite.InvokeAsync(forcedDict); } } #endregion Private Methods } }