CalendarResources Example... |
Post Reply |
Author | |
karthiksp
Groupie Joined: 09 May 2007 Location: United States Status: Offline Points: 30 |
Post Options
Thanks(0)
Posted: 28 June 2007 at 12:05pm |
Could someone please give me example of CalendarResources to user 2 datasources at the same time.
Any help or hint is greatly apprciated
Thanks
Karthik
|
|
Stilki
Groupie Joined: 27 May 2005 Status: Offline Points: 70 |
Post Options
Thanks(0)
|
Can you explain what you mean by 2 datasources?
Are you refering to 2 users calendar entries displayed in the one CalendarControl?
|
|
karthiksp
Groupie Joined: 09 May 2007 Location: United States Status: Offline Points: 30 |
Post Options
Thanks(0)
|
I am using one calendar. But I need to use 2 data sources.
One from XML File
and another from Outlook DAT file display in the same calendar.
I really need to know the CalendarResourcesManager Object model in order to acces its attributes.
Thanks
Karthik
|
|
Stilki
Groupie Joined: 27 May 2005 Status: Offline Points: 70 |
Post Options
Thanks(0)
|
Here is a sample of how you can display entries from 2 data sources (2 access databases). The principals will be the same if one is and XML data source and an OUTLOOK datasource.
I have attached the modified Calendar sample so you can see it working.
I am using v11.1.3
If you run the project, goto menu option
FILE|LOAD MULTISCHEDULES (SIMPLE)
choose 5 day week view and look at events for 2nd and 3rd July 2007
'-------------------------------------------------------------------------------------------- Private Sub mnuMultiSchedulesSimple_Click()
Dim arResources As New CalendarResources
Dim pRes0 As New CalendarResource Dim pRes1 As New CalendarResource Dim pSchedules As CalendarSchedules
Dim bResult As Boolean '// ** data provider
Dim strConnectionString As String '------------------------------------------------------------------------------------ '// FIRST DATA SOURCE (Events1.mdb) '------------------------------------------------------------------------------------ strConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & App.Path & "\Events1.mdb" & ";" & _ "Jet OLEDB:Encrypt Database=True;" bResult = g_DataResourcesMan.AddDataProvider( _ strConnectionString, xtpCalendarDPF_CreateIfNotExists + _ xtpCalendarDPF_SaveOnDestroy + xtpCalendarDPF_CloseOnDestroy) pRes0.SetDataProvider g_DataResourcesMan.DataProvider(0), True If pRes0.DataProvider Is Nothing Then Debug.Assert False Exit Sub End If If Not pRes0.DataProvider.Open Then If Not pRes0.DataProvider.Create Then Debug.Assert False Exit Sub End If End If '------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------ '// SECOND DATA SOURCE (Events2.mdb) '------------------------------------------------------------------------------------ strConnectionString = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & App.Path & "\Events2.mdb" & ";" & _ "Jet OLEDB:Encrypt Database=True;" bResult = g_DataResourcesMan.AddDataProvider( _ strConnectionString, xtpCalendarDPF_CreateIfNotExists + _ xtpCalendarDPF_SaveOnDestroy + xtpCalendarDPF_CloseOnDestroy) pRes1.SetDataProvider g_DataResourcesMan.DataProvider(1), True If pRes1.DataProvider Is Nothing Then Debug.Assert False Exit Sub End If If Not pRes1.DataProvider.Open Then If Not pRes1.DataProvider.Create Then Debug.Assert False Exit Sub End If End If '------------------------------------------------------------------------------------ '// ** schedules '// ** resources '------------------------------------------------------------------------------------ '// FIRST DATA SOURCE '------------------------------------------------------------------------------------ Set pSchedules = pRes0.DataProvider.Schedules pRes0.Name = pSchedules.Item(0).Name pRes0.ScheduleIDs.Add pSchedules.Item(0).Id '------------------------------------------------------------------------------------ '------------------------------------------------------------------------------------ '// SECOND DATA SOURCE '------------------------------------------------------------------------------------ Set pSchedules = pRes1.DataProvider.Schedules pRes1.Name = pSchedules.Item(0).Name pRes1.ScheduleIDs.Add pSchedules.Item(0).Id '------------------------------------------------------------------------------------ '------------------------------------------------------------------ 'When you are adding an event 'You need to use ' g_DataResourcesMan.DataProvider(0 or 1).AddEvent 'instead of 'frmMain.CalendarControl.DataProvider.AddEvent m_pEditingEvent '------------------------------------------------------------------ arResources.Add pRes0 arResources.Add pRes1 g_DataResourcesMan.ApplyToCalendar CalendarControl CalendarControl.SetMultipleResources arResources CalendarControl.Populate CalendarControl.RedrawControl End Sub
'--------------------------------------------------------------------------------------------
|
|
karthiksp
Groupie Joined: 09 May 2007 Location: United States Status: Offline Points: 30 |
Post Options
Thanks(0)
|
Hi Stilki,
Thanks for the example that you posted. It was really helpful in understanding the concept for 2 data sources.
My Quick question is I would like to know the Object model for CalendarResourcesManager Object in order to access its properties and methods.
Could you please help me in that.
Thanks
Karthik
|
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
-- WBR, Serge |
|
vbuser
Newbie Joined: 22 January 2004 Status: Offline Points: 39 |
Post Options
Thanks(0)
|
How can this code be modified to allow for MULTIPLE NAME RESOURCES, basically the
FILE|LOAD MULTISCHEDULES (EXTENDED), but using an ACCESS Database... I cannot get it to work... What am I missing? Thank you.
|
|
Stilki
Groupie Joined: 27 May 2005 Status: Offline Points: 70 |
Post Options
Thanks(0)
|
Hello vbUser,
Below is a snippet on how to display multischedules from one database.
I have also attached the modified sample calendar control project. This project uses v11.1.3.
Goto the procedure 'mnuMultiSchedulesExtended_Click' and you will see the code below in action.
In the access database, there is a table called Schedules, this is linked to the scheduleID field in the events database. The sample below is using each schedule as a user and each user as a resource.
If you load the sample attached, start the project;
Select the menu option, FILE|LOAD MULTISCHEDULES (EXTENDED)
change your view to 5 day view
Select the dates 2nd and 3rd July 2007 to see some calendar entries for User 1 and User 2 (these are the names of the schedules in the schedules table).
Have fun and hope this helps you
Private Sub mnuMultiSchedulesExtended_Click()
Dim arResources As New CalendarResources
Dim pRes() As CalendarResource Dim objSchedule As CalendarSchedule Dim strConnectionString As String Dim i As Long Dim j As Long strConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & App.Path & "\Events1.mdb" & ";" & _ "Jet OLEDB:Encrypt Database=True;" CalendarControl.SetDataProvider strConnectionString If Not CalendarControl.DataProvider.Open Then CalendarControl.DataProvider.Create End If j = CalendarControl.DataProvider.Schedules.Count - 1
For i = 0 To j ReDim Preserve pRes(i) Set pRes(i) = New CalendarResource If i = 0 Then 'Use the first connection string for the first datasource pRes(i).SetDataProvider2 strConnectionString, True Else 'add the first resources datasource object to any subsequent schedule in the database pRes(i).SetDataProvider pRes(0).DataProvider, False End If 'Open the datasource If pRes(i).DataProvider.Open Then 'get a list of the schedules Set objSchedule = CalendarControl.DataProvider.Schedules(i) 'add the schedule to the resource pRes(i).Name = objSchedule.Name pRes(i).ScheduleIDs.Add objSchedule.Id 'add resource to resource array arResources.Add pRes(i) End If Next i 'add resource array to calendarcontrol CalendarControl.SetMultipleResources arResources CalendarControl.Populate CalendarControl.RedrawControl Set arResources = Nothing Set objSchedule = Nothing If IsArray(pRes) Then Erase pRes End If End Sub
|
|
vbuser
Newbie Joined: 22 January 2004 Status: Offline Points: 39 |
Post Options
Thanks(0)
|
GREAT JOB !!! Thank you for the quick responce!!! |
|
vbuser
Newbie Joined: 22 January 2004 Status: Offline Points: 39 |
Post Options
Thanks(0)
|
I am adapting this to an existing application that ALREADY has a list of Names I need to use INSTEAD of the built in object. 'get a list of the schedules
Set objSchedule = CalendarControl.DataProvider.Schedules(i) 'add the schedule to the resource pRes(i).Name = objSchedule.Name pRes(i).ScheduleIDs.Add objSchedule.Id What is the best way to import this list & IDS form another table other than Schedules table?
|
|
Stilki
Groupie Joined: 27 May 2005 Status: Offline Points: 70 |
Post Options
Thanks(0)
|
You can manage your own list from another table if you like;
Foe example...
'get a list of the users
Set recordset = database.openrecordset("MyTable") while not recordset.eof
'previous code ......... Create new calendar resource object
.........assign dataprovider
.........Open dataprovider
'add the users from the table
pRes(i).Name = recordset!FirstName pRes(i).ScheduleIDs.Add recordset!UserId recordset.movenext wend
OR
It is better to use the schedules object for the Calendar control.
The schedules table is small so I would duplicate your users table and programmatically maintain both tables. If you add a new user also add it to the schedules table, if you modify or delete from the users table do it to the schedules table as well. This way you are letting the Calendar control behave as it was intended (designed) to by allowing the calendar control to use the tables it is expecting. Note: I prefer this method because if the design of the Calendar control changes in how/what it is reading from you can adapt it to easier.
You may also want to check out how to use the Calendar control with a custom data provider, this way you control the reading and writing to the database as well as being able to extend or modify each property of an event of the events table; for example I have added couple of extra fields in the events table that the calendar control reads from and writes to.
|
|
visualise01
Newbie Joined: 20 September 2009 Location: United Kingdom Status: Offline Points: 7 |
Post Options
Thanks(0)
|
anything for this in vb .net?
|
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
What is special in VB.NET case?
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |