Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/DynaPDF Graphics/Reporting/List Of Orders
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/List Of Orders
This example is the version from Fri, 2nd May 2019.
Project "List Of Orders.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control RunReportButton Inherits PushButton
ControlInstance RunReportButton Inherits PushButton
EventHandler Sub Action()
Dim ordersDB As New SQLiteDatabase
// Set Database File
ordersDB.DatabaseFile = GetDBFile
// Connect to the database
If ordersDB.DatabaseFile.Exists Then
// The database file already exists, so we want to connect to it.
If Not ordersDB.Connect Then
// there was an error connecting to the database
MsgBox("Database Error: " + Str(OrdersDB.ErrorCode) + EndOfLine + EndOfLine + OrdersDB.ErrorMessage)
Return
End If
Else
MsgBox("Database not found.")
Return
End If
// Build the SQL statement that will be used to select the records
Dim sql As String = "SELECT O.OrderNumber, C.ID, C.Company, C.LastName, O.DateOrdered, O.Total" + _
" FROM Orders O, Customers C WHERE O.CustomerID = C.ID"
Dim rpt As New ListofOrders
// Now we select the records from the database and add them to the list.
Dim orders As RecordSet
orders = ordersDB.SQLSelect(sql)
If orders = Nil Then
Beep
MsgBox("No records found to print.")
Else
Dim ps As New PrinterSetup
// set the resolution to 300 DPI for printing
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300
If ps.PageSetupDialog Then
Dim g As Graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then
// if the report runs successfully
If rpt.Run(orders, ps) Then
rpt.Document.Print(g)
End If
End If
End If
End If
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control PDFButton Inherits PushButton
ControlInstance PDFButton Inherits PushButton
EventHandler Sub Action()
Dim ordersDB As New SQLiteDatabase
// Set Database File
ordersDB.DatabaseFile = GetDBFile
// Connect to the database
If ordersDB.DatabaseFile.Exists Then
// The database file already exists, so we want to connect to it.
If Not ordersDB.Connect Then
// there was an error connecting to the database
MsgBox("Database Error: " + Str(OrdersDB.ErrorCode) + EndOfLine + EndOfLine + OrdersDB.ErrorMessage)
Return
End If
Else
MsgBox("Database not found.")
Return
End If
// Build the SQL statement that will be used to select the records
Dim sql As String = "SELECT O.OrderNumber, C.ID, C.Company, C.LastName, O.DateOrdered, O.Total" + _
" FROM Orders O, Customers C WHERE O.CustomerID = C.ID"
Dim rpt As New ListofOrders
// Now we select the records from the database and add them to the list.
Dim orders As RecordSet
orders = ordersDB.SQLSelect(sql)
If orders = Nil Then
Beep
MsgBox("No records found to print.")
Else
Dim ps As New PrinterSetup
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
// if the report runs successfully
If rpt.Run(orders, ps) Then
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
Call pdf.RenderPageToImage(1, f3, 150, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG)
Call pdf.CloseFile
f1.Launch True
End If
End EventHandler
End Control
Private Function GetDBFile() As FolderItem
Dim rscDB As Xojo.IO.FolderItem = Xojo.IO.SpecialFolder.GetResource("Orders.sqlite")
Dim dbFile As New FolderItem(rscDB.Path, FolderItem.PathTypeNative)
Return dbFile
End Function
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 ListOfOrders Inherits Report
Control RectangleShape1 Inherits ReportRectangleShape
ControlInstance RectangleShape1 Inherits ReportRectangleShape
End Control
Control Label1 Inherits ReportLabel
ControlInstance Label1 Inherits ReportLabel
End Control
Control Label2 Inherits ReportLabel
ControlInstance Label2 Inherits ReportLabel
End Control
Control Label3 Inherits ReportLabel
ControlInstance Label3 Inherits ReportLabel
End Control
Control Label4 Inherits ReportLabel
ControlInstance Label4 Inherits ReportLabel
End Control
Control LineShape1 Inherits ReportLineShape
ControlInstance LineShape1 Inherits ReportLineShape
End Control
Control Field1 Inherits ReportField
ControlInstance Field1 Inherits ReportField
End Control
Control Field2 Inherits ReportField
ControlInstance Field2 Inherits ReportField
End Control
Control Field3 Inherits ReportField
ControlInstance Field3 Inherits ReportField
End Control
ReportSection Body
ReportSection PageFooter
ReportSection PageHeader
End Class
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
End Project
See also:
- /DynaPDF/DynaPDF Graphics/DynaPDF Graphics
- /DynaPDF/DynaPDF Graphics/DynaPDF Graphics iOS
- /DynaPDF/DynaPDF Graphics/Reporting/Breaking List Of Orders
- /DynaPDF/DynaPDF Graphics/Reporting/GasReport/GasReport
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Orders with Background
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products
- /DynaPDF/DynaPDF Graphics/Reporting/List Of Products Preview
- /DynaPDF/DynaPDF Graphics/Reporting/ListBoxReport
- /DynaPDF/DynaPDF PDF Viewer
- /DynaPDF/DynaPDF transparent images/DynaPDF transparent images
The items on this page are in the following plugins: MBS DynaPDF Plugin.