home *** CD-ROM | disk | FTP | other *** search
- <%@ LANGUAGE="VBSCRIPT" %>
- <% 'ON ERROR RESUME NEXT 'Set this so that errors can be handled %>
-
- <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 - Add a Product</TITLE>
- <LINK REL="stylesheet" TYPE="text/css" HREF="nimstyle.css">
- <!-- #include file="adovbs.inc" -->
- </HEAD>
- <SCRIPT LANGUAGE="VBScript">
- <!--
- 'This clientside VBScript validates the add form to make sure the user
- 'entered valid product information.
- DIM ValidProduct
-
- Sub ValidateAddForm
-
- SET Add = document.AddForm
- ValidProduct = True
-
- Call CheckField (Add.ProductName.Value, "Please enter a product name!")
- Call CheckField (Add.QuantityPerUnit.Value, "Please enter a quantity per unit!")
-
- Call CheckField (Add.UnitPrice.Value, "Please enter a Unit Price!")
- Call CheckFieldNumeric (Add.UnitPrice.Value, "The Unit Price must be a monetary value!")
- Call CheckMonetaryField
-
- Call CheckField (Add.UnitsInStock.Value, "Please enter Units In Stock!")
- Call CheckFieldNumeric (Add.UnitsInStock.Value, "Units In Stock must be a numeric value!")
-
- Call CheckField (Add.UnitsOnOrder.Value, "Please enter Units On Order!")
- Call CheckFieldNumeric (Add.UnitsOnOrder.Value, "Units On Order must be a numeric value!")
-
- Call CheckField (Add.ReorderLevel.Value, "Please enter the Reorder Level!")
- Call CheckFieldNumeric (Add.ReorderLevel.Value, "The Reorder Level must be a numeric value!")
-
- IF ValidProduct THEN
- 'MsgBox "I'm adding your project now!"
- Add.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 AddForm.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>
- <BODY>
-
- <%
- 'Start processing form data if any
- IF Request.Form("ProductName") <> "" THEN
-
- 'Retrive the CategoryID from the input
- CategoryID = Request.Form("CategoryID")
-
- 'Reference the Session connection variable
- Set cn = Session("cnn")
-
- 'Create a recordset
- Set ProductInfo = Server.CreateObject("ADODB.Recordset")
-
- 'Create a query string
- querystr = "SELECT ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock," _
- & "UnitsOnOrder, ReorderLevel, Discontinued, ProductID FROM Products" _
- & " WHERE CategoryID = " & CategoryID & " ORDER BY ProductID"
-
- 'Set all the properties for the recordset
- ProductInfo.ActiveConnection = cn
- ProductInfo.CursorType = adOpenKeyset
- ProductInfo.LockType = adLockOptimistic
- ProductInfo.Source = querystr
- ProductInfo.Open
-
- 'Call the Recordset method AddNew to create a new record in the recordset
- ProductInfo.AddNew
-
- 'Set the values of the new record equal to the values entered by the user
- 'in the Add Product 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")
-
- 'Call the Recordset method Update to actually add the new record to the
- 'SQL Server database
- ProductInfo.Update %>
-
- <!-- Output the new product entry to the user so they can see what was added. -->
- <H3>The following product information has been added to 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 added product's information
- For i = 0 to 8
- Response.Write "<TD>"
- Response.Write ProductInfo.Fields(i).Value
- Response.Write "</TD>"
- NEXT %>
-
- </TR>
- </TABLE>
-
- <BR>
- <HR>
- Return to the <A HREF="default.htm">Main Menu</A>
-
- <% 'Close the recordset after use
- ProductInfo.Close
-
- ELSE 'Output a form so that the user can add a new cd to the collection %>
-
- <CENTER>
- <H2>Add a Product to the Inventory</H2>
- </CENTER>
- <HR>
- To add a product to the Northwind Inventory, fill out the following form and then press
- the button at the bottom of the page.
-
- <FORM NAME="AddForm" ACTION="add.asp" METHOD=POST>
- <TABLE ALIGN=CENTER CLASS=formtable CELLPADDING=2>
- <TR>
- <TD>Product Name</TD>
- <TD><INPUT TYPE="text" NAME="ProductName" MAXLENGTH=40></TD>
- </TR>
- <TR>
- <TD>Supplier</TD>
- <TD><SELECT NAME="SupplierID" SIZE=1>
- <OPTION VALUE=18>Aux joyeux ecclésiastiques
- <OPTION VALUE=16>Bigfoot Breweries
- <OPTION VALUE=5>Cooperativa de Quesos 'Las Cabras'
- <OPTION VALUE=27>Escargots Nouveaux
- <OPTION VALUE=1>Exotic Liquids
- <OPTION VALUE=29>Forêts d'érables
- <OPTION VALUE=14>Formaggi Fortini s.r.l.
- <OPTION VALUE=28>Gai pâturage
- <OPTION VALUE=24>G'day, Mate
- <OPTION VALUE=3>Grandma Kelly's Homestead
- <OPTION VALUE=11>Heli Süßwaren GmbH & Co. KG
- <OPTION VALUE=23>Karkki Oy
- <OPTION VALUE=20>Leka Trading
- <OPTION VALUE=21>Lyngbysild
- <OPTION VALUE=25>Ma Maison
- <OPTION VALUE=6>Mayumi's
- <OPTION VALUE=19>New England Seafood Cannery
- <OPTION VALUE=2>New Orleans Cajun Delights
- <OPTION VALUE=13>Nord-Ost-Fisch Handelsgesellschaft mbH
- <OPTION VALUE=15>Norske Meierier
- <OPTION VALUE=26>Pasta Buttini s.r.l.
- <OPTION VALUE=7>Pavlova, Ltd.
- <OPTION VALUE=9>PB Knäckebröd AB
- <OPTION VALUE=12>Plutzer Lebensmittelgroßmärkte AG
- <OPTION VALUE=10>Refrescos Americanas LTDA
- <OPTION VALUE=8>Specialty Biscuits, Ltd.
- <OPTION VALUE=17>Svensk Sj├╢f├╢da AB
- <OPTION VALUE=4>Tokyo Traders
- <OPTION VALUE=22>Zaanse Snoepfabriek
- </SELECT>
- </TD>
- </TR>
- <TR>
- <TD>Category</TD>
- <TD><SELECT NAME="CategoryID" SIZE=1>
- <OPTION VALUE=1>Beverages
- <OPTION VALUE=2>Condiments
- <OPTION VALUE=3>Confections
- <OPTION VALUE=4>Dairy Products
- <OPTION VALUE=5>Grains/Cereals
- <OPTION VALUE=6>Meat/Poultry
- <OPTION VALUE=7>Produce
- <OPTION VALUE=8>Seafood
- </SELECT>
- </TD>
- </TR>
- <TR>
- <TD>Quantity Per Unit</TD>
- <TD><INPUT TYPE="text" NAME="QuantityPerUnit" MAXLENGTH=20></TD>
- </TR>
- <TR>
- <TD>Unit Price</TD>
- <TD><INPUT TYPE="text" NAME="UnitPrice"></TD>
- </TR>
- <TR>
- <TD>Units In Stock</TD>
- <TD><INPUT TYPE="text" NAME="UnitsInStock" SIZE=4 MAXLENGTH=4></TD>
- </TR>
- <TR>
- <TD>Units On Order</TD>
- <TD><INPUT TYPE="text" NAME="UnitsOnOrder" SIZE=4 MAXLENGTH=4></TD>
- </TR>
- <TR>
- <TD>Reorder Level</TD>
- <TD><INPUT TYPE="text" NAME="ReorderLevel" SIZE=4 MAXLENGTH=4></TD>
- </TR>
- <TR>
- <TD>Discontinued</TD>
- <TD><INPUT TYPE="radio" NAME="Discontinued" VALUE=1>True
- <INPUT TYPE="radio" NAME="Discontinued" VALUE=0 CHECKED>False
- </TD>
- </TR>
- <TR>
- <TD></TD>
- <TD><INPUT TYPE="button" NAME="AddButton"
- VALUE="Add Product To Inventory" onClick="VBScript:ValidateAddForm"></TD>
- </TR>
- </TABLE>
- </FORM>
-
- <BR><BR><HR>
- Return to the <A HREF="default.htm">Main Menu</A>
- <% END IF %>
-
- </BODY>
- </HTML>
-