using EgwCoreLib.Lux.Data.DbModel.Report; using EgwCoreLib.Lux.Data.Services.Report; using Newtonsoft.Json; namespace Lux.UI.Components.Compo.Common { public partial class PrintModal { [Parameter] public string url { get; set; } = ""; [Parameter] public int currId { get; set; } [Parameter] public string repType { get; set; } = ""; [Parameter] public EventCallback EC_Close { get; set; } [Inject] private IFileService FService { get; set; } = null!; [Inject] private IReportService RService { get; set; } = null!; protected override async Task OnInitializedAsync() { isLoading = true; LoadFileList(); ReportList = await RService.GetAllAsync(); ReportModel currReport = ReportList.FirstOrDefault(x => x.Name.Contains(repType)) ?? new(); // fix alias disponibili if (!string.IsNullOrEmpty(currReport.FileConfDataRaw)) { DictAlias = JsonConvert.DeserializeObject>(currReport.FileConfDataRaw) ?? new(); } isLoading = false; } [Inject] private IOrderRowService OrdRService { get; set; } = null!; protected override async Task OnParametersSetAsync() { if(currId > 0) { // recupero righe ordine... List listRows = await OrdRService.GetByParentAsync(currId); // esplodo i distinct dei gruppi //List listBomComplete = listRows.SelectMany(x => x.ListBOM).ToList(); //listGroup = listBomComplete.Select(x => x.ClassCode).Distinct().ToList(); listGroup = listRows.SelectMany(x => x.ListBOM).Select(x => x.ClassCode).Distinct().ToList(); ; } } private List ReportList = new(); private Dictionary DictAlias = new(); private List ListRepFiles = new List(); private bool isLoading = false; private List listGroup = new(); private string codGroup = ""; private string SelectCodGroup { get => codGroup; set { if(codGroup != value) { codGroup = value; } } } private string DoPrint(string SelFile) { return $"{url}/download?ReqId={currId}&RepType={repType}&SelFile={SelFile}&codGroup={codGroup}"; } private Task DoCloseModal() { return EC_Close.InvokeAsync(false); } /// /// recupero elenco file per tipo di report /// private void LoadFileList() { string repPath = Path.Combine("reports", repType); var rawList = FService.ListFile(repPath, "*.repx", true); ListRepFiles = rawList.Select(x => Path.GetFileName(x)).ToList(); var SelFile = ListRepFiles.FirstOrDefault(); } /// /// Recupero descrizione report /// /// Nome file /// private string Descrizione(string currFileName) { string ans = ""; // cerco nel dizionario... if (DictAlias.ContainsKey(currFileName)) { ans = DictAlias[currFileName]; } return ans; } } }