Issues with moving appointments

4 posts, 0 answers
  1. Henrik Widlund
    Henrik Widlund avatar
    2 posts
    Member since:
    Apr 2010

    Posted 28 Jun 2011 Link to this post

    Hi,
    I've got a problem with the scheduler. I can't move one appointment before another one, only the other way. I.e: I've got one appointment at 10am to 11am and then another one from 1pm to 2pm. Now I want to move that second appointment to 9am to 9:30pm, but it doesn't and I'm unable to see why.
    I'm also wondering how I can change the hours shown in the dropdown-lists in the advanced form to show all 24 hours without 30-min intervals.

    This is my code:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="schedulerBooking.ascx.cs" Inherits="schedular.schedulerBooking" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
      <script type="text/javascript">
          function OnClientAppointmentMoving(sender, eventArgs) {
              eventArgs.set_cancel(true);
          
        </script>
    <telerik:RadScriptManager ID="radScriptManager" runat="server" />
    <telerik:RadAjaxPanel ID="radAjaxPanel" runat="server" LoadingPanelID="radAjaxLoadingPanel">
        <telerik:RadAjaxManager ID="radAjaxManager" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="radScheduler">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="radScheduler" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="ddlRooms">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="radScheduler" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="radAjaxManager">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="radScheduler" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <asp:UpdatePanel ID="upRadioButtons" runat="server">
            <ContentTemplate>
                <asp:Label ID="lblRooms" runat="server" AssociatedControlID="ddlRooms" Text="Stuga" />
                <telerik:RadComboBox ID="ddlRooms" runat="server" AutoPostBack="true" />
            </ContentTemplate>
        </asp:UpdatePanel>
        <telerik:RadScheduler
            ID="radScheduler"
            runat="server"
            FirstDayOfWeek="Monday"
            LastDayOfWeek="Sunday"
            DayStartTime="00:00:00"
            DayView-WorkDayStartTime="00:00:00"
            DayEndTime="23:59:59"
            DayView-WorkDayEndTime="23:59:59"
            TimeLabelRowSpan="1"
            MinutesPerRow="60"
            StartInsertingInAdvancedForm="True"
            Culture="sv-SE"
            HoursPanelTimeFormat="HH:mm"
            ShowAllDayRow="False"
            ShowFooter="False"
            CustomAttributeNames="Bokare"
            AdvancedForm-EnableCustomAttributeEditing="true"
            DataKeyField="BookingId" DataSubjectField="Subject"
            DataStartField="Start" DataEndField="End"
            DataSourceID="BookingDataSource"
            onappointmentdelete="radScheduler_AppointmentDelete"
            onappointmentinsert="radScheduler_AppointmentInsert"
            onappointmentupdate="radScheduler_AppointmentUpdate"
            NumberOfHoveredRows="2" onformcreated="radScheduler_FormCreated"
            onformcreating="radScheduler_FormCreating" OnClientAppointmentMoving="OnClientAppointmentMoving" WeekView-ReadOnly="false" WeekView-DayEndTime="23:59:59" WeekView-DayStartTime="00:00:00">
                <AdvancedForm Modal="true" />
                <AppointmentTemplate>
                    <strong><%# Eval("Bokare") %></strong>
                    <p><%# Eval("Subject") %></p>
                </AppointmentTemplate>
                <TimelineView UserSelectable="true" />
                <TimeSlotContextMenuSettings EnableDefault="false" />
                <TimeSlotContextMenus>
                    <telerik:RadSchedulerContextMenu ID="SchedulerTimeSlotContextMenu" runat="server">
                        <Items>
                            <telerik:RadMenuItem Text="Ny bokning" Value="CommandAddAppointment" />
                            <telerik:RadMenuItem IsSeparator="true" />
                            <telerik:RadMenuItem Text="Gå till idag" Value="CommandGoToToday" />
                        </Items>
                    </telerik:RadSchedulerContextMenu>
                </TimeSlotContextMenus>
                <AppointmentContextMenuSettings EnableDefault="false" />
                <AppointmentContextMenus>
                    <telerik:RadSchedulerContextMenu ID="SchedulerAppointmentContextMenu" runat="server">
                        <Items>
                            <telerik:RadMenuItem Text="Redigera" Value="CommandEdit" />
                            <telerik:RadMenuItem IsSeparator="true" />
                            <telerik:RadMenuItem Text="Ta bort" Value="CommandDelete" />
                        </Items>
                    </telerik:RadSchedulerContextMenu>
                </AppointmentContextMenus>
                <AdvancedForm Modal="True" />
                <Localization AdvancedAllDayEvent="Heldag" AdvancedCalendarCancel="Avbryt"
                    AdvancedCalendarToday="Idag" AdvancedClose="Stäng" AdvancedDaily="Dagligen"
                    AdvancedDay="Dag" AdvancedDays="dag(ar)" AdvancedDescription="Beskrivning"
                    AdvancedDone="Färdig" AdvancedEditAppointment="Ändra bokning"
                    AdvancedFrom="Start" AdvancedNewAppointment="Ny bokning" AdvancedSubject="Ämne"
                    AdvancedTo="Till" AdvancedWeekly="Veckovis" AllDay="Heldag" Cancel="Avbryt"
                    ConfirmCancel="Avbryt"
                    ConfirmDeleteText="Är du säker på att du vill ta bort bokningen?"
                    ConfirmDeleteTitle="Bekräfta borttagning"
                    ContextMenuAddAppointment="Ny bokning" ContextMenuDelete="Ta bort"
                    ContextMenuEdit="Ändra" ContextMenuGoToToday="Gå till idag" HeaderDay="Dag"
                    HeaderMonth="Månad" HeaderMultiDay="Flera dagar" HeaderNextDay="nästa dag"
                    HeaderPrevDay="föregående dag" HeaderTimeline="Tidslinje" HeaderToday="Idag"
                    HeaderWeek="Vecka" Save="Spara" Show24Hours="24 timmars format"
                    ShowAdvancedForm="Val" />
                <TimelineView UserSelectable="False" />
            </telerik:RadScheduler>
    </telerik:RadAjaxPanel>
     
    <asp:SqlDataSource ID="BookingDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:*%>"
        SelectCommand="SELECT [BookingId], [Subject], [Start], [End], [RoomId], [nodeId] FROM [Bookings] WHERE ([RoomId] = @RoomId)">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlRooms" DefaultValue="1" Name="RoomId"
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using umbraco.cms.businesslogic.member;
     
    namespace schedular
    {
        public partial class schedulerBooking : System.Web.UI.UserControl
        {
            protected dbDataContext db = new dbDataContext();
            protected int userId = umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id;
            protected bool IsBookingAdmin;
     
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    var rooms = (from r in db.Rooms
                                 select r);
                    ddlRooms.DataTextField = "RoomName";
                    ddlRooms.DataValueField = "RoomId";
                    ddlRooms.DataSource = rooms;
                    ddlRooms.DataBind();
                }
                BookingDataSource.SelectCommand = "SELECT b.[BookingId], b.[Subject], b.[End], b.[Start], b.[RoomId], b.[nodeId], u.[LoginName] Bokare FROM [Bookings] AS b JOIN [cmsMember] AS u ON u.[nodeId] = b.[nodeId] WHERE ([RoomId] = @RoomId)";
            }
     
            protected void radScheduler_AppointmentInsert(object sender, AppointmentInsertEventArgs e)
            {
                    BookingDataSource.InsertCommand = "INSERT INTO [Bookings] ([Subject], [Start], [End], [RoomId], [nodeId]) VALUES (@Subject, @Start, @End, " + int.Parse(ddlRooms.SelectedValue) + ", " + userId + ")";
                    radScheduler.Rebind();
            }
     
            protected void radScheduler_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
            {
                foreach (Member member in Member.GetAll)
                {
                    if (member.ContentType.Alias.ToString() == "BookingAdmin")
                        IsBookingAdmin = true;
                    else
                        IsBookingAdmin = false;
                }
                    foreach (Appointment a in radScheduler.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.End))
                    {
                        int id = (int)e.Appointment.ID;
                        int aId = (int)a.ID;
                        var bookingOwner = (from o in db.Bookings
                                            where o.BookingId == id
                                            select o).Single();
                        if (aId == id && bookingOwner.nodeId == userId || IsBookingAdmin)
                        {
                            BookingDataSource.UpdateCommand = "UPDATE [Bookings] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [RoomId] = " + int.Parse(ddlRooms.SelectedValue) + " WHERE [BookingId] = " + id;
                            radScheduler.Rebind();
                        }
                        else
                            e.Cancel = true;
                }
            }
     
            protected void radScheduler_AppointmentDelete(object sender, AppointmentDeleteEventArgs e)
            {
                foreach (Member member in Member.GetAll)
                {
                    if (member.ContentType.Alias.ToString() == "BookingAdmin")
                        IsBookingAdmin = true;
                    else
                        IsBookingAdmin = false;
                }
                int id = (int)e.Appointment.ID;
                var bookingOwner = (from o in db.Bookings
                                    where o.BookingId == id
                                    select o).Single();
                if (bookingOwner.nodeId == userId || IsBookingAdmin == true)
                {
                    BookingDataSource.DeleteCommand = "DELETE FROM [Bookings] WHERE [BookingId] = " + id;
                    radScheduler.Rebind();
                }
                else
                    e.Cancel = true;
            }
     
            protected void radScheduler_FormCreating(object sender, SchedulerFormCreatingEventArgs e)
            {
                var user = (from u in db.cmsMembers
                            where u.nodeId == userId
                            select u).Single();
                if (string.IsNullOrEmpty(e.Appointment.Attributes["Bokare"]))
                    e.Appointment.Attributes["Bokare"] = user.LoginName;
            }
     
            protected void radScheduler_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
            {
                if (e.Container.Mode == SchedulerFormMode.AdvancedEdit || e.Container.Mode == SchedulerFormMode.AdvancedInsert)
                {
                    RadTextBox txtBooker = e.Container.FindControl("AttrBokare") as RadTextBox;
                    txtBooker.Enabled = false;
                    txtBooker.Style.Value = "border:0;color:Black !important;background-color:#EEEEEE;";
                }
            }
        }
    }
  2. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 01 Jul 2011 Link to this post

    Hello Henrik,

    As we can not reproduce the issue on our demos I believe that it is caused by your particular implementation.
    Could you please send me your full project attached in a .zip file so I can inspect it and help you?

    Thank you!

    P.S: As this is a forum post and you are not able to attach .zip files - I suggest you to use one of the sites for free online storage as 4shared.com.

    Kind regards,
    Veronica Milcheva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Henrik Widlund
    Henrik Widlund avatar
    2 posts
    Member since:
    Apr 2010

    Posted 06 Jul 2011 Link to this post

    Here's the link to my source code. I've removed sensitive data like connectionstrings etc.
    http://www.megaupload.com/?d=TR18CKF1
  4. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 12 Jul 2011 Link to this post

    Hello Henrik Widlund,

    Thank you for the attached project. However could you please send me your database as well.

    Meantime as I see that you are using LinqDataSource to bind the RadScheduler - please run the project form this KB article and check whether the issue appears again. If not you can compare it with your own and see what may cause the problem.

    Greetings,
    Veronica Milcheva
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top