MindFusion.Scheduling for ASP.NET Programmer's Guide
Tutorial 1: Creating appointments

This tutorial will show you how to create Contact, Location and Appointment objects.

1. Initial preparations

Follow the steps from 'Adding the control' topic - create a web site, add a Calendar control and a System.Web.UI.ScriptManager.

2. Set the control's properties

Select the Calendar control and click View -> Properties Window from the menu. In the Properties window change the CurrentView property to Timetable and Theme to Vista. Set the Calendar's Height and Width to 400px.
Click to expand 'Timetable Settings'. Set the StartTime property to '420' and EndTime property to '1260'. These designate minutes from the start of the day and mean from 7 AM to, but not including, 21 PM respectively.

3. Create data for the schedule

Switch to Code view and the following method to the page's code. Within this method we will define some items and resources to display in the calendar.

C#  Copy Code

private void CreateScheduleData()
{
}

Visal Basic  Copy Code
Private Sub CreateScheduleData()
End Sub

3.1 Creating contacts

Add the following code to the body of CreateScheduleData method:

C#  Copy Code

Contact contact1 = new Contact();
contact1.FirstName = "James";
contact1.LastName = "Jones";
Calendar1.Schedule.Contacts.Add(contact1);

Contact contact2 = new Contact();
contact2.FirstName = "Mary";
contact2.LastName = "Brown";
Calendar1.Schedule.Contacts.Add(contact2);

Visual Basic  Copy Code

Dim contact1 As New Contact()
contact1.FirstName = "James"
contact1.LastName = "Jones"
Calendar1.Schedule.Contacts.Add(contact1)

Dim contact2 As New Contact()
contact2.FirstName = "Mary"
contact2.LastName = "Brown"
Calendar1.Schedule.Contacts.Add(contact2)

This code will create two contacts - James Jones and Mary Brown and add them to the Schedule's Contacts collection.

3.2 Creating locations

Add the following code to the body of CreateScheduleData method:

C#  Copy Code

Location location1 = new Location();
location1.City = "London";
location1.Name = "London";
Calendar1.Schedule.Locations.Add(location1);

Location location2 = new Location();
location2.City = "Paris";
location2.Name = "Paris";
Calendar1.Schedule.Locations.Add(location2);

Visual Basic  Copy Code

Dim location1 As New Location()
location1.City = "London"
location1.Name = "London"
Calendar1.Schedule.Locations.Add(location1)

Dim location2 As New Location()
location2.City = "Paris"
location2.Name = "Paris"
Calendar1.Schedule.Locations.Add(location2)

This code will create two locations - London and Paris and add them to the Schedule's Locations collection.

3.3 Creating appointments

Add the following code to the body of CreateScheduleData method:

C#  Copy Code

Appointment app1 = new Appointment();
app1.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0);
app1.EndTime = app1.StartTime.AddHours(2);
app1.Subject = "Meeting";
app1.DescriptionText = "I really must be there on time.";
app1.Locked = true;
app1.Location = location1;
app1.Contacts.Add(contact1);
Calendar1.Schedule.Items.Add(app1);

Appointment app2 = new Appointment();
app2.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 0, 0);
app2.EndTime = app2.StartTime.AddHours(1);
app2.Subject = "Lunch";
app2.DescriptionText = "Yummy!";
app2.Location = location1;
app2.Contacts.Add(contact1);
Calendar1.Schedule.Items.Add(app2);

Appointment app3 = new Appointment();
app3.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 0);
app3.EndTime = app3.StartTime.AddHours(3);
app3.Subject = "Yoga class";
app3.DescriptionText = "Yeah!";
app3.Location = location2;
app3.Contacts.Add(contact2);
Calendar1.Schedule.Items.Add(app3);

Appointment app4 = new Appointment();
app4.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 0, 0);
app4.EndTime = app4.StartTime.AddHours(1);
app4.Subject = "Dinner";
app4.DescriptionText = "with the family";
app4.Location = location2;
app4.Contacts.Add(contact2);
Calendar1.Schedule.Items.Add(app4);

Visual Basic  Copy Code

Dim app1 As New Appointment()
app1.StartTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 0, 0)
app1.EndTime = app1.StartTime.AddHours(2)
app1.Subject = "Meeting"
app1.DescriptionText = "I really must be there on time."
app1.Locked = True
app1.Location = location1
app1.Contacts.Add(contact1)
Calendar1.Schedule.Items.Add(app1)

Dim app2 As New Appointment()
app2.StartTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 13, 0, 0)
app2.EndTime = app2.StartTime.AddHours(1)
app2.Subject = "Lunch"
app2.DescriptionText = "Yummy!"
app2.Location = location1
app2.Contacts.Add(contact1)
Calendar1.Schedule.Items.Add(app2)

Dim app3 As New Appointment()
app3.StartTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 0)
app3.EndTime = app3.StartTime.AddHours(3)
app3.Subject = "Yoga class"
app3.DescriptionText = "Yeah!"
app3.Location = location2
app3.Contacts.Add(contact2)
Calendar1.Schedule.Items.Add(app3)

Dim app4 As New Appointment()
app4.StartTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 20, 30, 0)
app4.EndTime = app4.StartTime.AddHours(1)
app4.Subject = "Dinner"
app4.DescriptionText = "with the family"
app4.Location = location2
app4.Contacts.Add(contact2)
Calendar1.Schedule.Items.Add(app4)

This code will create four appointments and add them to the Schedule's Items collection.

Finally, add a call to the CreateScheduleData method to the page's Load event handler:

C#  Copy Code

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        CreateScheduleData();
    }
}

Visual Basic  Copy Code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    If Not IsPostBack Then
        CreateScheduleData()
    End If

End Sub

4. Build and run

Run the web page. The image below depicts what the page output would look like: