VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 1  'vbDataSource
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CReservation"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private cnReservation As ADODB.Connection
Public rsReservation As ADODB.Recordset
Attribute rsReservation.VB_VarHelpID = -1
'To fire this event, use RaiseEvent with the following syntax:
'RaiseEvent ResError[(arg1, arg2, ... , argn)]
Public Event ResError(ByVal Number As Long, ByVal Description As String)
Private Function MoveToArchive() As Boolean
    Dim rsArchive As ADODB.Recordset
    Set rsArchive = New ADODB.Recordset
    
    On Error GoTo HandleError
    rsArchive.Open "ReservationArchive", cnReservation, adOpenDynamic, adLockPessimistic
    rsArchive.AddNew
    With rsArchive
        ![FirstName] = rsReservation![FirstName]
        ![Lastname] = rsReservation![Lastname]
        ![Address] = rsReservation![Address]
        ![Phone] = rsReservation![Phone]
        ![PaymentType] = rsReservation![PaymentType]
        ![NumberOfPeople] = rsReservation![NumberOfPeople]
        ![Status] = rsReservation![Status]
        ![RoomNumber] = rsReservation![RoomNumber]
        ![Rate] = rsReservation![Rate]
        ![NumberOfDays] = rsReservation![NumberOfDays]
        ![CheckInDate] = rsReservation![CheckInDate]
        .Update
    End With
    rsReservation.Delete adAffectCurrent
    MoveToArchive = True
    Exit Function
HandleError:
    MoveToArchive = False
End Function

Public Function CancelReservation() As Boolean
    rsReservation![Status] = "CANCELED"
    If MoveToArchive Then
        CancelReservation = True
        rsReservation.MoveFirst
    Else
        CancelReservation = False
    End If
End Function

Public Function CheckOut() As Boolean
    'Check the status to make sure the guest is checked in
    If rsReservation![Status] = "ACTIVE" Then
        rsReservation![Status] = "INACTIVE"
        If MoveToArchive Then
            CheckOut = True
            rsReservation.MoveFirst
        End If
    Else
        MsgBox "Could not check-out INACTIVE guest."
        CheckOut = False
    End If
End Function

Public Function CheckIn() As Boolean
    'Check the status to make sure it is pending
    If rsReservation![Status] = "PENDING" Then
        rsReservation![Status] = "ACTIVE"
        rsReservation![CheckInDate] = Format(Date, "mm-dd-yyyy")
        rsReservation.Update
        CheckIn = True
    Else
        CheckIn = False
    End If
End Function

Public Function AddReservation() As Boolean
    rsReservation.AddNew
    rsReservation![Status] = "PENDING"
    AddReservation = True
End Function

Private Sub Class_GetDataMember(DataMember As String, Data As Object)
    Set Data = rsReservation
End Sub

Private Sub Class_Initialize()
    Dim SQL As String
    
    SQL = "SELECT * FROM Reservation;"
    
    'create and open the connection
    Set cnReservation = New ADODB.Connection
    cnReservation.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
        "Data Source=C:\Labs\Rsvn.mdb"
    cnReservation.Open
    
    Set rsReservation = New ADODB.Recordset
    'create and open the recordset
    rsReservation.Open SQL, cnReservation, adOpenDynamic, adLockPessimistic
    
End Sub
