home *** CD-ROM | disk | FTP | other *** search
- <%@ LANGUAGE="VBSCRIPT" %>
-
- <%
- '///////////////////////////////////////////////////////////////////////////////
- ' displayp.asp - Display Products page
- '
- ' This active server page displays the information for products.
- 'It has several different ways of displaying product information depending on the
- 'op and CategoryID variables that are sent into it via the querystring.
- '
- 'When CategoryID has no value, the information for all products is displayed
- 'in HTML format. Otherwise, the information only for products that belong
- 'to the category referenced by CategoryID is displayed in HTML format.
- '
- 'When the op variable is "Update", an additional column will be added to the
- 'product information table that contains "Update" buttons. The buttons allow
- 'the user to update the products' information.
- '
- 'When the op variable is "Remove",
- 'an additional column is added to the HTML output table that contains checkboxes
- 'and a "Remove Product(s)" button is added to the bottom of the page.
- 'The checkboxes allow the user to select as many products as they wish from the
- 'table to be removed when the "Remove Product(s)" button is pressed.
- '
- 'If the op variable has no value, then no extra columns are added and just the
- 'product information is displayed.
- '//////////////////////////////////////////////////////////////////////////////
-
- 'Set the page to expire so that the page is refresed everytime the
- 'user requests it.
- Response.Expires = 0 %>
-
- <HTML>
- <HEAD>
- <META NAME="GENERATOR" Content="Microsoft Visual InterDev 6.0">
- <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
- <TITLE>NIMS - All Products</TITLE>
- <LINK REL="stylesheet" TYPE="text/css" HREF="nimstyle.css">
-
- <SCRIPT LANGUAGE="VBScript">
- 'This clientside VBScript prompts the user to confirm the requested
- 'remove operation.
- Sub ConfirmRemove
- Set Form = Document.RemoveForm
- Dim Anychecked 'Keeps track if any products were selected to be removed
- Anychecked = 0
- 'Find out how many, if any, products were selected for removal
- FOR EACH product in Form.ProductID
- IF product.Checked THEN
- Anychecked = Anychecked + 1
- END IF
- NEXT
-
- IF Anychecked > 0 THEN 'Prompt for confirmation to remove product(s)
- removeconfirmed = MsgBox ("Are you sure you want to remove the selected product(s)?", vbYesNo)
- IF removeconfirmed = 6 THEN
- MsgBox "I'm removing the products!"
- document.RemoveForm.submit
- END IF
- ELSE 'None were selected
- rtn = MsgBox ("You did not select any products to remove. Return to Main Menu?", vbYesNo)
- IF rtn = 6 THEN 'Return to the main menu
- Document.Location = "default.htm"
- END IF
- END IF
- END Sub
- </SCRIPT>
-
- </HEAD>
- <BODY>
-
- <%
- 'Get the CategoryID number from the calling page if any.
- CategoryID = Request.QueryString("CategoryID")
-
- 'Get the display operation from the calling page if any.
- op = Request.QueryString("op")
-
- 'Reference the Session connection variable
- cn = Session("cnn")
-
- 'Create recordsets
- Set ProductInfo = Server.CreateObject("ADODB.Recordset")
- Set CategoryInfo = Server.CreateObject("ADODB.Recordset")
-
- 'Create query strings
-
- 'Returns products from the Products table that belong to the CategoryID category.
- querystr = "SELECT ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock," _
- & "UnitsOnOrder, ReorderLevel, Discontinued, ProductID FROM Products WHERE CategoryID = " & CategoryID & " ORDER BY ProductID"
- 'Returns the category name associated with CategoryID
- querystr2 = "SELECT CategoryName FROM Categories WHERE CategoryID = " & CategoryID
- 'Returns all products from the Products table
- defaultquery = "SELECT ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock," _
- & "UnitsOnOrder, ReorderLevel, Discontinued, ProductID FROM Products"
-
- 'Open the Recordsets
- IF CategoryID <> "" THEN 'This was a request to view products from only one
- 'category, only query for products in the category
- ProductInfo.Open querystr, cn
- CategoryInfo.Open querystr2, cn
- ELSE 'Retrieve all products in the query
- ProductInfo.Open defaultquery, cn
- END IF
- %>
-
- <CENTER>
- <H2>Northwind Inventory Management System</H2>
- <HR>
- <H3>
- <%
- IF CategoryID <> "" THEN 'Display the category of products being displayed.
- Response.Write CategoryInfo.Fields(0)
- CategoryInfo.Close 'Close this Recordset since it will not be used again.
- ELSE
- Response.Write "All Northwind Products"
- END IF %>
- </H3>
- </CENTER>
-
- <% 'If this is a remove operation, then output instructions the user.
- IF op = "Remove" THEN
- Response.Write "<p>Select each product you wish to remove from the inventory by marking its checkbox. " & _
- "When finished, press the Remove Products button at the bottom.</p>"
- END IF %>
-
- <TABLE CELLPADDING=3 BORDER=0 COLSPAN=8>
- <TR>
- <%
- 'Output a blank header if this is an Update or Remove display operation
- IF op <> "" THEN
- Response.Write "<TD CLASS=header></TD>"
- IF op = "Remove" THEN 'Create a form for the checkboxes to be submitted in %>
- <FORM NAME="RemoveForm" ACTION="remove.asp" METHOD=POST>
- <% END IF
- END IF
-
- 'Output the table headers
- For i = 0 To 8
- Response.Write "<TD CLASS=header>" & ProductInfo.Fields(i).Name & "</TD>"
- NEXT
- %>
- </TR>
-
- <% 'Loop through the recordset to output the table values
- Do While Not ProductInfo.EOF
- Response.Write "<TR>"
-
- 'Depending on the operation, add a "Remove" checkbox or "Edit" button to the row
- IF op <> "" THEN
- Response.Write "<TD>"
- IF op = "Update" THEN %>
- <FORM ACTION="update.asp?ProductID=<%=ProductInfo.Fields(9)%>" METHOD=POST>
- <INPUT TYPE=submit NAME=Edit VALUE=<%=op%>>
- </FORM>
- <% ELSE %>
- <INPUT TYPE=CHECKBOX NAME=ProductID VALUE=<%=ProductInfo.Fields(9)%>>
- <% END IF
- Response.Write "</TD>"
- END IF
-
- For i = 0 to 8 'Output the field values for the product
- Response.Write "<td>"
- Response.Write ProductInfo.Fields(i).Value
- Response.Write "</TD>"
- NEXT
-
- Response.Write "</TR>"
- ProductInfo.MoveNext
- LOOP
-
- 'Close the Recordset
- ProductInfo.Close %>
-
- </TABLE>
-
- <%
- IF op = "Remove" THEN 'Output a Remove button and close the RemoveForm
- 'form for the checkboxes to be submitted in %>
- <BR>
- <INPUT TYPE=BUTTON VALUE="Remove Product(s)" onClick="VBScript:ConfirmRemove">
- </FORM>
- <%END IF %>
-
- <HR>
- <BR>
- Return to the <A HREF="default.htm">Main Menu</A>
-
- </BODY>
- </HTML>
-