Most base libraries now loaded from googleapis. Changes to the way LiveGridForms...
[infodrom/rico3] / examples / asp / simplegrid.asp
1 <%@ LANGUAGE="VBSCRIPT" %>\r
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\r
3 <html>\r
4 <head>\r
5 <title>Rico SimpleGrid-Example 1</title>\r
6 \r
7 <!-- #INCLUDE FILE = "dbConnect.asp" --> \r
8 <!-- #INCLUDE FILE = "LoadRicoClient.asp" --> \r
9 <!-- #INCLUDE FILE = "../../plugins/asp/SimpleGrid.vbs" -->\r
10 \r
11 <link href="../demo.css" type="text/css" rel="stylesheet" />\r
12 \r
13 \r
14 <script type='text/javascript'>\r
15 Rico.loadModule('SimpleGrid');\r
16 \r
17 var ex1;\r
18 Rico.onLoad( function() {\r
19   var opts = {  \r
20     columnSpecs   : [{width:200},'specQty','specQty','specQty','specQty']\r
21   };\r
22   ex1=new Rico.SimpleGrid ('ex1', opts);\r
23   if (!Rico.isIE) document.getElementById('owc').disabled=true;\r
24 });\r
25 \r
26 function ExportGridClient(ExportType) {\r
27   ex1.printVisible(ExportType);\r
28 }\r
29 \r
30 function ExportGridServer(ExportType) {\r
31   if (Prototype.Browser.IE) {\r
32     location.href+='&fmt='+ExportType;\r
33   } else {\r
34     window.open(location.href+'&fmt='+ExportType);\r
35   }\r
36 }\r
37 </script>\r
38 \r
39 <style type="text/css">\r
40 .CatHead {\r
41   background:blue;\r
42   color:white;\r
43   font-weight:bold !important;\r
44 }\r
45 .Subtotal {\r
46   background:#888;\r
47   color:white;\r
48   font-weight:bold !important;\r
49 }\r
50 .GrandTotal {\r
51   background:black;\r
52   color:white;\r
53   font-weight:bold !important;\r
54 }\r
55 div.ricoLG_cell {\r
56   white-space:nowrap;\r
57 }\r
58 </style>\r
59 \r
60 </head>\r
61 \r
62 \r
63 <body>\r
64 \r
65 <div id='explanation'>\r
66 Base Library: \r
67 <script type='text/javascript'>\r
68 document.write(Rico.Lib+' '+Rico.LibVersion);\r
69 </script>\r
70 <hr>\r
71 <p><strong>Rico: SimpleGrid</strong></p>\r
72 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.\r
73 It shares many of the same characteristics as Rico's better known LiveGrid.\r
74 SimpleGrids have resizable columns, frozen columns on the left, and can use the\r
75 same CSS styling as LiveGrids. Sorting and filtering can also be enabled\r
76 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid\r
77 can be formatted individually.\r
78 </div>\r
79 \r
80 \r
81 <div>\r
82 <button onclick="ExportGridClient('plain')">Export from client<br>to HTML Table</button>\r
83 <button onclick="ExportGridClient('owc')" id="owc">Export from client<br>to OWC spreadsheet</button>\r
84 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>\r
85 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>\r
86 </div>\r
87 \r
88 \r
89 <%\r
90 dim grid\r
91 \r
92 if not OpenDB then\r
93   response.write "<p>ERROR opening database!"\r
94 else\r
95   set grid=new SimpleGrid  ' create instance of class\r
96   FillGrid\r
97   select case lcase(Request.QueryString("fmt"))\r
98     case "xl":  grid.RenderExcel "rico.xls"\r
99     case "csv": grid.RenderDelimited "rico.csv", ",", ""\r
100     case else:  grid.Render "ex1", 1   ' output html\r
101   end select\r
102   set grid=Nothing       ' clean up\r
103 end if\r
104 \r
105 \r
106 sub FillGrid()\r
107   dim rsMain,sqltext,category,lastCategory,Discounts,Gross,subtotals(1),grandtotals(1),i\r
108  \r
109   for i=0 to 1\r
110     grandtotals(i)=0\r
111   next\r
112 \r
113   ' define heading\r
114   grid.AddHeadingRow true\r
115   grid.AddCell "Product"\r
116   grid.AddCell "Gross Sales"\r
117   grid.AddCell "Discounts"\r
118   grid.AddCell "Net Sales"\r
119   grid.AddCell "Avg Discount"\r
120 \r
121   sqltext="select CategoryName,ProductName, " & _\r
122     "SUM(od.UnitPrice*Quantity) as GrossSales, " & _\r
123     "SUM(od.UnitPrice*Quantity*Discount) as Discounts " & _\r
124     "from ((Order_Details od " & _\r
125     "inner join Products p on p.ProductID=od.ProductID) " & _\r
126     "inner join Categories c on p.CategoryID=c.CategoryID) " & _\r
127     "group by CategoryName,ProductName " & _\r
128     "order by CategoryName,ProductName"\r
129   set rsMain = oDB.RunQuery(sqltext)\r
130   while not rsMain.eof\r
131     category=rsMain("CategoryName")\r
132     Gross=rsMain("GrossSales")\r
133     Discounts=rsMain("Discounts")\r
134     if category<>lastCategory then\r
135       if not IsEmpty(lastCategory) then\r
136         AddRow "Subtotal",subtotals(0),subtotals(1)\r
137         grid.SetRowAttr "class","Subtotal"\r
138       end if\r
139       grid.AddDataRow\r
140       grid.SetRowAttr "class","CatHead"\r
141       grid.AddCell category\r
142       grid.AddCell ""\r
143       grid.AddCell ""\r
144       grid.AddCell ""\r
145       grid.AddCell ""\r
146       for i=0 to 1\r
147         subtotals(i)=0\r
148       next\r
149       lastCategory=category\r
150     end if\r
151     subtotals(0)=subtotals(0)+Gross\r
152     grandtotals(0)=grandtotals(0)+Gross\r
153     subtotals(1)=subtotals(1)+Discounts\r
154     grandtotals(1)=grandtotals(1)+Discounts\r
155     AddRow rsMain("ProductName"),Gross,Discounts\r
156     rsMain.movenext\r
157   wend\r
158   oDB.rsClose rsMain\r
159   if not IsEmpty(lastCategory) then\r
160     AddRow "Subtotal",subtotals(0),subtotals(1)\r
161     grid.SetRowAttr "class","Subtotal"\r
162   end if\r
163   AddRow "Grand Total",grandtotals(0),grandtotals(1)\r
164   grid.SetRowAttr "class","GrandTotal"\r
165 end sub\r
166 \r
167 \r
168 sub AddRow(ProductName,Gross,Discounts)\r
169   grid.AddDataRow\r
170   grid.AddCell Server.HTMLencode(ProductName)\r
171   grid.AddCell "$" & FormatNumber(Gross,0,-1,0,-1)\r
172   grid.AddCell "$" & FormatNumber(Discounts,0,-1,0,-1)\r
173   grid.AddCell "$" & FormatNumber(Gross-Discounts,0,-1,0,-1)\r
174   grid.AddCell round(Discounts/Gross*100.0) & "%"\r
175 end sub\r
176 \r
177 %>\r
178 \r
179 </body>\r
180 </html>\r
181 \r