Faceți căutări pe acest blog

vineri, 24 aprilie 2015

Previewing two or more different reports on the same page

Sometimes you my want to see side by side two or more reports, in the same window.
Possible solutions:
1) Using a mixture of Reportbehavior 80 and Reportbehavior 90
PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
    width=1000
    height=500
    oFrm1=.Null.
    oFrm2=.Null.
    PROCEDURE load
        CREATE CURSOR aa (ii I autoinc,bb C(10) DEFAULT SYS(2015))
        FOR lni=1 TO 100
            APPEND BLANK
        NEXT
        CREATE REPORT rep1 FROM aa
        SELECT 0
        USE rep1.frx
        LOCATE FOR objtype=9 AND objcode=1
        replace tag WITH [_vfp.docmd("select aa")] && page header On Entry event
        USE
       
       
        CREATE CURSOR bb (jj I autoinc,cc C(10) DEFAULT SYS(2015))
        FOR lni=1 TO 100
            APPEND BLANK
        NEXT
        SELECT 0
        CREATE REPORT rep2 FROM bb
        USE rep2.frx
        LOCATE FOR objtype=9 AND objcode=1
        replace tag WITH [_vfp.docmd("select bb")] && page header On Entry event
        USE
    ENDPROC
    PROCEDURE init
        DEFINE WINDOW win1 FROM 0,0 TO 10,10 NAME ThisForm.ofrm1 IN WINDOW (This.Name)
        ThisForm.ofrm1.Name=SYS(2015)
        ThisForm.ofrm1.width=500
        ThisForm.ofrm1.height=500

        DEFINE WINDOW win2 FROM 0,0 TO 10,10 NAME ThisForm.ofrm2 IN WINDOW (This.Name)
        ThisForm.ofrm2.Name=SYS(2015)
        ThisForm.ofrm2.width=500
        ThisForm.ofrm2.height=500
        ThisForm.ofrm2.Left=500

        ACTIVATE WINDOW (ThisForm.ofrm2.Name)
        ACTIVATE WINDOW (ThisForm.ofrm1.Name)

        SET REPORTBEHAVIOR 80
        SELECT aa
        REPORT FORM rep1 PREVIEW WINDOW (ThisForm.ofrm1.Name) IN WINDOW (ThisForm.ofrm1.Name) NOWAIT
        SET REPORTBEHAVIOR 90
        SELECT bb
        REPORT FORM rep2 PREVIEW WINDOW (ThisForm.ofrm2.Name) IN WINDOW (ThisForm.ofrm2.Name) NOWAIT
    ENDPROC
    PROCEDURE QueryUnload
        DEACTIVATE WINDOW (ThisForm.ofrm1.Name)
        DEACTIVATE WINDOW (ThisForm.ofrm2.Name)
        ThisForm.ofrm1=.Null.
        ThisForm.ofrm2=.Null.
        CLEAR MEMORY
    ENDPROC
ENDDEFINE


2) Displaying three reports, using reportbehavior 90
PUBLIC ofrm
ofrm=CREATEOBJECT("MyForm")
ofrm.show()

DEFINE CLASS MyForm as Form
    width=1050
    height=500
    oFrm1=.Null.
    oFrm2=.Null.
    oFrm3=.Null.
    PROCEDURE load
        CREATE CURSOR aa (ii I autoinc,bb C(10) DEFAULT SYS(2015))
        FOR lni=1 TO 100
            APPEND BLANK
        NEXT
        CREATE REPORT rep1 FROM aa
        SELECT 0
        USE rep1.frx
        LOCATE FOR objtype=9 AND objcode=1
        replace tag WITH [_vfp.docmd("select aa")] && page header On Entry event
        USE
       
        CREATE CURSOR bb (jj I autoinc,cc C(10) DEFAULT SYS(2015))
        FOR lni=1 TO 100
            APPEND BLANK
        NEXT
        SELECT 0
        CREATE REPORT rep2 FROM bb
        USE rep2.frx
        LOCATE FOR objtype=9 AND objcode=1
        replace tag WITH [_vfp.docmd("select bb")] && page header On Entry event
        USE
       
        CREATE CURSOR cc (kk I autoinc,dd C(10) DEFAULT SYS(2015))
        FOR lni=1 TO 100
            APPEND BLANK
        NEXT
        SELECT 0
        CREATE REPORT rep3 FROM cc
        USE rep3.frx
        LOCATE FOR objtype=9 AND objcode=1
        replace tag WITH [_vfp.docmd("select cc")] && page header On Entry event
        USE
    ENDPROC
    PROCEDURE init
        DEFINE WINDOW win1 FROM 0,0 TO 10,10 NAME ThisForm.ofrm1 IN WINDOW (This.Name)
        ThisForm.ofrm1.Name=SYS(2015)
        ThisForm.ofrm1.width=350
        ThisForm.ofrm1.height=500

        DEFINE WINDOW win2 FROM 0,0 TO 10,10 NAME ThisForm.ofrm2 IN WINDOW (This.Name)
        ThisForm.ofrm2.Name=SYS(2015)
        ThisForm.ofrm2.width=350
        ThisForm.ofrm2.height=500
        ThisForm.ofrm2.Left=350

        DEFINE WINDOW win3 FROM 0,0 TO 10,10 NAME ThisForm.ofrm3 IN WINDOW (This.Name)
        ThisForm.ofrm3.Name=SYS(2015)
        ThisForm.ofrm3.width=350
        ThisForm.ofrm3.height=500
        ThisForm.ofrm3.Left=700

        ACTIVATE WINDOW (ThisForm.ofrm1.Name)
        ACTIVATE WINDOW (ThisForm.ofrm2.Name)
        ACTIVATE WINDOW (ThisForm.ofrm3.Name)

        SET REPORTBEHAVIOR 90
        LOCAL loRL1,loRL2
        loRL1= CREATEOBJECT("ReportListener")
        loRL2= CREATEOBJECT("ReportListener")
        loRL3= CREATEOBJECT("ReportListener")
        STORE 1 TO loRL1.ListenerType,loRL2.ListenerType,loRL3.ListenerType

        SELECT aa
        REPORT FORM rep1 OBJECT loRL1 WINDOW (ThisForm.ofrm1.Name) IN WINDOW (ThisForm.ofrm1.Name) NOWAIT
        SELECT bb
        REPORT FORM rep2 OBJECT loRL2 WINDOW (ThisForm.ofrm2.Name) IN WINDOW (ThisForm.ofrm2.Name) NOWAIT
        SELECT cc
        REPORT FORM rep3 OBJECT loRL3 WINDOW (ThisForm.ofrm3.Name) IN WINDOW (ThisForm.ofrm3.Name) NOWAIT
    ENDPROC
    PROCEDURE QueryUnload
        DEACTIVATE WINDOW (ThisForm.ofrm1.Name)
        DEACTIVATE WINDOW (ThisForm.ofrm2.Name)
        DEACTIVATE WINDOW (ThisForm.ofrm3.Name)
        ThisForm.ofrm1=.Null.
        ThisForm.ofrm2=.Null.
        ThisForm.ofrm3=.Null.
        CLEAR MEMORY
    ENDPROC
