' ------------------------------------------------------------
' Code generated automatically by Code Architects' VB Migration Partner
' ------------------------------------------------------------

Option Strict Off      ' Code migrated from VB6 has Option Strict disabled by default

<System.Runtime.InteropServices.ProgID("FMStocks_Bus.Ticker")> _ 
<Transaction(TransactionOption.Supported)> _
Public Class Ticker
	Inherits ServicedComponent

	#Region "Constructor"
	
	'A public default constructor
	Public Sub New()
		' Add initialization code here
	End Sub
	
	#End Region
	
	#Region "Static constructor"
	
	' This static constructor ensures that the VB6 support library be initialized before using current class.
	Shared Sub New()
		EnsureVB6LibraryInitialization()
	End Sub
	
	#End Region

	Private Const m_modName As String = "FMStocks_Bus.Ticker"
	
	'VerifySymbol
	'
	Public Function VerifySymbol(ByVal Ticker As String) As Boolean
		On Error GoTo errorHandler 
		Dim obj As FMStocks_DB.Ticker = New FMStocks_DB.Ticker()
		
		VerifySymbol = obj.VerifySymbol(Ticker)
		obj = Nothing
		
		VB6MtsMethods.GetObjectContext().SetComplete
		Exit Function
		
errorHandler:
		obj = Nothing
		VB6MtsMethods.GetObjectContext().SetAbort
		RaiseError(m_modName, "VerifySymbol(" & Ticker & ")")
		
	End Function

	' ListByTicker
	'
	Public Function ListByTicker(ByVal Ticker As String) As ADODB.Recordset
		On Error GoTo errorHandler 
		Dim obj As FMStocks_DB.Ticker = New FMStocks_DB.Ticker()
		
		ListByTicker = obj.ListByTicker(Ticker)
		obj = Nothing
		
		VB6MtsMethods.GetObjectContext().SetComplete
		Exit Function
		
errorHandler:
		obj = Nothing
		VB6MtsMethods.GetObjectContext().SetAbort
		RaiseError(m_modName, "ListByTicker(" & Ticker & ")")
	End Function

	' ListByCompany
	'
	Public Function ListByCompany(ByVal company As String) As ADODB.Recordset
		On Error GoTo errorHandler 
		Dim obj As FMStocks_DB.Ticker = New FMStocks_DB.Ticker()
		
		ListByCompany = obj.ListByCompany(company)
		obj = Nothing
		
		VB6MtsMethods.GetObjectContext().SetComplete
		Exit Function
		
errorHandler:
		obj = Nothing
		VB6MtsMethods.GetObjectContext().SetAbort
		RaiseError(m_modName, "ListByCompany(" & company & ")")
	End Function

	' GetFundamentals
	'
	' Takes a ticker symbol and returns an array of fundamental metric values,
	' the company name and the trading exchange.
	Public Function GetFundamentals(ByVal Ticker As String, ByRef company As Object, ByRef Exchange As Object) As ADODB.Recordset
		On Error GoTo errorHandler 
		Dim obj As FMStocks_DB.Ticker = New FMStocks_DB.Ticker()
		
		Dim rs As ADODB.Recordset = obj.GetFundamentals(Ticker)
		
		' Construct a new recordset based on the results from the fundamental queries
		
		Dim rsnew As ADODB.Recordset = New ADODB.Recordset()
		
		rsnew.CursorLocation = ADODB.CursorLocationEnum.adUseClient
		
		'Add Some Fields
		rsnew.Fields.Append("ShortDesc", ADODB.DataTypeEnum.adVarChar, 50)
		rsnew.Fields.Append("LongDesc", ADODB.DataTypeEnum.adVarChar, 100)
		rsnew.Fields.Append("Criteria", ADODB.DataTypeEnum.adVarChar, 50)
		rsnew.Fields.Append("Value", ADODB.DataTypeEnum.adVarChar, 50)
		rsnew.Fields.Append("Status", ADODB.DataTypeEnum.adInteger, 4)
		
		rsnew.Open(, , ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
		
		Do While Not (rs.EOF)
			company = rs.Fields("Company").Value
			Exchange = rs.Fields("Exchange").Value
			
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("MarketCap")) < 1000), "MarketCap", "$" & NullsToZero(rs.Fields("MarketCap")) & "M", "< $1B", "Total market capitalization less than $1 Billion.")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("Sales")) < 100), "Sales", "$" & NullsToZero(rs.Fields("Sales")) & "M", "< $100M", "Gross revenue (total sales) less than $100 Million.")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("Price")) > 7), "Price", "$" & NullsToZero(rs.Fields("Price")), "> $7/share", "Stock price greater than $7 per share.")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("DailyDollarVol")) > 1), "Daily dollar volume", "$" & NullsToZero(rs.Fields("DailyDollarVol")) & "M", "> $1M per day", "At least $100M in shares move on an average day.")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("SalesGrowth")) > 25), "Sales growth", NullsToZero(rs.Fields("SalesGrowth")) & "%", "> 25%", "Gross revenue growth of 25% trailing-twelve months (TTM).")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("EPSGrowth")) > 25), "Earnings growth", NullsToZero(rs.Fields("EPSGrowth")) & "%", "> 25%", "Earnings-per-share growth over TTM.")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("NetProfitMargin")) > 7), "Profit margin", NullsToZero(rs.Fields("NetProfitMargin")) & "%", "> 7%", "Net profit margin at least 7%.")
			FormatItem(rsnew, CShort(NullsToZero(rs.Fields("InsiderShares")) > 10), "Insider holdings", NullsToZero(rs.Fields("InsiderShares")) & "%", "> 10%", "At least 10% of the shares should be held by insiders.")
			
			rs.MoveNext()
		Loop
		rsnew.UpdateBatch(ADODB.AffectEnum.adAffectAll)
		rsnew.MoveFirst()
		
		obj = Nothing
		rs = Nothing
		GetFundamentals = rsnew
		VB6MtsMethods.GetObjectContext().SetComplete
		Exit Function
		
errorHandler:
		obj = Nothing
		rs = Nothing
		
		VB6MtsMethods.GetObjectContext().SetAbort
		RaiseError(m_modName, "GetFundamentals(" & Ticker & ")")
	End Function

	'Helper sub to add the new records
	Private Sub FormatItem(ByRef rs As ADODB.Recordset, ByRef Status As Short, ByRef ShortDesc As String, ByRef Value As String, ByRef Criteria As String, ByRef LongDesc As String)
		rs.AddNew(Array6("ShortDesc", "LongDesc", "Criteria", "Value", "Status"), Array6(ShortDesc, LongDesc, Criteria, Value, Status))
	End Sub

End Class
