pagebackrect
sitebanner

Quartam Reports - Examples

Home | Products | Services | Resources | Store | Company | Terms of Use | Privacy Policy | Site Map

Copyright 2004-2013, Quartam Software/Jan Schenkel. All Rights Reserved Worldwide.

Quartam is a trademark of Jan Schenkel. Other names may be trademarks or registered trademarks of their respective owners.

How to use Quartam Reports for LiveCode

Quartam Reports makes it easy for you to print reports with data coming from all types of sources :

How to print stacks using Quartam Reports

At the heart of LiveCode are stacks, which combine the user interface and the program logic and can also store data. In its most basic form, a stack is just a deck of cards. Many LiveCode developers will store data in these stacks - and if you are one of them, you'll be happy to know that we made it very easy to print a report from data stored in stacks.

Suppose you have made a little address book stack named "Addresses" and you want to print a report of the people in it, with their name and address.

First you make your report layout using the Layout Builder. You can easily draw the data fields and enter their LiveCode expression. Expressions can be as simple as :

field "First name"

or even the concatenation of several fields :

field "Last name" & comma && field "First name"

Add all the data fields that you need, and enter their expressions -- in a real report you will also place the label fields and the graphics needed to make it more organised and easier to spot the important data.

Printing the report is as easy as adding a button and setting its script to :

on mouseUp
-- define the variables
local tLayoutFile, tStackName, tShowPreview
-- set their values
put "mystackreport.qrl" into tLayoutFile
put "Addresses" into tStackName
put true into tShowPreview
-- print the report
qrtReports_PrintReportFromStack tLayoutFile, tStackName, tShowPreview
end mouseUp

When you click the button, Quartam Reports gets to work. It will automatically get the correct data from each card and combine this information with the layout to produce your report.

Advanced features of Quartam Reports

In the days of the Information Age, data can come from many sources : a stack, local or remote databases, a static web-page somewhere on the internet or a dynamic LAMP-driven website, the result of a call to Web Services -- LiveCode is an excellent tool to obtain data from various sources, and prepare them for printing in complex, integrated reports.

Quartam Reports provides you with a simple yet powerful library to connect the dots : you can script your own data broker which fetches the information from its various sources and provides it to the report printing engine. Below we've provided a sample data broker that :

In the end, you have a single button script:

-- define the local variables
local sConnectionID, sCursorID, sRecordCount, sCurrentRecord
local sRecordAsArray

on mouseUp
## PRINT MY COMPLEX REPORT
-- connect to the database and execute the query
put revdb_connect("mysql","localhost","dbase","user","password") \
into sConnectionID
put revdb_query(sConnectionID, "SELECT * FROM articles") into sCursorID
put revdb_recordcount(sCursorID) into sRecordCount
put 1 into sCurrentRecord
-- prepare the data of the first record for printing
PrepareRecordData
-- get ready to print
local tLayoutFile, tDataBroker, tShowPreview
put "mycomplexreport.qrl" into tLayoutFile
put the long ID of me into tDataBroker
put true into tShowPreview
-- print the report
qrtReports_PrintReport tLayoutFile, tDataBroker, tShowPreview
-- clean up after printing
get revdb_closecursor(sCursorID)
get revdb_disconnect(sConnectionID)
end mouseUp

on PrepareRecordData
## PREPARE THE DATA FROM THE CURRENT RECORD FOR PRINTING
-- define the variables
local tColumnNames, tColumnName
-- copy the contents of the current record into the array
-- column per column
put revdb_columnnames(sCursorID) into tColumnNames
repeat for each item tColumnName in tColumnNames
put revdb_columnbyname(sCursorID,tColumnName) into \
sRecordAsArray[tColumnName]
end repeat
-- retrieve the data from our supplier website
put "http://www.example.com/cgi-bin/delivery_days.pl?article=" & \
URLEncode(sRecordAsArray["article_id"]) into tRemoteURL
put URL tRemoteURL into sRecordAsArray["delivery_days"]
end PrepareRecordData

-- Quartam Reports Callback Handlers and Functions

function qrtReports_EndOfReport
## QR :: RETURN TRUE IF THE END OF THE REPORT HAS BEEN REACHED
-- we've reached the end if we've passed our last record
return (sCurrentRecord > sRecordCount)
end qrtReports_EndOfReport

on qrtReports_MoveNextRecord
## QR :: PREPARE EVERYTHING FOR PRINTING THE NEXT RECORD
-- update the sCurrentRecord local variable
add 1 to sCurrentRecord
-- move to the next record in the cursor
get revdb_movenext(sCursorID)
-- and prepare the record data
PrepareRecordData
end qrtReports_MoveNextRecord

function qrtReports_ValueOfExpression pExpression
## QR :: EVALUATE THE EXPRESSION AND RETURN THE RESULT
-- workaround for limitation in LiveCode engine
local tExpression
put pExpression into tExpression
replace "<QUOTE_REPLACEMENT>" with quote in tExpression
return value(tExpression)
end qrtReports_ValueOfExpression

With such a data broker, the data fields in your report layout will have an expression of the form

sRecordAsArray["delivery_days"]

As you can see from the above example, a few lines of script allow you to dynamically integrate data from multiple sources into a single report. With LiveCode and Quartam Reports the possibilities are endless !

largeered