<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!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">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadScheduler1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadScheduler1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadScheduler1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadScheduler ID="RadScheduler1" runat="server" OnClientTimeSlotClick="test"
            AllowDelete="True" AllowEdit="True" AllowInsert="True" DataEndField="End" DataKeyField="ID"
            DataRecurrenceField="RecurrenceRule" DataRecurrenceParentKeyField="RecurrenceParentID"
            DataSourceID="SqlDataSource1" DataStartField="Start" DataSubjectField="Subject"
            HoursPanelTimeFormat="h:mm tt" SelectedDate="2007-11-28">
        </telerik:RadScheduler>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SchedulerDataConnectionString %>"
            DeleteCommand="DELETE FROM [Appointments] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Appointments] ([Subject], [Start], [End], [UserID], [RoomID], [RecurrenceRule], [RecurrenceParentID], [Annotations]) VALUES (@Subject, @Start, @End, @UserID, @RoomID, @RecurrenceRule, @RecurrenceParentID, @Annotations)"
            SelectCommand="SELECT [ID], [Subject], [Start], [End], [UserID], [RoomID], [RecurrenceRule], [RecurrenceParentID], [Annotations] FROM [Appointments]"
            UpdateCommand="UPDATE [Appointments] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [UserID] = @UserID, [RoomID] = @RoomID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID, [Annotations] = @Annotations WHERE [ID] = @ID">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Subject" Type="String" />
                <asp:Parameter Name="Start" Type="DateTime" />
                <asp:Parameter Name="End" Type="DateTime" />
                <asp:Parameter Name="UserID" Type="Int32" />
                <asp:Parameter Name="RoomID" Type="Int32" />
                <asp:Parameter Name="RecurrenceRule" Type="String" />
                <asp:Parameter Name="RecurrenceParentID" Type="Int32" />
                <asp:Parameter Name="Annotations" Type="String" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Subject" Type="String" />
                <asp:Parameter Name="Start" Type="DateTime" />
                <asp:Parameter Name="End" Type="DateTime" />
                <asp:Parameter Name="UserID" Type="Int32" />
                <asp:Parameter Name="RoomID" Type="Int32" />
                <asp:Parameter Name="RecurrenceRule" Type="String" />
                <asp:Parameter Name="RecurrenceParentID" Type="Int32" />
                <asp:Parameter Name="Annotations" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

        <script type="text/javascript">
        function test(sender, eventArgs)
        {       
         var start = formatDate(eventArgs.get_Time());
         <%=RadAjaxManager1.ClientID %>.AjaxRequest(start);        
        }
        function formatDate(date)
        {
            var year = padNumber(date.getUTCFullYear(), 4);
            var month = padNumber(date.getUTCMonth() + 1, 2);
            var day = padNumber(date.getUTCDate(), 2);
            var hour = padNumber(date.getUTCHours(), 2);
            var minute = padNumber(date.getUTCMinutes(), 2);
            
            return year + month + day + hour + minute;
        }
         function padNumber(number, totalDigits) 
        { 
            number = number.toString(); 
            var padding = ''; 
            if (totalDigits > number.length) 
            { 
                for (i = 0; i < (totalDigits - number.length); i++) 
                { 
                    padding += '0'; 
                } 
            }
            
            return padding + number.toString(); 
        }
        </script>

        </telerik:RadCodeBlock>
    </form>
</body>
</html>
