<%@LANGUAGE="VBSCRIPT"%> <% ' *** Edit Operations: declare variables MM_editAction = CStr(Request("URL")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Request.QueryString End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) <> "") Then MM_editConnection = MM_OLEDB_STRING MM_editTable = "dbo.tblSHOP_Products" MM_editRedirectUrl = "/_admin/SHOP_AddProduct.asp" MM_fieldsStr = "DateAdded|value|Category|value|ProductName|value|SKU|value|Description|value|UnitPrice|value|SpecialPrice|value|QuantityPerUnit|value|Supplier|value|ProductImageName|value|OnSpecial|value|Discontinued|value|DiscountType|value|DiscountValue|value|UnitsInStock|value|UnitWeight|value" MM_columnsStr = "DateAdded|',none,NULL|CategoryID|none,none,NULL|ProductName|',none,''|SKU|',none,''|Description|',none,''|UnitPrice|none,none,NULL|SpecialPrice|none,none,NULL|QuantityPerUnit|none,none,NULL|SupplierID|none,none,NULL|ProductImageName|',none,''|OnSpecial|none,1,0|Discontinued|none,1,0|DiscountType|',none,''|DiscountValue|none,none,NULL|UnitsInStock|none,none,NULL|UnitWeight|',none,''" ' create the MM_fields and MM_columns arrays MM_fields = Split(MM_fieldsStr, "|") MM_columns = Split(MM_columnsStr, "|") ' set the form values For i = LBound(MM_fields) To UBound(MM_fields) Step 2 MM_fields(i+1) = CStr(Request.Form(MM_fields(i))) Next ' append the query string to the redirect URL If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString Else MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString End If End If End If %> <% ' *** Update Record: set variables If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then MM_editConnection = MM_OLEDB_STRING MM_editTable = "dbo.tblSHOP_Products" MM_editColumn = "ProductID" MM_recordId = "" + Request.Form("MM_recordId") + "" MM_editRedirectUrl = "/_admin/SHOP_AddProduct.asp" MM_fieldsStr = "DateAdded|value|Category|value|ProductName|value|SKU|value|Description|value|UnitPrice|value|SpecialPrice|value|QuantityPerUnit|value|Supplier|value|ProductImageName|value|OnSpecial|value|Discontinued|value|DiscountType|value|DiscountValue|value|UnitsInStock|value|UnitWeight|value" MM_columnsStr = "DateAdded|',none,NULL|CategoryID|none,none,NULL|ProductName|',none,''|SKU|',none,''|Description|',none,''|UnitPrice|none,none,NULL|SpecialPrice|none,none,NULL|QuantityPerUnit|none,none,NULL|SupplierID|none,none,NULL|ProductImageName|',none,''|OnSpecial|none,1,0|Discontinued|none,1,0|DiscountType|',none,''|DiscountValue|none,none,NULL|UnitsInStock|none,none,NULL|UnitWeight|',none,''" ' create the MM_fields and MM_columns arrays MM_fields = Split(MM_fieldsStr, "|") MM_columns = Split(MM_columnsStr, "|") ' set the form values For i = LBound(MM_fields) To UBound(MM_fields) Step 2 MM_fields(i+1) = CStr(Request.Form(MM_fields(i))) Next ' append the query string to the redirect URL If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString Else MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString End If End If End If %> <% ' *** Insert Record: construct a sql insert statement and execute it If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" For i = LBound(MM_fields) To UBound(MM_fields) Step 2 FormVal = MM_fields(i+1) MM_typeArray = Split(MM_columns(i+1),",") Delim = MM_typeArray(0) If (Delim = "none") Then Delim = "" AltVal = MM_typeArray(1) If (AltVal = "none") Then AltVal = "" EmptyVal = MM_typeArray(2) If (EmptyVal = "none") Then EmptyVal = "" If (FormVal = "") Then FormVal = EmptyVal Else If (AltVal <> "") Then FormVal = AltVal ElseIf (Delim = "'") Then ' escape quotes FormVal = "'" & Replace(FormVal,"'","''") & "'" Else FormVal = Delim + FormVal + Delim End If End If If (i <> LBound(MM_fields)) Then MM_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End if MM_tableValues = MM_tableValues & MM_columns(i) MM_dbValues = MM_dbValues & FormVal Next MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" If (Not MM_abortEdit) Then ' execute the insert Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute MM_editCmd.ActiveConnection.Close If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If End If %> <% ' *** Update Record: construct a sql update statement and execute it If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then ' create the sql update statement MM_editQuery = "update " & MM_editTable & " set " For i = LBound(MM_fields) To UBound(MM_fields) Step 2 FormVal = MM_fields(i+1) MM_typeArray = Split(MM_columns(i+1),",") Delim = MM_typeArray(0) If (Delim = "none") Then Delim = "" AltVal = MM_typeArray(1) If (AltVal = "none") Then AltVal = "" EmptyVal = MM_typeArray(2) If (EmptyVal = "none") Then EmptyVal = "" If (FormVal = "") Then FormVal = EmptyVal Else If (AltVal <> "") Then FormVal = AltVal ElseIf (Delim = "'") Then ' escape quotes FormVal = "'" & Replace(FormVal,"'","''") & "'" Else FormVal = Delim + FormVal + Delim End If End If If (i <> LBound(MM_fields)) Then MM_editQuery = MM_editQuery & "," End If MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal Next MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId If (Not MM_abortEdit) Then ' execute the update Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute MM_editCmd.ActiveConnection.Close If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If End If %> <% Session("Message") = "" %> <% set rsPRODUCTS = Server.CreateObject("ADODB.Recordset") rsPRODUCTS.ActiveConnection = MM_OLEDB_STRING rsPRODUCTS.Source = "SELECT * FROM dbo.vSHOP_Products" rsPRODUCTS.CursorType = 0 rsPRODUCTS.CursorLocation = 2 rsPRODUCTS.LockType = 3 rsPRODUCTS.Open() rsPRODUCTS_numRows = 0 %> <% set rsCATEGORIES = Server.CreateObject("ADODB.Recordset") rsCATEGORIES.ActiveConnection = MM_OLEDB_STRING rsCATEGORIES.Source = "SELECT CategoryID, CategoryName FROM dbo.tblSHOP_Categories" rsCATEGORIES.CursorType = 0 rsCATEGORIES.CursorLocation = 2 rsCATEGORIES.LockType = 3 rsCATEGORIES.Open() rsCATEGORIES_numRows = 0 %> <% set rsSUPPLIERS = Server.CreateObject("ADODB.Recordset") rsSUPPLIERS.ActiveConnection = MM_OLEDB_STRING rsSUPPLIERS.Source = "SELECT SupplierID, CompanyName FROM dbo.tblSHOP_Suppliers" rsSUPPLIERS.CursorType = 0 rsSUPPLIERS.CursorLocation = 2 rsSUPPLIERS.LockType = 3 rsSUPPLIERS.Open() rsSUPPLIERS_numRows = 0 %> <% set rsIMAGES = Server.CreateObject("ADODB.Recordset") rsIMAGES.ActiveConnection = MM_OLEDB_STRING rsIMAGES.Source = "SELECT FileName FROM dbo.tblImages" rsIMAGES.CursorType = 0 rsIMAGES.CursorLocation = 2 rsIMAGES.LockType = 3 rsIMAGES.Open() rsIMAGES_numRows = 0 %> <% Dim Repeat1__numRows Repeat1__numRows = -1 Dim Repeat1__index Repeat1__index = 0 rsPRODUCTS_numRows = rsPRODUCTS_numRows + Repeat1__numRows %> Add New Product
     |     |      |    Cancel
  Current Product Line
