diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html
index 3192baa..4e564c3 100644
--- a/Resources/ChangeLog.html
+++ b/Resources/ChangeLog.html
@@ -1,6 +1,6 @@
WebDoorCreator - Egalware
- Version: 0.9.2305.2517
+ Version: 0.9.2305.2519
Release note:
-
diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt
index a27d12d..3f6273e 100644
--- a/Resources/VersNum.txt
+++ b/Resources/VersNum.txt
@@ -1 +1 @@
-0.9.2305.2517
+0.9.2305.2519
diff --git a/Resources/manifest.xml b/Resources/manifest.xml
index 7fa03fb..16d2ec7 100644
--- a/Resources/manifest.xml
+++ b/Resources/manifest.xml
@@ -1,7 +1,7 @@
-
- 0.9.2305.2517
- http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.API.zip
+ 0.9.2305.2519
+ http://nexus.steamware.net/repository/SWS/WDC/stable/WDC.UI.zip
http://nexus.steamware.net/repository/SWS/WDC/stable/ChangeLog.html
false
diff --git a/WebDoorCreator.API/Controllers/ReportController.cs b/WebDoorCreator.API/Controllers/ReportController.cs
index 7ad367b..b2bb184 100644
--- a/WebDoorCreator.API/Controllers/ReportController.cs
+++ b/WebDoorCreator.API/Controllers/ReportController.cs
@@ -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 GetReport(int OrderId, string Format)
+ ///
+ /// Restituisce report dato ordine e formato
+ ///
+ /// ID univoco ordine
+ /// Formato: PDF/HTML/DOCX/XLSX
+ ///
+ [HttpGet("GetOrderReport")]
+ public async Task 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)
+ ///
+ /// Restituisce filestream del report richiesto
+ ///
+ /// Nome file desiderato x download
+ ///
+ ///
+ ///
+ ///
+ private IActionResult OrderReportGet(string FileName, string renderFormat, string extension, string mimeType)
{
- using var report = new LocalReport();
+ using (var report = new LocalReport())
+ {
+ // setup parametri
+ List RepParams = new List();
+ RepParams.Add(new ReportParameter("Title", "Invoice 4/2020"));
+ // setup DsReport
+ Dictionary DsDict = new Dictionary();
+ 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
diff --git a/WebDoorCreator.Core/ReportViewer/Report.cs b/WebDoorCreator.Core/ReportViewer/Report.cs
index cfbbdd9..ea49bd5 100644
--- a/WebDoorCreator.Core/ReportViewer/Report.cs
+++ b/WebDoorCreator.Core/ReportViewer/Report.cs
@@ -2,6 +2,7 @@
using Microsoft.ReportingServices.ReportProcessing.ReportObjectModel;
using System;
using System.Collections.Generic;
+using System.Data;
using System.IO;
using System.Reflection;
@@ -9,27 +10,41 @@ namespace WebDoorCreator.Core.ReportViewer
{
public class Report
{
- public static void Load(LocalReport report, decimal widgetPrice, decimal gizmoPrice)
+ ///
+ /// Effettua setup del Report corrente
+ ///
+ /// Oggetto LocalReport da impiegare
+ /// Nome del Report (file rdlc) da usare
+ /// Parametri opzionali report
+ /// Dizionario dei dataset del report (DsName + DataTable relativa)
+ public static void Load(LocalReport ReportObj, string FileNameRdlc, List RepParams, Dictionary ReportDatasets)
{
- var items = new[] { new ReportItem { Description = "Widget 6000", Price = widgetPrice, Qty = 1 }, new ReportItem { Description = "Gizmo MAX", Price = gizmoPrice, Qty = 25 } };
- var parameters = new[] { new ReportParameter("Title", "Invoice 4/2020") };
+ // setup preliminari
+ ReportObj.EnableExternalImages = true;
+ // calcolo path complessivo
+ string reportPath = Path.Combine(AppContext.BaseDirectory, "Reports", FileNameRdlc);
/*------------------------------------------------------------------------------------------
- * NB: SE volessi includere i report come EMBEDDED potrei usare una versione alternativa,
- * ad esempio (x report inclusi in area WebDoorCreator.Core\ReportViewer\Report.rdlc
+ * NB: SE volessi includere i ReportObj come EMBEDDED potrei usare una versione alternativa,
+ * ad esempio (x ReportObj inclusi in area WebDoorCreator.Core\ReportViewer\Report.rdlc
*
* using var rs = Assembly.GetExecutingAssembly().GetManifestResourceStream("WebDoorCreator.Core.ReportViewer.Report.rdlc");
- * report.LoadReportDefinition(rs);
+ * ReportObj.LoadReportDefinition(rs);
+ *
+ * oppure con filestream
+ * using (FileStream fs = File.OpenRead(reportPath))
+ * {
+ * ReportObj.LoadReportDefinition(fs);
+ * ....
+ * }
*
* ------------------------------------------------------------------------------------------*/
-
- string reportPath = Path.Combine(AppContext.BaseDirectory, "Reports", "Report.rdlc");
- using (FileStream fs = File.OpenRead(reportPath))
+ ReportObj.ReportPath = reportPath;
+ foreach (var item in ReportDatasets)
{
- report.LoadReportDefinition(fs);
- report.DataSources.Add(new ReportDataSource("Items", items));
- report.SetParameters(parameters);
+ ReportObj.DataSources.Add(new ReportDataSource(item.Key, item.Value));
}
+ ReportObj.SetParameters(RepParams);
}
}
}
diff --git a/WebDoorCreator.Core/ReportViewer/ReportExtUtils.cs b/WebDoorCreator.Core/ReportViewer/ReportExtUtils.cs
new file mode 100644
index 0000000..10c867e
--- /dev/null
+++ b/WebDoorCreator.Core/ReportViewer/ReportExtUtils.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WebDoorCreator.Core.ReportViewer
+{
+ public static class ReportExtUtils
+ {
+ public static DataTable ToDataTable(this T[] genList)
+ {
+ if (genList == null || genList.Length == 0) return null;
+
+ DataTable table = new DataTable();
+ var firstRec = genList[0];
+ table.Columns.AddRange(firstRec.GetType().GetFields().Select(field => new DataColumn(field.Name, field.FieldType)).ToArray());
+ int fieldCount = firstRec.GetType().GetFields().Count();
+
+ genList.All(singleRow =>
+ {
+ table.Rows.Add(Enumerable.Range(0, fieldCount).Select(index => singleRow.GetType().GetFields()[index].GetValue(singleRow)).ToArray());
+ return true;
+ });
+
+ return table;
+ }
+ }
+}
diff --git a/WebDoorCreator.UI/WebDoorCreator.UI.csproj b/WebDoorCreator.UI/WebDoorCreator.UI.csproj
index 422c88c..3ce2bd2 100644
--- a/WebDoorCreator.UI/WebDoorCreator.UI.csproj
+++ b/WebDoorCreator.UI/WebDoorCreator.UI.csproj
@@ -3,11 +3,15 @@
net6.0
enable
- 0.9.2305.2517
+ 0.9.2305.2519
enable
aspnet-WebDoorCreator.UI-dfe95fed-1398-4144-bd43-8b3a765d6608
+
+
+
+
@@ -50,7 +54,6 @@
-