예제 #1
0
 private void ApplySourceDataTemplate(ReportType reportType, ListDictionary reportParameters, ReportTemplate template)
 {
     int fromElection = -1;
     if (reportParameters.Contains(PRN_ELECTION))
     {
         fromElection = _electionManager.SourceData.GetElectionIndex(
             (Election)reportParameters[PRN_ELECTION]);
     }
     var toElection = fromElection != -1 ?
         fromElection + 1 : _electionManager.SourceData.Elections.Length;
     fromElection = fromElection == -1 ? 0 : fromElection;
     var tables = new List<BaseTableHolder>();
     for (int i = fromElection; i < toElection; i++)
     {
         var election = _electionManager.SourceData.Elections[i];
         Table headerTable = null;
         Table footerTable = null;
         Table bodyTable = null;
         if (election.Protocol.FontType != FontType.Default)
             template.Font = election.Protocol.FontType;
         if (election.Protocol.FontSize > 0)
             template.FontSize = election.Protocol.FontSize;
         ProtocolText protocolTemplate = election.Protocol.GetProtocolTemplate(
             reportType == ReportType.ElectionProtocol);
         if (protocolTemplate == null)
             return;
         if (protocolTemplate.ProtocolLines.Length > 0)
         {
             var headers = new Dictionary<PageSection, List<BasePlainElement>>();
             foreach (PageSection section in Enum.GetValues(typeof(PageSection)))
             {
                 headers[section] = new List<BasePlainElement>();
             }
             try
             {
                 ApplyStandartTemplates(protocolTemplate, election, headers);
                 template.PageHeader = new BasePlainElement[headers[PageSection.PageHeader].Count];
                 headers[PageSection.PageHeader].CopyTo(template.PageHeader);
                 if (toElection - fromElection > 1)
                 {
                     template.Header = new BasePlainElement[0];
                     headerTable = new Table
                     {
                         Columns = new[]
                             {
                                 new ColDefinition
                                     {
                                         Width = 100,
                                         Align = null,
                                     },
                             },
                         Body = headers[PageSection.Header].ToArray(),
                     };
                     template.Footer = new BasePlainElement[0];
                     headers[PageSection.Footer].Add(
                         new LineClause
                         {
                             Columns = new[] { new LinePart { Text = "" } },
                             NewPage = true,
                             ResetPageNumber = true
                         });
                     footerTable = new Table
                     {
                         Columns = new[]
                             {
                                 new ColDefinition
                                     {
                                         Width = 100,
                                         Align = null,
                                     },
                             },
                         Body = headers[PageSection.Footer].ToArray(),
                     };
                 }
                 else
                 {
                     template.Header = new BasePlainElement[headers[PageSection.Header].Count];
                     headers[PageSection.Header].CopyTo(template.Header);
                     template.Footer = new BasePlainElement[headers[PageSection.Footer].Count];
                     headers[PageSection.Footer].CopyTo(template.Footer);
                 }
                 template.PageFooter = new BasePlainElement[headers[PageSection.PageFooter].Count];
                 headers[PageSection.PageFooter].CopyTo(template.PageFooter);
             }
             catch (Exception ex)
             {
                 _printingManager.Logger.LogError(Message.PrintingReportHeadersBuildFailed, ex);
             }
         }
         if (protocolTemplate.VoteLines != null && protocolTemplate.VoteLines.Length > 0)
         {
             try
             {
                 bodyTable = new Table
                 {
                     Columns = new[]
                     {
                         new ColDefinition {Width = election.Protocol.NumberWidth},
                         new ColDefinition {Width = election.Protocol.NameWidth},
                         new ColDefinition {Width = election.Protocol.ValueWidth},
                         new ColDefinition {Width = election.Protocol.TextValueWidth},
                     }
                 };
                 var tableEntry = CreateProtocolBodyTable(
                     protocolTemplate,
                     election,
                     reportType == ReportType.ElectionProtocol,
                     (bool)reportParameters[PRN_PRINT_RESULTS]);
                 bodyTable.Body = tableEntry.ToArray();
             }
             catch (Exception ex)
             {
                 _printingManager.Logger.LogError(Message.PrintingReportBodyBuildFailed, ex);
             }
         }
         if (headerTable != null)
         {
             tables.Add(headerTable);
         }
         if (bodyTable != null)
         {
             tables.Add(bodyTable);
         }
         if (footerTable != null)
         {
             tables.Add(footerTable);
         }
     }
     template.Body = tables.ToArray();
 }
예제 #2
0
 public override Table[] GetTables(ReportTemplateParser parser)
 {
     Lines = new Lines();
     Lines.AddRange(ReportTemplate.ConstructHeader(Body));
     return(new[] { this });
 }