110 lines
3.9 KiB
C#
110 lines
3.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Reporting.NETCore;
|
|
using NLog;
|
|
using System.Data;
|
|
using ToDataTable;
|
|
using WebDoorCreator.Data.Services;
|
|
|
|
namespace WebDoorCreator.UI.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ReportController(IConfiguration configuration, WebDoorCreatorService DataService)
|
|
{
|
|
Log.Info("Starting ReportController");
|
|
_configuration = configuration;
|
|
WDCService = DataService;
|
|
Log.Info("Avviato ReportController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
// GET: api/Report
|
|
[HttpGet]
|
|
public string Get()
|
|
{
|
|
return "OK";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce report dato ordine e formato
|
|
/// </summary>
|
|
/// <param name="OrderId">ID univoco ordine</param>
|
|
/// <param name="Format">Formato: PDF/HTML/DOCX/XLSX</param>
|
|
/// <returns></returns>
|
|
[HttpGet("GetOrderReport")]
|
|
public async Task<IActionResult> GetOrderReport(int OrderId, string Format)
|
|
{
|
|
// dato il servizio è impostato il file rdlc e la struttura data DS da passare
|
|
await Task.Delay(1);
|
|
// inizializzo parametri report di default
|
|
Core.ReportViewer.Report.RenderParams currParams = new Core.ReportViewer.Report.RenderParams(Format);
|
|
currParams.FileName = $"DCA-Order-{OrderId:00000000}";
|
|
|
|
// restituisco oggetto ReportOrder specifico
|
|
return await OrderReportGet(OrderId, currParams);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private WebDoorCreatorService WDCService { get; set; } = null!;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Restituisce filestream del report richiesto
|
|
/// </summary>
|
|
/// <param name="OrderId">ID Ordine</param>
|
|
/// <param name="CurrParams">Parametri rendering report</param>
|
|
/// <returns></returns>
|
|
private async Task<IActionResult> OrderReportGet(int OrderId, Core.ReportViewer.Report.RenderParams CurrParams)
|
|
{
|
|
using (var report = new LocalReport())
|
|
{
|
|
// setup parametri
|
|
List<ReportParameter> RepParams = new List<ReportParameter>();
|
|
RepParams.Add(new ReportParameter("OrderID", $"{OrderId}"));
|
|
// setup DsReport
|
|
Dictionary<string, DataTable> DsDict = new Dictionary<string, DataTable>();
|
|
// recupero tab dati config...
|
|
var confList = await WDCService.ConfigGetAll();
|
|
DataTable tabDatiConf = confList.ToDataTable();
|
|
tabDatiConf.TableName = "DataSetConfig";
|
|
// aggiungo a dizionario
|
|
DsDict.Add("DataSetConfig", tabDatiConf);
|
|
|
|
// recupero dati veri del report...
|
|
var repDetailData = await WDCService.PreRepOrderGetByKey(OrderId);
|
|
DataTable tabDati = repDetailData.ToDataTable();
|
|
tabDati.TableName = "DataSetOrderReportExpl";
|
|
// aggiungo dizionario
|
|
DsDict.Add("DataSetOrderReportExpl", tabDati);
|
|
|
|
// carico dati nel report...
|
|
Core.ReportViewer.Report.Load(report, "ReportOrder.rdlc", RepParams, DsDict);
|
|
var rawData = report.Render(CurrParams.RenderFormat);
|
|
return File(rawData, CurrParams.MimeType, $"{CurrParams.FileName}.{CurrParams.Extension}");
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |