Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/DynaPDF Graphics/Reporting/GasReport/GasReport


Required plugins for this example: MBS DynaPDF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/DynaPDF Graphics/Reporting/GasReport/GasReport

This example is the version from Thu, 27th Nov 2019.

Project "GasReport.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class ReportWindow Inherits Window
Control ReportView Inherits ReportViewer
ControlInstance ReportView Inherits ReportViewer
End Control
EventHandler Sub Close() rpt.Close End EventHandler
EventHandler Sub Open() Dim ds As New GasDataSet Dim ps As New PrinterSetup rpt = New GasPricesReport If rpt.Run(ds, ps) Then If rpt.Document <> Nil Then ReportView.SetDocument(rpt.Document) End If End If End EventHandler
Property Private rpt As GasPricesReport
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class ReportViewer Inherits ContainerControl
Control ReportCanvas Inherits Canvas
ControlInstance ReportCanvas Inherits Canvas
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean #Pragma Unused X #Pragma Unused Y Zoomed = Not Zoomed Me.Invalidate(False) Return True End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If mCurrentPicture <> Nil Then If Zoomed Then g.DrawPicture(mCurrentPicture, 0, 0, Me.Width, Me.Height, 0, ReportScrollbar.Value, Me.Width / 2, Me.Height / 2) Else g.DrawPicture(mCurrentPicture, 0, 0, Me.Width, Me.Height, 0, ReportScrollbar.Value, Me.Width, Me.Height) End If Else g.DrawRect(0, 0, Me.Width, Me.Height) End If End EventHandler
End Control
Control ReportScrollbar Inherits ScrollBar
ControlInstance ReportScrollbar Inherits ScrollBar
EventHandler Sub ValueChanged() ReportCanvas.Refresh( False ) End EventHandler
End Control
Control PreviousButton Inherits PushButton
ControlInstance PreviousButton Inherits PushButton
EventHandler Sub Action() If mCurrentPage > 1 Then SetCurrentPage(mCurrentPage - 1) End If End EventHandler
End Control
Control NextButton Inherits PushButton
ControlInstance NextButton Inherits PushButton
EventHandler Sub Action() If mCurrentPage < mDocument.PageCount Then SetCurrentPage(mCurrentPage + 1) End If End EventHandler
End Control
Control PrintButton Inherits PushButton
ControlInstance PrintButton Inherits PushButton
EventHandler Sub Action() Dim ds As New GasDataSet Dim ps As New PrinterSetup Dim rpt As New GasPricesReport ' this is a report editor project item Dim g As Graphics ' set the resolution to 300 DPI for printing ps.MaxHorizontalResolution = 300 ps.MaxVerticalResolution = 300 If ps.PageSetupDialog Then ' necessary to update the PageSetup object to 300 DPI g = OpenPrinterDialog(ps, Nil) If g <> Nil Then If rpt.Run(ds, ps) Then ' if the report runs successfully rpt.Document.Print(g) End If End If End If End EventHandler
End Control
Control PDFButton Inherits PushButton
ControlInstance PDFButton Inherits PushButton
EventHandler Sub Action() Dim pdf As New MyDynapdfMBS Dim f1 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.pdf") Dim f2 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.png") Dim f3 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics Rendered.png") 'pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License If Not pdf.CreateNewPDF(f1) Then Return End If Call pdf.Append Dim g As Graphics = pdf.PageGraphics Dim ds As New GasDataSet Dim ps As New PrinterSetup Dim rpt As New GasPricesReport ' this is a report editor project item ' set the resolution to 300 DPI for printing ' not for PDF! 'ps.MaxHorizontalResolution = 300 'ps.MaxVerticalResolution = 300 If rpt.Run(ds, ps) Then ' if the report runs successfully rpt.Document.Print(g) End If // for debugging, show temp picture Dim p As Picture = pdf.PageGraphicsPicture p.Save(f2, p.SaveAsPNG) Call pdf.EndPage If pdf.HasPro Then Call pdf.RenderPageToImage(1, f3, 150, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG) End If Call pdf.CloseFile f1.Launch True End EventHandler
End Control
Private Sub SetCurrentPage(pageNum As Integer) mCurrentPage = pageNum mCurrentPicture = mDocument.Page(mCurrentPage) ReportScrollbar.Maximum = mCurrentPicture.Height - ReportCanvas.Height ReportScrollbar.Value = 0 ReportCanvas.Refresh(False) End Sub
Sub SetDocument(doc As Reports.RBReportDocument) mDocument = doc mCurrentPage = 1 If doc.PageCount > 0 Then SetCurrentPage(mCurrentPage) End Sub
Property Zoomed As Boolean
Property Private mCurrentPage As Integer
Property Private mCurrentPicture As Picture
Property Private mDocument As Reports.RBReportDocument
End Class
Class GasDataSet
Function EOF() As Boolean // Part of the Reports.DataSet interface. If mCurrentRecord > mData.Ubound Then Return True Return False End Function
Function Field(idx As Integer) As Variant #pragma unused idx // Part of the Reports.DataSet interface. Return "" End Function
Function Field(name As String) As Variant // Part of the Reports.DataSet interface. Static months() As String = Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ) Dim data() As String = SplitB( mData(mCurrentRecord), "," ) If name = "Year" Then Return data(0) Else Dim idx As Integer = months.IndexOf( name ) If idx <> -1 Then Return val(data( idx + 1 )) End If Return Nil End Function
Function NextRecord() As Boolean // Part of the Reports.DataSet interface. mCurrentRecord = mCurrentRecord + 1 End Function
Sub Run() // Part of the Reports.DataSet interface. mData = SplitB( Price_of_Gasoline, ChrB(13) ) mCurrentRecord = 0 End Sub
Function Type(fieldName as string) As integer // Part of the Reports.DataSet interface. // Types are defined here: // http://docs.xojo.com/index.php/Database.FieldSchema If fieldName = "Year" Then Return 5 // Text Else return 7 // Double End If End Function
Property Private mCurrentRecord As Integer
Property mData() As String
End Class
ExternalFile gasolinetank
End ExternalFile
ExternalFile Price_of_Gasoline
End ExternalFile
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer // output all messages on the console: System.DebugLog str(ErrorCode)+": "+ErrorMessage // and display dialog: Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Continue" d.CancelButton.Visible=True //show the Cancel button // a warning or an error? if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then // if user decided to ignore, we'll ignore if IgnoreWarnings then Return 0 d.Message="A warning occurred while processing your PDF code." // we add a third button to display all warnings d.AlternateActionButton.Caption = "Ignore warnings" d.AlternateActionButton.Visible = true else d.Message="An error occurred while processing your PDF code." end if d.Explanation = str(ErrorCode)+": "+ErrorMessage b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton Return 0 // ignore Case d.AlternateActionButton IgnoreWarnings = true Return 0 // ignore Case d.CancelButton Return -1 // stop End select End EventHandler
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer PageBreak = true Return -1 // stop End EventHandler
Property IgnoreWarnings As Boolean
Property PageBreak As Boolean
End Class
Class GasPricesReport Inherits Report
Control Label1 Inherits ReportLabel
ControlInstance Label1 Inherits ReportLabel
End Control
Control Picture1 Inherits ReportPicture
ControlInstance Picture1 Inherits ReportPicture
End Control
Control Label2 Inherits ReportLabel
ControlInstance Label2 Inherits ReportLabel
End Control
Control Field1 Inherits ReportField
ControlInstance Field1 Inherits ReportField
End Control
Control RectangleShape1 Inherits ReportRectangleShape
ControlInstance RectangleShape1 Inherits ReportRectangleShape
End Control
Control Label3 Inherits ReportLabel
ControlInstance Label3 Inherits ReportLabel
End Control
Control Field2 Inherits ReportField
ControlInstance Field2 Inherits ReportField
End Control
Control Label4 Inherits ReportLabel
ControlInstance Label4 Inherits ReportLabel
End Control
Control Field3 Inherits ReportField
ControlInstance Field3 Inherits ReportField
End Control
Control Label5 Inherits ReportLabel
ControlInstance Label5 Inherits ReportLabel
End Control
Control Field4 Inherits ReportField
ControlInstance Field4 Inherits ReportField
End Control
Control Label6 Inherits ReportLabel
ControlInstance Label6 Inherits ReportLabel
End Control
Control Field5 Inherits ReportField
ControlInstance Field5 Inherits ReportField
End Control
Control Label7 Inherits ReportLabel
ControlInstance Label7 Inherits ReportLabel
End Control
Control Field6 Inherits ReportField
ControlInstance Field6 Inherits ReportField
End Control
Control Label8 Inherits ReportLabel
ControlInstance Label8 Inherits ReportLabel
End Control
Control Field7 Inherits ReportField
ControlInstance Field7 Inherits ReportField
End Control
Control Label9 Inherits ReportLabel
ControlInstance Label9 Inherits ReportLabel
End Control
Control Field8 Inherits ReportField
ControlInstance Field8 Inherits ReportField
End Control
Control Label10 Inherits ReportLabel
ControlInstance Label10 Inherits ReportLabel
End Control
Control Field9 Inherits ReportField
ControlInstance Field9 Inherits ReportField
End Control
Control Label11 Inherits ReportLabel
ControlInstance Label11 Inherits ReportLabel
End Control
Control Field10 Inherits ReportField
ControlInstance Field10 Inherits ReportField
End Control
Control Label12 Inherits ReportLabel
ControlInstance Label12 Inherits ReportLabel
End Control
Control Field11 Inherits ReportField
ControlInstance Field11 Inherits ReportField
End Control
Control Label13 Inherits ReportLabel
ControlInstance Label13 Inherits ReportLabel
End Control
Control Field12 Inherits ReportField
ControlInstance Field12 Inherits ReportField
End Control
Control Label14 Inherits ReportLabel
ControlInstance Label14 Inherits ReportLabel
End Control
Control Field13 Inherits ReportField
ControlInstance Field13 Inherits ReportField
End Control
Control LineShape1 Inherits ReportLineShape
ControlInstance LineShape1 Inherits ReportLineShape
End Control
Control LineShape2 Inherits ReportLineShape
ControlInstance LineShape2 Inherits ReportLineShape
End Control
ReportSection Body
ReportSection GroupFooter1
ReportSection GroupHeader1
ReportSection PageFooter
ReportSection PageHeader
End Class
End Project

See also:

The items on this page are in the following plugins: MBS DynaPDF Plugin.


The biggest plugin in space...