Forráskód Böngészése

Improved auto-report generation.

Kenric Nugteren 2 éve
szülő
commit
b07f3c0944

+ 1 - 1
InABox.Core/DigitalForms/Layouts/Controls/DFLayoutLabel/DFLayoutTextStyle.cs

@@ -126,6 +126,6 @@ namespace InABox.Core
 
         public static string ColourToString(Color colour) => colour == Color.Empty
             ? ""
-            : colour.IsKnownColor ? colour.ToString() : $"#{colour.ToArgb():X4}";
+            : colour.IsKnownColor ? colour.ToKnownColor().ToString() : $"#{colour.ToArgb():X4}";
     }
 }

+ 2 - 2
inabox.wpf/DigitalForms/DigitalFormReportGrid.cs

@@ -150,12 +150,12 @@ namespace InABox.DynamicGrid
         
         private void AddLayout(DigitalFormLayout layout)
         {
-            var model = DigitalFormUtils.GetDataModel(Form.AppliesTo,GetVariables());
+            var model = DigitalFormUtils.GetDataModel(Form.AppliesTo, GetVariables());
             
             var item = CreateItem();
             item.DataModel = model.Name;
             item.Name = string.IsNullOrWhiteSpace(layout.Description) ? layout.Code : layout.Description;
-            item.RDL = DigitalFormUtils.GenerateReport(layout,model)?.SaveToString();
+            item.RDL = DigitalFormUtils.GenerateReport(layout, model)?.SaveToString();
 
             if (EditItems(new[] { item }))
             {

+ 99 - 33
inabox.wpf/DigitalForms/DigitalFormUtils.cs

@@ -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;
         }

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorGrid.xaml.cs

@@ -338,7 +338,7 @@ namespace InABox.DynamicGrid
             public bool TryFindEditor(string columnname, [NotNullWhen(true)] out IDynamicEditorControl? editor)
             {
                 editor = Editors.FirstOrDefault(x => x.ColumnName.Equals(columnname));
-                editor ??= Editors.FirstOrDefault(x => columnname.StartsWith(x.ColumnName));
+                editor ??= Editors.FirstOrDefault(x => columnname.StartsWith(x.ColumnName + '.'));
                 return editor is not null;
             }