![]() ![]() ![]() ![]() Gravitybox Schedule Primer
Page 59
1998-2004 Gravitybox Software LLC
Call Me.Schedule1.Categories.Clear
While Not rs.EOF
Set objCategory = Me.Schedule1.Categories.Add(rs!Name,
rs!Color)
objCategory.Id = rs!CategoryId
Call rs.MoveNext
Wend
Set Db = Nothing
Set rs = Nothing
End Sub
Saving Appointments
Now that we have addressed loading, we need to think about how to get all of that
information into the database in the first place. The saving routines should not be very
difficult to understand after viewing the loading routines. The save method will remove
the appointments for the specified date and save the ones on the schedule as that
dates new appointments.
This is not a perfect scheme. Some will disagree with removing appointments that have
not changed only to read them. This is a valid point but the code was written this way for
a few reasons. First this is an example of how to save to a database, not a tutorial on
algorithm perfection. This said, I agree that examples should teach the correct way to
build code and this is a perfectly valid way to build it. There is a more important reason
that we are removing all appointments first; appointment moves. Posit, in an MDI
environment, the user may open multiple dates. This database example application
opens one window for each day. If the user opens two (or more) days and moves an
appointment from one day to the other, there is a problem at save time. If you choose to
merely loop through the appointments and save those appointments that have their
IsDirty property set to true, you will add an extra appointment each time you move
across windows. This is because the source schedule will lose an appointment and
since no appointments on the schedule have changed, you save nothing. The
destination schedule has one new appointment, so you save it. Now think about it, the
source date still has the moved appointment in the database. Now you save the same
appointment with the destination date. You have one more appointment than the
number with which you started. You may use the appointments UniqueKey property to
overcome this limitation, but this is beyond the current scope.
Public Sub SaveSchedule()
'This procedure saves a schedule to the database
Dim Db As ADODB.Connection
Dim sSql As String
Dim lCategoryId As Long
|