Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Professional VB 6 Databases by Charles William


Message #1 by "Vibha Prajapati" <vprajapati@i...> on Tue, 15 Aug 2000 15:1:15
Hi:

I am sorry i send you the one i was practicing on.
But this is the actual one.  Sorry for the inconvenience.  I hope you can look into the matter once more and try to help me out. 
Thanks again.

I think somehow i am losing the variable when i am passing it from Checkout.asp page to DarrenBusiness.dll
I would appreciate if you could help me solve this piece.  If you need any other information do let me know.

Thank you,

Vibha Prajapati

CheckOut.asp


<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim Darren
Dim address
dim item
dim iProductId
dim iQuantity
dim prd
dim qty
dim UpdateStock
dim processor
dim result
dim objProducts
%>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Darren's Store</TITLE>
</HEAD>
<%
        'Connect to the store
        Set darren = server.CreateObject("darrenstore.store")
%>
<BODY>

        <font size=5>Checkout</font>
        <br><br>
       
        <%
              'Create the order process object
              Set processor = server.CreateObject("darrenbusiness.orderprocessor")
             
              'Create some dummy address and credit card info...
             
              set address = server.CreateObject("Scripting.Dictionary")
              address.add "FirstName", "Vibha"
              address.add "LastName", "Prajapati"
              address.add "Address 1", "19 Rutgers Lane"
              address.add "Address 2", "Bldg No 14"
              address.add "City", "Parsippany"
              address.add "State", "NJ"
              address.add "Zip", "07054"
              address.add "Country", "USA"
              address.add "Email", "vkprajapati@i..."
              address.add "Card", "4929 1234 1234 1234"
              address.add "Card Expires", "04/2001"
             
'I have added this piece of code to get the productID and Quantity from Cart.asp page

'loop all of the items in the cart

for each item in session("cart").items

              iProductId = item.ProductId
              response.Write iProductId   'this is just to check if my variable has a value
             
              iQuantity = item.quantity
              Response.Write iQuantity    'this is just to check if my variable has a value
next   
             
              'i have modified this to pass the 2 variable productId and quantity to the DarrenBusiness dll
              'which is in MTS
              result = processor.ProcessOrder(session("cart"), address, cint(iProductId), cint(iQuantity))
             

              'Now pass the cart and address to the processor        
              if result = true then
                  Response.Write "Your order was processed"
              else
                  Response.Write "Your order was not Processed"
              end if

             
              'Clean up
              set address = nothing
              set processor = nothing
             
        %>

</BODY>
<h1><%= iProductId%></h1>  'This is just to check whether i am losing the variable or not
<h1><%= iQuantity%></h1>
        <%
              'Close the store
              set darren = nothing
        %>
</HTML>

DarrenBusiness.dll

Option Explicit
Implements ObjectControl


'MTS transaction mode is set to RequireNewTransaction - tells MTS when an object is
'created , a new transaction should start
'When component is running inside MTS, MTS with provide us with some enviromental
'info as well few methods we have to use in order to tell MTS about the state of
'our transaction execution

'ObjectControl Interface    `
'When an app (ASP) creates instance for component, COM will manage the connection
'to MTS
'ObjectControl Activate event fired when a client start to use that object
        'to instantiate an ObjectContext object in the objectControl Dectivate event
        'fired when client releases the object
       
Private m_objCtx As ObjectContext

'Tell MTS --- support the objectControl interface
'Implements ObjectControl


'MTS will call this when our object is instantiated

Private Sub ObjectControl_Activate()
   
    Set m_objCtx = GetObjectContext
   
End Sub

'MTS will call this when our object is deleted

Private Sub ObjectControl_Deactivate()



    Set m_objCtx = Nothing
   
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
   '
End Function


'Process the order this function is called from my checkout.asp page
Public Function ProcessOrder(cart, address, iProductId As Integer, iQuantity As Integer) As Boolean

'Some where to put the results

Dim blnResult As Boolean
blnResult = False

'Firtly create a new customer

blnResult = CreateCustomer(address)

'Only do the rest if that succeeded, create customer succeeded

If blnResult = True Then
    'tell mts we did it
              
    Dim store
    Set store = CreateObject("darrenstore.store")
   
    'this is where i want to update my Product Table
    'Field StockLevel - iQuantity
   
    store.propConn.Execute ("Update Products Set StockLevel = StockLevel - iQuantity Where ProductID = iProductId")
   
    End If
   
    Set store = Nothing
   
    m_objCtx.SetComplete
Else
    'tell mts it all went wrong
    m_objCtx.SetAbort
End If

'Return the result back to the caller
ProcessOrder = blnResult

End Function

'Insert a new customer into the db based on the info contained in "address" collection
Public Function CreateCustomer(address)
   
    'pretend we succeed
   
    Dim store
    Set store = CreateObject("darrenstore.store")
   
    Dim strSQL
    strSQL = "insert into customers (first, last, email) values ("
    strSQL = strSQL & "'" & address("FirstName") & "', "
    strSQL = strSQL & "'" & address("LastName") & "', "
    strSQL = strSQL & "'" & address("Email") & "')"
    store.propConn.Execute strSQL
   
    Set store = Nothing
   
    CreateCustomer = True
   
       
End Function 


  Return to Index