Option Strict On
''' -----------------------------------------------------------------------------
''' Project : AML
''' Class : FormsCollection
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' Replicates the forms collection that was inherant to VB
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [RIngram] 17/09/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Class FormsCollection
Inherits System.Collections.CollectionBase
''' -----------------------------------------------------------------------------
''' <summary>
''' Adds a new item to the forms collection
''' </summary>
''' <param name="formToAdd">The form to add to the collection</param>
''' <remarks>
''' If the form count is greater than two then it shows the window menu.
''' This is because the MDI form and the error form stay in memory the entire time so
''' a window count of greater than two indicates that the user is likely to want to toggle
''' the window about
''' </remarks>
''' <history>
''' [RIngram] 17/09/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Sub Add(ByVal formToAdd As Form)
MyBase.InnerList.Add(formToAdd)
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Removes the selected form from the collection
''' </summary>
''' <param name="formToRemove"></param>
''' <remarks>
''' If the form count drops to two or below then hide the window menu
''' </remarks>
''' <history>
''' [RIngram] 17/09/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Sub Remove(ByVal formToRemove As Form)
MyBase.InnerList.Remove(formToRemove)
End Sub
''' -----------------------------------------------------------------------------
''' <summary>
''' Checks to see if the form is in the collection
''' </summary>
''' <param name="formName">The name of the form to locate</param>
''' <returns>The form specified</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [RIngram] 17/09/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Function IsInCollection(ByVal formName As String) As Form
Dim item As Form
Try
For Each item In list
If Not IsNothing(item) Then
If item.Name.ToLower = formName.ToLower Then
Return CType(item, Form)
End If
End If
Next
'if execution reaches here then the form was not found so return nothing
Return Nothing
Catch ex As Exception
Return Nothing
Finally
item = Nothing
End Try
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' Checks to see if an instance of a form is in a collection
''' </summary>
''' <param name="formName">The name of the form to look for</param>
''' <param name="row">The datarow to match</param>
''' <returns>The instance of the form if a match is made</returns>
''' <remarks>
''' Used when multiple instances of the same form are required. Identifies a unique instance
''' by iterating the forms collection, matching first by name and then by the data row that
''' should be stored in each form's tag.
''' Assumes that the record identifier will always be stored in the first column of the record
''' </remarks>
''' <history>
''' [RIngram] 17/09/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Function IsInstanceInCollection(ByVal formName As String, ByVal row As DataRow) As Form
Dim item As Form
Dim formRow As DataRow
Dim counter As Integer
Try
'loop through the forms collection
For Each item In list
If item.Name.ToLower = formName.ToLower Then
'if the form names match then retrieve the row
formRow = CType(item.Tag, DataRow)
'if the items in the left most columns match then return the form as the correct item
If formRow(0) Is row(0) Then
Return item
End If
End If
Next
Catch ex As Exception
Return Nothing
Finally
formRow = Nothing
item = Nothing
End Try
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' Overloaded function.
''' </summary>
''' <param name="formName">The name of the form to look for</param>
''' <param name="id">The ID of the record which is stored in the form's tag as a string</param>
''' <returns>The form if found otherwise nothing</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [RIngram] 15/03/2005 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Function IsInstanceInCollection(ByVal formName As String, ByVal id As String) As Form
Dim item As Form
Dim tag As String
Try
For Each item In list
If item.Name.ToLower = formName.ToLower Then
tag = item.Tag.ToString.ToLower
If tag.ToLower = id.ToLower Then
Return item
End If
End If
Next
Catch ex As Exception
Return Nothing
Finally
item = Nothing
End Try
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' Overloaded function. Checks to see if an instance of a form is in the collection
''' </summary>
''' <param name="formName">The name of the form to look for eg frmLookupList</param>
''' <param name="table">The associated datatable</param>
''' <returns>The matched form or nothing if the form is not found</returns>
''' <remarks>
''' Used when multiple instances of the same form are required. Identifies a unique instance
''' by iterating the forms collection, matching first by name and then by the datatable that
''' should be stored in each form's tag.
''' Assumes that the table names will match.
''' </remarks>
''' <history>
''' [RIngram] 20/09/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Function IsInstanceInCollection(ByVal formName As String, ByVal table As DataTable) As Form
Dim item As Form
Dim formTable As DataTable
Dim counter As Integer
Try
'loop through the forms collection
For Each item In list
If item.Name.ToLower = formName.ToLower Then
'if the form names match then retrieve the row
formTable = CType(item.Tag, DataTable)
'if the items in the left most columns match then return the form as the correct item
If formTable.TableName.ToLower = table.TableName.ToLower Then
Return item
End If
End If
Next
Catch ex As Exception
Return Nothing
Finally
formTable = Nothing
item = Nothing
End Try
End Function
End Class