VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDatabase"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'---------------------------------------------------------------------------------------
' Module    : clsDatabase
' Date      : 7/16/2004
' Author    : LoRd[nK] (thevirushunter@hotmail.com)
' Purpose   : Class for dealing with Microsoft Access Database (DAO: Data Access Objects) functions
'---------------------------------------------------------------------------------------

Option Explicit

Private dbDB As Database
Private rsRS As Recordset

Private strDBPath As String

Public Function LoadDB() As Boolean
On Error GoTo ERROR_HANDLER

Set dbDB = OpenDatabase(strDBPath)
Set rsRS = dbDB.OpenRecordset("Users", dbOpenDynaset)

LoadDB = True

Exit Function

ERROR_HANDLER:
    LoadDB = False
    Exit Function
End Function
Public Function UnloadDB() As Boolean
On Error GoTo ERROR_HANDLER

rsRS.Close
dbDB.Close

UnloadDB = True

Exit Function

ERROR_HANDLER:
    UnloadDB = False
    Exit Function
End Function
Public Function CreateDB() As Boolean
On Error GoTo ERROR_HANDLER

Dim tdfTDF As New TableDef
Dim flFL As New Field

Set dbDB = CreateDatabase(strDBPath, dbLangGeneral, dbOpenDynaset)

'Groups:
Set tdfTDF = dbDB.CreateTableDef("Groups")

Set flFL = tdfTDF.CreateField("Group", dbText)
tdfTDF.Fields.Append flFL
Set flFL = tdfTDF.CreateField("Flags", dbLong)
tdfTDF.Fields.Append flFL
Set flFL = tdfTDF.CreateField("Additional Information", dbText)
tdfTDF.Fields.Append flFL

dbDB.TableDefs.Append tdfTDF

'Users:
Set tdfTDF = dbDB.CreateTableDef("Users")

Set flFL = tdfTDF.CreateField("User", dbText)
tdfTDF.Fields.Append flFL
Set flFL = tdfTDF.CreateField("Flags", dbLong)
tdfTDF.Fields.Append flFL
Set flFL = tdfTDF.CreateField("Additional Information", dbText)
tdfTDF.Fields.Append flFL

dbDB.TableDefs.Append tdfTDF

'Unload:
rsRS.Close
dbDB.Close

CreateDB = True

Exit Function

ERROR_HANDLER:
    CreateDB = False
    Exit Function
End Function

Public Function AddUser(ByVal strUser As String, ByVal lngFlags As Long) As Boolean
On Error GoTo ERROR_HANDLER

With rsRS
    .FindFirst "User = '" & strUser & "'"
    If .NoMatch = True Then
        .AddNew
        !User = strUser
    Else
        .Edit
        !User = strUser
    End If
    !flags = lngFlags
    .Update
End With

AddUser = True

Exit Function

ERROR_HANDLER:
    AddUser = False
    Exit Function
End Function
Public Function RemoveUser(ByVal strUser As String) As Boolean
On Error GoTo ERROR_HANDLER

With rsRS
    .FindFirst "User = '" & strUser & "'"
    If .NoMatch = True Then
        RemoveUser = False
        Exit Function
    Else
        .Delete
        .Update
    End If
End With

RemoveUser = False

Exit Function

ERROR_HANDLER:
    AddUser = False
    Exit Function
End Function

Public Property Let Path(ByVal strPath As String)
strDBPath = strPath
End Property
Public Property Get Path() As String
Path = strDBPath
End Property

Public Property Get RecordCount() As Long
RecordCount = rsRS.RecordCount
End Property
