I am using a SQL Server database as a back-end for my Planner.NET calendar. The database has separate tables for Items, Recurrences, and Exceptions; all Items are (currently) Appointment objects. In the calendar, when a user makes a change to an appointment, I need to make the corresponding change in the database. To do this, I need to know the RecurrenceState property of the item so I can post the change to the appropriate table (Items, Recurrences, or Exceptions). For one-time items (i.e., those with RecurrenceState = None), this is easy. The problem I have is with recurring items. For example, take the Calendar's ItemInplaceEdited() event. After the user edits an item, its RecurrenceState will be RecurrenceState.Exception. However, before the user made changes, its RecurrenceState could have been either RecurrenceState.Occurence or RecurrenceState.Exception. If the former, I need to add a new exception to the Exceptions table; if the latter I just need to edit the existing Exception record in the table.
So I need some way to determine the ORIGINAL state of the recurring item before the edit, right? I have an idea how to do this and I just want to verify it is a viable solution. I am using the ItemSelecting() handler of the calendar to set a class-level variable, like the following: Dim mOrigRecurrenceState As MindFusion.Scheduling.RecurrenceState Private Sub calendar_ItemSelecting(...) Handles calendar.ItemSelecting mOrigRecurrenceState = e.Item.RecurrenceState End Sub
Then, after the user edits the item, I have code in the ItemInPlaceEdited() handler like this:
Private Sub calendar_ItemInplaceEdited(...) Handles calendar.ItemInplaceEdited If Not e.Item.RecurrenceState = RecurrenceState.None Then
If mOrigRecurrenceState = RecurrenceState.Exception Then ' Original RecurrenceState = Exception, ' Put code here to UPDATE existing exception Else ' Original RecurrenceState = Occurrence, ' Put code here to ADD new exception End If Else ' Original RecurrenceState = None, ' Put code here to edit one-time item End If
mbItemSelected = False End Sub
Does this sound like a good way to go, or do you suggest something else?
|