VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ShoppingCart"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Const m_modName As String = "FMSStore_DB.ShoppingCart"
'Declare the DBHelper Object--see class initialization
Private m_dbh As DBHelper

Private Sub Class_Initialize()
    Set m_dbh = New FMStocks_DB.DBHelper
End Sub

Private Sub Class_Terminate()
    Set m_dbh = Nothing
End Sub

Public Sub Add(ByVal AccountID As Long, _
        ByVal SKU As Long, _
        ByVal Quantity As Integer)
    
    On Error GoTo errorHandler
    
    m_dbh.RunSP "ShoppingCart_Add", Array( _
        mp("@AccountID", adInteger, 4, AccountID), _
        mp("@SKU", adInteger, 4, SKU), _
        mp("@Quantity", adInteger, 2, Quantity))
    
    Exit Sub
    
errorHandler:
    
    RaiseError m_modName, "Add(" & AccountID & ")"
End Sub

Public Function GetByKey(ByVal AccountID As Long, ByVal SKU As Long) As ADODB.Recordset
    On Error GoTo errorHandler
    
    Set GetByKey = m_dbh.RunSPReturnRS("ShoppingCart_GetByKey", Array( _
        mp("@AccountID", adInteger, 4, AccountID), _
        mp("@SKU", adInteger, 4, SKU)))
        
    Exit Function
    
errorHandler:
    
    RaiseError m_modName, "GetByKey(" & AccountID & "," & SKU & ")"
End Function

Public Function ListByAccount(ByVal AccountID As Long) As ADODB.Recordset
    On Error GoTo errorHandler
    
    Set ListByAccount = m_dbh.RunSPReturnRS("ShoppingCart_ListByAccount", Array( _
        mp("@AccountID", adInteger, 4, AccountID)))
        
    Exit Function
    
errorHandler:
    
    RaiseError m_modName, "ListByAccount(" & AccountID & ")"
End Function

Public Sub Modify(ByVal AccountID As Long, _
        ByVal SKU As Long, _
        ByVal Quantity As Integer)
    
    On Error GoTo errorHandler
    
    m_dbh.RunSP "ShoppingCart_Modify", Array( _
        mp("@AccountID", adInteger, 4, AccountID), _
        mp("@SKU", adInteger, 4, SKU), _
        mp("@Quantity", adInteger, 2, Quantity))
    
    Exit Sub
    
errorHandler:
    
    RaiseError m_modName, "Modify(" & AccountID & "," & SKU & "," & Quantity & ")"
End Sub

Public Sub Remove(ByVal AccountID As Long, ByVal SKU As Long)
    On Error GoTo errorHandler
    
    m_dbh.RunSP "ShoppingCart_Remove", Array( _
        mp("@AccountID", adInteger, 4, AccountID), _
        mp("@SKU", adInteger, 4, SKU))
    
    Exit Sub
    
errorHandler:
    
    RaiseError m_modName, "Remove(" & AccountID & "," & SKU & ")"
End Sub

Public Sub RemoveAll(ByVal AccountID As Long)
    On Error GoTo errorHandler
    
    m_dbh.RunSP "ShoppingCart_RemoveAll", Array( _
        mp("@AccountID", adInteger, 4, AccountID))
    
    Exit Sub
    
errorHandler:
    
    RaiseError m_modName, "RemoveAll(" & AccountID & ")"
End Sub

Public Function TotalByAccount(ByVal AccountID As Long) As ADODB.Recordset
    On Error GoTo errorHandler
    
    Set TotalByAccount = m_dbh.RunSPReturnRS("ShoppingCart_TotalByAccount", _
        Array(mp("@AccountID", adInteger, 4, AccountID)))
        
    Exit Function
    
errorHandler:
    
    RaiseError m_modName, "TotalByAccount(" & AccountID & ")"
End Function

