Files
2026-04-30 17:31:48 +02:00

108 lines
3.6 KiB
C#

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<bool> 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<Dictionary<string, string>>(currReport.FileConfDataRaw) ?? new();
}
isLoading = false;
}
[Inject]
private IOrderRowService OrdRService { get; set; } = null!;
protected override async Task OnParametersSetAsync()
{
if(currId > 0)
{
// recupero righe ordine...
List<OrderRowModel> listRows = await OrdRService.GetByParentAsync(currId);
// esplodo i distinct dei gruppi
//List<BomItemDTO> 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<ReportModel> ReportList = new();
private Dictionary<string, string> DictAlias = new();
private List<string> ListRepFiles = new List<string>();
private bool isLoading = false;
private List<string> 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);
}
/// <summary>
/// recupero elenco file per tipo di report
/// </summary>
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();
}
/// <summary>
/// Recupero descrizione report
/// </summary>
/// <param name="currFileName"> Nome file</param>
/// <returns></returns>
private string Descrizione(string currFileName)
{
string ans = "";
// cerco nel dizionario...
if (DictAlias.ContainsKey(currFileName))
{
ans = DictAlias[currFileName];
}
return ans;
}
}
}