An introduction to DCCXP.CH and DCREAD HTML

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

An introduction to DCCXP.CH and DCREAD HTML

#1 Post by rdonnay »

eXpress++ 2.0 is going to give eXpress++ users a simpler way to create reports that can be sent to a web browser and then printed from the web browser.

The below code shows how commands from DCCXP.CH can be used to do this.
DCREAD HTML creates HTML code from DC* commands. This is an improvement over the old DCHTML.CH system which never really took off because it needed a better framework to make it useful.

CXP is that framework, so now I am committed to improving this command based system. DCREAD GUI allowed creation of GUI dialogs from a simple command syntax, yet it was completely open and therefore allowed for mixing of command based code, function based code or class based code. DCREAD HTML has the same flexibility. DC* commands can be used where it would simplify the design of a report, especially when using DCTABLE to create a grid-based report.

Click here to see the invoice in your browser that is rendered from the below source code:

http://bb.donnay-software.com/ds/customers/invoice.cxp

Code: Select all

<%#Code locality="page-global"%>
<%
 /// This code is injected at the beginning of the intermediate
 /// code generated by the CXC Builder. This is the perfect place
 /// for the statics, classes, functions and procedures being
 /// used in your CXP page.
 ///
 #include "dcdialog.ch"
 #include "dccxp.ch"

FUNCTION RenderInvoice( aItems, cCustomer, dDate )

LOCAL GetList := {}, oTable, oTableItems, i, nTotal, cDonnay

DCTABLE OBJECT oTable ROWS 50 COLUMNS 50 CLASS 'invoice' 

TEXT INTO cDonnay WRAP
<b>Donnay Software Designs</b><br>
1486 S. Loggers Pond Place, #11<br>
Boise, ID 83706<br>
Phone: 208-867-6091<br>
rogerdonnay@donnay-software.com<br>
ENDTEXT

@ 2,21 DCHTML '<h3>Invoice</h3>' PARENT oTable ;
       COLSPAN 10 ROWSPAN 2 TDOPTION "align = "center"

@ 5, 2 DCHTML '<pre><b>' + cCustomer + '</b></pre>' PARENT oTable ;
       COLSPAN 25 ROWSPAN 6 ;
       TDOPTION 'align = center'

@ 5,30 DCHTML 'Date: ' + DtoC(Date()) PARENT oTable ;
       COLSPAN 10 ROWSPAN 2

@ 5,42 DCIMAGE SRC "donnay-logo.jpg" HEIGHT 100 ;
       PARENT oTable COLSPAN 8 ROWSPAN 6

@ 12,2 DCTABLE OBJECT oTableItems ROWS Len(aItems) COLUMNS 5 ;
       PARENT oTable ;
       COLSPAN 48 ROWSPAN Len(aItems)+ 6

@ DCHTML_TABLE_HEADER, 1 DCHTML 'Part #' PARENT oTableItems
@ DCHTML_TABLE_HEADER, 2 DCHTML 'Description' PARENT oTableItems
@ DCHTML_TABLE_HEADER, 3 DCHTML 'Qty' PARENT oTableItems
@ DCHTML_TABLE_HEADER, 4 DCHTML 'U/Price' PARENT oTableItems
@ DCHTML_TABLE_HEADER, 5 DCHTML 'T/Price' PARENT oTableItems

nTotal := 0

FOR i := 1 TO Len(aItems)
  @ i,1 DCHTML aItems[i,1] PARENT oTableItems
  @ i,2 DCHTML aItems[i,2] PARENT oTableItems
  @ i,3 DCHTML aItems[i,3] PARENT oTableItems TDOPTION "align = right"
  @ i,4 DCHTML Transform(aItems[i,4],'$9999.99') PARENT oTableItems TDOPTION "align = right"
  @ i,5 DCHTML aItems[i,3]*aItems[i,4] PARENT oTableItems TDOPTION "align = right"
  nTotal += aItems[i,3]*aItems[i,4]
NEXT

@ 34,40 DCHTML 'Total Due:<br><br><b>' + Transform(nTotal,'$999999.99') +'</b>' ;
        PARENT oTable COLSPAN 10 ROWSPAN 4

@ 39,2 DCHTML 'Remit to:<br><br>' + cDonnay ;
        PARENT oTable COLSPAN 48 ROWSPAN 8 ;
        TDOPTION 'align = center'

DCREAD HTML TO cHtml

RETURN cHtml

%>

<%#Code locality="page-render"%>

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
   <link rel="stylesheet" type="text/css" href="dccxp.css" />
</head>

<body>

<%

TEXT INTO cCustomer WRAP
Joe Doakes Consulting Group
2430 Fair Weather Drive
Missoula, MT 84900

Attn: Joseph A. Doakes
ENDTEXT

aItems := { ;
 { '123855','Computer, Dell', 1, 2345.00 }, ;
 { '388772','Monitor, Dell', 1, 234.00 }, ;
 { '1999','eXpress++ 2-year Subscription',2,399.00 } }

cHtml := RenderInvoice( aItems, cCustomer, Date() )

? cHtml

%>

</body>

</html>
The eXpress train is coming - and it has more cars.

Post Reply