home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 32 / IOPROG_32.ISO / SOFT / SqlEval7 / devtools / samples / ADO / Web / displayp.asp < prev    next >
Encoding:
Text File  |  1998-07-22  |  6.4 KB  |  191 lines

  1. <%@ LANGUAGE="VBSCRIPT" %>
  2.  
  3. <%
  4. '///////////////////////////////////////////////////////////////////////////////
  5. ' displayp.asp - Display Products page
  6. '
  7. '    This active server page displays the information for products.
  8. 'It has several different ways of displaying product information depending on the 
  9. 'op and CategoryID variables that are sent into it via the querystring.
  10. '
  11. 'When CategoryID has no value, the information for all products is displayed
  12. 'in HTML format.  Otherwise, the information only for products that belong
  13. 'to the category referenced by CategoryID is displayed in HTML format.
  14. '
  15. 'When the op variable is "Update", an additional column will be added to the 
  16. 'product information table that contains "Update" buttons.  The buttons allow
  17. 'the user to update the products' information.  
  18. '
  19. 'When the op variable is "Remove",
  20. 'an additional column is added to the HTML output table that contains checkboxes
  21. 'and a "Remove Product(s)" button is added to the bottom of the page.
  22. 'The checkboxes allow the user to select as many products as they wish from the 
  23. 'table to be removed when the "Remove Product(s)" button is pressed.
  24. '
  25. 'If the op variable has no value, then no extra columns are added and just the 
  26. 'product information is displayed.
  27. '//////////////////////////////////////////////////////////////////////////////
  28.  
  29. 'Set the page to expire so that the page is refresed everytime the
  30. 'user requests it.
  31. Response.Expires = 0 %>
  32.  
  33. <HTML>
  34. <HEAD>
  35. <META NAME="GENERATOR" Content="Microsoft Visual InterDev 6.0">
  36. <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
  37. <TITLE>NIMS - All Products</TITLE>
  38. <LINK REL="stylesheet" TYPE="text/css" HREF="nimstyle.css">
  39.  
  40. <SCRIPT LANGUAGE="VBScript">
  41. 'This clientside VBScript prompts the user to confirm the requested
  42. 'remove operation.
  43. Sub ConfirmRemove
  44.     Set Form = Document.RemoveForm
  45.     Dim Anychecked    'Keeps track if any products were selected to be removed
  46.     Anychecked = 0
  47.     'Find out how many, if any, products were selected for removal
  48.     FOR EACH product in Form.ProductID
  49.         IF product.Checked THEN
  50.             Anychecked = Anychecked + 1
  51.         END IF 
  52.     NEXT
  53.  
  54.     IF Anychecked > 0 THEN 'Prompt for confirmation to remove product(s)
  55.         removeconfirmed = MsgBox ("Are you sure you want to remove the selected product(s)?", vbYesNo)
  56.         IF removeconfirmed = 6 THEN
  57.             MsgBox "I'm removing the products!"
  58.             document.RemoveForm.submit
  59.         END IF
  60.     ELSE 'None were selected
  61.         rtn = MsgBox ("You did not select any products to remove.  Return to Main Menu?", vbYesNo)
  62.         IF rtn = 6 THEN  'Return to the main menu
  63.             Document.Location = "default.htm"
  64.         END IF
  65.     END IF
  66. END Sub
  67. </SCRIPT>
  68.  
  69. </HEAD>
  70. <BODY>
  71.  
  72. <% 
  73. 'Get the CategoryID number from the calling page if any.
  74. CategoryID = Request.QueryString("CategoryID")
  75.  
  76. 'Get the display operation from the calling page if any.
  77. op = Request.QueryString("op")
  78.  
  79. 'Reference the Session connection variable
  80. cn = Session("cnn")
  81.  
  82. 'Create recordsets
  83. Set ProductInfo = Server.CreateObject("ADODB.Recordset") 
  84. Set CategoryInfo = Server.CreateObject("ADODB.Recordset")
  85.  
  86. 'Create query strings
  87.  
  88. 'Returns products from the Products table that belong to the CategoryID category.
  89. querystr = "SELECT ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock," _
  90.             & "UnitsOnOrder, ReorderLevel, Discontinued, ProductID FROM Products WHERE CategoryID = " & CategoryID & " ORDER BY ProductID"
  91. 'Returns the category name associated with CategoryID
  92. querystr2 = "SELECT CategoryName FROM Categories WHERE  CategoryID = " & CategoryID 
  93. 'Returns all products from the Products table
  94. defaultquery = "SELECT ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock," _
  95.             & "UnitsOnOrder, ReorderLevel, Discontinued, ProductID FROM Products"
  96.  
  97. 'Open the Recordsets 
  98. IF CategoryID <> "" THEN 'This was a request to view products from only one
  99.                          'category, only query for products in the category
  100.     ProductInfo.Open querystr, cn
  101.     CategoryInfo.Open querystr2, cn
  102. ELSE 'Retrieve all products in the query
  103.     ProductInfo.Open defaultquery, cn
  104. END IF
  105. %>
  106.  
  107. <CENTER>
  108. <H2>Northwind Inventory Management System</H2>
  109. <HR>
  110. <H3>
  111. <% 
  112. IF CategoryID <> "" THEN 'Display the category of products being displayed.
  113.     Response.Write CategoryInfo.Fields(0)
  114.     CategoryInfo.Close  'Close this Recordset since it will not be used again.
  115. ELSE 
  116.     Response.Write "All Northwind Products"
  117. END IF %>
  118. </H3>
  119. </CENTER>
  120.  
  121. <% 'If this is a remove operation, then output instructions the user. 
  122. IF op = "Remove" THEN
  123.     Response.Write "<p>Select each product you wish to remove from the inventory by marking its checkbox. " & _
  124.                    "When finished, press the Remove Products button at the bottom.</p>"
  125. END IF %>
  126.  
  127. <TABLE CELLPADDING=3 BORDER=0 COLSPAN=8>
  128.     <TR>
  129. <% 
  130.    'Output a blank header if this is an Update or Remove display operation
  131.    IF op <> "" THEN
  132.         Response.Write "<TD CLASS=header></TD>"
  133.         IF op = "Remove" THEN 'Create a form for the checkboxes to be submitted in %>
  134.             <FORM NAME="RemoveForm" ACTION="remove.asp" METHOD=POST>
  135. <%        END IF
  136.    END IF
  137.     
  138.    'Output the table headers
  139.    For i = 0 To 8
  140.         Response.Write "<TD CLASS=header>" & ProductInfo.Fields(i).Name & "</TD>"
  141.    NEXT
  142. %>
  143.     </TR>
  144.  
  145. <% 'Loop through the recordset to output the table values  
  146.     Do While Not ProductInfo.EOF
  147.         Response.Write "<TR>"
  148.  
  149.         'Depending on the operation, add a "Remove" checkbox or "Edit" button to the row
  150.         IF op <> "" THEN 
  151.             Response.Write "<TD>"
  152.             IF op = "Update" THEN %>
  153.                     <FORM ACTION="update.asp?ProductID=<%=ProductInfo.Fields(9)%>" METHOD=POST> 
  154.                         <INPUT TYPE=submit NAME=Edit VALUE=<%=op%>>
  155.                     </FORM>
  156. <%            ELSE %>
  157.                     <INPUT TYPE=CHECKBOX NAME=ProductID VALUE=<%=ProductInfo.Fields(9)%>>    
  158. <%            END IF
  159.             Response.Write "</TD>"
  160.         END IF
  161.     
  162.         For i = 0 to 8 'Output the field values for the product
  163.             Response.Write "<td>"
  164.             Response.Write ProductInfo.Fields(i).Value
  165.             Response.Write "</TD>"
  166.         NEXT
  167.  
  168.         Response.Write "</TR>"
  169.         ProductInfo.MoveNext    
  170.     LOOP
  171.  
  172.     'Close the Recordset
  173.     ProductInfo.Close %>
  174.  
  175. </TABLE>
  176.  
  177. <%
  178. IF op = "Remove" THEN 'Output a Remove button and close the RemoveForm
  179.                       'form for the checkboxes to be submitted in %>
  180.     <BR>
  181.     <INPUT TYPE=BUTTON VALUE="Remove Product(s)" onClick="VBScript:ConfirmRemove">
  182.     </FORM>
  183. <%END IF %>
  184.  
  185. <HR>
  186. <BR>
  187. Return to the <A HREF="default.htm">Main Menu</A>
  188.  
  189. </BODY>
  190. </HTML>
  191.