bool NextSection(bool child) { SubReport subrep; Section sec; Section oldsection; int lastdetail; int firstdetail; bool dataavail; int index; bool SearchGroupHeader; SearchGroupHeader = false; oldsection = section; section = null; // If the old selected section has a child subreport then execute first if ((oldsection != null) && child) { if (oldsection.ChildSubReport != null) { dataavail = false; subrep = oldsection.ChildSubReport; if (subrep.Alias.Length == 0) { dataavail = true; } else { index = DataInfo.IndexOf(subrep.Alias); if (index < 0) { throw new NamedException("Data alias not found:" + subrep.Alias, subrep.Alias); } if (DataInfo[index].DataSource.Length == 0) { DataInfo[index].DisConnect(); UpdateParamsBeforeOpen(index, true); DataInfo[index].Connect(); DataInfo[index].GoFirstMem(); } else { if (DataInfo[index].Data.Eof) { if (subrep.ReOpenOnPrint) { DataInfo[index].DisConnect(); UpdateParamsBeforeOpen(index, true); DataInfo[index].Connect(); DataInfo[index].GoFirstMem(); } } } if (!DataInfo[index].Data.Eof) { dataavail = true; } else { SearchGroupHeader = true; } } subrep.LastRecord = !dataavail; if (dataavail || (!subrep.PrintOnlyIfDataAvailable)) { subrep.SubReportChanged(SubReportEvent.SubReportStart, ""); subreport = subrep; section = null; CurrentSectionIndex = -1; PendingSections.Add(oldsection); CurrentSubReportIndex = SubReports.IndexOf(subreport); subreport.SubReportChanged(SubReportEvent.DataChange, ""); subreport.CurrentGroupIndex = -subreport.GroupCount; if (subreport.CurrentGroupIndex < 0) { CurrentSectionIndex = subreport.FirstDetail + subreport.CurrentGroupIndex - 1; } } } else { SearchGroupHeader = true; } } else { SearchGroupHeader = true; } if (FGroupHeaders.Count == 0) { SearchGroupHeader = false; } if (SearchGroupHeader) { index = FGroupHeaders.IndexOf(oldsection); if (index >= 0) { FGroupHeaders.RemoveAt(index); if (FGroupHeaders.Count > 0) { section = FGroupHeaders[0]; Section asec = PendingSections[PendingSections.Count - 1]; CurrentSubReportIndex = SubReports.IndexOf(asec.SubReport); if (CurrentSubReportIndex < 0) { throw new UnNamedException("SubReport not found"); } subreport = section.SubReport; } else { section = PendingSections[PendingSections.Count - 1]; CurrentSubReportIndex = SubReports.IndexOf(section.SubReport); if (CurrentSubReportIndex < 0) { throw new UnNamedException("SubReport not found"); } PendingSections.RemoveAt(PendingSections.Count - 1); subreport = section.SubReport; CurrentSectionIndex = subreport.Sections.IndexOf(section); if (CurrentSectionIndex < 0) { throw new UnNamedException("Section not found"); } } } } if (section != null) { return(true); } // Check the condition while (CurrentSubReportIndex < SubReports.Count) { CheckProgress(false); subrep = SubReports[CurrentSubReportIndex]; // The first section are the group footers until // CurrentGroup while (subrep.CurrentGroupIndex != 0) { CheckProgress(false); lastdetail = subrep.LastDetail; firstdetail = subrep.FirstDetail; CurrentSectionIndex++; if (subrep.CurrentGroupIndex > 0) { if (subrep.CurrentGroupIndex < (CurrentSectionIndex - lastdetail)) { // Restore position // And the next will be group headers if (subrep.LastRecord) { CurrentSectionIndex = subrep.Sections.Count; subrep.CurrentGroupIndex = 0; break; } else { // Send Messages for each group subrep.InitGroups(subrep.CurrentGroupIndex); // Restores position NextRecord(true); CurrentSectionIndex = subrep.FirstDetail - subrep.CurrentGroupIndex; subrep.CurrentGroupIndex = -subrep.CurrentGroupIndex; sec = subrep.Sections[CurrentSectionIndex]; if (sec.EvaluatePrintCondition()) { section = sec; subreport = subrep; break; } } } else { sec = subrep.Sections[CurrentSectionIndex]; if (sec.EvaluatePrintCondition()) { section = sec; subreport = subrep; break; } } } else { // Group headers if (CurrentSectionIndex < firstdetail) { sec = subrep.Sections[CurrentSectionIndex]; if (sec.EvaluatePrintCondition()) { section = sec; subreport = subrep; break; } } else { subrep.CurrentGroupIndex = 0; CurrentSectionIndex = -1; } } } if (section != null) { break; } while (CurrentSectionIndex < subrep.Sections.Count) { CheckProgress(false); if (CurrentSectionIndex < 0) { CurrentSectionIndex = subrep.FirstDetail; } else { CurrentSectionIndex++; } if (!subrep.LastRecord) { if (CurrentSectionIndex > subrep.LastDetail) { if (NextRecord(false)) { CurrentSectionIndex = subrep.LastDetail; break; } if (!subrep.LastRecord) { CurrentSectionIndex = subrep.FirstDetail; sec = subrep.Sections[CurrentSectionIndex]; if (sec.EvaluatePrintCondition()) { section = sec; subreport = subrep; break; } } else { CurrentSectionIndex = subrep.LastDetail; subrep.CurrentGroupIndex = subrep.GroupCount; break; } } else { if (CurrentSectionIndex <= subrep.LastDetail) { sec = subrep.Sections[CurrentSectionIndex]; if (sec.EvaluatePrintCondition()) { section = sec; subreport = subrep; break; } } } } } if ((section == null) && (subrep.CurrentGroupIndex == 0)) { // If it's a child subreport // Returns null section so pending will print if (subrep.ParentSubReport != null) { break; } do { subrep.SubReportChanged(SubReportEvent.SubReportEnd, ""); CurrentSubReportIndex++; if (CurrentSubReportIndex >= SubReports.Count) { break; } subrep = SubReports[CurrentSubReportIndex]; if (subrep.ParentSubReport == null) { if (subrep.IsDataAvailable()) { subrep.SubReportChanged(SubReportEvent.SubReportStart, ""); subrep.SubReportChanged(SubReportEvent.DataChange, ""); break; } } } while (true); if (CurrentSubReportIndex >= SubReports.Count) { break; } CurrentSectionIndex = subrep.FirstDetail - subrep.GroupCount - 1; subrep.CurrentGroupIndex = -subrep.GroupCount; subrep.LastRecord = false; } else if (subrep.CurrentGroupIndex == 0) { break; } } bool aresult = (section != null); // If there are still pending sections if (section == null) { if (PendingSections.Count > 0) { section = PendingSections[PendingSections.Count - 1]; CurrentSubReportIndex = SubReports.IndexOf(section.SubReport); if (CurrentSubReportIndex < 0) { throw new UnNamedException("Subreport not found"); } PendingSections.RemoveAt(PendingSections.Count - 1); subreport = section.SubReport; CurrentSectionIndex = subreport.Sections.IndexOf(section); if (CurrentSectionIndex < 0) { throw new UnNamedException("Subreport not found"); } NextSection(false); } } return(aresult); }
void PrintFixedSections(bool Headers) { int pheader, pfooter; int i, pheadercount, pfootercount; Section psection; int afirstdetail; bool printit; Point MaxExtent = new Point(); bool PartialPrint; PartialPrint = false; MaxExtent.X = pagespacex; MaxExtent.Y = FreeSpace; if (Headers) { // First the global headers for (i = 0; i < GHeaders.Count; i++) { psection = GHeaders[i]; if (psection.EvaluatePrintCondition()) { asection = psection; CheckSpace(); PrintSection(false, ref PartialPrint); } } // Print the header fixed sections pheader = subreport.FirstPageHeader; pheadercount = subreport.PageHeaderCount; for (i = 0; i < pheadercount; i++) { psection = subreport.Sections[i + pheader]; if (!psection.Global) { if (psection.EvaluatePrintCondition()) { asection = psection; CheckSpace(); PrintSection(false, ref PartialPrint); } } } int index; SubReports psubreports = new SubReports(); for (i = 0; i < PendingSections.Count; i++) { psection = PendingSections[i]; index = psubreports.IndexOf(psection.SubReport); if (index < 0) { psubreports.Add(psection.SubReport); } } index = psubreports.IndexOf(subreport); if (index < 0) { psubreports.Add(subreport); } // Now prints repeated group headers for (int j = 0; j < psubreports.Count; j++) { SubReport subrep = psubreports[j]; afirstdetail = subrep.FirstDetail; for (i = subrep.GroupCount; i > 0; i--) { psection = subrep.Sections[afirstdetail - i]; if (psection.PageRepeat) { // if ((Math.Abs(subrep.CurrentGroupIndex) <= i) && (section!=psection)) // if ((Math.Abs(subreport.CurrentGroupIndex) < i)) // Group headers are printed when page repeat=true bool dopagerepeat = false; // Allways if there is another active subreport if (subrep != subreport) { dopagerepeat = true; } else { // Never if the current section is just the group header if (section != psection) { // If the section is enclosed between the header // and the footer if (CurrentSectionIndex > subrep.FirstDetail - i) { if (psection.ForcePrint) { // (footer included) if (CurrentSectionIndex <= subrep.LastDetail + i) { dopagerepeat = true; } } else { // (footer not included) if (CurrentSectionIndex < subrep.LastDetail + i) { dopagerepeat = true; } } } } } if (dopagerepeat) { if (psection.EvaluatePrintCondition()) { // Add group headers to be printed at the // main print loop (child subreports and horz/vert.desp) FGroupHeaders.Add(psection); } } } } } pagefooterpos = pageposy + FreeSpace; // Reserve space for page footers // Print conditions for footers are evaluated at the begining of // the page // Global page footers for (i = 0; i < GFooters.Count; i++) { psection = GFooters[i]; asection = psection; CheckSpace(); pagefooterpos = pageposy + FreeSpace - sectionext.Y; FreeSpace = FreeSpace - sectionext.Y; } pfooter = subreport.FirstPageFooter; pfootercount = subreport.PageFooterCount; for (i = 0; i < pfootercount; i++) { psection = subreport.Sections[i + pfooter]; if (!psection.Global) { asection = psection; havepagefooters = true; CheckSpace(); pagefooters.Add(psection); pagefooterpos = pageposy + FreeSpace - sectionext.Y; FreeSpace = FreeSpace - sectionext.Y; } } } else { // Print page footers if ((GFooters.Count > 0) || (pagefooters.Count > 0)) { pageposy = pagefooterpos; for (i = 0; i < pagefooters.Count; i++) { asection = pagefooters[i]; if (!asection.Global) { printit = true; if (!asection.ForcePrint) { if (section == null) { printit = false; } } if (printit) { if (asection.EvaluatePrintCondition()) { sectionext = asection.GetExtension(FDriver, MaxExtent, false); PrintSection(false, ref PartialPrint); FreeSpace = 0; } } } } // Global page footers for (i = 0; i < GFooters.Count; i++) { asection = GFooters[i]; printit = true; if (!asection.ForcePrint) { if (section == null) { printit = false; } } if (printit) { if (asection.EvaluatePrintCondition()) { sectionext = asection.GetExtension(FDriver, MaxExtent, false); PrintSection(false, ref PartialPrint); FreeSpace = 0; } } } } } }
public SubReportsEnumerator(SubReports t) { this.t = t; }