Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Calendar
  New Posts New Posts RSS Feed - CalendarResources Example...
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CalendarResources Example...

 Post Reply Post Reply
Author
Message
karthiksp View Drop Down
Groupie
Groupie


Joined: 09 May 2007
Location: United States
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote karthiksp Quote  Post ReplyReply Direct Link To This Post Topic: CalendarResources Example...
    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
Back to Top
Stilki View Drop Down
Groupie
Groupie


Joined: 27 May 2005
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Stilki Quote  Post ReplyReply Direct Link To This Post Posted: 30 June 2007 at 3:06pm
Can you explain what you mean by 2 datasources?
Are you refering to 2 users calendar entries displayed in the one CalendarControl?
Back to Top
karthiksp View Drop Down
Groupie
Groupie


Joined: 09 May 2007
Location: United States
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote karthiksp Quote  Post ReplyReply Direct Link To This Post Posted: 30 June 2007 at 5:15pm
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
Back to Top
Stilki View Drop Down
Groupie
Groupie


Joined: 27 May 2005
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Stilki Quote  Post ReplyReply Direct Link To This Post Posted: 01 July 2007 at 1:18am
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
'--------------------------------------------------------------------------------------------
 
Back to Top
karthiksp View Drop Down
Groupie
Groupie


Joined: 09 May 2007
Location: United States
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote karthiksp Quote  Post ReplyReply Direct Link To This Post Posted: 02 July 2007 at 8:35am
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
Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post Posted: 04 July 2007 at 4:26pm


--
WBR,
Serge
Back to Top
vbuser View Drop Down
Newbie
Newbie


Joined: 22 January 2004
Status: Offline
Points: 39
Post Options Post Options   Thanks (0) Thanks(0)   Quote vbuser Quote  Post ReplyReply Direct Link To This Post Posted: 26 July 2007 at 7:04pm
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.
Back to Top
Stilki View Drop Down
Groupie
Groupie


Joined: 27 May 2005
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Stilki Quote  Post ReplyReply Direct Link To This Post Posted: 27 July 2007 at 12:06pm
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
 
 
 
 
 
 
 
Back to Top
vbuser View Drop Down
Newbie
Newbie


Joined: 22 January 2004
Status: Offline
Points: 39
Post Options Post Options   Thanks (0) Thanks(0)   Quote vbuser Quote  Post ReplyReply Direct Link To This Post Posted: 27 July 2007 at 2:55pm

GREAT JOB !!!

Thank you for the quick responce!!!

Back to Top
vbuser View Drop Down
Newbie
Newbie


Joined: 22 January 2004
Status: Offline
Points: 39
Post Options Post Options   Thanks (0) Thanks(0)   Quote vbuser Quote  Post ReplyReply Direct Link To This Post Posted: 27 July 2007 at 7:28pm

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?
Back to Top
Stilki View Drop Down
Groupie
Groupie


Joined: 27 May 2005
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Stilki Quote  Post ReplyReply Direct Link To This Post Posted: 27 July 2007 at 8:02pm
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.
Back to Top
visualise01 View Drop Down
Newbie
Newbie


Joined: 20 September 2009
Location: United Kingdom
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote visualise01 Quote  Post ReplyReply Direct Link To This Post Posted: 02 October 2009 at 5:08pm
anything for this in vb .net?
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 05 October 2009 at 12:07pm
What is special in VB.NET case?
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.188 seconds.