Option Strict Off
Option Explicit On
Imports System.Linq
Imports System.Collections.Generic
Namespace FMStocks_DB
   Public Class Tx : Implements System.IDisposable
   Dim _disposed As Boolean = False
   Private Const m_modName As String = "FMStocks_DB.Tx"
   Private m_dbh As DBHelper = Nothing
   Public Sub New()
      MyBase.New()
      Class_Initialize()
   End Sub
   Private Sub Class_Initialize()
      'must call CreateObject or COM+ will
      'not call IObjectConstructor inferface that DBHelper needs
      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 Function GetByID(ByVal TxID As Integer) As gmRTL.DataLib.SqlClient.Recordset
      GetByID = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         GetByID = m_dbh.RunSPReturnRS("Tx_GetByID",New Object(){Helpers.mp("@TxID",System.Data.SqlDbType.Int,4,TxID)})

         Exit Function

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

         Helpers.RaiseError(m_modName,"GetByID(" & TxID & ")")
      End Try
   End Function
   Public Function AddSellOrder(ByVal AccountID As Integer,ByVal Ticker As String,ByVal Shares As Integer) As Integer
      AddSellOrder = 0


      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         AddSellOrder = m_dbh.RunSPReturnInteger("Tx_AddSellOrder",New Object(){Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),Helpers.mp("@Ticker",System.Data.SqlDbType.VarChar,12,Ticker),Helpers.mp("@Shares",System.Data.SqlDbType.Int,4,Shares)})


         Exit Function

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

         Helpers.RaiseError(m_modName,"AddSellOrder(" & AccountID & "," & Ticker & "," & Shares & ")")
      End Try
   End Function
   Public Function AddBuyOrder(ByVal AccountID As Integer,ByVal Ticker As String,ByVal Shares As Integer) As Integer
      AddBuyOrder = 0

      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         AddBuyOrder = m_dbh.RunSPReturnInteger("Tx_AddBuyOrder",New Object(){Helpers.mp("@AccountID",System.Data.SqlDbType.Int,4,AccountID),Helpers.mp("@Ticker",System.Data.SqlDbType.VarChar,12,Ticker),Helpers.mp("@Shares",System.Data.SqlDbType.Int,4,Shares)})


         Exit Function

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

         Helpers.RaiseError(m_modName,"AddBuyOrder(" & AccountID & "," & Ticker & "," & Shares & ")")
      End Try
   End Function
   End Class
End Namespace
