?? shoppingcartdb.vb
字號:
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
Dim parameterCartID As SQLParameter = New SQLParameter("@CartID", SQLDataType.NChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)
' Add Parameters to SPROC
Dim parameterItemCount As SQLParameter = New SQLParameter("@ItemCount", SQLDataType.Int, 4)
parameterItemCount.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterItemCount)
Try
' Open the connection and execute the Command
myConnection.Open()
myCommand.Execute()
Catch e As Exception
' An error occurred, pass the exception up
throw e
Finally
' Close the Connection
If myConnection.State = DBObjectState.Open then
myConnection.Close()
End If
End Try
' Return the ItemCount (obtained as out paramter of SPROC)
return CInt(parameterItemCount.Value)
End Function
'*******************************************************
'
' ShoppingCartDB.GetTotal() Method <a name="GetTotal"></a>
'
' The GetTotal method returns the total price of all
' items within the shopping cart.
'
' Other relevant sources:
' + <a href="srcview.aspx?path=../ShoppingCart.src&file=docs/ShoppingCartTotal.htm" style="color:green">ShoppingCartTotal Stored Procedure</a>
'
'*******************************************************
Public Function GetTotal(cartID As String) As Double
' Create Instance of Connection and Command Object
Dim myConnection As SQLConnection = New SQLConnection(ConferenceDB.ConnectionString)
Dim myCommand As SQLCommand = New SQLCommand("ShoppingCartTotal", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterCartID As SQLParameter = New SQLParameter("@CartID", SQLDataType.NChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)
Dim parameterTotalCost As SQLParameter = New SQLParameter("@TotalCost", SQLDataType.Float, 8)
parameterTotalCost.Direction = ParameterDirection.Output
myCommand.Parameters.Add(parameterTotalCost)
Try
' Open the connection and execute the Command
myConnection.Open()
myCommand.Execute()
Catch e As Exception
' An error occurred, pass the exception up
throw e
Finally
' Close the Connection
If myConnection.State = DBObjectState.Open then
myConnection.Close()
End If
End Try
' Return the Total
return CDbl(parameterTotalCost.Value)
End Function
'*******************************************************
'
' ShoppingCartDB.MigrateCart() Method <a name="MigrateCart"></a>
'
' The MigrateCart method migrates the items from one
' cartId to another. This is used during the login
' and/or registration process to transfer a user's
' temporary cart items to a permanent account.
'
' Other relevant sources:
' + <a href="srcview.aspx?path=../Login.src&file=docs/ShoppingCartMigrate.htm" style="color:green">ShoppingCartMigrate Stored Procedure</a>
'
'*******************************************************
Public Sub MigrateCart(oldCartId As String, NewCartId As String)
' Create Instance of Connection and Command Object
Dim myConnection As SQLConnection = New SQLConnection(ConferenceDB.ConnectionString)
Dim myCommand As SQLCommand = New SQLCommand("ShoppingCartMigrate", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim cart1 As SQLParameter = New SQLParameter("@OriginalCartId ", SQLDataType.NChar, 50)
cart1.Value = oldCartId
myCommand.Parameters.Add(cart1)
Dim cart2 As SQLParameter= New SQLParameter("@NewCartId ", SQLDataType.NChar, 50)
cart2.Value = NewCartId
myCommand.Parameters.Add(cart2)
Try
' Open the connection and execute the Command
myConnection.Open()
myCommand.Execute()
Catch e As Exception
' An error occurred, pass the exception up
throw e
Finally
' Close the Connection
If myConnection.State = DBObjectState.Open then
myConnection.Close()
End If
End Try
End Sub
'*******************************************************
'
' ShoppingCartDB.EmptyCart() Method <a name="EmptyCart"></a>
'
' The EmptyCart method removes all current items within
' the shopping cart.
'
' Other relevant sources:
' + <a href="srcview.aspx?path=../ShoppingCart.src&file=docs/ShoppingCartEmpty.htm" style="color:green">ShoppingCartEmpty Stored Procedure</a>
'
'*******************************************************
Public Sub EmptyCart(cartID As String)
' Create Instance of Connection and Command Object
Dim myConnection As SQLConnection = New SQLConnection(ConferenceDB.ConnectionString)
Dim myCommand As SQLCommand = New SQLCommand("ShoppingCartEmpty", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim mycartid As SQLParameter = New SQLParameter("@CartID", SQLDataType.NChar, 50)
mycartid.Value = cartID
myCommand.Parameters.Add(mycartid)
Try
' Open the connection and execute the Command
myConnection.Open()
myCommand.Execute()
Catch e As Exception
' An error occurred, pass the exception up
throw e
Finally
' Close the Connection
If myConnection.State = DBObjectState.Open then
myConnection.Close()
End If
End Try
End Sub
'*******************************************************
'
' ShoppingCartDB.GetShoppingCartId() Method <a name="GetShoppingCartId"></a>
'
' The GetShoppingCartId method is used to calculate the
' "ShoppingCart" ID key used for a tracking a browser.
'
' The ShoppingCartID value is either the User's Identity
' Name (if they are a registered and authenticated user),
' or a random GUID calculated for guest visitors or
' customers who have not yet logged in.
'
'*******************************************************
Public Function GetShoppingCartId() As String
' Obtain current HttpContext of ASP+ Request
Dim context as System.Web.HttpContext = System.Web.HttpContext.Current
' If the user is authenticated, use their customerId as a permanent shopping cart id
If context.User.Identity.Name <> "" Then
return context.User.Identity.Name
End If
' If user is not authenticated, either fetch (or issue) a new temporary cartID
If context.Request.Cookies("Conference_CartID") <> Nothing Then
return context.Request.Cookies("Conference_CartID").Value
Else
' Generate a new random GUID using System.Guid Class
Dim tempCartId As Guid = Guid.NewGuid()
' Send tempCartId back to client as a cookie
context.Response.Cookies("Conference_CartID").Value = tempCartId.ToString()
' Return tempCartId
return tempCartId.ToString()
End If
End Function
End Class
End Namespace
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -