Bind Rad Scheduler To two Different Datasources(SQL)

10 posts, 0 answers
  1. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 22 Nov 2012 Link to this post

    Heey guys

    I have  a question is it possible to bind tow sql sources in one RadScheudler ?  An example with sql would really help  

    My code 
    <%@ Page Title="" Language="C#" MasterPageFile="~/ABBMaster.Master" AutoEventWireup="true" CodeBehind="UserScheduler.aspx.cs" Inherits="HolidayTracker.User.UserScheduler" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="MainRegionContentPlaceHolder" runat="server">
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
                function Export(sender, e) {
                    $find("<%= RadAjaxManager1.ClientID %>").__doPostBack(sender.name, "");
                }
     
            </script>
        </telerik:RadCodeBlock>
        <style type="text/css">
            .RadScheduler .rsExportButton {
                position: absolute;
                bottom: 0;
                right: 0;
                border: 0;
                height: 24px;
                width: 24px;
                background: url('exportButtonli.gif') no-repeat center center;
            }
     
            .RadScheduler .rsAllDayRow .rsExportButton {
                right: 20px;
                height: 16px;
                width: 16px;
                bottom: 20px;
                background: url('exportButton.gif');
            }
     
            #Label1Panel {
                display: inline !important;
            }
     
            .lblError {
                background: #CC0000;
                border: 1px solid darkred;
                color: white;
                font: bold 16px "Segoe UI", Arial, sans-serif;
                vertical-align: middle;
                display: none;
                height: 30px;
                line-height: 28px;
                position: absolute;
                padding-left: 5px;
                width: 743px;
                z-index: 1001;
                cursor: pointer;
                opacity: 0.9;
                -moz-opacity: 0.9;
                filter: alpha(opacity=90);
            }
     
            .rsCustomAppointmentContainer div {
                width: 100% !important;
            }
     
            .rsCustomAppointmentContainer h2 {
                overflow: hidden !important;
                white-space: nowrap !important;
                text-overflow: ellipsis !important;
            }
        </style>
     
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadScheduler1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadScheduler1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                        <telerik:AjaxUpdatedControl ControlID="Label1"></telerik:AjaxUpdatedControl>
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <asp:Label ID="Label1" runat="server" CssClass="lblError"></asp:Label>
        <div style="margin: 5px 0">
            <asp:ImageButton runat="server" ID="Button2" ImageUrl="exportButton.gif" AlternateText="Export All to Lotus Notes"
                OnClientClick="Export(this, event); return false;" OnClick="Button2_Click"></asp:ImageButton>
        </div>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" InitialDelayTime="200">
        </telerik:RadAjaxLoadingPanel>
        <div class="exampleContainer">
            <telerik:RadScheduler runat="server" ID="RadScheduler1" Width="750px"
                DayStartTime="07:00:00" DayEndTime="18:00:00" DataSourceID="SqlDataSource1"
                DataKeyField="VacationDayId" DataSubjectField="Title" DataStartField="FromDate" DataEndField="ToDate"
                OnAppointmentUpdate="RadScheduler1_AppointmentUpdate"
                OnAppointmentInsert="RadScheduler1_AppointmentInsert"
                OnRecurrenceExceptionCreated="RadScheduler1_RecurrenceExceptionCreated">
                <AdvancedForm Modal="true"></AdvancedForm>
                <TimelineView UserSelectable="false"></TimelineView>
                <TimeSlotContextMenuSettings EnableDefault="true"></TimeSlotContextMenuSettings>
                <AppointmentContextMenuSettings EnableDefault="true"></AppointmentContextMenuSettings>
            </telerik:RadScheduler>
        </div>
     
        <asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=HolidayTrackerEntities" DefaultContainerName="HolidayTrackerEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EntitySetName="HtVacationDays"></asp:EntityDataSource>
     
     
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HolidayTrackerConnectionString %>" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [HtVacationDay]" DeleteCommand="DELETE FROM [HtVacationDay] WHERE [VacationDayId] = @original_VacationDayId" InsertCommand="INSERT INTO [HtVacationDay] ([Title], [FromDate], [UserId], [Hours], [ToDate], [RecurrenceRule], [RecurrenceRuleID]) VALUES (@Title, @FromDate, @UserId, @Hours, @ToDate, @RecurrenceRule, @RecurrenceRuleID)" UpdateCommand="UPDATE [HtVacationDay] SET [Title] = @Title, [FromDate] = @FromDate, [UserId] = @UserId, [Hours] = @Hours, [ToDate] = @ToDate, [RecurrenceRule] = @RecurrenceRule, [RecurrenceRuleID] = @RecurrenceRuleID WHERE [VacationDayId] = @original_VacationDayId">
            <DeleteParameters>
                <asp:Parameter Name="original_VacationDayId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="FromDate" Type="DateTime" />
                <asp:Parameter Name="UserId" Type="Int32" />
                <asp:Parameter Name="Hours" Type="Double" />
                <asp:Parameter Name="ToDate" Type="DateTime" />
                <asp:Parameter Name="RecurrenceRule" Type="String" />
                <asp:Parameter Name="RecurrenceRuleID" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="FromDate" Type="DateTime" />
                <asp:Parameter Name="UserId" Type="Int32" />
                <asp:Parameter Name="Hours" Type="Double" />
                <asp:Parameter Name="ToDate" Type="DateTime" />
                <asp:Parameter Name="RecurrenceRule" Type="String" />
                <asp:Parameter Name="RecurrenceRuleID" Type="String" />
                <asp:Parameter Name="original_VacationDayId" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
       
    </asp:Content>

    Thanks for help and fast answer
  2. Plamen
    Admin
    Plamen avatar
    2958 posts

    Posted 23 Nov 2012 Link to this post

    Hi Nikola,

     
    Binding RadScheduler to two DataSources at the same time is a not supported scenario. If you want to change them somehow you can achieve it in the code behind as it is explained in the Using The Data Source Property help article.

    Hope this will be helpful.

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 23 Nov 2012 Link to this post

    Heey

     but then i got another question how can i display some special  days like public vacation but the user can not edit them ? 

    Thanks for help and fast answer 
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Nov 2012 Link to this post

    Hi Nikola,

    You can disable the editing of the appointments in the special days using the AppointmentCreated event of RadScheduler as follows.

    C#:
    protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
    {
        foreach (DateTime dt in SpecialDays)
        {
            if (DateTime.Compare(e.Appointment.Start.Date, dt) == 0)
            {
                e.Appointment.AllowEdit = false;
            }
        }
    }

    Hope this helps.

    Regards,
    Princy.
  5. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 23 Nov 2012 Link to this post

    heey 

    thanks for the answer but i found this awesome link form you !! 
    Setting special days or time slots in RadScheduler
    http://www.telerik.com/support/kb/aspnet-ajax/scheduler/setting-special-days-or-time-slots-in-radscheduler.aspx




    show me every thing that i want but one question how can i make this method dynamic  

    private readonly DateTime[] SpecialDays = new DateTime[] { new DateTime(2012, 12, 24), new DateTime(2012, 12, 25), new DateTime(2012, 12, 26), new DateTime(2012, 12, 27), new DateTime(2012, 12, 28), new DateTime(2012, 12, 29), new DateTime(2012, 12, 30) };

    it should load from dates directly from the DB 
  6. Plamen
    Admin
    Plamen avatar
    2958 posts

    Posted 23 Nov 2012 Link to this post

    Hi Nikola,

     
    You can refer to our Customizing Time Slots demo where similar functionality have been implemented. 

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 23 Nov 2012 Link to this post

    heey

    thanks for your input  

    is there not a real solution and not just workaround  for my question ? 

    thanks for help 
  8. Plamen
    Admin
    Plamen avatar
    2958 posts

    Posted 26 Nov 2012 Link to this post

    Hi Nikola,

     
    As far as I understand the functionality you are trying to implement is to bind the "special days" or "slots" from a DB-and that is exactly what is implemented in the Customized Time slots demo( even with additional ability to add and remove such time slots  from the time slot context menu).

     If the scenario you are trying to achieve is somehow different please let us know how exactly so we could be more helpful.

    Greetings,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 27 Nov 2012 Link to this post

    Heey 

    Here is the solution i got it by my self
    Code behind in UserScheduler 
    private List<DateTime> specialDays;
          //private readonly DateTime[] SpecialDays = new DateTime[] { new DateTime(2012, 12, 24), new DateTime(2012, 12, 25), new DateTime(2012, 12, 26), new DateTime(2012, 12, 27), new DateTime(2012, 12, 28), new DateTime(2012, 12, 29), new DateTime(2012, 12, 30), new DateTime(2012, 12, 31), new DateTime(2012, 1, 1), new DateTime(2012, 1, 2), };
          private List<DateTime> SpecialDays
          {
              get
              {
                  if (specialDays == null)
                  {
                      specialDays = PublicVacation.SpecialDays();
                  }
                  return specialDays;
              }
          }
      

    In my Model (PublicVacation.cs)

    public static List<DateTime> SpecialDays()
            {
                List<DateTime> result = new List<DateTime>();
                HolidayTrackerEntities ctx = HtEntityFactory.Context;
                foreach (PublicVacation pv in ctx.PublicVacations)
                {
                    if (string.IsNullOrEmpty(pv.RecurrenceRule))
                    {
                        DateTime StartDate = pv.FromDate.Value;
                        DateTime EndDate = pv.ToDate.Value;
     
                        while (StartDate < EndDate)
                        {
                            result.Add(StartDate);
                            StartDate = StartDate.AddDays(1);
                        }
                    }
     
    return result;


    Have Fun 
  10. Plamen
    Admin
    Plamen avatar
    2958 posts

    Posted 28 Nov 2012 Link to this post

    Hello Nikola,

     
    Thank you for sharing the solution of your scenario with the community and for your concern with RadControls.

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top