![]() ![]() ![]() ![]() Gravitybox Schedule Primer
Page 60
1998-2004 Gravitybox Software LLC
Dim oAppt As CScheduleEl
Set Db = New ADODB.Connection
Db.ConnectionString = GetConnectString & AppPath & _
"schedule.mdb"
Call Db.Open
sSql = "delete from tbl_Schedule where StartDate & _
= #1/1/2002#"
Call Db.Execute(sSql)
For Each oAppt In Schedule1.ScheduleItems
If Schedule1.Categories.Exists(oAppt.Category) Then
lCategoryId = Schedule1.Categories(oAppt.Category).Id
Else
lCategoryId = 0
End If
sSql = "insert into tbl_Schedule (StartDate, " & _
"StartTime , Length, Description, RoomId, " & _
"CategoryId) values (" & _
"#1/1/2002#," & _
"#" & oAppt.StartTime & "#," & _
oAppt.Length & "," & _
"'" & oAppt.DisplayText & "'," & _
Schedule1.Rooms(oAppt.Room).Id & "," & _
lCategoryId & ")"
Call Db.Execute(sSql)
Next
Changed = False
End Sub
This example illustrates the reason we remove all appointments and resave
them. There are other schemes of course, some of which may be quite complicated.
You could, for example, store the appointments database key in the ScheduleItems Id
property. Then on save the source dates schedule, you could update the appointment
by adding this Id to a SQL where clause, to uniquely identify the appointment.
However you must also loop and create a delete query to remove all appointments that
are not now in the set of appointments for a particular date. Does that sound
complicated? It is a bit and depending on the database and number of appointments
could be quite time consuming as well. I have chosen the quick and dirty approach. You
may feel free to construct arbitrarily, complex algorithms that accomplish the same thing
as I have done here with minimal code.
|