Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports C1.C1Schedule

Namespace Grouping
	Partial Public Class MainPage
		Inherits UserControl
		Implements IDisposable
		Public Sub New()
			InitializeComponent()
			cmbGroup.Items.Add("None")
			cmbGroup.Items.Add("Category")
			cmbGroup.Items.Add("Resource")
			cmbGroup.Items.Add("Contact")
			cmbGroup.SelectedIndex = 3

			cmbView.Items.Add("Day")
			cmbView.Items.Add("Working Week")
			cmbView.Items.Add("Week")
			cmbView.Items.Add("Month")
			cmbView.Items.Add("Time Line")
			cmbView.SelectedIndex = 4

			' add some resources
			Dim res As New Resource()
			res.Text = "Meeting room"
			res.Color = Color.FromArgb(255, 218, 186, 198)
			sched1.DataStorage.ResourceStorage.Resources.Add(res)
			Dim res1 As New Resource()
			res1.Text = "Conference hall"
			res1.Color = Color.FromArgb(255, 220, 236, 201)
			sched1.DataStorage.ResourceStorage.Resources.Add(res1)

			' add some contacts
			Dim cnt As New Contact()
			cnt.Text = "Andy Garcia"
			sched1.DataStorage.ContactStorage.Contacts.Add(cnt)
			Dim cnt1 As New Contact()
			cnt1.Text = "Nancy Drew"
			sched1.DataStorage.ContactStorage.Contacts.Add(cnt1)
			Dim cnt2 As New Contact()
			cnt2.Text = "Robert Clark"
			sched1.DataStorage.ContactStorage.Contacts.Add(cnt2)

			' add sample appointments
			Dim app As New Appointment(Date.Today.AddHours(12), TimeSpan.FromHours(1))
			app.Subject = "Sales meeting"
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app.Resources.Add(res)
			app.Links.Add(cnt1)
			app.Links.Add(cnt2)

			app = New Appointment(Date.Today.AddHours(14), TimeSpan.FromHours(3))
			app.Subject = "Retirement Planning Session"
			app.Body = "A retirement planning education session. Please attend if possible."
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app.Resources.Add(res1)
			app.Links.Add(cnt1)
			app.Links.Add(cnt2)
			app.Links.Add(cnt)

			app = New Appointment(Date.Today.AddHours(10), TimeSpan.FromMinutes(15))
			app.Subject = "Conference call"
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app.Links.Add(cnt)

			AddHandler sched1.VisibleGroupItems.CollectionChanged, AddressOf VisibleGroupItems_CollectionChanged
		End Sub

		Private Sub VisibleGroupItems_CollectionChanged(ByVal sender As Object, ByVal e As System.Collections.Specialized.NotifyCollectionChangedEventArgs)
			C1.Silverlight.CommandManager.InvalidateRequerySuggested()
		End Sub

		Private Sub ComboBoxGroup_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
			Dim str As String = CStr(cmbGroup.SelectedItem)
			If str = "None" Then
				sched1.GroupBy = String.Empty
			Else
				sched1.GroupBy = str
			End If
		End Sub

		Private Sub ComboBoxView_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
			Select Case CStr(cmbView.SelectedItem)
				Case "Month"
					sched1.ChangeStyle(sched1.MonthStyle)
				Case "Day"
					sched1.ChangeStyle(sched1.OneDayStyle)
				Case "Working Week"
					sched1.ChangeStyle(sched1.WorkingWeekStyle)
				Case "Week"
					sched1.ChangeStyle(sched1.WeekStyle)
				Case "Time Line"
					sched1.ChangeStyle(sched1.TimeLineStyle)
			End Select
		End Sub

		Private Sub sched1_StyleChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
			' update toolbar buttons state according to the current C1Scheduler view
            If sched1.Style Is sched1.WorkingWeekStyle Then
                cmbView.SelectedIndex = 1
            ElseIf sched1.Style Is sched1.WeekStyle Then
                cmbView.SelectedIndex = 2
            ElseIf sched1.Style Is sched1.MonthStyle Then
                cmbView.SelectedIndex = 3
            ElseIf sched1.Style Is sched1.TimeLineStyle Then
                cmbView.SelectedIndex = 4
            Else
                cmbView.SelectedIndex = 0
            End If
		End Sub


		#Region "IDisposable Members"

		Public Sub Dispose() Implements IDisposable.Dispose
			sched1.Dispose()
		End Sub

		#End Region

	End Class
End Namespace
