ancora update gest dataser report
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Microsoft.Reporting.NETCore;
|
||||
using NLog;
|
||||
using System.Data;
|
||||
using WebDoorCreator.Core.ReportViewer;
|
||||
using WebDoorCreator.Data.Services;
|
||||
|
||||
namespace WebDoorCreator.API.Controllers
|
||||
@@ -30,25 +33,32 @@ namespace WebDoorCreator.API.Controllers
|
||||
return "OK";
|
||||
}
|
||||
|
||||
[HttpGet("GetReport")]
|
||||
public async Task<IActionResult> GetReport(int OrderId, string Format)
|
||||
/// <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)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
string FileName = $"DCA-Order-{OrderId:00000000}";
|
||||
string Extension = "";
|
||||
string MimeType = "";
|
||||
switch (Format.ToUpper())
|
||||
{
|
||||
case "HTML5":
|
||||
case "HTML":
|
||||
Extension = "html";
|
||||
MimeType = "text/html";
|
||||
break;
|
||||
|
||||
case "WORDOPENXML":
|
||||
case "DOCX":
|
||||
Extension = "docx";
|
||||
MimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
||||
break;
|
||||
|
||||
case "EXCELOPENXML":
|
||||
case "XLSX":
|
||||
Extension = "xlsx";
|
||||
MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
break;
|
||||
@@ -60,7 +70,7 @@ namespace WebDoorCreator.API.Controllers
|
||||
break;
|
||||
}
|
||||
// restituisco oggetto
|
||||
return PrepareReport(Format, Extension, MimeType);
|
||||
return OrderReportGet(FileName, Format, Extension, MimeType);
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
@@ -75,26 +85,66 @@ namespace WebDoorCreator.API.Controllers
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private decimal GizmoPrice { get; set; }
|
||||
|
||||
private QueueDataService QDataServ { get; set; } = null!;
|
||||
|
||||
private decimal WidgetPrice { get; set; }
|
||||
|
||||
#endregion Private Properties
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private IActionResult PrepareReport(string renderFormat, string extension, string mimeType)
|
||||
/// <summary>
|
||||
/// Restituisce filestream del report richiesto
|
||||
/// </summary>
|
||||
/// <param name="FileName">Nome file desiderato x download</param>
|
||||
/// <param name="renderFormat"></param>
|
||||
/// <param name="extension"></param>
|
||||
/// <param name="mimeType"></param>
|
||||
/// <returns></returns>
|
||||
private IActionResult OrderReportGet(string FileName, string renderFormat, string extension, string mimeType)
|
||||
{
|
||||
using var report = new LocalReport();
|
||||
using (var report = new LocalReport())
|
||||
{
|
||||
// setup parametri
|
||||
List<ReportParameter> RepParams = new List<ReportParameter>();
|
||||
RepParams.Add(new ReportParameter("Title", "Invoice 4/2020"));
|
||||
// setup DsReport
|
||||
Dictionary<string, DataTable> DsDict = new Dictionary<string, DataTable>();
|
||||
Random rnd = new Random();
|
||||
decimal WidgetPrice = 204.99m;
|
||||
decimal GizmoPrice = 2.41m;
|
||||
ReportItem[] items = new[] {
|
||||
new ReportItem { Description = "Widget 6000", Price = WidgetPrice, Qty = rnd.Next(1,5) },
|
||||
new ReportItem { Description = "Gizmo MAX", Price = GizmoPrice, Qty = rnd.Next(10,50) },
|
||||
new ReportItem { Description = "Pippo", Price = 1.2m, Qty = rnd.Next(3,9) },
|
||||
new ReportItem { Description = "Paperino", Price = 1.74m, Qty = rnd.Next(5,15) }
|
||||
};
|
||||
DataTable tabDati = new DataTable("Items");
|
||||
|
||||
WidgetPrice = 104.99m;
|
||||
GizmoPrice = 1.41m;
|
||||
//tabDati = items.ToDataTable();
|
||||
|
||||
Core.ReportViewer.Report.Load(report, WidgetPrice, GizmoPrice);
|
||||
var pdf = report.Render(renderFormat);
|
||||
return File(pdf, mimeType, "report." + extension);
|
||||
tabDati.Columns.Add("Description", typeof(string));
|
||||
tabDati.Columns.Add("Price", typeof(decimal));
|
||||
tabDati.Columns.Add("Qty", typeof(int));
|
||||
tabDati.Columns.Add("Total", typeof(decimal));
|
||||
DataRow newRow = tabDati.NewRow();
|
||||
foreach (var item in items)
|
||||
{
|
||||
newRow = tabDati.NewRow();
|
||||
newRow["Description"] = item.Description;
|
||||
newRow["Price"] = item.Price;
|
||||
newRow["Qty"] = item.Qty;
|
||||
newRow["Total"] = item.Price*item.Qty;
|
||||
|
||||
// Add the row to the rows collection.
|
||||
tabDati.Rows.Add(newRow);
|
||||
}
|
||||
// aggiungo dizionario
|
||||
DsDict.Add("Items", tabDati);
|
||||
|
||||
// carico dati nel report...
|
||||
Core.ReportViewer.Report.Load(report, "Report.rdlc", RepParams, DsDict);
|
||||
var rawData = report.Render(renderFormat);
|
||||
return File(rawData, mimeType, $"{FileName}.{extension}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
|
||||
Reference in New Issue
Block a user