<%@ Page Language="VB" AutoEventWireup="true" CodeFile="RadSchedulerAdvancedForm.aspx.vb"
	Inherits="RadSchedulerAdvancedForm" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="scheduler" TagName="AdvancedForm" Src="AdvancedForm.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<style type="text/css">
		.RadScheduler .rsAdvancedEdit .RadColorPicker label
		{
			text-align: left;
			display: block;
			padding: 0;
		}
	</style>
	<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body class="BODY">
	<form id="Form1" method="post" runat="server">
	<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
		<Scripts>
			<asp:ScriptReference Path="~/VB.NET/AdvancedForm.js" />
			<%--Needed for JavaScript IntelliSense in VS2010--%>
			<%--For VS2008 replace RadScriptManager with ScriptManager--%>
			<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
		</Scripts>
	</telerik:RadScriptManager>
	<script type="text/javascript">	
		//<![CDATA[

		// Dictionary containing the advanced template client object
		// for a given RadScheduler instance (the control ID is used as key).
		var schedulerTemplates = {};

		function schedulerFormCreated(scheduler, eventArgs) {
			// Create a client-side object only for the advanced templates
			var mode = eventArgs.get_mode();
			if (mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert ||
					mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit) {
				// Initialize the client-side object for the advanced form
				var formElement = eventArgs.get_formElement();
				var templateKey = scheduler.get_id() + "_" + mode;
				var advancedTemplate = schedulerTemplates[templateKey];
				if (!advancedTemplate) {
					// Initialize the template for this RadScheduler instance
					// and cache it in the schedulerTemplates dictionary
					var schedulerElement = scheduler.get_element();
					var isModal = scheduler.get_advancedFormSettings().modal;
					advancedTemplate = new window.SchedulerAdvancedTemplate(schedulerElement, formElement, isModal);
					advancedTemplate.initialize();

					schedulerTemplates[templateKey] = advancedTemplate;

					// Remove the template object from the dictionary on dispose.
					scheduler.add_disposing(function () {
						schedulerTemplates[templateKey] = null;
					});
				}

				// Are we using Web Service data binding?
				if (!scheduler.get_webServiceSettings().get_isEmpty()) {
					// Populate the form with the appointment data
					var apt = eventArgs.get_appointment();
					var isInsert = mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert;
					advancedTemplate.populate(apt, isInsert);
				}
			}
		}
			
		//]]>
	</script>
	<telerik:RadAjaxPanel ID="RadAjaxPanel" runat="server">
		<telerik:RadScheduler runat="server" ID="RadScheduler1" Width="750px" AppointmentStyleMode="Default"
			StartInsertingInAdvancedForm="true" StartEditingInAdvancedForm="true" OnAppointmentDataBound="RadScheduler1_AppointmentDataBound"
			OnClientFormCreated="schedulerFormCreated" CustomAttributeNames="AppointmentColor, Continent, Country"
			EnableDescriptionField="True" DataDescriptionField="Description" DataEndField="End"
			DataKeyField="ClassID" DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID"
			DataReminderField="Reminder" DataSourceID="SqlDataSource1" DataStartField="Start"
			DataSubjectField="Subject">
			<AdvancedForm Modal="true" />
			<Reminders Enabled="true" />
			<AdvancedEditTemplate>
				<scheduler:AdvancedForm runat="server" ID="AdvancedEditForm1" Mode="Edit" Subject='<%# Bind("Subject") %>'
					Description='<%# Bind("Description") %>' Start='<%# Bind("Start") %>' End='<%# Bind("End") %>'
					RecurrenceRuleText='<%# Bind("RecurrenceRule") %>' Continent='<%# Bind("Continent") %>'
					Country='<%# Bind("Country") %>' Reminder='<%# Bind("Reminder") %>' AppointmentColor='<%# Bind("AppointmentColor") %>'
					TeacherID='<%# Bind("Teacher") %>' />
			</AdvancedEditTemplate>
			<AdvancedInsertTemplate>
				<scheduler:AdvancedForm runat="server" ID="AdvancedInsertForm1" Mode="Insert" Subject='<%# Bind("Subject") %>'
					Start='<%# Bind("Start") %>' End='<%# Bind("End") %>' Description='<%# Bind("Description") %>'
					RecurrenceRuleText='<%# Bind("RecurrenceRule") %>' Continent='<%# Bind("Continent") %>'
					Country='<%# Bind("Country") %>' Reminder='<%# Bind("Reminder") %>' AppointmentColor='<%# Bind("AppointmentColor") %>'
					TeacherID='<%# Bind("Teacher") %>' />
			</AdvancedInsertTemplate>
			<ResourceTypes>
				<telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="TeacherID" KeyField="TeacherID"
					Name="Teacher" TextField="Name" />
			</ResourceTypes>
			<TimelineView UserSelectable="false" />
			<TimeSlotContextMenuSettings EnableDefault="true" />
			<AppointmentContextMenuSettings EnableDefault="true" />
		</telerik:RadScheduler>
	</telerik:RadAjaxPanel>
	<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikVSXConnString %>"
		DeleteCommand="DELETE FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID" InsertCommand="INSERT INTO [DbProvider_Classes] ([Subject], [Start], [End], [TeacherID], [RecurrenceRule], [RecurrenceParentID], [Reminder], [Description], [AppointmentColor], [Continent], [Country]) VALUES (@Subject, @Start, @End, @TeacherID, @RecurrenceRule, @RecurrenceParentID, @Reminder, @Description, @AppointmentColor, @Continent, @Country)"
		SelectCommand="SELECT * FROM [DbProvider_Classes]" UpdateCommand="UPDATE [DbProvider_Classes] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [TeacherID] = @TeacherID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID, [Reminder] = @Reminder, [Description] = @Description, [AppointmentColor] = @AppointmentColor, [Continent] = @Continent, [Country] = @Country WHERE [ClassID] = @ClassID">
		<DeleteParameters>
			<asp:Parameter Name="ClassID" Type="Int32" />
		</DeleteParameters>
		<InsertParameters>
			<asp:Parameter Name="Subject" Type="String" />
			<asp:Parameter Name="Start" Type="DateTime" />
			<asp:Parameter Name="End" Type="DateTime" />
			<asp:Parameter Name="TeacherID" Type="Int32" />
			<asp:Parameter Name="RecurrenceRule" Type="String" />
			<asp:Parameter Name="RecurrenceParentID" Type="Int32" />
			<asp:Parameter Name="Reminder" Type="String" />
			<asp:Parameter Name="Description" Type="String" />
			<asp:Parameter Name="AppointmentColor" Type="String" />
			<asp:Parameter Name="Continent" Type="String" />
			<asp:Parameter Name="Country" Type="String" />
		</InsertParameters>
		<UpdateParameters>
			<asp:Parameter Name="Subject" Type="String" />
			<asp:Parameter Name="Start" Type="DateTime" />
			<asp:Parameter Name="End" Type="DateTime" />
			<asp:Parameter Name="TeacherID" Type="Int32" />
			<asp:Parameter Name="RecurrenceRule" Type="String" />
			<asp:Parameter Name="RecurrenceParentID" Type="Int32" />
			<asp:Parameter Name="Reminder" Type="String" />
			<asp:Parameter Name="Description" Type="String" />
			<asp:Parameter Name="AppointmentColor" Type="String" />
			<asp:Parameter Name="Continent" Type="String" />
			<asp:Parameter Name="Country" Type="String" />
			<asp:Parameter Name="ClassID" Type="Int32" />
		</UpdateParameters>
	</asp:SqlDataSource>
	<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikVSXConnString %>"
		SelectCommand="SELECT * FROM [DbProvider_Teachers]"></asp:SqlDataSource>
	</form>
</body>
</html>
