📄 bclass.asp
字号:
var ERR_MAPPINGS_LENGTH = "Array length must match the number of cart columns<BR>";
var ERR_TRANS = "An error occured when inserting cart items in the database. The transaction was rolled back<BR>";
destCols = UC_VbToJsArray(destCols);
destColTypes = UC_VbToJsArray(destColTypes);
assert (destCols.length == this.numCols, "SaveToDatabase: " + "destCols - " + ERR_MAPPINGS_LENGTH);
assert (destColTypes.length == this.numCols, "SaveToDatabase: " + "destColTypes - " + ERR_MAPPINGS_LENGTH);
var insertColList = this.BuildInsertColumnList(orderIDCol, destCols);
if (insertColList != "") { //proceed only if we have a column list
var insertClause = "INSERT INTO " + dbTable + " " + insertColList + " VALUES ";
var recs;
adoConn.BeginTrans();
for (var iRow=0; iRow<this.GetItemCount(); iRow++){
var valList = this.BuildInsertValueList(orderIDColType, orderIDVal, destCols, destColTypes, iRow);
var sql = insertClause + valList;
adoConn.Execute(sql, recs, 1 /*adCmdText*/);
}
if (adoConn.Errors.Count == 0){
adoConn.CommitTrans();
this.Destroy(); // All items saved to database, we can trash the cart
} else {
adoConn.RollbackTrans();
//assert(false, "SaveToDatabase: " + ERR_TRANS); Don't assert here - let ASP display the database error.
}
}
}
function GetItemCount(){
return this.SC[0].length
}
function GetColumnTotal(colName){
// Generic column Total function
var colTotal = 0.0;
index = this.GetIndexOfColName(colName);
for (var i=0; i<this.SC[index].length; i++)
colTotal += parseFloat(this.SC[index][i]);
return colTotal
}
function DeleteLineItem(row){
assert(!isNaN(row), "Failure in call to DeleteLineItem - row is not a number");
assert(row>=0 && row <this.GetItemCount(), "failure in call to DeleteLineItem (internal error 121)");
var tmpSC= new Array(this.numCols);
var iDest = 0;
for (var iCol=0; iCol<this.numCols; iCol++) tmpSC[iCol] = new Array();
for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
if (iRow != row) {
for (iCol=0; iCol<this.numCols; iCol++) {
tmpSC[iCol][iDest] = this.SC[iCol][iRow];
}
iDest++;
}
}
this.SC = tmpSC;
this.persist();
}
function UCGetColNamesSerial(colDelim) {
var serialCols = "";
for (var iCol=0; iCol<this.numCols; iCol++) {
if (iCol != 0) serialCols += colDelim;
serialCols += this.colNames[iCol];
}
return serialCols;
}
function UCGetContentsSerial(colDelim, rowDelim) {
var serialCart = "";
for (var iRow=0; iRow<this.GetItemCount(); iRow++) {
if (iRow != 0) serialCart += rowDelim
for (var iCol=0; iCol<this.numCols; iCol++) {
if (iCol != 0) serialCart += colDelim;
serialCart += this.SC[iCol][iRow];
}
}
return serialCart;
}
function UCSetContentsSerial(serialCart, colDelim, rowDelim) {
var Rows = String(serialCart).split(rowDelim)
for (iRow = 0; iRow < Rows.length; iRow++) {
if (Rows[iRow] != "undefined" && Rows[iRow] != "") {
Cols = Rows[iRow].split(colDelim)
iCol = 0
for (iCol = 0; iCol<Cols.length; iCol++) {
this.SC[iCol][iRow] = Cols[iCol]
}
}
}
this.persist();
}
function SetCookie(){
var cookieName = this.GetCookieName()
var cookieStr = this.GetContentsSerial(this.cookieColDel, this.cookieRowDel)
var cookieExp = GetCookieExp(this.cookieLifetime)
Response.Cookies(cookieName) = cookieStr
Response.Cookies(cookieName).expires = cookieExp
}
function GetCookieName(){
var server = Request.ServerVariables("SERVER_NAME");
return server + this.Name;
}
function UCDestroyCookie(){
cookieName = this.GetCookieName();
Response.Cookies(cookieName) = ""
Response.Cookies(cookieName).expires = "1/1/90"
}
function PopulateFromCookie(cookieStr){
this.SetContentsSerial(cookieStr, this.cookieColDel, this.cookieRowDel)
}
// ***************** debug code ********************
function assert(bool, msg) {
if (!bool) {
Response.Write("<BR><BR>An error occured in the UltraDev shopping cart:<BR>" + msg + "<BR>");
//Response.End();
}
}
function AssertCartValid(colNames, msg) {
// go through all cart data structures and insure consistency.
// For example all column arrays should be the same length.
// this function should be called often, especially just after
// makeing changes to the data structures (adding, deleting, etc.)
// also verify we always have the required columns:
// ProductID, Quantity, Price, Total
// the input arg is some I add as I code this package like
// "Prior to return from AddToCart"
//
var ERR_COOKIE_SETTINGS = "Cookie settings on this page are inconsistent with those stored in the session cart<BR>";
var ERR_BAD_NAME = "Cart name defined on this page is inconsistent with the cart name stored in the session<BR>";
var ERR_COLUMN_COUNT = "The number of cart columns defined on this page is inconsistent with the cart stored in the session<BR>";
var ERR_REQUIRED_COLUMNS = "Too few columns; minimum number of columns is 4<BR>";
var ERR_REQUIRED_COLUMN_NAME = "Required Column is missing or at the wrong offset: ";
var ERR_COLUMN_NAMES = "Cart column names defined on this page are inconsistent with the cart stored in the session";
var ERR_INCONSISTENT_ARRAY_LENGTH = "Length of the arrays passed to cart constructor are inconsistent<BR>"
var errMsg = "";
var sessCart = Session(this.Name);
if (sessCart != null) { // Validate inputs against session cart if it exists
if (sessCart.Name != this.Name) errMsg += ERR_BAD_NAME;
if (this.numCols < 4) errMsg += ERR_REQUIRED_COLUMNS;
if (sessCart.numCols != this.numCols) errMsg += "Column Name Array: " + ERR_COLUMN_COUNT;
if (sessCart.numCols != this.colComputed.length) errMsg += "Computed Column Array: " + ERR_COLUMN_COUNT;
if (sessCart.bStoreCookie != this.bStoreCookie) errMsg += "Using Cookies: " + ERR_COOKIE_SETTINGS;
if (sessCart.cookieLifetime != this.cookieLifetime) errMsg += "Cookie Lifetime: " + ERR_COOKIE_SETTINGS;
// check that required columns are in the same place
var productIndex = this.GetIndexOfColName(this.PRODUCTID);
var quantityIndex = this.GetIndexOfColName(this.QUANTITY);
var priceIndex = this.GetIndexOfColName(this.PRICE);
var totalIndex = this.GetIndexOfColName(this.TOTAL);
if (colNames[productIndex] != "ProductID") errMsg += ERR_REQUIRED_COLUMN_NAME + "ProductID<BR>";
if (colNames[quantityIndex] != "Quantity") errMsg += ERR_REQUIRED_COLUMN_NAME + "Quantity<BR>";
if (colNames[priceIndex] != "Price") errMsg += ERR_REQUIRED_COLUMN_NAME + "Price<BR>";
if (colNames[totalIndex] != "Total") errMsg += ERR_REQUIRED_COLUMN_NAME + "Total<BR>";
}
else { // if cart doesn't exist in session, validate input array lengths and presence of reqiured columns
if (this.numCols != this.colComputed.length) errMsg += ERR_INCONSISTENT_ARRAY_LENGTH;
var bProductID = false, bQuantity = false, bPrice = false, bTotal = false;
for (var j = 0; j < colNames.length; j++) {
if (colNames[j] == "ProductID") bProductID = true;
if (colNames[j] == "Quantity") bQuantity= true;
if (colNames[j] == "Price") bPrice = true;
if (colNames[j] == "Total") bTotal = true;
}
if (!bProductID) errMsg += ERR_REQUIRED_COLUMN_NAME + "ProductID<BR>";
if (!bQuantity) errMsg += ERR_REQUIRED_COLUMN_NAME + "Quantity<BR>";
if (!bPrice) errMsg += ERR_REQUIRED_COLUMN_NAME + "Price<BR>";
if (!bTotal) errMsg += ERR_REQUIRED_COLUMN_NAME + "Total<BR>";
}
if (errMsg != "") {
Response.Write(msg + "<BR>");
Response.Write(errMsg + "<BR>");
Response.End();
}
}
function VBConstuctCart(Name, cookieLifetime, vbArrColNames, vbArrColComputed){
var myObj;
var a = new VBArray(vbArrColNames);
var b = new VBArray(vbArrColComputed);
eval("myObj = new UC_ShoppingCart(Name, cookieLifetime, a.toArray(), b.toArray())");
return myObj;
}
</SCRIPT>
<SCRIPT LANGUAGE=vbscript runat=server NAME="UC_CART">
Function GetCookieExp(expDays)
vDate = DateAdd("d", CInt(expDays), Now())
GetCookieExp = CStr(vDate)
End Function
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT NAME="UC_CART">
function DoNumber(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
DoNumber = FormatNumber(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
End Function
function DoCurrency(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
DoCurrency = FormatCurrency(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
End Function
function DoDateTime(str, nNamedFormat, nLCID)
dim strRet
dim nOldLCID
strRet = str
If (nLCID > -1) Then
oldLCID = Session.LCID
End If
On Error Resume Next
If (nLCID > -1) Then
Session.LCID = nLCID
End If
If ((nLCID < 0) Or (Session.LCID = nLCID)) Then
strRet = FormatDateTime(str, nNamedFormat)
End If
If (nLCID > -1) Then
Session.LCID = oldLCID
End If
DoDateTime = strRet
End Function
function DoPercent(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
DoPercent = FormatPercent(str, nDigitsAfterDecimal, nLeadingDigit, nUseParensForNeg, nGroupDigits)
End Function
function DoTrim(str, side)
dim strRet
strRet = str
If (side = "left") Then
strRet = LTrim(str)
ElseIf (side = "right") Then
strRet = RTrim(str)
Else
strRet = Trim(str)
End If
DoTrim = strRet
End Function
</SCRIPT>
<%
UC_CartColNames=Array("ProductID","Quantity","productName","Price","totalweight","weight","Total")
UC_ComputedCols=Array("","","","","weight","","Price")
set UCCart1=VBConstuctCart("UCCart",2,UC_CartColNames,UC_ComputedCols)
UCCart1__i=0
%>
<%
Dim sclass__MMColParam
sclass__MMColParam = "1"
if (Request.QueryString("bclassid") <> "") then sclass__MMColParam = Request.QueryString("bclassid")
%>
<%
set sclass = Server.CreateObject("ADODB.Recordset")
sclass.ActiveConnection = MM_conn_STRING
sclass.Source = "SELECT * FROM sclass WHERE bclassid = " + Replace(sclass__MMColParam, "'", "''") + ""
sclass.CursorType = 0
sclass.CursorLocation = 2
sclass.LockType = 3
sclass.Open()
sclass_numRows = 0
%>
<%
Dim dh__MMColParam
dh__MMColParam = "1"
if (Request.QueryString("bclassid") <> "") then dh__MMColParam = Request.QueryString("bclassid")
%>
<%
set dh = Server.CreateObject("ADODB.Recordset")
dh.ActiveConnection = MM_conn_STRING
dh.Source = "SELECT * FROM bclass WHERE bclassid = " + Replace(dh__MMColParam, "'", "''") + ""
dh.CursorType = 0
dh.CursorLocation = 2
dh.LockType = 3
dh.Open()
dh_numRows = 0
%>
<%
Dim product__MMColParam
product__MMColParam = "1"
if (Request.QueryString("bclassid") <> "") then product__MMColParam = Request.QueryString("bclassid")
%>
<%
set product = Server.CreateObject("ADODB.Recordset")
product.ActiveConnection = MM_conn_STRING
product.Source = "SELECT * FROM product WHERE bclassid = " + Replace(product__MMColParam, "'", "''") + ""
product.CursorType = 0
product.CursorLocation = 2
product.LockType = 3
product.Open()
product_numRows = 0
%>
<%
Dim HLooper1__numRows
HLooper1__numRows = 10
Dim HLooper1__index
HLooper1__index = 0
product_numRows = product_numRows + HLooper1__numRows
%>
<%
' *** Add item to UC Shopping cart
set UC_rs=product
UC_uniqueCol="productid"
UC_AddLink=""
If (Request.QueryString = "") Then
UC_AddLink = Request.ServerVariables("URL") & "?UC_AddId="
Else
UC_AddLink = Request.ServerVariables("URL") & "?" & Request.QueryString & "&UC_AddId="
End If
UC_AddId = CStr(Request("UC_AddId"))
If (UC_AddId <> "") Then
UC_redirectPage = ""
If (NOT (UC_rs is Nothing)) Then
' Position recordset to correct location
If (UC_rs.Fields.Item(UC_uniqueCol).Value <> UC_AddId) Then
' reset the cursor to the beginning
If (UC_rs.CursorType > 0) Then
If (Not UC_rs.BOF) Then UC_rs.MoveFirst
Else
UC_rs.Close
UC_rs.Open
End If
Do While (Not UC_rs.EOF)
If (Cstr(UC_rs.Fields.Item(UC_uniqueCol).Value) = UC_AddId) Then
Exit Do
End If
UC_rs.MoveNext
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -