Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) SQL Data in vb.net (Read 5913 times)
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
SQL Data in vb.net
Apr 23rd, 2007 at 12:09pm
Print Post  
I'm trying to use the planner calendar to display appointments from a sql database.
I'm only using it for displaying purposes.
Can anyone give an example of how I would do this?
Thanks in advance
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: SQL Data in vb.net
Reply #1 - Apr 23rd, 2007 at 3:07pm
Print Post  
You could do that as shown below.

Dim Cmd As New SqlCommand
Cmd.Connection = Conn1
Cmd.CommandType = CommandType.Text
Cmd.CommandText = "SELECT * FROM dbo.Appointments"
Dim reader As SqlDataReader = Cmd.ExecuteReader()
While (reader.Read())
  Dim app As Appointment
  app = new  Appointment()
  app.HeaderText = reader.GetValue(0).ToString()
  app.StartTime = reader.GetDateTime(1)
  app.EndTime = reader.GetDateTime(2)
  calendar.Schedule.Items.Add(app);
End While

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
Re: SQL Data in vb.net
Reply #2 - Apr 23rd, 2007 at 11:27pm
Print Post  
Thank you that works. One more question if you don't mind. I'd like to show seperate schedules for each "Person". I tried adding the names in the contact collection but then my appointments don't show. Any advice?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: SQL Data in vb.net
Reply #3 - Apr 24th, 2007 at 6:33am
Print Post  
Once you have your contacts defined in the Calendar.Schedule.Contacts collection, you must add the contacts you would like to group by to the Calendar.Contacts collection and set Calendar.GroupType to GroupType.GroupByContacts. This will enable grouping in the current view (keep in mind that some views don't support grouping). Now associate each appointment with one or more contacts by adding a reference of these contacts to the Appointment.Contacts collection of the individual appointments.

Meppy
  
Back to top
 
IP Logged
 
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
Re: SQL Data in vb.net
Reply #4 - Apr 25th, 2007 at 12:33pm
Print Post  
Thanks for the help, I'll give that a try.
  
Back to top
 
IP Logged
 
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
Re: SQL Data in vb.net
Reply #5 - May 7th, 2007 at 12:29pm
Print Post  
I'm getting duplicates in my GroupbyContacts.
It must be something I'm doing. For example if I have 2 Appointments for a Tech(contact) Jeff, it creates them under 2 seperate columns. Here is the code I'm using.

While (reader.Read())
   Dim app As Appointment
   Dim con As Contact
   con = New Contact
   con.FirstName = reader.Item("Tech").ToString
   Calendar.Contacts.Add(con)
    app = New Appointment()
   app.DescriptionText = reader.Item       ("Description").ToString
   app.HeaderText = reader.Item("Name").ToString()
   app.StartTime = reader.GetDateTime(17)
   app.EndTime = reader.GetDateTime(18)
   app.AllowChangeStart = False
   app.AllowChangeEnd = False
   app.AllowMove = False
   app.Contacts.Add(con)
   Calendar.Schedule.Items.Add(app)
End While
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: SQL Data in vb.net
Reply #6 - May 7th, 2007 at 12:40pm
Print Post  
You should avoid creating new Contact object for each item because these contacts (although having the same names) are actually different resources. To prevent this, instead of creating new contact each time, simply check whether there is a contact with the same name already defined in the schedule and add him in the item's Contact collection.

Meppy
  
Back to top
 
IP Logged
 
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
Re: SQL Data in vb.net
Reply #7 - May 7th, 2007 at 9:40pm
Print Post  
Ok sorry about this but this is what I have but it won't add an existing contact. Your help is appreciated.

Dim app As Appointment
Dim con As Contact
Dim strName As String

app = New Appointment()
app.DescriptionText = reader.Item("Description").ToString
app.HeaderText = reader.Item("Name").ToString()
app.StartTime = reader.GetDateTime(17)
app.EndTime = reader.GetDateTime(18)
app.AllowChangeStart = False
app.AllowChangeEnd = False
app.AllowMove = False
strName = reader.Item("Tech").ToString()
con = New Contact
con.Id = strName
con.FirstName = strName

If Calendar.Schedule.Contacts.Contains(con.Id) = False Then
Calendar.Contacts.Add(con)
app.Contacts.Add(con)
Calendar.Schedule.Items.Add(app)
Else
app.Contacts.Add(con)
Calendar.Schedule.Items.Add(app)

End If[code][/code]
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: SQL Data in vb.net
Reply #8 - May 8th, 2007 at 5:52am
Print Post  
Try this slight modification in your code:

Code
Select All
Dim strName As String
Dim con As Contact

strName = reader.Item("Tech").ToString()

If Calendar.Schedule.Contacts.Contains(strName) Then
   ' Obtain a reference to the existing contact
   con = Calendar.Schedule.Contacts(strName)
Else
   ' A contact with this id does not exist - create it
   con = new Contact
   con.Id = strName
   con.FirstName = strName

   ' Add this contact to the schedule
   Calendar.Schedule.Contacts.Add(con)
End If

' Ensure we are performing grouping on the contact
If Not Calendar.Contacts.Contains(con) Then
   Calendar.Contacts.Add(con)
End If

' Associate the item with this contact (assuming
' the item is already created and initialized)
app.Contacts.Add(con) 



Meppy
« Last Edit: May 8th, 2007 at 12:44pm by Meppy »  
Back to top
 
IP Logged
 
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
Re: SQL Data in vb.net
Reply #9 - May 8th, 2007 at 12:38pm
Print Post  
I tried it but get the following error on the reference to the existin contact. Thanks for the help by the way.
[code]Error
2
Value of type 'MindFusion.Scheduling.ContactCollection' cannot be converted to 'MindFusion.Scheduling.Contact'.

[/code]
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: SQL Data in vb.net
Reply #10 - May 8th, 2007 at 12:45pm
Print Post  
My bad. The code from my previous post should now be correct.

Meppy
  
Back to top
 
IP Logged
 
CodingJeff
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Apr 22nd, 2007
Re: SQL Data in vb.net
Reply #11 - May 8th, 2007 at 1:11pm
Print Post  
Thanks, that worked great and sorry I should have caught the [] in th previous example.
Appreciate all the help!!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint