Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic load/save appointments from DB in ResourceView (Read 2630 times)
cenobite
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
load/save appointments from DB in ResourceView
Nov 16th, 2007 at 7:24pm
Print Post  
Hi,

I'm trying to load items from a database and display them on the resourceview of the calendar, but I cannot figure out how to do this exactly ???.

With following code I put appointments on the calendar (which is in resourceview):
Code
Select All
        private void calendar1_DateClick(object sender, ResourceDateEventArgs e)
        {
            if (e.Clicks == 2 && e.Button == MouseButtons.Left)
            {
                calendar1.ResetDrag();

                Contact c = calendar1.GetContactAt(calendar1.PointToClient(MousePosition));

                if (c == null)
                    return;

                Appointment tpt = new Appointment();

                tpt.StartTime = e.Date;
                tpt.EndTime = e.Date + TimeSpan.FromDays(1);
                tpt.HeaderText = "test";

                tpt.Contacts.Add(c);

                calendar1.Schedule.Items.Add(tpt);
            }
        } 



Following code saves the appointment to the database (new record is correctly created in tables Item and ItemContacts):
Code
Select All
        private void cmdSave_Click(object sender, EventArgs e)
        {
            calendar1.SaveToDataSource(
                reminderTableAdapter1,
                styleTableAdapter1,
                customBrushesTableAdapter1,
                contactTableAdapter1,
                locationTableAdapter1,
                resourceTableAdapter1,
                taskTableAdapter1,
                itemTableAdapter1,
                itemContactsTableAdapter1,
                itemResourcesTableAdapter1,
                recurrenceTableAdapter1,
                recurrenceExceptionTableAdapter1,
                recurrenceExceptionsTableAdapter1
                        );

        } 



I use the following code to load the data back to the calendar:
Code
Select All
        private void cmdLoad_Click(object sender, EventArgs e)
        {

            calendar1.Schedule.Clear();
            plannerDataSet.Clear();

            reminderTableAdapter1.Fill(plannerDataSet.Reminder);
            styleTableAdapter1.Fill(plannerDataSet.Style);
            customBrushesTableAdapter1.Fill(plannerDataSet.CustomBrushes);
            contactTableAdapter1.Fill(plannerDataSet.Contact);
            locationTableAdapter1.Fill(plannerDataSet.Location);
            resourceTableAdapter1.Fill(plannerDataSet.Resource);
            taskTableAdapter1.Fill(plannerDataSet.Task);
            itemTableAdapter1.Fill(plannerDataSet.Item);
            itemContactsTableAdapter1.Fill(plannerDataSet.ItemContacts);
            itemResourcesTableAdapter1.Fill(plannerDataSet.ItemResources);
            recurrenceTableAdapter1.Fill(plannerDataSet.Recurrence);
            recurrenceExceptionTableAdapter1.Fill(plannerDataSet.RecurrenceException);
            recurrenceExceptionsTableAdapter1.Fill(plannerDataSet.RecurrenceExceptions);

            calendar1.LoadFromDataSource();

        } 



I get no error messages when executing this, but the calendar remains empty, no appointment is shown.

I've read tutorial #9 but I'm clueless why this won't work.

thanks for helping.
  
Back to top
 
IP Logged
 
cenobite
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
Re: load/save appointments from DB in ResourceView
Reply #1 - Nov 17th, 2007 at 8:21am
Print Post  
GroupType is configured as GroupByContacts, so I must place this code right after calendar1.LoadFromDataSource():
Code
Select All
       ...
            calendar1.BeginInit();

            foreach (Contact c in calendar1.Schedule.Contacts)
                calendar1.Contacts.Add(c);

            calendar1.EndInit();
        } 



Items are then loaded and displayed on the calendar, however the calendar duplicates contacts each time I load data ?
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: load/save appointments from DB in ResourceView
Reply #2 - Nov 19th, 2007 at 6:03am
Print Post  
Have you tried calling calendar1.Contacts.Clear() before adding any contacts to this collection after a load?

Meppy
  
Back to top
 
IP Logged
 
cenobite
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Nov 16th, 2007
Re: load/save appointments from DB in ResourceView
Reply #3 - Nov 29th, 2007 at 8:39pm
Print Post  
Thanks Meppy! it works fine now by using calendar1.Contact.Clear() first.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint