|
|
@@ -9,6 +9,7 @@ using System.Drawing.Printing;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using FastReport;
|
|
|
@@ -138,6 +139,8 @@ namespace InABox.Wpf.Reports
|
|
|
report.LoadFromString(templaterdl);
|
|
|
report.FileName = template?.Name ?? "";
|
|
|
|
|
|
+
|
|
|
+
|
|
|
foreach(var tableName in data.TableNames)
|
|
|
{
|
|
|
var modelTable = data.GetDataModelTable(tableName);
|
|
|
@@ -145,18 +148,34 @@ namespace InABox.Wpf.Reports
|
|
|
if (dataSource != null && modelTable.Type is not null)
|
|
|
{
|
|
|
var columnNames = CoreUtils.GetColumnNames(modelTable.Type, x => true);
|
|
|
- foreach (var column in dataSource.Columns)
|
|
|
+ if (template.OptimiseData)
|
|
|
{
|
|
|
- if(column is FastReport.Data.Column col && !col.Enabled)
|
|
|
+ // DataColumn="(table).(field)" or [(table).(field)]
|
|
|
+ var pattern = @"DataColumn=""(?<value>[^""]+)""|\[(?<value>[^\]]+)\]";
|
|
|
+ var matches = Regex.Matches(templaterdl, pattern);
|
|
|
+ var usedcolumns = matches
|
|
|
+ .Cast<Match>()
|
|
|
+ .Select(m => m.Groups["value"].Value)
|
|
|
+ .ToList();
|
|
|
+ columnNames = columnNames
|
|
|
+ .Where(x=>x.Equals("ID") || usedcolumns.Contains($"{modelTable.Type.Name}.{x.Replace(".","_")}"))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var column in dataSource.Columns)
|
|
|
{
|
|
|
- //columns.Add(col.Name.Replace('_','.'));
|
|
|
- columnNames.Remove(col.Name.Replace('_', '.'));
|
|
|
+ if(column is FastReport.Data.Column col && !col.Enabled)
|
|
|
+ {
|
|
|
+ columnNames.Remove(col.Name.Replace('_', '.'));
|
|
|
+ }
|
|
|
+ /*if (column is FastReport.Data.Column col && col.DataType != null && col.DataType.IsAssignableTo(typeof(IEnumerable<byte[]>)))
|
|
|
+ {
|
|
|
+ col.BindableControl = ColumnBindableControl.Custom;
|
|
|
+ col.CustomBindableControl = "MultiImageObject";
|
|
|
+ }*/
|
|
|
}
|
|
|
- /*if (column is FastReport.Data.Column col && col.DataType != null && col.DataType.IsAssignableTo(typeof(IEnumerable<byte[]>)))
|
|
|
- {
|
|
|
- col.BindableControl = ColumnBindableControl.Custom;
|
|
|
- col.CustomBindableControl = "MultiImageObject";
|
|
|
- }*/
|
|
|
}
|
|
|
modelTable.Columns = Columns.None(modelTable.Type).Add(columnNames);
|
|
|
}
|