|
@@ -4,11 +4,13 @@ using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using FastReport;
|
|
|
+using FastReport.Data;
|
|
|
using FastReport.Table;
|
|
|
using FastReport.Utils;
|
|
|
using InABox.Core;
|
|
|
using InABox.Scripting;
|
|
|
using InABox.Wpf.Reports;
|
|
|
+using InABox.Wpf.Reports.CustomObjects;
|
|
|
using UnderlineType = InABox.Core.UnderlineType;
|
|
|
|
|
|
namespace InABox.DynamicGrid
|
|
@@ -282,12 +284,10 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
#region Report Generator
|
|
|
|
|
|
public static Report? GenerateReport(DigitalFormLayout layout, DataModel model)
|
|
|
{
|
|
|
-
|
|
|
var report = ReportUtils.SetupReport(null, model, true);
|
|
|
|
|
|
var dfLayout = new DFLayout();
|
|
@@ -304,56 +304,120 @@ namespace InABox.DynamicGrid
|
|
|
page.BottomMargin = 10;
|
|
|
report.Pages.Add(page);
|
|
|
|
|
|
- DataBand band = new DataBand();
|
|
|
+ var formData = report.GetDataSource("Form_Data");
|
|
|
+
|
|
|
+ var band = new DataBand();
|
|
|
band.Name = "Data1";
|
|
|
band.Height = Units.Millimeters * (page.PaperHeight - (page.TopMargin + page.BottomMargin));
|
|
|
band.Width = Units.Millimeters * (page.PaperWidth - (page.LeftMargin + page.RightMargin));
|
|
|
band.PrintIfDatasourceEmpty = true;
|
|
|
- band.DataSource = report.GetDataSource("Form_Data");
|
|
|
+ band.DataSource = formData;
|
|
|
page.AddChild(band);
|
|
|
-
|
|
|
- TableObject table = new TableObject();
|
|
|
- table.ColumnCount = dfLayout.ColumnWidths.Count;
|
|
|
- table.RowCount = dfLayout.RowHeights.Count;
|
|
|
- ProcessColumnWidths(band.Width, dfLayout.ColumnWidths, table.Columns);
|
|
|
- ProcessRowHeights(band.Height, dfLayout.RowHeights, table.Rows);
|
|
|
+
|
|
|
+ var table = new TableObject()
|
|
|
+ {
|
|
|
+ ColumnCount = dfLayout.ColumnWidths.Count,
|
|
|
+ RowCount = dfLayout.RowHeights.Count
|
|
|
+ };
|
|
|
band.AddChild(table);
|
|
|
foreach(var element in dfLayout.Elements)
|
|
|
{
|
|
|
- var row = table.Rows[element.Row-1];
|
|
|
- var cell = row.ChildObjects[element.Column-1] as TableCell;
|
|
|
- cell.Border.Lines = BorderLines.All;
|
|
|
- cell.ColSpan = element.ColumnSpan;
|
|
|
- cell.RowSpan = element.RowSpan;
|
|
|
- if (element is DFLayoutField field)
|
|
|
- {
|
|
|
- cell.Text = $"[Form_Data.{field.Name}]";
|
|
|
- cell.Font = new System.Drawing.Font(cell.Font.FontFamily, 8F);
|
|
|
- }
|
|
|
- else if (element is DFLayoutLabel label)
|
|
|
- {
|
|
|
- cell.Text = label.Description;
|
|
|
- ApplyStyle(cell, label.Style);
|
|
|
- }
|
|
|
- else if (element is DFLayoutHeader header)
|
|
|
+ if (element.Row < 1 || element.Row + element.RowSpan - 1 > table.RowCount
|
|
|
+ || element.Column < 1 || element.Column + element.ColumnSpan - 1 > table.ColumnCount) continue;
|
|
|
+
|
|
|
+ var row = table.Rows[element.Row - 1];
|
|
|
+ if(row.ChildObjects[element.Column - 1] is TableCell cell)
|
|
|
{
|
|
|
- cell.Text = header.Header;
|
|
|
- ApplyStyle(cell, header.Style);
|
|
|
+ cell.Border.Lines = BorderLines.All;
|
|
|
+ cell.ColSpan = element.ColumnSpan;
|
|
|
+ cell.RowSpan = element.RowSpan;
|
|
|
+ if (element is DFLayoutField field)
|
|
|
+ {
|
|
|
+ var manualHeight = 0.0f;
|
|
|
+
|
|
|
+ var dataColumn = $"Form_Data.{field.Name}";
|
|
|
+ if(field is DFLayoutEmbeddedImage || field is DFLayoutSignaturePad)
|
|
|
+ {
|
|
|
+ var picture = new PictureObject
|
|
|
+ {
|
|
|
+ DataColumn = dataColumn,
|
|
|
+ Dock = System.Windows.Forms.DockStyle.Fill
|
|
|
+ };
|
|
|
+ cell.AddChild(picture);
|
|
|
+
|
|
|
+ manualHeight = 40;
|
|
|
+ }
|
|
|
+ else if(field is DFLayoutMultiImage)
|
|
|
+ {
|
|
|
+ var image = new MultiImageObject
|
|
|
+ {
|
|
|
+ DataColumn = dataColumn,
|
|
|
+ };
|
|
|
+ cell.AddChild(image);
|
|
|
+
|
|
|
+ manualHeight = 40;
|
|
|
+ }
|
|
|
+ else if(field is DFLayoutMultiSignaturePad)
|
|
|
+ {
|
|
|
+ var image = new MultiSignatureObject
|
|
|
+ {
|
|
|
+ DataColumn = dataColumn,
|
|
|
+ };
|
|
|
+ cell.AddChild(image);
|
|
|
+
|
|
|
+ manualHeight = 40;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cell.Text = $"[{dataColumn}]";
|
|
|
+ cell.Font = new System.Drawing.Font(cell.Font.FontFamily, 8F, FontStyle.Italic);
|
|
|
+ cell.TextColor = Color.Navy;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(manualHeight > 0 && dfLayout.RowHeights[element.Row - 1] == "Auto")
|
|
|
+ {
|
|
|
+ dfLayout.RowHeights[element.Row - 1] = manualHeight.ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (element is DFLayoutLabel label)
|
|
|
+ {
|
|
|
+ var background = label.Style.BackgroundColour;
|
|
|
+ if (background == Color.Empty)
|
|
|
+ {
|
|
|
+ label.Style.BackgroundColour = Color.WhiteSmoke;
|
|
|
+ }
|
|
|
+ cell.Text = label.Description;
|
|
|
+ ApplyStyle(cell, label.Style);
|
|
|
+ }
|
|
|
+ else if (element is DFLayoutHeader header)
|
|
|
+ {
|
|
|
+ cell.Text = header.Header;
|
|
|
+ ApplyStyle(cell, header.Style);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ ProcessColumnWidths(band.Width, dfLayout.ColumnWidths, table.Columns);
|
|
|
+ ProcessRowHeights(band.Height, dfLayout.RowHeights, table.Rows);
|
|
|
|
|
|
return report;
|
|
|
}
|
|
|
|
|
|
private static void ApplyStyle(TableCell cell, DFLayoutTextStyle style)
|
|
|
{
|
|
|
- cell.FillColor = style.BackgroundColour;
|
|
|
+ var background = style.BackgroundColour;
|
|
|
+ if(background != Color.Empty) cell.FillColor = background;
|
|
|
+
|
|
|
+ var foreground = style.ForegroundColour;
|
|
|
+ if (foreground != Color.Empty) cell.TextColor = foreground;
|
|
|
+
|
|
|
FontStyle fontstyle = System.Drawing.FontStyle.Regular;
|
|
|
if (style.IsBold)
|
|
|
- fontstyle = fontstyle | System.Drawing.FontStyle.Bold;
|
|
|
+ fontstyle |= System.Drawing.FontStyle.Bold;
|
|
|
if (style.IsItalic)
|
|
|
- fontstyle = fontstyle | System.Drawing.FontStyle.Italic;
|
|
|
+ fontstyle |= System.Drawing.FontStyle.Italic;
|
|
|
+ if (style.Underline != UnderlineType.None)
|
|
|
+ fontstyle |= FontStyle.Underline;
|
|
|
float fontsize = (float)style.FontSize * 8F / 12F;
|
|
|
fontsize = fontsize == 0F ? 8F : fontsize;
|
|
|
cell.Font = new System.Drawing.Font(cell.Font.FontFamily, fontsize, fontstyle);
|
|
@@ -362,14 +426,16 @@ namespace InABox.DynamicGrid
|
|
|
DFLayoutAlignment.Start => HorzAlign.Left,
|
|
|
DFLayoutAlignment.Middle => HorzAlign.Center,
|
|
|
DFLayoutAlignment.End => HorzAlign.Right,
|
|
|
- DFLayoutAlignment.Stretch => HorzAlign.Justify
|
|
|
+ DFLayoutAlignment.Stretch => HorzAlign.Justify,
|
|
|
+ _ => HorzAlign.Left
|
|
|
};
|
|
|
cell.VertAlign = style.VerticalTextAlignment switch
|
|
|
{
|
|
|
DFLayoutAlignment.Start => VertAlign.Top,
|
|
|
DFLayoutAlignment.Middle => VertAlign.Center,
|
|
|
DFLayoutAlignment.End => VertAlign.Bottom,
|
|
|
- DFLayoutAlignment.Stretch => VertAlign.Center
|
|
|
+ DFLayoutAlignment.Stretch => VertAlign.Center,
|
|
|
+ _ => VertAlign.Center
|
|
|
};
|
|
|
cell.WordWrap = style.TextWrapping;
|
|
|
}
|