ENDDEFINE


In both solutions, in the main form were embedded two or more forms (windows), one for each report.
But a more elegant solution is to add two containers in the same form

3) Using the reportbehavior 90 and the report listener
*----------------------------------------------------------------------------------
* Adapted from VFP help topic Creating a Custom Preview Container
* code example: simplepreview.prg
*----------------------------------------------------------------------------------

CREATE CURSOR x1 (ii I autoinc,aa C(10) DEFAULT REPLICATE(CHR(32+ii),10))
FOR lni=1 TO 100
    APPEND BLANK
NEXT
CREATE REPORT rep1 FROM x1

CREATE CURSOR x2 (jj I autoinc,bb C(10) DEFAULT REPLICATE(CHR(64+jj),10))
FOR lni=1 TO 50
    APPEND BLANK
NEXT
CREATE REPORT rep2 FROM x2

pc = CREATEOBJECT("FormPreview")

rl1 = NEWOBJECT("ReportListener")
rl1.ListenerType     = 1 && Buffer all pages, use preview container
rl1.PreviewContainer = pc.SimplePreview1

rl2 = NEWOBJECT("ReportListener")
rl2.ListenerType     = 1 && Buffer all pages, use preview container
rl2.PreviewContainer = pc.SimplePreview2
SELECT x1
REPORT FORM rep1 OBJECT rl1 &&NOWAIT
SELECT x2
REPORT FORM rep2 OBJECT rl2 &&NOWAIT

pc.visible=.T.


DEFINE CLASS FormPreview as Form
    caption="Click - next, Rightclick - previous page"
    width=1000
    height=800
    ADD OBJECT SimplePreview1 as SimplePreview
    ADD OBJECT SimplePreview2 as SimplePreview WITH left=500
    PROCEDURE QueryUnload
        IF NOT ISNULL( THIS.SimplePreview1.ListenerRef )
            THIS.SimplePreview1.ListenerRef.OnPreviewClose(.F.)
            THIS.SimplePreview1.ListenerRef = .NULL.
        ENDIF
        IF NOT ISNULL( THIS.SimplePreview2.ListenerRef )
            THIS.SimplePreview2.ListenerRef.OnPreviewClose(.F.)
            THIS.SimplePreview2.ListenerRef = .NULL.
        ENDIF
        THIS.Hide()
        NODEFAULT
    ENDPROC
    PROCEDURE Paint
        IF NOT ISNULL( THIS.SimplePreview1.ListenerRef )
            THIS.SimplePreview1.ListenerRef.OutputPage( THIS.SimplePreview1.PageNo, THIS.SimplePreview1.Canvas, 2 )
        ENDIF
        IF NOT ISNULL( THIS.SimplePreview2.ListenerRef )
            THIS.SimplePreview2.ListenerRef.OutputPage( THIS.SimplePreview2.PageNo, THIS.SimplePreview2.Canvas, 2 )
        ENDIF
    ENDPROC
ENDDEFINE
   
DEFINE CLASS SimplePreview AS Container
    ListenerRef = .NULL.
    PageNo      = 1
    width=500
    height=800
    ADD OBJECT Canvas AS Shape WITH ;
        Height = 800, Width = 500
    PROCEDURE Canvas.Click
        WITH THIS.Parent
            IF .PageNo < .ListenerRef.OutputPageCount
                .PageNo = .PageNo + 1
                .Refresh()
            ENDIF
        ENDWITH
    ENDPROC
    PROCEDURE Canvas.RightClick
        WITH THIS.Parent
            IF .PageNo > 1
                .PageNo = .PageNo - 1
                .Refresh()
            ENDIF
        ENDWITH
    ENDPROC
    PROCEDURE SetReport
        LPARAMETER oListenerRef
        THIS.ListenerRef = oListenerRef
    ENDPROC
ENDDEFINE

Niciun comentariu:

Trimiteți un comentariu