Tornado Class Library

Special Topic - Data Export

 

It is easy to understand in the master/slave operations where a key is picked in from master table and the slave use this key to construct a query to supply the details. Tornado extends the Data Export envelop to cover the following area -

A Raw format is the native data value like integer 3. An HTML format is the same field data being masked and displayed like $3.00. The HTML format is the blue color $3.00 . These two formats are required in different situation - Raw format is used in computation and charting while HTML format is for display.

 

Export Fields and Columns
<script language="vb" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
   Dim GD As New Tornado.Getdata()
   Dim Export As New Tornado.Z()
   With Export
      .dbQP = "U=13| S=13| M=ty=G!sysindex=t| Gdf=0,1,2,3,4,5| Ps=10|D=Nwind.mdb|Q=Products|Th=Tit=Export Fields and Columns"
      .dbGridMagicCell = "field=0|macro=My ID is - #0#"
      .dbExportFlds = "(0),1,2,3"             'Export Fields
      .dbExportCols = "4,(5)"                 'Export Columns
      .ASPdbNET()
   End With

'------ User Code to process Exported data --------

   Response.Write("<Center><P><table class=ts cellspacing='1'><tr><td class=gh COLSPAN=4>Export Fields 0, 1, 2 & 3 (Row)</td><tr>")
   Dim c As Integer
   Dim r As Long
   Dim arr() As String = GD.Get_Fexport
   For c = 0 To UBound(arr)
      Response.Write("<td class=nr align=center>" & arr(c) & "</td>")
   Next c
   Response.Write("</tr></table>")
   Response.Write("<Center><P><table class=ts cellspacing='1'><tr><td class=gh COLSPAN=2>Export Columns 4 and 5</td>")
   Dim Carr(,) As String = GD.Get_Cexport
   For r = 0 To UBound(Carr, 2)
      Response.Write("<tr>")
      For c = 0 To UBound(Carr, 1)
         Response.Write("<td class=nr align=center>" & Carr(c,r) & "</td>")
      Next c
      Response.Write("</tr>")
   Next r
   Response.Write("</table></center>")
End Sub
</script>

Not that field 1 and column 5 are exported in raw format. All the exported data can be retrieved by via a Tornado.GetData call. The grid display indicated that a system index is added for navigation. Click the Index '#' will change the active row and the fields exports will reflect the change.

 

Array Formatter - Lists

The above example process the exported data manually. Tornado has a feature called 'Array Formatter' which allow user to arrange the exported data into many formats. The following example is a 'List' example. the exported data is formatted as <OL> and <UL> in the template.

<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim MemTemp1 As String = "<P><center><h3>Lists Export is one of the many options of the Array Formatter<BR>In this example, the Picture field is exported and displayed as OL and UL Lists via the Array Formatter</h3><P><table width=20% class=ts Cellspacing=1><tr><td class=Ch>[[XC::93::0::<OL>]]</td><td class=FL>[[XC::93::0::<UL>]]</td></tr></table></center>"
Dim Tmpx1 As New Tornado.Z()
   With Tmpx1
      .dbQP="U=90| S=9|D=Car2000.mdb|Q=Carspecs|Ps=10|Gdf=0,1,2,3,Picture|Xc=Picture|Th=tit=Export to Array Formatter"
      .ASPdbNET()
      .ASPdbSendTemplate("display", , MemTemp1)
   End with
End Sub
</script> 

 

Array Formatter - Table Rows and Columns

Now, we are going to go a bit deeper and combine Export data and MagicCell filter to illustrate how easy it is to apply the powerful features of Tornado. 

<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
Dim MemTemp As String = "<center>[[title]]<p>[[XC::98::0::4CV]]<P>[[GridNav]]<P>[[GridStat]]</center>"
Dim Tmpx3 As New Tornado.Z()
   With Tmpx3
      .dbQP = "U=98| S=29|Gtp=[[Grid]]| Ps=16| D=Car2000.mdb| Rc=227| Xc=Picture| Iv=t| Th=tit=Advanced Magic Export"
      .dbSQL = "Select Yr, Car, Price, Picture From Carspecs"
      .dbGridMagicCell = "field=Picture|macro=(/tornado/db/images-car/#Picture#|FX|True||<IMG WIDTH=150 BORDER=0 VSPACE=0 HSPACE=0 SRC='/tornado/notruck.jpg'>~#price#|GT|35000||<A HREF='/tornado/db/images-car/#Picture#'><IMG WIDTH=150 BORDER=0 VSPACE=0 HSPACE=0 SRC='/tornado/db/images-car/#Picture#' ALT='Click to see large picture'></A><br>#yr# #Car#<br><Strike>#Price:currency#</Strike> <<#Price# * 0.85::Currency>> ~ #Price:Currency#|EL|||<A HREF='/tornado/db/images-car/#Picture#'><IMG WIDTH=150 BORDER=0 VSPACE=0 HSPACE=0 SRC='/tornado/db/images-car/#Picture#' ALT='Click to see large picture'></A><br>#yr# #Car#<br>#Price:currency#)"
      .ASPdbNET()
      .ASPdbSendTemplate("display", , MemTemp)
   End with
End Sub
</script> 

In this example, we export just one column - 'picture', but we packed in it Year, Name, Price and Picture.

In the display template, we specify a Block-Row-Col type of formatting - [[XC::98::0::4CV]] means The data source is from Export Column unit 98 column 0. The array formatter is 4CV (4 columns in the vertical direction) with a page size of 16. The rest of the details will be filled in automatically. Further more, we'll apply the MagicCell filter to turn the picture into thumbnails; display the year, name, and price data below the thumbnail; if there is no picture data, display a no-show image instead; display the price as currency; if the price is > $35,000  then give it a 15% discount.

Now, can you feel the power of Tornado!

 

Real Time Data Query

The following is a simple example of a real time authentication query application. The real time device submit a key to the web application and in return get data from the database. Because Tornado is so rich in functions, this application can be done in a few lines of aspx code.

<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
   Dim GD As New Tornado.GetData
   Dim Tag As String = Request.QueryString("Tag")
   Dim x As New Tornado.z
   x.dbQP = "U=1|D=NWIND"
   x.dbSQL = "Select lastname, firstname from employees where employeeid = " & Tag
   x.dbInvisible = True
   x.dbNoHead = True
   x.dbExportFlds = "(0),(1)"
   x.ASPdbNET()
   Dim flds() As String = GD.Get_Fexport '...1 Dim array
   Response.Write(flds(0) & "," & flds(1))
End Sub
</script> 

The above example submit the employeeid number and get the last and first name back without any HTML display.


Send comments on this topic.


Copyright 1998-2006 ASP-db