431 lines
14 KiB
C#
431 lines
14 KiB
C#
using EgwCoreLib.Lux.Core;
|
|
using EgwCoreLib.Lux.Core.RestPayload;
|
|
using EgwCoreLib.Lux.Data;
|
|
using EgwCoreLib.Lux.Data.DbModel.Config;
|
|
using EgwCoreLib.Lux.Data.DbModel.Sales;
|
|
using EgwCoreLib.Lux.Data.DbModel.Utils;
|
|
using EgwCoreLib.Lux.Data.Services;
|
|
using EgwMultiEngineManager.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using static EgwCoreLib.Lux.Core.Enums;
|
|
|
|
namespace Lux.UI.Components.Compo
|
|
{
|
|
public partial class OfferRowMan : IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public DisplayMode DisplayMode { get; set; } = DisplayMode.Standard;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> EC_Updated { get; set; }
|
|
|
|
[Parameter]
|
|
public int OfferID { get; set; } = 0;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Dispose sottoscrizione canale
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
DLService.UpdatePipe.EA_NewMessage -= UpdatePipe_EA_NewMessage;
|
|
DLService.CalcDonePipe.EA_NewMessage -= CalcDonePipe_EA_NewMessage;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected ConfigDataService CDService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected IConfiguration Config { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected CalcRequestService CService { 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Calcolo URL immagine
|
|
/// </summary>
|
|
/// <param name="imgUid"></param>
|
|
/// <param name="env"></param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// init obj
|
|
/// </summary>
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ConfInit();
|
|
await ReloadBaseList();
|
|
DLService.UpdatePipe.EA_NewMessage += UpdatePipe_EA_NewMessage;
|
|
DLService.CalcDonePipe.EA_NewMessage += CalcDonePipe_EA_NewMessage;
|
|
}
|
|
|
|
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;
|
|
|
|
await DoRecalcOffer();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lancia la richiesta di ricaolo della BOM dal JWD (o equivalente)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected async Task RequestBom(OfferRowModel currRec)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Confermi di voler ricalcolare la BOM?"))
|
|
return;
|
|
|
|
// salvo richiesta BOM su record
|
|
currRec.AwaitBom = true;
|
|
currRec.AwaitPrice = true;
|
|
await DLService.OffertUpdateAwaitState(currRec.OfferRowID, true, true);
|
|
#if false
|
|
// devo recuperare da ofgferta environment corrente, ora cablato
|
|
EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS currEnv = EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW;
|
|
#endif
|
|
// preparo la domanda serializzata
|
|
Dictionary<string, string> DictExec = new Dictionary<string, string>();
|
|
// cablata la BOM
|
|
DictExec.Add("Mode", "2");
|
|
// UID cablato x ora...
|
|
DictExec.Add("UID", currRec.OfferRowUID);
|
|
DictExec.Add("Jwd", currRec.SerStruct);
|
|
|
|
CalcRequestDTO req = new CalcRequestDTO()
|
|
{
|
|
EnvType = currRec.Envir,
|
|
//EnvType = currEnv,
|
|
DictExec = DictExec
|
|
};
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
// chiamo la chiamata POST alla API, che manda la richiesta via REDIS
|
|
await CService.CallRestPost($"{apiUrl}/{genBasePath}", $"{calcTag}/{currRec.OfferRowUID}", req);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private List<GenValueModel> AllColors = new();
|
|
|
|
private List<GlassModel> AllConfGlass = new();
|
|
|
|
private List<HardwareModel> AllConfHardware = new();
|
|
|
|
private List<ProfileModel> AllConfProfile = new();
|
|
|
|
private List<WoodModel> AllConfWood = new();
|
|
|
|
private List<OfferRowModel> AllRecords = new List<OfferRowModel>();
|
|
|
|
private string apiUrl = "";
|
|
|
|
private List<string> AvailColorMaterialList = new List<string>();
|
|
|
|
private List<string> AvailGlassList = new List<string>();
|
|
|
|
private List<Egw.Window.Data.Hardware> AvailHardwareList = new();
|
|
|
|
private List<string> AvailMaterialList = new List<string>();
|
|
private List<string> AvailFamilyHardwareList = new List<string>();
|
|
|
|
|
|
private string calcTag = "calc";
|
|
|
|
private List<BomItemDTO>? CurrBomList = null;
|
|
|
|
private int currPage = 1;
|
|
|
|
private string currSvg = "";
|
|
|
|
private OfferRowModel? EditBomRecord = null;
|
|
|
|
private OfferRowModel? EditRecord = null;
|
|
|
|
private string genBasePath = "generic";
|
|
|
|
private string GenericBasePath = "";
|
|
|
|
private string imgBasePath = "";
|
|
|
|
private bool isLoading = false;
|
|
|
|
private List<OfferRowModel> ListRecords = new List<OfferRowModel>();
|
|
|
|
private int numRecord = 10;
|
|
|
|
private bool showChangeMat = false;
|
|
|
|
private string subChannel = "";
|
|
|
|
private int totalCount = 0;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Ricevuto SVG, se è il mio lo aggiorno...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private async void CalcDonePipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
// vale SOLO SE sono in editing...
|
|
if (EditRecord != null)
|
|
{
|
|
// aggiorno visualizzazione
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly SVG da mostrare
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
if (currArgs.msgUid.Equals($"{subChannel}:{EditRecord.OfferRowUID}"))
|
|
{
|
|
currSvg = currArgs.newMessage;
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ConfInit()
|
|
{
|
|
apiUrl = Config.GetValue<string>("ServerConf:Prog.ApiUrl") ?? "";
|
|
imgBasePath = Config.GetValue<string>("ServerConf:ImageBaseUrl") ?? "";
|
|
GenericBasePath = Config.GetValue<string>("ServerConf:GenericBaseUrl") ?? "";
|
|
calcTag = Config.GetValue<string>("ServerConf:CalcTag") ?? "";
|
|
subChannel = Config.GetValue<string>("ServerConf:SvgChannel") ?? "";
|
|
}
|
|
|
|
private async Task DoRecalcOffer()
|
|
{
|
|
isLoading = true;
|
|
// ciclo sulle righe...
|
|
await setAwaitPrice(true, false);
|
|
await Task.Delay(50);
|
|
await DLService.OffertUpdateCost(OfferID);
|
|
await Task.Delay(50);
|
|
await setAwaitPrice(false, true);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
await EC_Updated.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Svuota cache corrente + rilegge dati
|
|
/// </summary>
|
|
private async Task ForceReloadData()
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(20);
|
|
await DLService.FlushCacheOffersAsync();
|
|
await Task.Delay(20);
|
|
await ReloadData();
|
|
UpdateTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// init classi configurazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task ReloadBaseList()
|
|
{
|
|
// lettura conf da DB/Cache Redis
|
|
AllConfGlass = await DLService.ConfGlassGetAllAsync();
|
|
var rawHw = CDService.ElencoHw(EgwMultiEngineManager.Data.Constants.EXECENVIRONMENTS.WINDOW, "HW.AGB");
|
|
// hw filtro solo validi...
|
|
AllConfHardware = rawHw
|
|
.Where(x => !x.FamilyName.Equals(x.Description, StringComparison.OrdinalIgnoreCase))
|
|
.ToList();
|
|
AllConfProfile = await DLService.ConfProfileGetAllAsync();
|
|
AllConfWood = await DLService.ConfWoodGetAllAsync();
|
|
AllColors = await DLService.GenValGetFiltAsync("WoodCol");
|
|
// conversione tipi
|
|
AvailGlassList = AllConfGlass
|
|
.Select(x => x.Description)
|
|
.ToList();
|
|
AvailFamilyHardwareList = AllConfHardware
|
|
.DistinctBy(x => x.FamilyName)
|
|
.OrderBy(x => x.FamilyName)
|
|
.Select(x => x.FamilyName)
|
|
.ToList();
|
|
AvailHardwareList = AllConfHardware
|
|
.Select(x => new Egw.Window.Data.Hardware(x.Id, x.FamilyName, x.Description, x.OpeningType, x.Shape, x.SashQty, x.SashPosition))
|
|
.ToList();
|
|
AvailMaterialList = AllConfWood
|
|
.Select(x => x.Description)
|
|
.ToList();
|
|
// FixMe Todo: aggiunta profili (manca anche nel costruttore...)
|
|
AvailColorMaterialList = AllColors
|
|
.OrderBy(x => x.Ordinal)
|
|
.Select(x => x.ValString)
|
|
.ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Legge i dati dei record completi
|
|
/// </summary>
|
|
private async Task ReloadData()
|
|
{
|
|
if (OfferID > 0)
|
|
{
|
|
AllRecords = await DLService.OfferRowGetByOffer(OfferID);
|
|
totalCount = AllRecords.Count();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salvataggio del JWD aggiornato nella mia riga di offerta
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
private async void SaveJWD(Dictionary<string, string> args)
|
|
{
|
|
// ...se ho editing
|
|
if (EditRecord != null)
|
|
{
|
|
// SE contiene il mio JWD...
|
|
if (args.ContainsKey("JWD"))
|
|
{
|
|
string serStruct = args["JWD"];
|
|
// salvo!
|
|
await DLService.OffertRowUpdateSerStruct(EditRecord.OfferRowID, serStruct);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task setAwaitPrice(bool awaitPrice, bool flushCache)
|
|
{
|
|
foreach (var item in AllRecords)
|
|
{
|
|
await DLService.OffertUpdateAwaitState(item.OfferRowID, false, awaitPrice, flushCache);
|
|
}
|
|
}
|
|
|
|
private void SetTemplate(WebWindowComplex.DTO.TemplateSelectDTO args)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// salva nel record corrente la BOM aggiornata e poi ricalcola importo...
|
|
/// </summary>
|
|
/// <param name="newBomList"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private async void UpdateBom(List<BomItemDTO> newBomList)
|
|
{
|
|
if (EditBomRecord != null)
|
|
{
|
|
// salvo BOM nel record corrente...
|
|
bool fatto = await DLService.OffertRowUpdateBom(EditBomRecord.OfferRowID, newBomList);
|
|
// ricalcolo offerta completa
|
|
await ReloadData();
|
|
UpdateTable();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Task verifica update ricevuti
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
private async void UpdatePipe_EA_NewMessage(object? sender, EventArgs e)
|
|
{
|
|
// aggiorno visualizzazione
|
|
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
|
// conversione on-the-fly SVG da mostrare
|
|
if (!string.IsNullOrEmpty(currArgs.newMessage))
|
|
{
|
|
// cerco se faccia aprte dei record correnti...
|
|
var recFound = AllRecords.Any(x => x.OfferRowUID == currArgs.newMessage);
|
|
if (recFound)
|
|
{
|
|
isLoading = true;
|
|
await Task.Delay(10);
|
|
#if false
|
|
if (currArgs.msgUid.Equals($"{subChannel}:{windowUid}"))
|
|
{
|
|
}
|
|
#endif
|
|
// se si tratta dell'UID corrente --> fa update
|
|
await DoRecalcOffer();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Filtro e paginazione
|
|
/// </summary>
|
|
private void UpdateTable()
|
|
{
|
|
// fix paginazione
|
|
ListRecords = AllRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
isLoading = false;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |