📄 order.asp
字号:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/conn.asp" -->
<%
' *** Logout the current user.
MM_Logout = CStr(Request.ServerVariables("URL")) & "?MM_Logoutnow=1"
If (CStr(Request("MM_Logoutnow")) = "1") Then
Session.Abandon
MM_logoutRedirectPage = "userlogin.asp"
' redirect with URL parameters (remove the "MM_Logoutnow" query param).
if (MM_logoutRedirectPage = "") Then MM_logoutRedirectPage = CStr(Request.ServerVariables("URL"))
If (InStr(1, UC_redirectPage, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_newQS = "?"
For Each Item In Request.QueryString
If (Item <> "MM_Logoutnow") Then
If (Len(MM_newQS) > 1) Then MM_newQS = MM_newQS & "&"
MM_newQS = MM_newQS & Item & "=" & Server.URLencode(Request.QueryString(Item))
End If
Next
if (Len(MM_newQS) > 1) Then MM_logoutRedirectPage = MM_logoutRedirectPage & MM_newQS
End If
Response.Redirect(MM_logoutRedirectPage)
End If
%>
<%
' *** Restrict Access To Page: Grant or deny access to this page
MM_authorizedUsers=""
MM_authFailedURL="userlogin.asp"
MM_grantAccess=false
If Session("MM_Username") <> "" Then
If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
(InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
MM_grantAccess = true
End If
End If
If Not MM_grantAccess Then
MM_qsChar = "?"
If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
MM_referrer = Request.ServerVariables("URL")
if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
Response.Redirect(MM_authFailedURL)
End If
%>
<%
' *** 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_conn_STRING
MM_editTable = "orders"
MM_editRedirectUrl = ""
MM_fieldsStr = "username|value|city|value|phone|value|zip|value|snumber|value|address|value|select|value|select2|value|user|value|orderid|value"
MM_columnsStr = "username|',none,''|city|',none,''|phone|',none,''|zip|',none,''|snumber|',none,''|address|',none,''|paymethodid|none,none,NULL|shippingid|none,none,NULL|user|',none,''|orderid|none,none,NULL"
' 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
%>
<%
UC_OrderIdSessionVar = "orderid"
If Session(UC_OrderIdSessionVar)="" Then
' Get a unique OrderID number and save to session.
UC_tableName = "nextorderid"
UC_fieldName = "nextorderid"
UC_sql = "select " & UC_fieldName & " from " & UC_tableName
tmp = "ADODB.Recordset"
set UC_rsId = Server.CreateObject(tmp)
UC_rsId.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="& Server.Mappath("db1.mdb")
UC_rsId.Source = UC_sql
UC_rsId.CursorType = 0 ' adOpenForwardOnly
UC_rsId.CursorLocation = 2 ' adUseServer
UC_rsId.LockType = 2 ' adLockPessimistic
UC_rsId.Open
Session(UC_OrderIdSessionVar) = UC_rsId.Fields(UC_fieldName).value
UC_rsId.Fields(UC_fieldName).value = Session(UC_OrderIdSessionVar) + 1
UC_rsId.Update
UC_rsId.Close
set UC_rsId = Nothing
End If
%>
<SCRIPT LANGUAGE=JavaScript RUNAT=Server NAME="UC_CART">
//
// UltraDev UCart include file Version 1.0
//
function UC_ShoppingCart(Name, cookieLifetime, colNames, colComputed) // Cart constructor
{
// Name is the name of this cart. This is not really used in this implementation.
// cookieLifeTime is in days. A value of 0 means do not use cookies.
// colNames is a list of column names (must contain: ProductID, Quantity, Price, Total)
// colComputed is a list of computed columns (zero length string means don't compute col.)
// Public methods or UC_Cart API
this.AddItem = UCaddItem; // Add an item to the cart
this.GetColumnValue = GetColumnValue; // Get a value from the cart
this.Destroy = UCDestroy; // remove all items, delete session, delete client cookie (if any)
this.SaveToDatabase = SaveToDatabase; // persist cart to database.
this.GetItemCount = GetItemCount; // the number of items in the cart.
this.Update = Update; // Update the cart quantities.
this.GetColumnTotal = GetColumnTotal; // Get the sum of a cart column for all items (e.g. price or shipping wt.).
this.GetContentsSerial = UCGetContentsSerial// Get the contents of the cart as a single delimited string
this.SetContentsSerial = UCSetContentsSerial// Set the contents of the cart from a serial string (obtained from GetContentsSerial)
this.GetColNamesSerial = UCGetColNamesSerial// Get the list of column names as a delimited string.
// PROPERTIES
this.SC = null; // Cart data array
this.numCols = colNames.length;
this.colComputed = colComputed;
this.colNames = colNames;
this.Name = Name;
this.cookieLifetime = cookieLifetime;
this.bStoreCookie = (cookieLifetime != 0);
// *CONVENIENCE* PROPERTIES
// (not used internally, but added to provide a place to store this data)
this.CustomerID = null;
this.OrderID = null;
this.Tax = null;
this.ShippingCost = null;
// CONSTANTS
this.PRODUCTID = "ProductID"; // Required SKU cart column
this.QUANTITY = "Quantity"; // Required Quantity cart column
this.PRICE = "Price"; // Required Price cart column
this.TOTAL = "Total"; // Required Total column
this.cookieColDel = "#UC_C#"
this.cookieRowDel = "#UC_R#"
// METHODS
this.AssertCartValid = AssertCartValid
// Private methods - don't call these unless you understand the internals.
this.GetIndexOfColName = UCgetIndexOfColName;
this.GetDataFromBindings = UCgetDataFromBindings;
this.FindItem = UCfindItem;
this.ComputeItemTotals = ComputeItemTotals;
this.persist = UCpersist;
this.BuildInsertColumnList = BuildInsertColumnList;
this.BuildInsertValueList = BuildInsertValueList;
this.UpdateQuantities = UpdateQuantities;
this.UpdateTotals = UpdateTotals;
this.DeleteItemsWithNoQuantity = DeleteItemsWithNoQuantity;
this.CheckAddItemConfig = CheckAddItemConfig;
this.ColumnExistsInRS = ColumnExistsInRS;
this.DeleteLineItem = DeleteLineItem;
this.GetCookieName = GetCookieName;
this.SetCookie = SetCookie;
this.PopulateFromCookie = PopulateFromCookie;
this.DestroyCookie = UCDestroyCookie;
// Cart "internals" documentation:
// The this.SC datastructure is a single variable of type array.
// Each array element corresponds to a cart column. For example:
// Array element 1: ProductID
// Array element 2: Quantity
// Array element 3: Price
// Array elemetn 4: Total
//
// Each of these is an array. Each array index corresponds to a line item.
// As such, each array should always be exactly the same length.
this.AssertCartValid(colNames, "Cart Initialization: ");
if (Session(this.Name) != null) {
this.SC = Session(this.Name).SC;
} else {
this.SC = new Array(this.numCols);
for (var i = 0; i < this.numCols; i++) this.SC[i] = new Array();
// Since the cart doesn't exist in session, check for cookie from previous session
if (this.bStoreCookie){
cookieName = this.GetCookieName();
cookieStr = Request.Cookies(cookieName);
if (cookieStr != null && String(cookieStr) != "undefined" && cookieStr != "")
this.PopulateFromCookie(cookieStr);
}
// Create a reference in the Session, pass the whole object (methods are not copied)
this.persist();
}
}
// convert vb style arrays to js style arrays.
function UC_VbToJsArray(a) {
if (a!=null && a.length==null) {
a = new VBArray(a);
a = a.toArray();
}
return a;
}
function UCpersist() {
Session(this.Name) = this;
if (this.bStoreCookie) this.SetCookie();
}
function UCDestroy(){
this.SC = new Array(this.numCols); // empty the "in-memory" cart.
for (var i = 0; i < this.numCols; i++) this.SC[i] = new Array();
this.persist();
if (this.bStoreCookie) this.DestroyCookie() // remove the cookie
}
function UCgetDataFromBindings(adoRS, bindingTypes, bindingValues) {
var values = new Array(bindingTypes.length)
for (i=0; i<bindingTypes.length; i++) {
var bindVal = bindingValues[i];
if (bindingTypes[i] == "RS"){
values[i] = String(adoRS(bindVal).Value)
if (values[i] == "undefined") values[i] = "";
}
else if (bindingTypes[i] == "FORM"){
values[i] = String(Request(bindVal))
if (values[i] == "undefined") values[i] = "";
}
else if (bindingTypes[i] == "LITERAL") values[i] = bindVal;
else if (bindingTypes[i] == "NONE") values[i] = ""; // no binding
else assert(false,"Unrecognized binding type: " + bindingTypes[i]); // Unrecognized binding type
}
return values;
}
function UCfindItem(bindingTypes, values){
// A product is a duplicate if it has the same unique ID
// AND all values from form bindings (except quantity) are the same
var indexProductID = this.GetIndexOfColName(this.PRODUCTID);
var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
assert(indexProductID >=0, "UC_Cart.js: Internal error 143");
assert(indexQuantity >=0, "UC_Cart.js: Internal error 144");
var newRow = -1
for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
found = true; // assume found
for (var iCol=0; iCol<this.numCols; iCol++) {
if (iCol != indexQuantity) {
if ((iCol==indexProductID) || (bindingTypes[iCol]=="FORM")) {
if (this.SC[iCol][iRow] != values[iCol]) {
found = false;
break;
} }
} }
if (found) {
newRow = iRow;
break;
}
}
return newRow
}
function UCaddItem(adoRS, bindingTypes, bindingValues, alreadyInCart){
// alreadyInCart can be "increment" or "replace" to handle duplicate items in cart.
bindingTypes = UC_VbToJsArray(bindingTypes);
bindingValues = UC_VbToJsArray(bindingValues);
// Check that length of binding types/values arrays is consistent with cart configuration
assert(bindingTypes.length == this.numCols, "UCaddItem: Array length mismatch (internal error 403)");
assert(bindingValues.length == this.numCols, "UCaddItem: Array length mismatch (internal error 404)");
// debug call
//this.CheckAddItemConfig(adoRS, bindingTypes, bindingValues);
var values = this.GetDataFromBindings(adoRS, bindingTypes, bindingValues) // get the actual values based on bindings
var newRow = this.FindItem(bindingTypes, values); // Check if this item is already in cart
if (newRow == -1) { // append a new item
newRow = this.GetItemCount();
for (var iCol=0; iCol<this.numCols; iCol++) { // add data
this.SC[iCol][newRow] = values[iCol];
}
this.ComputeItemTotals(newRow); // add computed columns (defined in colsComputed)
this.persist();
} else if (alreadyInCart == "increment") {
var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
this.SC[indexQuantity][newRow] = parseInt(this.SC[indexQuantity][newRow]) + parseInt(values[indexQuantity])
if (isNaN(this.SC[indexQuantity][newRow])) this.SC[indexQuantity][newRow] = 1;
this.ComputeItemTotals(newRow);
this.persist();
}
}
function UCgetIndexOfColName(colName) {
var retIndex = -1;
for (var i=0; i<this.numCols; i++) {
if (this.colNames[i] == colName) {
retIndex = i;
break;
}
}
return retIndex;
}
function ComputeItemTotals(row){
var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
var qty = parseInt(this.SC[indexQuantity][row])
for (var iCol=0; iCol<this.numCols; iCol++) {
var colToCompute = this.colComputed[iCol];
if (colToCompute != "") {
indexColToCompute = this.GetIndexOfColName(colToCompute);
this.SC[iCol][row] = parseFloat(this.SC[indexColToCompute][row]) * qty;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -