Преглед изворни кода

Fixed blank report generation from forms and added names to generated objects.

Kenric Nugteren пре 1 година
родитељ
комит
174e76c330

+ 5 - 1
inabox.wpf/DigitalForms/DigitalFormReportGrid.cs

@@ -14,6 +14,7 @@ using FastReport.Table;
 using FastReport.Utils;
 using Border = System.Windows.Controls.Border;
 using Size = System.Windows.Size;
+using netDxf.Objects;
 
 namespace InABox.DynamicGrid
 {
@@ -212,7 +213,10 @@ namespace InABox.DynamicGrid
         protected override ReportTemplate CreateItem()
         {
             var item = base.CreateItem();
-            if(Form.ID != Guid.Empty)
+            var model = DigitalFormUtils.GetDataModel(Form.AppliesTo, GetVariables());
+            item.DataModel = model.Name;
+            
+            if (Form.ID != Guid.Empty)
             {
                 item.Section = Form.ID.ToString();
             }

+ 31 - 6
inabox.wpf/DigitalForms/DigitalFormUtils.cs

@@ -285,6 +285,22 @@ namespace InABox.DynamicGrid
         #endregion
         
         #region Report Generator
+
+        private static string ElementName(HashSet<string> names, string name)
+        {
+            int i = 0;
+            if(names.Contains(name))
+            {
+                string newName;
+                do
+                {
+                    newName = $"{name}{i}";
+                    ++i;
+                } while (names.Contains(newName));
+                name = newName;
+            }
+            return name;
+        }
         
         public static Report? GenerateReport(DigitalFormLayout layout, DataModel model)
         {
@@ -306,16 +322,21 @@ namespace InABox.DynamicGrid
 
             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 = formData;
+            var band = new DataBand
+            {
+                Name = "Data1",
+                Height = Units.Millimeters * (page.PaperHeight - (page.TopMargin + page.BottomMargin)),
+                Width = Units.Millimeters * (page.PaperWidth - (page.LeftMargin + page.RightMargin)),
+                PrintIfDatasourceEmpty = true,
+                DataSource = formData
+            };
             page.AddChild(band);
 
+            var elementNames = new HashSet<string>();
+
             var table = new TableObject()
             {
+                Name = "FormTable",
                 ColumnCount = dfLayout.ColumnWidths.Count,
                 RowCount = dfLayout.RowHeights.Count
             };
@@ -335,6 +356,8 @@ namespace InABox.DynamicGrid
                     {
                         var manualHeight = 0.0f;
 
+                        cell.Name = ElementName(elementNames, $"Cell_{new string(field.Name.Where(c => !Char.IsWhiteSpace(c)).ToArray())}");
+
                         var dataColumn = $"Form_Data.{field.Name}";
                         if(field is DFLayoutEmbeddedImage || field is DFLayoutSignaturePad)
                         {
@@ -389,10 +412,12 @@ namespace InABox.DynamicGrid
                             label.Style.BackgroundColour = Color.WhiteSmoke;
                         }
                         cell.Text = label.Description;
+                        cell.Name = ElementName(elementNames, "Label_" + element.Row + "_" + element.Column);
                         ApplyStyle(cell, label.Style);
                     }
                     else if (element is DFLayoutHeader header)
                     {
+                        cell.Name = ElementName(elementNames, "Header_" + element.Row + "_" + element.Column);
                         cell.Text = header.Header;
                         ApplyStyle(cell, header.Style);
                     }

+ 7 - 2
inabox.wpf/Reports/ReportUtils.cs

@@ -287,11 +287,16 @@ namespace InABox.Wpf.Reports
             return result;
         }
 
+        public static Filter<ReportTemplate> GetReportFilter(string sectionName, DataModel model)
+        {
+            return new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
+                    .And(x => x.Section).IsEqualTo(sectionName);
+        }
+
         public static IEnumerable<ReportTemplate> LoadReports(string sectionName, DataModel model)
         {
             return new Client<ReportTemplate>().Query(
-                new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
-                    .And(x => x.Section).IsEqualTo(sectionName),
+                GetReportFilter(sectionName, model),
                 null,
                 new SortOrder<ReportTemplate>(x => x.Name)).Rows.Select(x => x.ToObject<ReportTemplate>());
         }