' This class is "generated" and will be overwritten.
' Your customizations should be made in EmployeesRecord.vb

Imports System.Data.SqlTypes
Imports System.Data
Imports BaseClasses
Imports BaseClasses.Data
Imports BaseClasses.Data.SqlProvider
Imports UseDAL.Data

Namespace UseDAL.Business

''' <summary>
''' The generated superclass for the <see cref="EmployeesTable"></see> class.
''' Provides access to the schema information and record data of a database table or view named Employees.
''' </summary>
''' <remarks>
''' The connection details (name, location, etc.) of the database and table (or view) accessed by this class 
''' are resolved at runtime based on the connection string in the application's Web.Config file.
''' <para>
''' This class is not intended to be instantiated directly.  To obtain an instance of this class, use 
''' <see cref="EmployeesTable.Instance">EmployeesTable.Instance</see>.
''' </para>
''' </remarks>
''' <seealso cref="EmployeesTable"></seealso>

<Serializable()> Public Class BaseEmployeesTable
    Inherits PrimaryKeyTable
    

    Private ReadOnly TableDefinitionString As String = EmployeesDefinition.GetXMLString()







    Protected Sub New()
        MyBase.New()
        Me.Initialize()
    End Sub

    Protected Overridable Sub Initialize()
        Dim def As New XmlTableDefinition(TableDefinitionString)
        Me.TableDefinition = New TableDefinition()
        Me.TableDefinition.TableClassName = System.Reflection.Assembly.CreateQualifiedName("App_Code", "UseDAL.Business.EmployeesTable")
        def.InitializeTableDefinition(Me.TableDefinition)
        Me.ConnectionName = def.GetConnectionName()
        Me.RecordClassName = System.Reflection.Assembly.CreateQualifiedName("App_Code", "UseDAL.Business.EmployeesRecord")
        Me.ApplicationName = "App_Code"
        Me.DataAdapter = New EmployeesSqlTable()
        Directcast(Me.DataAdapter, EmployeesSqlTable).ConnectionName = Me.ConnectionName
        
        Me.TableDefinition.AdapterMetaData = Me.DataAdapter.AdapterMetaData
    End Sub

#Region "Properties for columns"

    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.EmployeeID column object.
    ''' </summary>
    Public ReadOnly Property EmployeeIDColumn() As BaseClasses.Data.NumberColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(0), BaseClasses.Data.NumberColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.EmployeeID column object.
    ''' </summary>
    Public Shared ReadOnly Property EmployeeID() As BaseClasses.Data.NumberColumn
        Get
            Return EmployeesTable.Instance.EmployeeIDColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.LastName column object.
    ''' </summary>
    Public ReadOnly Property LastNameColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(1), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.LastName column object.
    ''' </summary>
    Public Shared ReadOnly Property LastName() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.LastNameColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.FirstName column object.
    ''' </summary>
    Public ReadOnly Property FirstNameColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(2), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.FirstName column object.
    ''' </summary>
    Public Shared ReadOnly Property FirstName() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.FirstNameColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Title column object.
    ''' </summary>
    Public ReadOnly Property TitleColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(3), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Title column object.
    ''' </summary>
    Public Shared ReadOnly Property Title() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.TitleColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.TitleOfCourtesy column object.
    ''' </summary>
    Public ReadOnly Property TitleOfCourtesyColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(4), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.TitleOfCourtesy column object.
    ''' </summary>
    Public Shared ReadOnly Property TitleOfCourtesy() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.TitleOfCourtesyColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.BirthDate column object.
    ''' </summary>
    Public ReadOnly Property BirthDateColumn() As BaseClasses.Data.DateColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(5), BaseClasses.Data.DateColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.BirthDate column object.
    ''' </summary>
    Public Shared ReadOnly Property BirthDate() As BaseClasses.Data.DateColumn
        Get
            Return EmployeesTable.Instance.BirthDateColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.HireDate column object.
    ''' </summary>
    Public ReadOnly Property HireDateColumn() As BaseClasses.Data.DateColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(6), BaseClasses.Data.DateColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.HireDate column object.
    ''' </summary>
    Public Shared ReadOnly Property HireDate() As BaseClasses.Data.DateColumn
        Get
            Return EmployeesTable.Instance.HireDateColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Address column object.
    ''' </summary>
    Public ReadOnly Property AddressColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(7), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Address column object.
    ''' </summary>
    Public Shared ReadOnly Property Address() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.AddressColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.City column object.
    ''' </summary>
    Public ReadOnly Property CityColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(8), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.City column object.
    ''' </summary>
    Public Shared ReadOnly Property City() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.CityColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Region column object.
    ''' </summary>
    Public ReadOnly Property RegionColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(9), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Region column object.
    ''' </summary>
    Public Shared ReadOnly Property Region() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.RegionColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.PostalCode column object.
    ''' </summary>
    Public ReadOnly Property PostalCodeColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(10), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.PostalCode column object.
    ''' </summary>
    Public Shared ReadOnly Property PostalCode() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.PostalCodeColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Country column object.
    ''' </summary>
    Public ReadOnly Property CountryColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(11), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Country column object.
    ''' </summary>
    Public Shared ReadOnly Property Country() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.CountryColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.HomePhone column object.
    ''' </summary>
    Public ReadOnly Property HomePhoneColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(12), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.HomePhone column object.
    ''' </summary>
    Public Shared ReadOnly Property HomePhone() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.HomePhoneColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Extension column object.
    ''' </summary>
    Public ReadOnly Property ExtensionColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(13), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Extension column object.
    ''' </summary>
    Public Shared ReadOnly Property Extension() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.ExtensionColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Photo column object.
    ''' </summary>
    Public ReadOnly Property PhotoColumn() As BaseClasses.Data.ImageColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(14), BaseClasses.Data.ImageColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Photo column object.
    ''' </summary>
    Public Shared ReadOnly Property Photo() As BaseClasses.Data.ImageColumn
        Get
            Return EmployeesTable.Instance.PhotoColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Notes column object.
    ''' </summary>
    Public ReadOnly Property NotesColumn() As BaseClasses.Data.ClobColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(15), BaseClasses.Data.ClobColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.Notes column object.
    ''' </summary>
    Public Shared ReadOnly Property Notes() As BaseClasses.Data.ClobColumn
        Get
            Return EmployeesTable.Instance.NotesColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.ReportsTo column object.
    ''' </summary>
    Public ReadOnly Property ReportsToColumn() As BaseClasses.Data.NumberColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(16), BaseClasses.Data.NumberColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.ReportsTo column object.
    ''' </summary>
    Public Shared ReadOnly Property ReportsTo() As BaseClasses.Data.NumberColumn
        Get
            Return EmployeesTable.Instance.ReportsToColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.CreatedOn column object.
    ''' </summary>
    Public ReadOnly Property CreatedOnColumn() As BaseClasses.Data.DateColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(17), BaseClasses.Data.DateColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.CreatedOn column object.
    ''' </summary>
    Public Shared ReadOnly Property CreatedOn() As BaseClasses.Data.DateColumn
        Get
            Return EmployeesTable.Instance.CreatedOnColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.CreatedBy column object.
    ''' </summary>
    Public ReadOnly Property CreatedByColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(18), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.CreatedBy column object.
    ''' </summary>
    Public Shared ReadOnly Property CreatedBy() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.CreatedByColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.LastUpdatedOn column object.
    ''' </summary>
    Public ReadOnly Property LastUpdatedOnColumn() As BaseClasses.Data.DateColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(19), BaseClasses.Data.DateColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.LastUpdatedOn column object.
    ''' </summary>
    Public Shared ReadOnly Property LastUpdatedOn() As BaseClasses.Data.DateColumn
        Get
            Return EmployeesTable.Instance.LastUpdatedOnColumn
        End Get
    End Property
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.LastUpdatedBy column object.
    ''' </summary>
    Public ReadOnly Property LastUpdatedByColumn() As BaseClasses.Data.StringColumn
        Get
            Return CType(Me.TableDefinition.ColumnList(20), BaseClasses.Data.StringColumn)
        End Get
    End Property


    
    ''' <summary>
    ''' This is a convenience property that provides direct access to the table's Employees_.LastUpdatedBy column object.
    ''' </summary>
    Public Shared ReadOnly Property LastUpdatedBy() As BaseClasses.Data.StringColumn
        Get
            Return EmployeesTable.Instance.LastUpdatedByColumn
        End Get
    End Property


#End Region


#Region "Shared helper methods"

    ''' <summary>
    ''' This is a shared function that can be used to get an array of EmployeesRecord records using a where clause.
    ''' </summary>
    Public Shared Function GetRecords(ByVal where As String) As EmployeesRecord()

        Return GetRecords(where, Nothing, BaseTable.MIN_PAGE_NUMBER, BaseTable.MAX_BATCH_SIZE)
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get an array of EmployeesRecord records using a where and order by clause.
    ''' </summary>
    Public Shared Function GetRecords( _
     ByVal where As String, _
     ByVal orderBy As OrderBy) As EmployeesRecord()

        Return GetRecords(where, orderBy, BaseTable.MIN_PAGE_NUMBER, BaseTable.MAX_BATCH_SIZE)
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get an array of EmployeesRecord records using a where and order by clause clause with pagination.
    ''' </summary>
    Public Shared Function GetRecords( _
     ByVal where As String, _
     ByVal orderBy As OrderBy, _
     ByVal pageIndex As Integer, _
     ByVal pageSize As Integer) As EmployeesRecord()
        
        Dim whereFilter As SqlFilter =  Nothing
        If Not where Is Nothing AndAlso where.trim() <> "" Then
            whereFilter =  New SqlFilter(where)
        End If
         
        Dim recList As ArrayList =  EmployeesTable.Instance.GetRecordList(whereFilter, orderBy, pageIndex, pageSize)
 
        Return CType(recList.ToArray(GetType(UseDAL.Business.EmployeesRecord)), EmployeesRecord())
    End Function

    Public Shared Function GetRecords( _
     ByVal where As WhereClause, _
     ByVal orderBy As OrderBy, _
     ByVal pageIndex As Integer, _
     ByVal pageSize As Integer) As EmployeesRecord()

        Dim recList As ArrayList = EmployeesTable.Instance.GetRecordList(where.GetFilter(), orderBy, pageIndex, pageSize)

        Return CType(recList.ToArray(GetType(UseDAL.Business.EmployeesRecord)), EmployeesRecord())
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get total number of records that will be returned using the where clause.
    ''' </summary>
    Public Shared Function GetRecordCount(ByVal where As String) As Integer

        Dim whereFilter As SqlFilter = Nothing
        If Not where Is Nothing AndAlso where.Trim() <> "" Then
            whereFilter = New SqlFilter(where)
        End If

        Return CInt(EmployeesTable.Instance.GetRecordListCount(whereFilter, Nothing))
    End Function

    Public Shared Function GetRecordCount(ByVal where As WhereClause) As Integer
        Return CInt(EmployeesTable.Instance.GetRecordListCount(where.GetFilter(), Nothing))
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get a EmployeesRecord record using a where clause.
    ''' </summary>
    Public Shared Function GetRecord(ByVal where As String) As EmployeesRecord
        Dim orderBy As OrderBy = Nothing
        Return GetRecord(where, orderBy)
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get a EmployeesRecord record using a where and order by clause.
    ''' </summary>
    Public Shared Function GetRecord( _
     ByVal where As String, _
     ByVal orderBy As OrderBy) As EmployeesRecord

        Dim whereFilter As SqlFilter = Nothing
        If Not where Is Nothing AndAlso where.Trim() <> "" Then
            whereFilter = New SqlFilter(where)
        End If

        Dim recList As ArrayList = EmployeesTable.Instance.GetRecordList(whereFilter, orderBy, BaseTable.MIN_PAGE_NUMBER, BaseTable.MIN_BATCH_SIZE)

        Dim rec As EmployeesRecord = Nothing
        If recList.Count > 0 Then
            rec = CType(recList(0), EmployeesRecord)
        End If

        Return rec
    End Function

    Public Shared Function GetValues( _
        ByVal col As BaseColumn, _
         ByVal where As WhereClause, _
         ByVal orderBy As OrderBy, _
         ByVal maxItems As Integer) As String()

        ' Create the filter list.
        Dim retCol As SqlBuilderColumnSelection = New SqlBuilderColumnSelection(False, True)
        retCol.AddColumn(col)

        Return EmployeesTable.Instance.GetColumnValues(retCol, where.GetFilter(), orderBy, BaseTable.MIN_PAGE_NUMBER, maxItems)

    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get a DataTable to bound with a data bound control using a where clause.
    ''' </summary>
    Public Shared Function GetDataTable(ByVal where As String) As System.Data.DataTable

        Dim recs() As EmployeesRecord = GetRecords(where)
        Return EmployeesTable.Instance.CreateDataTable(recs, Nothing)
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get a DataTable to bound with a data bound control using a where and order by clause.
    ''' </summary>
    Public Shared Function GetDataTable(ByVal where As String, ByVal orderBy As OrderBy) As System.Data.DataTable

        Dim recs() As EmployeesRecord = GetRecords(where, orderBy)
        Return EmployeesTable.Instance.CreateDataTable(recs, Nothing)
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to get a DataTable to bound with a data bound control using a where and order by clause with pagination.
    ''' </summary>
    Public Shared Function GetDataTable( _
     ByVal where As String, _
     ByVal orderBy As OrderBy, _
     ByVal pageIndex As Integer, _
     ByVal pageSize As Integer) As System.Data.DataTable

        Dim recs() As EmployeesRecord = GetRecords(where, orderBy, pageIndex, pageSize)
        Return EmployeesTable.Instance.CreateDataTable(recs, Nothing)
    End Function

    ''' <summary>
    ''' This is a shared function that can be used to delete records using a where clause.
    ''' </summary>
    Public Shared Sub DeleteRecords(ByVal where As String)
        If where = Nothing OrElse where.Trim() = "" Then
            Return
        End If

        Dim whereFilter As SqlFilter = New SqlFilter(where)
        EmployeesTable.Instance.DeleteRecordList(whereFilter)
    End Sub

    ''' <summary>
    ''' This is a shared function that can be used to export records using a where clause.
    ''' </summary>
    Public Shared Function Export(ByVal where As String) As String
        Dim whereFilter As SqlFilter = Nothing
        If Not where Is Nothing AndAlso where.Trim() <> "" Then
            whereFilter = New SqlFilter(where)
        End If

        Return EmployeesTable.Instance.ExportRecordData(whereFilter)
    End Function

    Public Shared Function Export(ByVal where As WhereClause) As String
        Dim whereFilter As BaseFilter = Nothing
        If Not where Is Nothing Then
            whereFilter = where.GetFilter()
        End If

        Return EmployeesTable.Instance.ExportRecordData(whereFilter)
    End Function

    Public Shared Function GetSum( _
        ByVal col As BaseColumn, _
        ByVal where As WhereClause, _
        ByVal orderBy As OrderBy, _
        ByVal pageIndex As Integer, _
        ByVal pageSize As Integer) _
        As String

        Dim colSel As SqlBuilderColumnSelection = New SqlBuilderColumnSelection(False, False)
        colSel.AddColumn(col, SqlBuilderColumnOperation.OperationType.Sum)

        Return EmployeesTable.Instance.GetColumnStatistics(colSel, where.GetFilter(), orderBy, pageIndex, pageSize)

    End Function
    
    Public Shared Function GetCount( _
        ByVal col As BaseColumn, _
        ByVal where As WhereClause, _
        ByVal orderBy As OrderBy, _
        ByVal pageIndex As Integer, _
        ByVal pageSize As Integer) _
        As String

        Dim colSel As SqlBuilderColumnSelection = New SqlBuilderColumnSelection(False, False)
        colSel.AddColumn(col, SqlBuilderColumnOperation.OperationType.Count)

        Return EmployeesTable.Instance.GetColumnStatistics(colSel, where.GetFilter(), orderBy, pageIndex, pageSize)

    End Function

    ''' <summary>
    '''  This method returns the columns in the table.
    ''' </summary>
    Public Shared Function GetColumns() As BaseColumn()
        Return EmployeesTable.Instance.TableDefinition.Columns
    End Function

    ''' <summary>
    '''  This method returns the columnlist in the table.
    ''' </summary>  
    Public Shared Function GetColumnList() As ColumnList
        Return EmployeesTable.Instance.TableDefinition.ColumnList
    End Function


    ''' <summary>
    ''' This method creates a new record and returns it to be edited.
    ''' </summary>
    Public Shared Function CreateNewRecord() As IRecord
        Return EmployeesTable.Instance.CreateRecord()
    End Function

    ''' <summary>
    ''' This method creates a new record and returns it to be edited.
    ''' </summary>
    ''' <param name="tempId">ID of the new record.</param>  
    Public Shared Function CreateNewRecord(ByVal tempId As String) As IRecord
        Return EmployeesTable.Instance.CreateRecord(tempId)
    End Function

    ''' <summary>
    ''' This method checks if column is editable.
    ''' </summary>
    ''' <param name="columnName">Name of the column to check.</param>
    Public Shared Function isReadOnlyColumn(ByVal columnName As String) As Boolean
        Dim column As BaseColumn = GetColumn(columnName)
        If (Not IsNothing(column)) Then
            Return column.IsValuesReadOnly
        Else
            Return True
        End If
    End Function

    ''' <summary>
    ''' This method gets the specified column.
    ''' </summary>
    ''' <param name="uniqueColumnName">Unique name of the column to fetch.</param>
    Public Shared Function GetColumn(ByVal uniqueColumnName As String) As BaseColumn
        Dim column As BaseColumn = EmployeesTable.Instance.TableDefinition.ColumnList.GetByUniqueName(uniqueColumnName)
        Return column
    End Function     

    ' Convenience method for getting a record using a string-based record identifier
    Public Shared Function GetRecord(ByVal id As String, ByVal bMutable As Boolean) As EmployeesRecord
        Return CType(EmployeesTable.Instance.GetRecordData(id, bMutable), EmployeesRecord)
    End Function

    ' Convenience method for getting a record using a KeyValue record identifier
    Public Shared Function GetRecord(ByVal id As KeyValue, ByVal bMutable As Boolean) As EmployeesRecord
        Return CType(EmployeesTable.Instance.GetRecordData(id, bMutable), EmployeesRecord)
    End Function

    ' Convenience method for creating a record
    Public Overloads Function NewRecord( _
        ByVal LastNameValue As String, _
        ByVal FirstNameValue As String, _
        ByVal TitleValue As String, _
        ByVal TitleOfCourtesyValue As String, _
        ByVal BirthDateValue As String, _
        ByVal HireDateValue As String, _
        ByVal AddressValue As String, _
        ByVal CityValue As String, _
        ByVal RegionValue As String, _
        ByVal PostalCodeValue As String, _
        ByVal CountryValue As String, _
        ByVal HomePhoneValue As String, _
        ByVal ExtensionValue As String, _
        ByVal PhotoValue As String, _
        ByVal NotesValue As String, _
        ByVal ReportsToValue As String, _
        ByVal CreatedOnValue As String, _
        ByVal CreatedByValue As String, _
        ByVal LastUpdatedOnValue As String, _
        ByVal LastUpdatedByValue As String _
    ) As KeyValue
        Dim rec As IPrimaryKeyRecord = CType(Me.CreateRecord(), IPrimaryKeyRecord)
                rec.SetString(LastNameValue, LastNameColumn)
        rec.SetString(FirstNameValue, FirstNameColumn)
        rec.SetString(TitleValue, TitleColumn)
        rec.SetString(TitleOfCourtesyValue, TitleOfCourtesyColumn)
        rec.SetString(BirthDateValue, BirthDateColumn)
        rec.SetString(HireDateValue, HireDateColumn)
        rec.SetString(AddressValue, AddressColumn)
        rec.SetString(CityValue, CityColumn)
        rec.SetString(RegionValue, RegionColumn)
        rec.SetString(PostalCodeValue, PostalCodeColumn)
        rec.SetString(CountryValue, CountryColumn)
        rec.SetString(HomePhoneValue, HomePhoneColumn)
        rec.SetString(ExtensionValue, ExtensionColumn)
        rec.SetString(PhotoValue, PhotoColumn)
        rec.SetString(NotesValue, NotesColumn)
        rec.SetString(ReportsToValue, ReportsToColumn)
        rec.SetString(CreatedOnValue, CreatedOnColumn)
        rec.SetString(CreatedByValue, CreatedByColumn)
        rec.SetString(LastUpdatedOnValue, LastUpdatedOnColumn)
        rec.SetString(LastUpdatedByValue, LastUpdatedByColumn)


        rec.Create() 'update the DB so any DB-initialized fields (like autoincrement IDs) can be initialized

        Dim key As KeyValue = rec.GetID()
        Return key
    End Function

    ''' <summary>
    '''  This method deletes a specified record
    ''' </summary>
    ''' <param name="kv">Keyvalue of the record to be deleted.</param>
    Public Shared Sub DeleteRecord(ByVal kv As KeyValue)
        EmployeesTable.Instance.DeleteOneRecord(kv)
    End Sub

    ''' <summary>
    ''' This method checks if record exist in the database using the keyvalue provided.
    ''' </summary>
    ''' <param name="kv">Key value of the record.</param>
    Public Shared Function DoesRecordExist(ByVal kv As KeyValue) As Boolean
        Dim recordExist As Boolean = True
        Try
            EmployeesTable.GetRecord(kv, False)
        Catch ex As Exception
            recordExist = False
        End Try
        Return recordExist
    End Function
    
    ''' <summary>
    '''  This method returns all the primary columns in the table.
    ''' </summary>
    Public Shared Function GetPrimaryKeyColumns() As ColumnList
        If (Not IsNothing(EmployeesTable.Instance.TableDefinition.PrimaryKey)) Then
            Return EmployeesTable.Instance.TableDefinition.PrimaryKey.Columns
        Else
            Return Nothing
        End If
    End Function

    ''' <summary>
    ''' This method takes a key and returns a keyvalue.
    ''' </summary>
    ''' <param name="key">key could be array of primary key values in case of composite primary key or a string containing single primary key value in case of non-composite primary key.</param>
    Public Shared Function GetKeyValue(ByVal key As Object) As KeyValue
        Dim kv As KeyValue = Nothing

        If (Not (IsNothing(EmployeesTable.Instance.TableDefinition.PrimaryKey))) Then

            Dim isCompositePrimaryKey As Boolean = False
            isCompositePrimaryKey = EmployeesTable.Instance.TableDefinition.PrimaryKey.IsCompositeKey

            If ((isCompositePrimaryKey) AndAlso (key.GetType.IsArray())) Then

                ' If the key is composite, then construct a key value.
                kv = New KeyValue
                Dim fullKeyString As String = ""
                Dim keyArray As Array = CType(key, Array)
                If (Not IsNothing(keyArray)) Then
                    Dim length As Integer = keyArray.Length
                    Dim pkColumns As ColumnList = EmployeesTable.Instance.TableDefinition.PrimaryKey.Columns
                    Dim pkColumn As BaseColumn
                    Dim index As Integer = 0
                    For Each pkColumn In pkColumns
                        Dim keyString As String = CType(keyArray.GetValue(index), String)
                        If (EmployeesTable.Instance.TableDefinition.TableType = BaseClasses.Data.TableDefinition.TableTypes.Virtual) Then
                            kv.AddElement(pkColumn.UniqueName, keyString)
                        Else
                            kv.AddElement(pkColumn.InternalName, keyString)
                        End If
                        index = index + 1
                    Next pkColumn
                End If

            Else
                ' If the key is not composite, then get the key value.
                kv = EmployeesTable.Instance.TableDefinition.PrimaryKey.ParseValue(CType(key, String))
            End If
        End If
        Return kv
    End Function    


#End Region 

End Class
End Namespace
