In .net, changed bold, italic, underline, and wrap to TriState. Also in .net, Excel...
[infodrom/rico3] / examples / dotnet / simplegrid.aspx
1 <%@ Page Language="VB" ResponseEncoding="iso-8859-1" Debug="true" %>\r
2 <%@ Register TagPrefix="Rico" Assembly="Rico" NameSpace="Rico" %>\r
3 <%@ Register TagPrefix="My" TagName="dbLib" Src="dbConnect.ascx" %>\r
4 <My:dbLib id='app' runat='server' />\r
5 \r
6 <script runat="server">\r
7 \r
8 Sub Page_Load(Sender As object, e As EventArgs)\r
9   dim category,lastCategory,Discounts,Gross,subtotals(1),grandtotals(1),i\r
10   dim command,rdr\r
11 \r
12   if not app.OpenDB() then exit sub\r
13   \r
14   for i=0 to 1\r
15     grandtotals(i)=0\r
16   next\r
17 \r
18   command = app.dbConnection.CreateCommand()\r
19   command.CommandText="select CategoryName,ProductName, " & _\r
20     "SUM(od.UnitPrice*Quantity) as GrossSales, " & _\r
21     "SUM(od.UnitPrice*Quantity*Discount) as Discounts " & _\r
22     "from ((Order_Details od " & _\r
23     "inner join Products p on p.ProductID=od.ProductID) " & _\r
24     "inner join Categories c on p.CategoryID=c.CategoryID) " & _\r
25     "group by CategoryName,ProductName " & _\r
26     "order by CategoryName,ProductName"\r
27   rdr = command.ExecuteReader()\r
28   while rdr.Read()\r
29     category=rdr("CategoryName")\r
30     Gross=rdr("GrossSales")\r
31     Discounts=rdr("Discounts")\r
32     if category<>lastCategory then\r
33       if not IsNothing(lastCategory) then\r
34         AddRow("Subtotal",subtotals(0),subtotals(1),"Subtotal")\r
35       end if\r
36       ex1.AddDataRow\r
37       ex1.AddCell(new SimpleGrid.TextCell(category, "CatHead"))\r
38       ex1.AddCell(new SimpleGrid.TextCell("", "CatHead"))\r
39       ex1.AddCell(new SimpleGrid.TextCell("", "CatHead"))\r
40       ex1.AddCell(new SimpleGrid.TextCell("", "CatHead"))\r
41       ex1.AddCell(new SimpleGrid.TextCell("", "CatHead"))\r
42       for i=0 to 1\r
43         subtotals(i)=0\r
44       next\r
45       lastCategory=category\r
46     end if\r
47     subtotals(0)+=Gross\r
48     grandtotals(0)+=Gross\r
49     subtotals(1)+=Discounts\r
50     grandtotals(1)+=Discounts\r
51     AddRow(rdr("ProductName"),Gross,Discounts,"")\r
52   end while\r
53   rdr.Close()\r
54   if not IsNothing(lastCategory) then\r
55     AddRow("Subtotal",subtotals(0),subtotals(1),"Subtotal")\r
56   end if\r
57   AddRow("Grand Total",grandtotals(0),grandtotals(1),"GrandTotal")\r
58 End Sub\r
59 \r
60 sub AddRow(ProductName as String, Gross as Double, Discounts as Double, StyleId as String)\r
61   dim pct as double\r
62   ex1.AddDataRow()\r
63   ex1.AddCell(new SimpleGrid.TextCell(ProductName, StyleId))\r
64   ex1.AddCell(new SimpleGrid.NumberCell(Gross, StyleId & "Number"))\r
65   ex1.AddCell(new SimpleGrid.NumberCell(Discounts, StyleId & "Number"))\r
66   ex1.AddCell(new SimpleGrid.NumberCell(Gross-Discounts, StyleId & "Number"))\r
67   pct=Discounts/Gross\r
68   ex1.AddCell(new SimpleGrid.NumberCell(pct, StyleId & "Percent"))\r
69 end sub\r
70 \r
71 Protected Overrides Sub Render(writer as HTMLTextWriter)\r
72   select case lcase(Request.QueryString("fmt"))\r
73     case "xl":  ex1.RenderExcel("ProductSalesSummary.xml")\r
74     case "csv": ex1.RenderDelimited("ProductSalesSummary.csv")\r
75     case else:  MyBase.Render(writer)   ' output html\r
76   end select\r
77 End Sub\r
78 \r
79 </script>\r
80 \r
81 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
82 <html>\r
83 <head>\r
84 <title>Rico SimpleGrid-Example 1</title>\r
85 \r
86 <Rico:LoadClient checkQueryString='true' runat='server' />\r
87 <link href="../demo.css" type="text/css" rel="stylesheet" />\r
88 \r
89 \r
90 <script type='text/javascript'>\r
91 function ExportGridClient() {\r
92   ex1['grid'].printVisible();\r
93 }\r
94 \r
95 function ExportGridServer(ExportType) {\r
96   if (Rico.isIE) {\r
97     location.href+='&fmt='+ExportType;\r
98   } else {\r
99     window.open(location.href+'&fmt='+ExportType);\r
100   }\r
101 }\r
102 </script>\r
103 \r
104 </head>\r
105 \r
106 <body>\r
107 \r
108 <div id='explanation'>\r
109 Base Library: \r
110 <script type='text/javascript'>\r
111 document.write(Rico.Lib+' '+Rico.LibVersion);\r
112 </script>\r
113 <hr>\r
114 <p><strong>Rico: SimpleGrid</strong></p>\r
115 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.\r
116 It shares many of the same characteristics as Rico's better known LiveGrid.\r
117 SimpleGrids have resizable columns, frozen columns on the left, and can use the\r
118 same CSS styling as LiveGrids. Sorting and filtering can also be enabled\r
119 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid\r
120 can be formatted individually.\r
121 </div>\r
122 \r
123 \r
124 <div>\r
125 <button onclick="ExportGridClient()">Export from client<br>to HTML Table</button>\r
126 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>\r
127 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>\r
128 </div>\r
129 \r
130 <Rico:SimpleGrid runat='server' id='ex1' frozenColumns='1'>\r
131   <Rico:Style runat='server' StyleID='CatHead' BackColor="blue" ForeColor="white" bold="true" />\r
132   <Rico:Style runat='server' StyleID='Subtotal' BackColor="#888888" ForeColor="white" bold="true" />\r
133   <Rico:Style runat='server' StyleID='GrandTotal' BackColor="black" ForeColor="white" bold="true" />\r
134   <Rico:Style runat='server' StyleID='Number' NumberFormat="$#,##0" HorizontalAlign="right" />\r
135   <Rico:Style runat='server' StyleID='SubtotalNumber' NumberFormat="$#,##0" HorizontalAlign="right" BackColor="#888888" ForeColor="white" bold="true" />\r
136   <Rico:Style runat='server' StyleID='GrandTotalNumber' NumberFormat="$#,##0" HorizontalAlign="right" BackColor="black" ForeColor="white" bold="true" />\r
137   <Rico:Style runat='server' StyleID='Percent' NumberFormat="0%" HorizontalAlign="right" />\r
138   <Rico:Style runat='server' StyleID='SubtotalPercent' NumberFormat="0%" HorizontalAlign="right" BackColor="#888888" ForeColor="white" bold="true" />\r
139   <Rico:Style runat='server' StyleID='GrandTotalPercent' NumberFormat="0%" HorizontalAlign="right" BackColor="black" ForeColor="white" bold="true" />\r
140 \r
141   <Rico:SimpleCol runat='server' heading="Product" width='200' />\r
142   <Rico:SimpleCol runat='server' heading="Gross Sales" />\r
143   <Rico:SimpleCol runat='server' heading="Discounts" />\r
144   <Rico:SimpleCol runat='server' heading="Net Sales" />\r
145   <Rico:SimpleCol runat='server' heading="Avg Discount" />\r
146 </Rico:SimpleGrid>\r
147 \r
148 </body>\r
149 </html>\r