Navigation bar
  Home Print document Start Previous page
 65 of 234 
Next page End  

Gravitybox Schedule Primer
Page 63 
1998-2004 Gravitybox Software LLC
  Next i
End Sub
The “SaveForm” method will save the configuration the user has specified. It
loops through the Rooms collection, to determine if the room has a database entry. If it
does its “Id” property is non-zero. On load from the database, each room has its unique
non-zero number stored in its “Id” property. If the room was added in this session of the
configuration, it has not been saved to the database yet. If there is no database record
then one must be created. It there is a record then the record must be updated. After
the save have been performed, we loop through the deleted array and remove all of
these room entries from the database.
Private Sub SaveForm()
Dim i As Integer
Dim NewEl As CItemEl
Dim Db As ADODB.Connection
Dim sSql As String
Dim oRoom As CRoomEl
  Set Db = New ADODB.Connection
  Db.ConnectionString = GetConnectString & _
            AppPath & "schedule.mdb"
  Call Db.Open
  
  For Each oRoom In Rooms
    If oRoom.Id = 0 Then
      sSql = "insert into [Room] (Name, SortOrder) " & _
             "values ('" & DoubleChar(oRoom.Name, "'") & _
             "', " & i & ")"
    Else
      sSql = "update [Room] set Name ='" & _
             DoubleChar(oRoom.Name, "'") & _
             "', SortOrder=" & i & _
             " where RoomId = " & oRoom.Id
    End If
    
    Call Db.Execute(sSql)
  
  Next i
  
  'Delete all the one we removed in this session
  For i = 0 To UBound(arrDeleted) - 1
    sSql = "delete from [Room] " & _
           "where RoomId = " & arrDeleted(i)
    Call Db.Execute(sSql)
http://www.purepage.com