Option Strict Off
Option Explicit On
Imports System.Linq
Imports System.Collections.Generic
Namespace FMStocks_DB
   Public Class Ticker : Implements System.IDisposable
   Dim _disposed As Boolean = False
   Private Const m_modName As String = "FMStocks_DB.Ticker"
   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 VerifySymbol(ByVal Ticker As String) As Boolean
      VerifySymbol = False
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         VerifySymbol = m_dbh.RunSPReturnInteger("Ticker_VerifySymbol",New Object(){Helpers.mp("@Ticker",System.Data.SqlDbType.Char,12,Ticker)}) <> 0


         Exit Function

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

         Helpers.RaiseError(m_modName,"VerifySymbol(" & Ticker & ")")
      End Try
   End Function
   Public Function GetPrice(ByVal Ticker As String) As Decimal
      GetPrice = 0.00
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()

         Dim x As Integer = 0
         x = m_dbh.RunSPReturnInteger("Ticker_GetPrice",New Object(){Helpers.mp("@Ticker",System.Data.SqlDbType.Char,12,Ticker)})

         GetPrice = Helpers.NullsToZero(x)  'changes a null return value into a zero, or returns x


         Exit Function

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

         Helpers.RaiseError(m_modName,"GetPrice(" & Ticker & ")")
      End Try
   End Function
   Public Function ListByTicker(ByVal Ticker As String) As gmRTL.DataLib.SqlClient.Recordset
      ListByTicker = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()
         ListByTicker = m_dbh.RunSPReturnRS("Ticker_ListByTicker",New Object(){Helpers.mp("@Ticker",System.Data.SqlDbType.VarChar,12,Ticker)})

         Exit Function

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

         Helpers.RaiseError(m_modName,"ListByTicker(" & Ticker & ")")
      End Try
   End Function
   Public Function ListByCompany(ByVal Company As String) As gmRTL.DataLib.SqlClient.Recordset
      ListByCompany = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()
         ListByCompany = m_dbh.RunSPReturnRS("Ticker_ListByCompany",New Object(){Helpers.mp("@Company",System.Data.SqlDbType.VarChar,60,Company)})

         Exit Function

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

         Helpers.RaiseError(m_modName,"ListByCompany(" & Company & ")")
      End Try
   End Function
   Public Function GetFundamentals(ByVal Ticker As String) As gmRTL.DataLib.SqlClient.Recordset
      GetFundamentals = Nothing
      Try
         gmRTL.Core.GlobalException.ClearErrorObject()
         GetFundamentals = m_dbh.RunSPReturnRS("Ticker_Fundamentals",New Object(){Helpers.mp("@Ticker",System.Data.SqlDbType.VarChar,12,Ticker)})

         Exit Function

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

         Helpers.RaiseError(m_modName,"GetFundamentals(" & Ticker & ")")
      End Try
   End Function
   End Class
End Namespace
