Managing Each Product in the Store Manager
Introduction. Now
we really get down to the nitty gritty of managing each product.
This interface is more sophisticated because of the variety of things
you need to be able to do with each product. Remember, with the
ListProducts.asp we were setting up options for "grosser"
operations on products, adding products, finding products, listing them
out. Even when we wanted to add a product we needed to create a
more specialized interface in NewProduct.asp. Now we will focus on
what needs to be donw to manage each product that might be selected by
the user.
The following table gives the ASP and five stored procedure we will develop in this page. |
Stored Procedure | ASP Container |
sp_RetrieveProduct
sp_RetrieveDeptByProd sp_RetrieveDepts sp_Attributes sp_RetrieveAttributes |
ManageProduct.asp |
The Stored Procedures.
First we present the stored procedures. Remember, you do not need
to implement the stored procedures, this is to illustrate what you would
need to do if you had the correct permissions in your database.
Since three of the stored procedures listed above have been developed already we will provide a link to the page that contains the ASP files used to create them. Remember, the ability to use stored procedures in a number of different locations in a web via the ASP middleware is one of the advantages of using them. The sp_RetrieveProduct uses a SELECT command to retrieve all of the fields in the record for a specified product in the Products table. This was developed when we developed the Product.asp for the store. The sp_RetrieveDeptByProd is relatively complicated in its simplicity and it is used to select all of the fields from the Department and DepartmentProduct tables for a particular product. This allows you to find out all of the departments the product is listed in. The following file should be called sp_RetrieveDeptByProd.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connDeptProds, strSQLCreate Set connDeptProds = Server.CreateObject("ADODB.Connection") connDeptProds.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connDeptProds.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_RetrieveDeptByProd " & _ "@idProduct int AS " & _ "select * from department, departmentproducts " & _ "where departmentproducts.idProduct = @idProduct and " & _ "department.iddepartment = departmentproducts.iddepartment" connDeptProds.execute(strSQLCreate) connDeptProds.Close Set connDeptProds = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
The sp_RetrieveDepts uses
a SELECT command to retrieve all of the information within the
Department table. This was developed when we developed the
Dept.asp for the store.
The sp_Attributes uses a SELECT command to return attributes for a specified product from four different tables, Products, ProductAttribute, Attribute and AttributeCategory. This was developed when we developed the Product.asp for the store. The sp_RetrieveAttributes is returns all of the information from the Attribute and AttributeCategory tables. The following file should be called sp_RetrieveAttributes.asp. |
<%@ Language=VBScript %> <% Option Explicit %> <!--#include File="adovbs.inc"--> <% ' Open a connection to our SQL Server database ' We will use the ADO Driver connection Dim connDeptProds, strSQLCreate Set connDeptProds = Server.CreateObject("ADODB.Connection") connDeptProds.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=YourUserName;UID=cis; PWD=csatqu" connDeptProds.Open ' Creating the SQL String to create the stored procedure strSQLCreate = "CREATE PROCEDURE sp_RetrieveAttributes AS " & _ "select * from attribute, attributecategory " & _ "where attribute.idattributecategory = attributecategory.idAttributeCategory " & _ "order by attributecategory.chrCategoryName" connDeptProds.execute(strSQLCreate) connDeptProds.Close Set connDeptProds = Nothing Response.Write "<font size = 5>The SQL has executed</font>" %> |
As with all of the stored procedures you create, this
file would only need to be executed once in your database. After
that you should get an error that the stored procedure already
exists. Since this is linked to the WildWillies database you do not even
need to do this much. But, remember, if you do execute such an ASP
you can delete the ASP immediately after the stored procedure has been
created.
The ManageProduct.asp. This is essentially a form page to get the inputs for the new product. You need to save this file and upload it to your StoreManager subdirectory. This ASP will do the following.
Call the file ManageProduct.asp. |
<%@ Language=VBScript %> <!-- #Include file="include/validatecheck.asp" --> <html> <!-- ManageProduct.asp - Provides the tools to manage the product data. --> <head> <meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </head> <body> <!-- #Include file="include/navinclude.asp" --> <% ' Create an ADO database connection set dbProduct = server.createobject("adodb.connection") ' Create the record set set rsProduct = server.CreateObject("adodb.recordset") ' Open the connection using our SQL Server DSN-less connection dbProduct.ConnectionString="Driver={SQL Server}; Server=cisdev.quinnipiac.edu;" & _ "Database=WildWillies;UID=cis; PWD=csatqu" dbProduct.Open ' The sp_RetrieveProduct stored procedure is utilized to ' get the data for the specified product. sql = "execute sp_RetrieveProduct " & request("idProduct") ' Execute the statement set rsProduct = dbProduct.Execute(sql) %> <!-- Start the form to update the product data. --> <form method="post" action="UpdateProduct.asp"> <!-- Start the table to display the product data. --> <table cellpadding="3" cellspacing="3"> <tr> <td align="right"><b>Preview Product:</b></td> <!-- To preview the product a link is built to the product.asp page in the live store. The Id of the product is passed on the URL. Notice the relative path --> <td><a href="../product.asp?idProduct=<%=request("idProduct")%>">Preview</a></td> </tr> <tr> <td align="right"><b>Delete Product:</b></td> <!-- A link to the deleteproduct.asp page is created to remove the product from the database. The ID of the product is passed. --> <td><a href="DeleteProduct.asp?idProduct=<%=request("idProduct")%>">Delete</a></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <!-- The product ID is displayed. To ensure the ID can be retrieved for the update a hidden HTML element is created. --> <td align="right"><b>Product ID:</b></td> <td><%=rsProduct("idProduct")%> <input type="hidden" value="<%=request("idProduct")%>" name="idProduct"> </td> </tr> <tr> <td align="right"><b>Product Name:</b></td> <!-- Display the product name. --> <td><input type="text" value="<%=rsProduct("chrProductName")%>" name="chrProductName" size="60"> </td> </tr> <tr> <td align="right"><b>Product Description:</b></td> <!-- Display the product description. --> <td><textarea cols="50" rows="10" name="txtDescription"><%=rsProduct("txtDescription")%></textarea></td> </tr> <tr> <td align="right"><b>Product Image:</b></td> <!-- Display the product image file name and display the image as well. Notice the relative path to the image file --> <td><input type="text" value="<%=rsProduct("chrProductImage")%>" name="chrProductImage"> <img src="../images/products/sm_<%=rsProduct("chrProductImage")%>" align="center"></td> </tr> <tr> <td align="right"><b>Product Price:</b></td> <!-- The product price is displayed. --> <td><input type="text" value="<%=rsProduct("intPrice")/100%>" name="intPrice"></td> </tr> <tr> <td align="right"><b>Active:</b></td> <td> <% ' Check to see if the product is active. if rsProduct("intActive") = 1 then %>
<%
<% end if %>
Loop
loop
' Loop back
' Loop back
' Loop back |
After you upload this ASP and access it in your web, probably by clicking on the Joe Bob's Thimble Sounds link you should see something like the following. Notice you need to scroll in order to get access all parts of this form. |
Notice the very large variety of options available on
this page.
|