Option Strict Off
Option Explicit On
Imports System.Linq
Imports System.Collections.Generic
Namespace FMSStore_DB
   Public Class ShoppingCart : Implements System.IDisposable
   Dim _disposed As Boolean = False
   Private Const m_modName As String = "FMSStore_DB.ShoppingCart"
   'Declare the DBHelper Object--see class initialization
   Private m_dbh As FMStocks_DB.DBHelper = Nothing
   Public Sub New()
      MyBase.New()
      Class_Initialize()
   End Sub
   Private Sub Class_Initialize()
      m_dbh = New FMStocks_DB.DBHelper
   End Sub
   Public Sub Dispose() Implements System.IDisposable.Dispose
      Dispose(True)
      GC.SuppressFinalize(Me)
   End Sub
   Protected Overridable Sub Dispose(disposing As Boolean)
      If _disposed Then
         Return
      End If
      If (disposing) Then
         Class_Terminate()
      End If
      _disposed = True
   End Sub
   Private Sub Class_Terminate()
      m_dbh = Nothing
   End Sub
   Public Sub Add(ByVal AccountID As Integer,ByVal SKU As Integer,ByVal Quantity As Integer)

      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         m_dbh.RunSP("ShoppingCart_Add",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU),FMStocks_DB.Helpers.mp("@Quantity",System.Data.SqlDbType.Int,2,Quantity)},String.Empty)

         Exit Sub

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"Add(" & AccountID & ")",String.Empty,0,False)
      End Try
   End Sub
   Public Function GetByKey(ByVal AccountID As Integer,ByVal SKU As Integer) As gmRTL.DataLib.SqlClient.Recordset
      GetByKey = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         GetByKey = m_dbh.RunSPReturnRS("ShoppingCart_GetByKey",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU)},String.Empty)

         Exit Function

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"GetByKey(" & AccountID & "," & SKU & ")",String.Empty,0,False)
      End Try
   End Function
   Public Function ListByAccount(ByVal AccountID As Integer) As gmRTL.DataLib.SqlClient.Recordset
      ListByAccount = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         ListByAccount = m_dbh.RunSPReturnRS("ShoppingCart_ListByAccount",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID)},String.Empty)

         Exit Function

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"ListByAccount(" & AccountID & ")",String.Empty,0,False)
      End Try
   End Function
   Public Sub Modify(ByVal AccountID As Integer,ByVal SKU As Integer,ByVal Quantity As Integer)

      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         m_dbh.RunSP("ShoppingCart_Modify",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU),FMStocks_DB.Helpers.mp("@Quantity",System.Data.SqlDbType.Int,2,Quantity)},String.Empty)

         Exit Sub

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"Modify(" & AccountID & "," & SKU & "," & Quantity & ")",String.Empty,0,False)
      End Try
   End Sub
   Public Sub Remove(ByVal AccountID As Integer,ByVal SKU As Integer)
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         m_dbh.RunSP("ShoppingCart_Remove",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),FMStocks_DB.Helpers.mp("@SKU",System.Data.SqlDbType.Int,4,SKU)},String.Empty)

         Exit Sub

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"Remove(" & AccountID & "," & SKU & ")",String.Empty,0,False)
      End Try
   End Sub
   Public Sub RemoveAll(ByVal AccountID As Integer)
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         m_dbh.RunSP("ShoppingCart_RemoveAll",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID)},String.Empty)

         Exit Sub

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"RemoveAll(" & AccountID & ")",String.Empty,0,False)
      End Try
   End Sub
   Public Function TotalByAccount(ByVal AccountID As Integer) As gmRTL.DataLib.SqlClient.Recordset
      TotalByAccount = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         TotalByAccount = m_dbh.RunSPReturnRS("ShoppingCart_TotalByAccount",New Object(){FMStocks_DB.Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID)},String.Empty)

         Exit Function

      Catch exc As System.Exception
         gmRTL.Core.GlobalException.SetErrorObject(exc)

         FMStocks_DB.Helpers.RaiseError(m_modName,"TotalByAccount(" & AccountID & ")",String.Empty,0,False)
      End Try
   End Function
   End Class
End Namespace