<% Function IfStockEmpty(val) If val = 0 Then IfStockEmpty = "Alert" Else IfStockEmpty = val End If End Function %> <% if NOT rsPRODUCTS.EOF then %> <% Dim Counter: Counter = 0 %> <% While ((Repeat1__numRows <> 0) AND (NOT rsPRODUCTS.EOF)) %> <% Counter = Counter +1 %> <% Repeat1__index=Repeat1__index+1 Repeat1__numRows=Repeat1__numRows-1 rsPRODUCTS.MoveNext() Wend %> <% else %> <% end if %>
         PRODUCT CAT SUP PPU QPU UOO UIS DISCON SPECIAL Last Modified
<%=Left(rsPRODUCTS.Fields.Item("ProductName").Value,23)%> <%=(rsPRODUCTS.Fields.Item("CategoryName").Value)%> <%=Left(rsPRODUCTS.Fields.Item("CompanyName").Value, 16)%> <%= FormatCurrency((rsPRODUCTS.Fields.Item("UnitPrice").Value), -1, -2, -2, -2) %> <%=(rsPRODUCTS.Fields.Item("QuantityPerUnit").Value)%> <%=(rsPRODUCTS.Fields.Item("UnitsOnOrder").Value)%> <%=IfStockEmpty(rsPRODUCTS.Fields.Item("UnitsInStock").Value)%> <% If rsPRODUCTS.Fields.Item("Discontinued").Value = True Then Response.Write "Yes" Else Response.Write "No" End If %> <% If rsPRODUCTS.Fields.Item("OnSpecial").Value = True Then Response.Write "Yes" Else Response.Write "No" End If %> <%= DoDateTime((rsPRODUCTS.Fields.Item("DateAdded").Value), 2, 2057) %>
No products listed
<% rsPRODUCTS.Close() %> <% rsCATEGORIES.Close() %> <% rsSUPPLIERS.Close() %> <% rsIMAGES.Close() %>