Loading rico1 and rico3 files
[infodrom/rico3] / examples / dotnet / simplegrid.aspx
1 <%@ Page Language="VB" ResponseEncoding="iso-8859-1" Debug="true" %>\r
2 <%@ Register TagPrefix="Rico" TagName="SimpleGrid" Src="../../plugins/dotnet/SimpleGrid.ascx" %>\r
3 <%@ Register TagPrefix="Rico" TagName="Column" Src="../../plugins/dotnet/GridColumn.ascx" %>\r
4 <%@ Register TagPrefix="My" TagName="LoadRicoClient" Src="LoadRicoClient.ascx" %>\r
5 <%@ Register TagPrefix="My" TagName="dbLib" Src="dbConnect.ascx" %>\r
6 <My:dbLib id='app' runat='server' />\r
7 \r
8 <script runat="server">\r
9 \r
10 Sub Page_Load(Sender As object, e As EventArgs)\r
11   dim category,lastCategory,Discounts,Gross,subtotals(1),grandtotals(1),i\r
12   dim command,rdr\r
13 \r
14   if not app.OpenDB() then exit sub\r
15   \r
16   for i=0 to 1\r
17     grandtotals(i)=0\r
18   next\r
19 \r
20   ' define heading\r
21   ex1.AddHeadingRow(true)\r
22   ex1.AddCell("Product")\r
23   ex1.AddCell("Gross Sales")\r
24   ex1.AddCell("Discounts")\r
25   ex1.AddCell("Net Sales")\r
26   ex1.AddCell("Avg Discount")\r
27 \r
28   command = app.dbConnection.CreateCommand()\r
29   command.CommandText="select CategoryName,ProductName, " & _\r
30     "SUM(od.UnitPrice*Quantity) as GrossSales, " & _\r
31     "SUM(od.UnitPrice*Quantity*Discount) as Discounts " & _\r
32     "from ((Order_Details od " & _\r
33     "inner join Products p on p.ProductID=od.ProductID) " & _\r
34     "inner join Categories c on p.CategoryID=c.CategoryID) " & _\r
35     "group by CategoryName,ProductName " & _\r
36     "order by CategoryName,ProductName"\r
37   rdr = command.ExecuteReader()\r
38   while rdr.Read()\r
39     category=rdr("CategoryName")\r
40     Gross=rdr("GrossSales")\r
41     Discounts=rdr("Discounts")\r
42     if category<>lastCategory then\r
43       if not IsNothing(lastCategory) then\r
44         AddRow("Subtotal",subtotals(0),subtotals(1))\r
45         ex1.SetRowAttr("class","Subtotal")\r
46       end if\r
47       ex1.AddDataRow\r
48       ex1.SetRowAttr("class","CatHead")\r
49       ex1.AddCell(category)\r
50       ex1.AddCell("")\r
51       ex1.AddCell("")\r
52       ex1.AddCell("")\r
53       ex1.AddCell("")\r
54       for i=0 to 1\r
55         subtotals(i)=0\r
56       next\r
57       lastCategory=category\r
58     end if\r
59     subtotals(0)+=Gross\r
60     grandtotals(0)+=Gross\r
61     subtotals(1)+=Discounts\r
62     grandtotals(1)+=Discounts\r
63     AddRow(rdr("ProductName"),Gross,Discounts)\r
64   end while\r
65   rdr.Close()\r
66   if not IsNothing(lastCategory) then\r
67     AddRow("Subtotal",subtotals(0),subtotals(1))\r
68     ex1.SetRowAttr("class","Subtotal")\r
69   end if\r
70   AddRow("Grand Total",grandtotals(0),grandtotals(1))\r
71   ex1.SetRowAttr("class","GrandTotal")\r
72 End Sub\r
73 \r
74 sub AddRow(ProductName as String, Gross as Double, Discounts as Double)\r
75   dim pct as double\r
76   ex1.AddDataRow()\r
77   ex1.AddCell(ProductName)\r
78   ex1.AddCell("$" & FormatNumber(Gross,0,-1,0,-1))\r
79   ex1.AddCell("$" & FormatNumber(Discounts,0,-1,0,-1))\r
80   ex1.AddCell("$" & FormatNumber(Gross-Discounts,0,-1,0,-1))\r
81   pct=Discounts/Gross\r
82   ex1.AddCell(pct.toString("0%"))\r
83 end sub\r
84 \r
85 Protected Overrides Sub Render(writer as HTMLTextWriter)\r
86   select case lcase(Request.QueryString("fmt"))\r
87     case "xl":  ex1.RenderExcel("rico.xls")\r
88     case "csv": ex1.RenderDelimited("rico.csv", ",", "")\r
89     case else:  MyBase.Render(writer)   ' output html\r
90   end select\r
91 End Sub\r
92 \r
93 </script>\r
94 \r
95 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
96 <html>\r
97 <head>\r
98 <title>Rico SimpleGrid-Example 1</title>\r
99 \r
100 <My:LoadRicoClient id='initlibs' runat='server' />\r
101 <link href="../demo.css" type="text/css" rel="stylesheet" />\r
102 \r
103 \r
104 <script type='text/javascript'>\r
105 Rico.loadModule('SimpleGrid');\r
106 \r
107 Rico.onLoad( function() {\r
108   if (!Rico.isIE) document.getElementById('owc').disabled=true;\r
109 });\r
110 \r
111 function ExportGridClient(ExportType) {\r
112   ex1['grid'].printVisible(ExportType);\r
113 }\r
114 \r
115 function ExportGridServer(ExportType) {\r
116   if (Rico.isIE) {\r
117     location.href+='&fmt='+ExportType;\r
118   } else {\r
119     window.open(location.href+'&fmt='+ExportType);\r
120   }\r
121 }\r
122 </script>\r
123 \r
124 <style type="text/css">\r
125 .CatHead {\r
126   background:blue;\r
127   color:white;\r
128   font-weight:bold !important;\r
129 }\r
130 .Subtotal {\r
131   background:#888;\r
132   color:white;\r
133   font-weight:bold !important;\r
134 }\r
135 .GrandTotal {\r
136   background:black;\r
137   color:white;\r
138   font-weight:bold !important;\r
139 }\r
140 div.ricoLG_cell {\r
141   white-space:nowrap;\r
142 }\r
143 </style>\r
144 \r
145 </head>\r
146 \r
147 <body>\r
148 \r
149 <table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>\r
150 Base Library: \r
151 <script type='text/javascript'>\r
152 document.write(Rico.Lib+' '+Rico.LibVersion);\r
153 </script>\r
154 <hr>\r
155 <p><strong>Rico: SimpleGrid</strong></p>\r
156 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.\r
157 It shares many of the same characteristics as Rico's better known LiveGrid.\r
158 SimpleGrids have resizable columns, frozen columns on the left, and can use the\r
159 same CSS styling as LiveGrids. Sorting and filtering can also be enabled\r
160 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid\r
161 can be formatted individually.\r
162 </td>\r
163 <td>\r
164 <script type="text/javascript"><!--\r
165 google_ad_client = "pub-7218597156507462";\r
166 /* 125x125, created 5/11/09 */\r
167 google_ad_slot = "9298106441";\r
168 google_ad_width = 125;\r
169 google_ad_height = 125;\r
170 //-->\r
171 </script>\r
172 <script type="text/javascript"\r
173 src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\r
174 </script>\r
175 </td>\r
176 </tr></table>\r
177 \r
178 \r
179 <div>\r
180 <button onclick="ExportGridClient('plain')">Export from client<br>to HTML Table</button>\r
181 <button onclick="ExportGridClient('owc')" id="owc">Export from client<br>to OWC spreadsheet</button>\r
182 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>\r
183 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>\r
184 </div>\r
185 \r
186 <Rico:SimpleGrid runat='server' id='ex1' FrozenCols='1'>\r
187 <GridColumns>\r
188   <Rico:Column runat='server' width='200' />\r
189   <Rico:Column runat='server' spec='specQty' />\r
190   <Rico:Column runat='server' spec='specQty' />\r
191   <Rico:Column runat='server' spec='specQty' />\r
192   <Rico:Column runat='server' spec='specQty' />\r
193 </GridColumns>\r
194 </Rico:SimpleGrid>\r
195 \r
196 </body>\r
197 </html>\r
198 \r