Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do I create a control to print specific report pages
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01082398
Message ID:
01082580
Vues:
7
"IncludePageInOutput" is a method in the reportlistener. If you create a listener, you can override this method with code that checks the current page against the array you have created to determine whether it should print the page.

Here's some sample code I put together for the SW Fox conference. You can alter this as needed to use your array. The simple solution is that you just check the tnPageNo parameter of the method against your array and then return .t. or .f. to indicate whether the particular page should be printed.
LPARAMETERS tnPageNo

*-- Expecting This.cPagesToPrint to contain any of the following:
*-- A Numeric Value for an individual page
*--    10
*-- A list of pages to print, separated by ',' or ' '
*--    1, 5, 7
*-- The list of pages can include a range indicated with a "-"
*--    1, 5, 7-10, 12
*-- The word "odd" or "even" to indicate only odd or even pages
*--    If ODD or EVEN is combined with anything else, only do the
*--    Odd or Even pages that match the other criteria.

LOCAL 	llPrint, ;
		lnPages, ;
		laPages, ;
		lnRange, ;
		laRange, ;
		lnStart, ;
		lnEnd, ;
		lnFor, ;
		lnForPages, ;
		lcOddEvenAll, ;
		lcTmp
		

llPrint = .f.
lcOddEvenAll = "A"

*-- Make it easy to get out
FOR lnFor = 1 TO 1

	*-- Nothing special to do, just get out and print
	IF EMPTY(This.cPagesToPrint)
		llPrint = .t.
		EXIT
	ENDIF

	*-- If numeric, assume this page
	IF VARTYPE(This.cPagesToPrint) == 'N'
		llPrint = m.tnPageNo == This.cPagesToPrint
		EXIT
	ENDIF

	*-- Determine whether odd or even has been indicated
	DO CASE
		CASE 'ODD' $ UPPER(This.cPagesToPrint) AND ;
				'EVEN' $ UPPER(This.cPagesToPrint)
			lcOddEvenAll = "A"
		CASE 'ODD' $ UPPER(This.cPagesToPrint)
			lcOddEvenAll = "O"
		CASE 'EVEN' $ UPPER(This.cPagesToPrint)
			lcOddEvenAll = "E"
		OTHERWISE
			lcOddEvenAll = "A"
	ENDCASE		

	*-- If Odd or Even, get out if that's all there is
	IF NOT m.lcOddEvenAll = "A"
		lcTmp = UPPER(This.cPagesToPrint)
		lcTmp = STRTRAN(m.lcTmp, 'ODD', '')
		lcTmp = STRTRAN(m.lcTmp, 'EVEN', '')
		lcTmp = ALLTRIM(m.lcTmp, 1,',- ')
		IF EMPTY(m.lcTmp)
			llPrint = .t.
			EXIT
		ENDIF	
	ENDIF

	*-- Create an array of pages
	DIMENSION laPages[1]
	lnPages = ALINES(m.laPages, This.cPagesToPrint, 1+4, ',', ' ')

	*-- If nothing was found, get out w/o printing
	*-- (This can happen if the string just has parse characters)
	IF m.lnPages = 0
		EXIT
	ENDIF

	*-- See if this page exists in the array
	FOR ln = 1 TO m.lnPages

		*-- Loop if this is the Odd/Even row
		IF UPPER(m.laPages[m.ln]) = 'ODD' OR UPPER(m.laPages[m.ln]) = 'EVEN'
			LOOP
		ENDIF
		
		*-- If this row is a range, process accordingly
		IF '-' $ m.laPages[m.ln]
			DIMENSION laRange[1]
			lnRange = ALINES(m.laRange, m.laPages[m.ln], 1+4, '-')
			
			*-- There should only be 2 rows (a start and end page)
			IF m.lnRange <> 2
				LOOP
			ENDIF

			*-- Get the starting and ending pages
			lnStart = INT(VAL(m.laRange[1]))
			lnEnd = INT(VAL(m.laRange[2]))

			*-- Make sure the starting page is not greater than the ending page
			IF m.lnStart > m.lnEnd
				LOOP
			ENDIF

			*-- Is this page in this range?
			IF BETWEEN(m.tnPageNo, m.lnStart, m.lnEnd)		
				m.llPrint = .t.
				EXIT
			ENDIF

			*-- Nothing more to check on this one
			LOOP
		ENDIF

		*-- Is this page listed?
		lnStart = INT(VAL(m.laPages[m.ln]))
		IF m.tnPageNo == m.lnStart
			m.llPrint = .t.
			EXIT
		ENDIF
	ENDFOR
ENDFOR

*-- Check the Odd/Even page
IF (m.lcOddEvenAll = "O" AND MOD(m.tnPageNo,2) = 0) OR ;
		(m.lcOddEvenAll = "E" AND NOT MOD(m.tnPageNo,2) = 0)
	m.llPrint = .f.
ENDIF

RETURN m.llPrint
Cathy Pountney, Microsoft Visual FoxPro MVP
Memorial Business Systems, Inc. (www.mbs-intl.com)

My Website: (www.frontier2000.com)
My Blog: (www.cathypountney.blogspot.com)
My Book: The Visual FoxPro Report Writer - Pushing it to the Limit and Beyond
Free MSDN Article: What's New in the VFP 9.0 Report Writer
Free MSDN Article: The VFP 9.0 Report Writer In Action
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform