home *** CD-ROM | disk | FTP | other *** search
- <%@ LANGUAGE="VBSCRIPT" %>
-
- <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 - Update a Product</TITLE>
- <LINK REL="stylesheet" TYPE="text/css" HREF="nimstyle.css">
- <!-- #include file="adovbs.inc" -->
- <SCRIPT LANGUAGE="VBScript">
- <!--
- 'This clientside VBScript validates the Update form to make sure the user
- 'entered valid product information.
- DIM ValidProduct
-
- Sub ValidateUpdateForm
-
- SET Update = document.UpdateForm
- ValidProduct = True
-
- Call CheckField (Update.ProductName.Value, "Please enter a product name!")
- Call CheckField (Update.QuantityPerUnit.Value, "Please enter a quantity per unit!")
-
- Call CheckField (Update.UnitPrice.Value, "Please enter a Unit Price!")
- Call CheckFieldNumeric (Update.UnitPrice.Value, "The Unit Price must be a monetary value!")
- Call CheckMonetaryField
-
- Call CheckField (Update.UnitsInStock.Value, "Please enter Units In Stock!")
- Call CheckFieldNumeric (Update.UnitsInStock.Value, "Units In Stock must be a numeric value!")
-
- Call CheckField (Update.UnitsOnOrder.Value, "Please enter Units On Order!")
- Call CheckFieldNumeric (Update.UnitsOnOrder.Value, "Units On Order must be a numeric value!")
-
- Call CheckField (Update.ReorderLevel.Value, "Please enter the Reorder Level!")
- Call CheckFieldNumeric (Update.ReorderLevel.Value, "The Reorder Level must be a numeric value!")
-
- IF ValidProduct THEN
- Update.Submit
- END IF
-
- END Sub
-
- Sub CheckField (ByVal strFieldValue, ByVal strMsg)
- IF ValidProduct THEN 'Check to see if the field is invalid
- 'If a field name was not entered, prompt the user.
- IF strFieldValue = "" THEN
- ValidProduct = False
- MsgBox strMsg
- END IF
- END IF
- END Sub 'Check Field
-
- Sub CheckFieldNumeric (ByVal strFieldValue, ByVal strMsg)
- IF ValidProduct THEN 'Check to see if the field is invalid with non-numeric values
- IF NOT IsNumeric(strFieldValue) THEN
- ValidProduct = False
- MsgBox strMsg
- ELSE 'It is numeric, make sure it is a positive number
- IF NOT strFieldValue >= 0 THEN 'Set project to not valid
- ValidProduct = False
- MsgBox "All numeric values must be greater than or equal to zero!"
- END IF
- END IF
- END IF
- END Sub 'Check Field Numeric
-
- Sub CheckMonetaryField
- IF ValidProduct THEN 'Check to see if the Unit Price field value is within
- 'the proper range
- IF UpdateForm.UnitPrice.Value > 99999999999999.99 THEN
- ValidProduct = False
- MsgBox "The unit price must be less than $99,999,999,999,999.99!"
- END IF
-
- END IF
- END Sub 'Check Monetary Field
- -->
- </SCRIPT>
- </HEAD>
- <BODY>
-
- <%
- 'Retrieve the ProductID to be updated from the querystring
- ProductID = Request.QueryString("ProductID")
-
- 'Reference the Session connection variable
- cn = Session("cnn")
-
- 'Create a recordset
- Set ProductInfo = Server.CreateObject("ADODB.Recordset")
-
- 'Create a query string that retrieves the information for product number "ProductID"
- querystr = "SELECT ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock," _
- & "UnitsOnOrder, ReorderLevel, Discontinued, ProductID FROM Products" _
- & " WHERE ProductID = " & ProductID
-
- 'Set all the properties for the recordset and then open it.
- ProductInfo.ActiveConnection = cn
- ProductInfo.CursorType = adOpenKeyset
- ProductInfo.LockType = adLockOptimistic
- ProductInfo.Source = querystr
- ProductInfo.Open
-
- 'When called from the display page, output a form with the product's current
- 'information so that it may be edited or updated by the user.
- IF Request.QueryString("Update") <> "1" THEN
-
- 'Retrieve the Supplier & Category IDs from the Recordset so that they
- 'can be used to display the actual Supplier and product Category in the
- 'selection box in the update product form.
- SupplierID = ProductInfo.Fields(1)
- CategoryID = ProductInfo.Fields(2) %>
-
- <CENTER>
- <H2>Update a Product's information the Inventory</H2>
- </CENTER>
- <HR>
-
- <P>To update a product's information in the Northwind Inventory, make any changes
- necessary in the following form and then press the "Update Information" button at the bottom
- of the page.</P>
-
- <P>You can also press the "Reset" button to undo any changes before you click the
- "Update Information" button.</P>
-
- <FORM NAME="UpdateForm" ACTION="update.asp?ProductID=<%=ProductID%>&Update=1" METHOD=POST>
- <TABLE ALIGN=CENTER CLASS=formtable CELLPADDING=2>
- <TR>
- <TD>Product Name</TD>
- <TD><INPUT TYPE="text" NAME="ProductName" VALUE="<%=ProductInfo.Fields(0)%>"></TD>
- </TR>
- <TR>
- <TD>Supplier</TD>
- <TD><SELECT NAME="SupplierID" SIZE=1>
- <OPTION VALUE=18 <% IF SupplierID = 18 THEN%>SELECTED<%END IF%>>Aux joyeux ecclésiastiques
- <OPTION VALUE=16 <% IF SupplierID = 16 THEN%>SELECTED<%END IF%>>Bigfoot Breweries
- <OPTION VALUE=5 <% IF SupplierID = 5 THEN%>SELECTED<%END IF%>>Cooperativa de Quesos 'Las Cabras'
- <OPTION VALUE=27 <% IF SupplierID = 27 THEN%>SELECTED<%END IF%>>Escargots Nouveaux
- <OPTION VALUE=1 <% IF SupplierID = 1 THEN%>SELECTED<%END IF%>>Exotic Liquids
- <OPTION VALUE=29 <% IF SupplierID = 29 THEN%>SELECTED<%END IF%>>Forêts d'érables
- <OPTION VALUE=14 <% IF SupplierID = 14 THEN%>SELECTED<%END IF%>>Formaggi Fortini s.r.l.
- <OPTION VALUE=28 <% IF SupplierID = 28 THEN%>SELECTED<%END IF%>>Gai pâturage
- <OPTION VALUE=24 <% IF SupplierID = 24 THEN%>SELECTED<%END IF%>>G'day, Mate
- <OPTION VALUE=3 <% IF SupplierID = 3 THEN%>SELECTED<%END IF%>>Grandma Kelly's Homestead
- <OPTION VALUE=11 <% IF SupplierID = 11 THEN%>SELECTED<%END IF%>>Heli Süßwaren GmbH & Co. KG
- <OPTION VALUE=23 <% IF SupplierID = 23 THEN%>SELECTED<%END IF%>>Karkki Oy
- <OPTION VALUE=20 <% IF SupplierID = 20 THEN%>SELECTED<%END IF%>>Leka Trading
- <OPTION VALUE=21 <% IF SupplierID = 21 THEN%>SELECTED<%END IF%>>Lyngbysild
- <OPTION VALUE=25 <% IF SupplierID = 25 THEN%>SELECTED<%END IF%>>Ma Maison
- <OPTION VALUE=6 <% IF SupplierID = 6 THEN%>SELECTED<%END IF%>>Mayumi's
- <OPTION VALUE=19 <% IF SupplierID = 19 THEN%>SELECTED<%END IF%>>New England Seafood Cannery
- <OPTION VALUE=2 <% IF SupplierID = 2 THEN%>SELECTED<%END IF%>>New Orleans Cajun Delights
- <OPTION VALUE=13 <% IF SupplierID = 13 THEN%>SELECTED<%END IF%>>Nord-Ost-Fisch Handelsgesellschaft mbH
- <OPTION VALUE=15 <% IF SupplierID = 15 THEN%>SELECTED<%END IF%>>Norske Meierier
- <OPTION VALUE=26 <% IF SupplierID = 26 THEN%>SELECTED<%END IF%>>Pasta Buttini s.r.l.
- <OPTION VALUE=7 <% IF SupplierID = 7 THEN%>SELECTED<%END IF%>>Pavlova, Ltd.
- <OPTION VALUE=9 <% IF SupplierID = 9 THEN%>SELECTED<%END IF%>>PB Knäckebröd AB
- <OPTION VALUE=12 <% IF SupplierID = 12 THEN%>SELECTED<%END IF%>>Plutzer Lebensmittelgroßmärkte AG
- <OPTION VALUE=10 <% IF SupplierID = 10 THEN%>SELECTED<%END IF%>>Refrescos Americanas LTDA
- <OPTION VALUE=8 <% IF SupplierID = 8 THEN%>SELECTED<%END IF%>>Specialty Biscuits, Ltd.
- <OPTION VALUE=17 <% IF SupplierID = 17 THEN%>SELECTED<%END IF%>>Svensk Sj├╢f├╢da AB
- <OPTION VALUE=4 <% IF SupplierID = 4 THEN%>SELECTED<%END IF%>>Tokyo Traders
- <OPTION VALUE=22 <% IF SupplierID = 22 THEN%>SELECTED<%END IF%>>Zaanse Snoepfabriek
- </SELECT>
- </TD>
- </TR>
- <TR>
- <TD>Category</TD>
- <TD><SELECT NAME="CategoryID" SIZE=1>
- <OPTION VALUE=1 <% IF CategoryID = 1 THEN%>SELECTED<%END IF%>>Beverages
- <OPTION VALUE=2 <% IF CategoryID = 2 THEN%>SELECTED<%END IF%>>Condiments
- <OPTION VALUE=3 <% IF CategoryID = 3 THEN%>SELECTED<%END IF%>>Confections
- <OPTION VALUE=4 <% IF CategoryID = 4 THEN%>SELECTED<%END IF%>>Dairy Products
- <OPTION VALUE=5 <% IF CategoryID = 5 THEN%>SELECTED<%END IF%>>Grains/Cereals
- <OPTION VALUE=6 <% IF CategoryID = 6 THEN%>SELECTED<%END IF%>>Meat/Poultry
- <OPTION VALUE=7 <% IF CategoryID = 7 THEN%>SELECTED<%END IF%>>Produce
- <OPTION VALUE=8 <% IF CategoryID = 8 THEN%>SELECTED<%END IF%>>Seafood
- </SELECT>
- </TD>
- </TR>
- <TR>
- <TD>Quantity Per Unit</TD>
- <TD><INPUT TYPE="text" NAME="QuantityPerUnit" VALUE="<%=ProductInfo.Fields(3)%>"></TD>
- </TR>
- <TR>
- <TD>Unit Price</TD>
- <TD><INPUT TYPE="text" NAME="UnitPrice" VALUE="<%=ProductInfo.Fields(4)%>"></TD>
- </TR>
- <TR>
- <TD>Units In Stock</TD>
- <TD><INPUT TYPE="text" NAME="UnitsInStock" SIZE=4 MAXLENGTH=4 VALUE="<%=ProductInfo.Fields(5)%>"></TD>
- </TR>
- <TR>
- <TD>Units On Order</TD>
- <TD><INPUT TYPE="text" NAME="UnitsOnOrder" SIZE=4 MAXLENGTH=4 VALUE="<%=ProductInfo.Fields(6)%>"></TD>
- </TR>
- <TR>
- <TD>Reorder Level</TD>
- <TD><INPUT TYPE="text" NAME="ReorderLevel" SIZE=4 MAXLENGTH=4 VALUE="<%=ProductInfo.Fields(7)%>"></TD>
- </TR>
- <TR>
- <TD>Discontinued</TD>
- <TD><INPUT TYPE="radio" NAME="Discontinued"
- VALUE=1 <% IF ProductInfo.Fields(8) THEN%>CHECKED<%END IF%>>True
- <INPUT TYPE="radio" NAME="Discontinued"
- VALUE=0 <% IF NOT ProductInfo.Fields(8) THEN%>CHECKED<%END IF%>>False
- </TD>
- </TR>
- <TR>
- <TD></TD>
- <TD><INPUT TYPE="button" NAME="UpdateButton"
- VALUE="Update Information" onClick="VBScript:ValidateUpdateForm">
- <INPUT TYPE="reset" NAME="reset" VALUE="Reset"></TD>
- </TR>
- </TABLE>
- </FORM>
-
- <% ELSE 'Update the recordset with the information the user provided
- 'in the submitted update form.
-
- ProductInfo("ProductName") = Request.Form("ProductName")
- ProductInfo("SupplierID") = Request.Form("SupplierID")
- ProductInfo("CategoryID") = Request.Form("CategoryID")
- ProductInfo("QuantityPerUnit") = Request.Form("QuantityPerUnit")
- ProductInfo("UnitPrice") = Request.Form("UnitPrice")
- ProductInfo("UnitsInStock") = Request.Form("UnitsInStock")
- ProductInfo("UnitsOnOrder") = Request.Form("UnitsOnOrder")
- ProductInfo("ReorderLevel") = Request.Form("ReorderLevel")
- ProductInfo("Discontinued") = Request.Form("Discontinued")
-
- 'Move the cursor to the beginning of the recordset so that the updated
- 'information can be outputted to the user.
- ProductInfo.MoveFirst
-
- 'Output the updated product information to the user %>
- <H3>The following product information has been updated in the inventory database:</H3>
- <HR>
-
- <TABLE CELLPADDING=5>
- <TR>
-
- <% 'Output the Table Header row
- For i = 0 To 8
- Response.Write "<TD CLASS=header>" & ProductInfo.Fields(i).Name & "</TD>"
- NEXT %>
-
- </TR>
- <TR>
-
- <% 'Output the row containing the updated product's information
- For i = 0 to 8
- Response.Write "<td>"
- Response.Write ProductInfo.Fields(i).Value
- Response.Write "</TD>"
- NEXT %>
-
- </TR>
- </TABLE>
-
- <% END IF
-
- 'Close the recordset after using it.
- ProductInfo.Close %>
-
- <BR><BR><HR>
- <P>Return to the <A HREF="default.htm">Main Menu</A></P>
-
- </BODY>
- </HTML>
-