<*--------------------------------------------------------------------------
UNSW WUHR005 Michael Nitschke 12/11/2012
Utility to take a rowset and return all its values.
At time of writing only handles a single record, flat rowset.
Example:
import NS_NEXTGEN:Utilities:RowsetToHTML;
/* Create and fill a rowset. */
Local Rowset &rowset = CreateRowset(Record.SOME_RECORD);
&rowset.Fill();
/* Put the rowset's data into an HTML Area on a Page. */
Local NS_NEXTGEN:Utilities:RowsetToHTML &rs2HTML = create NS_NEXTGEN:Utilities:RowsetToHTML(&rowset);
NS_DERIVED.HTML_AREA_01.Value = &rs2HTML.RowsetAsHTML;
The above will populate a HTML Area on a page with the values of the rowset.
This utility could be extended to include heirarchical data.
----------------------------------------------------------------------------*>
class RowsetToHTML
method RowsetToHTML(&rs As Rowset);
property string RowsetAsHTML;
end-class;
method RowsetToHTML
/+ &rs as Rowset +/
Local string &style;
&style = &style | "<style type=""text/css"">";
&style = &style | "table.rowset {";
&style = &style | " border-width: 3px;";
&style = &style | " border-spacing: 0px;";
&style = &style | " border-style: solid;";
&style = &style | " border-color: black;";
&style = &style | " border-collapse: collapse;";
&style = &style | " background-color: white;";
&style = &style | "}";
&style = &style | "table.rowset th {";
&style = &style | " border-width: 1px;";
&style = &style | " padding: 4px;";
&style = &style | " border-style: dotted;";
&style = &style | " border-color: gray;";
&style = &style | " background-color: rgb(200, 200, 200);";
&style = &style | " -moz-border-radius: ;";
&style = &style | " font-size: small ;";
&style = &style | "}";
&style = &style | "table.rowset th.recname {";
&style = &style | " background-color: rgb(0, 0, 0);";
&style = &style | " color: white;";
&style = &style | " font-size: large;";
&style = &style | " font-weight: normal;";
&style = &style | " text-align: left;";
&style = &style | "}";
&style = &style | "table.rowset tr.r0 td {";
&style = &style | " background-color: rgb(240, 240, 240);";
&style = &style | "}";
&style = &style | "table.rowset tr.r1 td {";
&style = &style | " background-color: rgb(250, 250, 250);";
&style = &style | "}";
&style = &style | "table.rowset td {";
&style = &style | " border-width: 1px;";
&style = &style | " padding: 4px;";
&style = &style | " border-style: dotted;";
&style = &style | " border-color: gray;";
&style = &style | " background-color: white;";
&style = &style | " -moz-border-radius: ;";
&style = &style | " font-size: small ;";
&style = &style | "}";
&style = &style | "</style>";
Local string &html;
&html = &html | "<table class=""rowset"">";
&html = &html | "<tr>";
&html = &html | "<th class=""recname"" colspan=""" | (&rs(1).GetRecord(1).FieldCount + 1) | """>" | &rs(1).GetRecord(1).Name | "</th>";
&html = &html | "</tr>";
&html = &html | "<tr>";
Local integer &f;
&html = &html | "<th>row</th>";
For &f = 1 To &rs(1).GetRecord(1).FieldCount
&html = &html | "<th>" | &rs(1).GetRecord(1).GetField(&f).Name | "</th>";
End-For;
&html = &html | "</tr>";
Local string &alternate = "1";
Local integer &i;
For &i = 1 To &rs.RowCount
If &alternate = "1" Then
&alternate = "0";
Else
&alternate = "1";
End-If;
&html = &html | "<tr class=""r" | &alternate | """>";
&html = &html | "<td>" | &i | "</td>";
For &f = 1 To &rs(&i).GetRecord(1).FieldCount
&html = &html | "<td>" | &rs(&i).GetRecord(1).GetField(&f).Value | "</td>";
End-For;
&html = &html | "</tr>";
End-For;
&html = &html | "</table>";
%This.RowsetAsHTML = &style | &html;
end-method;
Rowset to HTML Table
Posted by
Michael Nitschke
on Tuesday, 13 November 2012
Another possibly useless tool:
2 comments:
Well done Nutters - Dave Dickson and I just read this and we are like really impressed dude...........
Very nice. Wealth of info here.
Post a Comment