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.Silverlight.Schedule
Imports C1.C1Schedule
Imports C1.Silverlight

Namespace IntervalAppointmentTemplate
	Partial Public Class MainPage
		Inherits UserControl
		Implements IDisposable
		Public Sub New()
			InitializeComponent()

			' initialize palette combo
			paletteBox.SelectedIndex = 0

			Dim app As New Appointment(Date.Today.AddDays(-1), TimeSpan.FromDays(1))
			app.AllDayEvent = True
			app.Private = True
			app.Subject = "Test All-Day Event"
			app.Label = sched1.DataStorage.LabelStorage.Labels(8)
			app.Location = "Room 15"
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app = New Appointment(Date.Today, TimeSpan.FromDays(1))
			app.AllDayEvent = True
			app.BusyStatus = sched1.DataStorage.StatusStorage.Statuses(StatusTypeEnum.Tentative)
			app.Subject = "Another test All-Day Event"
			app.Label = sched1.DataStorage.LabelStorage.Labels(7)
			app.Location = "Room 22"
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app = New Appointment()
			app.Duration = TimeSpan.FromMinutes(60)
			app.Subject = "Test Appointment"
			app.Location = "Room 327"
			app.Label = sched1.DataStorage.LabelStorage.Labels(5)
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app = New Appointment()
			app.Duration = TimeSpan.FromMinutes(20)
			app.Subject = "Another test Appointment"
			app.Location = "Room 327"
			app.BusyStatus = sched1.DataStorage.StatusStorage.Statuses(StatusTypeEnum.OutOfOffice)
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
			app = New Appointment(Date.Today.AddDays(-3).AddHours(11), TimeSpan.FromMinutes(60))
			app.Subject = "Silverlight lesson"
			app.Location = "Conference room"
			app.Label = sched1.DataStorage.LabelStorage.Labels(8)
			Dim pattern As RecurrencePattern = app.GetRecurrencePattern()
			pattern.RecurrenceType = RecurrenceTypeEnum.Weekly
			pattern.DayOfWeekMask = WeekDaysEnum.Monday
			pattern.Occurrences = 5
			sched1.DataStorage.AppointmentStorage.Appointments.Add(app)
		End Sub

		Private Sub UserControl_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
			' update toolbar buttons state
			sched1_StyleChanged(Nothing, Nothing)
		End Sub

		Private Sub btnToday_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
			sched1.VisibleDates.BeginUpdate()
			sched1.VisibleDates.Clear()
			sched1.VisibleDates.Add(Date.Today)
			sched1.VisibleDates.EndUpdate()
		End Sub

		Private Sub sched1_LayoutUpdated(ByVal sender As Object, ByVal e As EventArgs)
			' update IntervalAppointmentTemplate for all AppointmentsCoverPanes in the control template
			' (you can use different templates for different views, or for AppointmentsCoverPanes with different orientation)
			If needUpdateIntervalAppointmentTemplate Then
				Dim list As IList(Of DependencyObject) = New List(Of DependencyObject)()
				VTreeHelper.GetChildrenOfType(sched1, GetType(AppointmentsCoverPane), list)
				For Each pane As AppointmentsCoverPane In list
					pane.IntervalAppointmentTemplate = sched1.IntervalAppointmentTemplate
				Next pane
				needUpdateIntervalAppointmentTemplate = False
			End If
		End Sub

		Private needUpdateIntervalAppointmentTemplate As Boolean = False
		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
                btnWorkWeek.IsChecked = True
            ElseIf sched1.Style Is sched1.WeekStyle Then
                btnWeek.IsChecked = True
            ElseIf sched1.Style Is sched1.MonthStyle Then
                btnMonth.IsChecked = True
            ElseIf sched1.Style Is sched1.TimeLineStyle Then
                btnTimeLine.IsChecked = True
            Else
                btnDay.IsChecked = True
            End If
            If sched1.Style IsNot sched1.MonthStyle Then
                needUpdateIntervalAppointmentTemplate = True
            End If
		End Sub

		#Region "IDisposable Members"

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

		#End Region

	End Class
End Namespace
