Пример #1
0
        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);
        }
Пример #2
0
        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;
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        override public bool PrintNextPage()
        {
            int i;

            if (ErrorProcessing)
            {
                throw new UnNamedException("Error processing\n" + LastErrorProcessing);
            }
            PageNum++;
            PageNumGroup++;
            // Updates page size, and orientation
            if (MetaFile.Pages.CurrentCount <= PageNum)
            {
                if (TwoPass)
                {
                    MetaFile.ForwardOnly = false;
                }
                MetaFile.Pages.Add(new MetaPage(MetaFile));
            }
            MetaFile.CurrentPage = PageNum;
            DoUpdatePageSize(MetaFile.Pages[MetaFile.Pages.CurrentCount - 1]);
            FGroupHeaders.Clear();
            PrintedSomething = false;
            if (section == null)
            {
                throw new UnNamedException("Last sectoin reached");
            }
            if (subreport != null)
            {
                for (i = 0; i < SubReports.Count; i++)
                {
                    SubReports[i].SubReportChanged(SubReportEvent.PageChange, "");
                }
            }
            havepagefooters     = false;
            sectionextevaluated = false;
            oldprintedsection   = null;
            if (!FCompose)
            {
                FreeSpace = InternalPageHeight;
                FreeSpace = FreeSpace - TopMargin - BottomMargin;
                pageposy  = TopMargin;
                pageposx  = LeftMargin;
            }
            else
            {
                if ((GHeaders.Count > 0) ||
                    (subreport.PageHeaderCount > 0))
                {
                    MetaFile.Pages.Add(new MetaPage(MetaFile));
                    PageNum++;
                    MetaFile.CurrentPage = MetaFile.Pages.CurrentCount - 1;
                    FreeSpace            = InternalPageHeight;
                    FreeSpace            = FreeSpace - TopMargin - BottomMargin;
                    pageposy             = TopMargin;
                    pageposx             = LeftMargin;
                    DoUpdatePageSize(MetaFile.Pages[MetaFile.Pages.CurrentCount - 1]);
                }
                else
                {
                    PrintedSomething = true;
                }
                //FCompose = false;
            }
            pagespacex = InternalPageWidth;
            int oldhorzdespposition = LeftMargin;

            pagefooters = new Sections();
            try
            {
                Point MaxExtent = new Point();
                bool  PartialPrint;
                // Fills the page with fixed sections
                PrintFixedSections(true);
                // Group headers with child subreports
                if (FGroupHeaders.Count > 0)
                {
                    PendingSections.Add(section);
                    section = FGroupHeaders[0];
                }
                oldsubreport = subreport;
                Point lastvertpos = new Point();
                lastvertpos.X = pageposx;
                lastvertpos.Y = pageposy;
                while (section != null)
                {
                    if (PrintedSomething)
                    {
                        if (section.EvaluateBeginPage())
                        {
                            break;
                        }
                    }
                    asection = section;
                    // Horz.Desp.
                    if (oldprintedsection != null)
                    {
                        if (oldprintedsection.HorzDesp)
                        {
                            if (section.HorzDesp)
                            {
                                MaxExtent.X         = pagespacex;
                                MaxExtent.Y         = FreeSpace;
                                sectionext          = section.GetExtension(FDriver, MaxExtent, false);
                                sectionextevaluated = true;
                                if ((pageposx + oldprintedsectionext.X + sectionext.X) <= pagespacex)
                                {
                                    pageposx  = pageposx + oldprintedsectionext.X;
                                    pageposy  = pageposy - oldprintedsectionext.Y;
                                    FreeSpace = FreeSpace + oldprintedsectionext.Y;
                                }
                                else
                                {
                                    pageposx = LeftMargin;
                                }
                            }
                            else
                            {
                                pageposx = oldhorzdespposition;
                            }
                        }
                        else
                        {
                            oldhorzdespposition = pageposx;
                        }
                    }
                    if (!CheckSpace())
                    {
                        // If the current section have vert desp, do
                        // a vertical and horz. desp if possible
                        if (section.VertDesp)
                        {
                            // Go to old vertical position if fits horizontally
                            MaxExtent.X         = pagespacex;
                            MaxExtent.Y         = lastvertpos.Y - BottomMargin;
                            sectionext          = section.GetExtension(FDriver, MaxExtent, false);
                            sectionextevaluated = true;
                            if ((pageposx + sectionext.X * 2) <= pagespacex)
                            {
                                FreeSpace = FreeSpace + (pageposy - lastvertpos.Y);
                                pageposx  = pageposx + sectionext.X;
                                pageposy  = lastvertpos.Y;
                            }
                            else
                            {
                                pageposx = LeftMargin;
                                break;
                            }
                            if (!CheckSpace())
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    PartialPrint = false;
                    PrintSection(true, ref PartialPrint);
                    if (!PartialPrint)
                    {
                        if (!section.VertDesp)
                        {
                            lastvertpos.X = pageposx;
                            lastvertpos.Y = pageposy;
                        }
                        NextSection(true);
                        if (section != null)
                        {
                            if (!section.VertDesp)
                            {
                                lastvertpos.X = pageposx;
                                lastvertpos.Y = pageposy;
                            }
                        }
                    }
                    if (PrintedSomething)
                    {
                        if (asection.SkipPage)
                        {
                            break;
                        }
                    }
                    // if Subreport changed and has have pagefooter
                    if ((oldsubreport != subreport) && (havepagefooters))
                    {
                        break;
                    }
                    oldsubreport = subreport;
                }
                // Fills the page with fixed sections
                if (PrintedSomething)
                {
                    if (oldprintedsection != null)
                    {
                        if (oldprintedsection.HorzDesp)
                        {
                            pageposx = oldhorzdespposition;
                        }
                    }
                }
                PrintFixedSections(false);
                pagefooters = null;
            }
            catch (Exception E)
            {
                pagefooters         = null;
                ErrorProcessing     = true;
                LastErrorProcessing = E.Message;
                throw;
            }
            bool aresult = (section == null);

            LastPage = aresult;
            if (LastPage)
            {
                MetaFile.Finish();
                CheckProgress(true);
            }
            if (aresult)
            {
                EndPrint();
            }
            return(aresult);
        }