How to group a Generic List through databinding in RadScheduler

2 posts, 0 answers
  1. Blaine
    Blaine avatar
    1 posts
    Member since:
    May 2013

    Posted 05 Oct 2015 Link to this post

    Hi there,


    I have tried to follow the demo you have online to produce a "schedule" of activity by databinding a list to the RadScheduler datasource. I would like to have these activities grouped by employee.


    However, i can either display my list as I wish to in your scheduler but I can not use the groupheader OR I can use the groupheader but none of my activities display. Please find enclosed my code.


    Thank you,

     

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ActivityDP.ascx.cs" Inherits="ActivityDP" %>
    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>
    <telerik:RadSkinManager ID="RadSkinManager1" Runat="server">
    </telerik:RadSkinManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Runat="server" 
        Skin="Default">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" height="337px" 
        width="1147px">
        <div class="demo-container no-bg">
            <telerik:RadScheduler ID="RadScheduler1" runat="server" GroupBy="Employee" GroupingDirection="Horizontal"
                    OnNavigationCommand="RadScheduler1_NavigationCommand" DataSourceID="EventsDataSource"
                    AppointmentStyleMode="Default" Subject="Subject"
                    FirstDayOfWeek="Monday" LastDayOfWeek="Sunday" 
                    DataStartField="StartTime" DataEndField="FinishTime" 
                    SelectedView="DayView" 
                    OverflowBehavior="Auto" DataKeyField="EmployeeID">
                <AdvancedForm Modal="true"></AdvancedForm>
                <MonthView UserSelectable="false"></MonthView>
                <TimelineView />
                <%--<ResourceHeaderTemplate>
                    <asp:Panel ID="ResourceImageWrapper" runat="server" CssClass="ResCustomClass">
                        <asp:Image ID="SpeakerImage" runat="server" AlternateText='<%# Eval("Text") %>'></asp:Image>
                    </asp:Panel>
                </ResourceHeaderTemplate>--%>
                <ResourceTypes>
                    <telerik:ResourceType KeyField="EmployeeID" Name="Employee" TextField="Employee" ForeignKeyField="EmployeeID"
                        DataSourceID="SpeakersDataSource"></telerik:ResourceType>
                </ResourceTypes>
    <%--            <ResourceStyles>
                    <telerik:ResourceStyleMapping Type="Employee" Key="1" BackColor="#eb901b"></telerik:ResourceStyleMapping>
                    <telerik:ResourceStyleMapping Type="Employee" Key="2" BackColor="#8fd21b"></telerik:ResourceStyleMapping>
                    <telerik:ResourceStyleMapping Type="Employee" Key="3" BackColor="#278ce9"></telerik:ResourceStyleMapping>
                    <telerik:ResourceStyleMapping Type="Employee" Key="4" BackColor="#f14db2"></telerik:ResourceStyleMapping>
                </ResourceStyles>--%>
                <TimeSlotContextMenuSettings EnableDefault="true"></TimeSlotContextMenuSettings>
                <AppointmentContextMenuSettings EnableDefault="true"></AppointmentContextMenuSettings>
            </telerik:RadScheduler>
        </div>
    </telerik:RadAjaxPanel>
     <asp:SqlDataSource ID="SpeakersDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:Mailshop2kSQLConnectionString %>" SelectCommand="SELECT DISTINCT tblEmployee.EmployeeID, tblJobLogDP.Employee FROM tblEmployee INNER JOIN tblJobLogDP ON tblEmployee.FirstName = tblJobLogDP.Employee ORDER BY tblJobLogDP.Employee;"
            >
        </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 System.Data;
    using System.Windows.Forms;

    public partial class ActivityDP : System.Web.UI.UserControl
    {

        private const string ProviderSessionKey = "Telerik.Web.Examples.Scheduler.XmlSchedulerProvider.ActivityLog";
        private const string AppointmentsKey = "Telerik.Examples.Scheduler.BindToList_Apts";
        private DataSet ds = new DataSet();

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                HttpContext.Current.Session.Remove(AppointmentsKey);
                RadScheduler1.DataKeyField = "ID";
                RadScheduler1.DataStartField = "Start";
                RadScheduler1.DataEndField = "End";
                RadScheduler1.DataSubjectField = "Subject";
                RadScheduler1.DataRecurrenceField = "RecurrenceRule";
                RadScheduler1.DataRecurrenceParentKeyField = "RecurrenceParentID";
                ResourceType rt = new ResourceType("Room");
                rt.DataSource = Rooms;
                rt.KeyField = "RoomNo";
                rt.ForeignKeyField = "RoomNo";
                rt.TextField = "RoomName";
                RadScheduler1.ResourceTypes.Add(rt);
            }
            RadScheduler1.GroupBy = "Employee";
            RadScheduler1.Rebind();
            //MessageBox.Show(RadScheduler1.SelectedDate.ToString());
            DateTime sd = new DateTime(RadScheduler1.SelectedDate.Year, RadScheduler1.SelectedDate.Month, RadScheduler1.SelectedDate.Day);
            ActivityL a = new ActivityL();
            //ds = a.getDaysActivityWarehouse(sd.ToString("yyyy/MM/dd"));
            ds = a.getDaysDataProcessing(sd.ToString("yyyy/MM/dd"));
            //RadScheduler1.DataSource = Appointments;

        }

        private List<AppointmentInfo> Appointments
        {
            get
            {
                //List<AppointmentInfo> sessApts = HttpContext.Current.Session[AppointmentsKey] as List<AppointmentInfo>;
                List<AppointmentInfo> sessApts = new List<AppointmentInfo>();

                for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++)
                {
                    AppointmentInfo ai = new AppointmentInfo(ds.Tables[0].Rows[i][0].ToString() + " : " + ds.Tables[0].Rows[i][4].ToString() + "-" + ds.Tables[0].Rows[i][5].ToString() + Environment.NewLine + Environment.NewLine + ds.Tables[0].Rows[i][6].ToString());
                    DateTime value = new DateTime(DateTime.Parse(ds.Tables[0].Rows[i][2].ToString()).Year, DateTime.Parse(ds.Tables[0].Rows[i][2].ToString()).Month, DateTime.Parse(ds.Tables[0].Rows[i][2].ToString()).Day, DateTime.Parse(ds.Tables[0].Rows[i][2].ToString()).Hour, DateTime.Parse(ds.Tables[0].Rows[i][2].ToString()).Minute, DateTime.Parse(ds.Tables[0].Rows[i][2].ToString()).Second);
                    ai.Start = value;
                    //MessageBox.Show(ds.Tables[0].Rows[i][3].ToString());
                    var temp = DateTime.Now;
                    if ((!DBNull.Value.Equals(ds.Tables[0].Rows[i][3].ToString())) && (ds.Tables[0].Rows[i][3].ToString().Length > 0))
                    {
                       // MessageBox.Show(ds.Tables[0].Rows[i][3].ToString());
                        temp = DateTime.Parse(ds.Tables[0].Rows[i][3].ToString());
                    }
                    else
                    {
                        temp = DateTime.Now;
                    }
                    DateTime valuee = new DateTime(temp.Year, temp.Month, temp.Day, temp.Hour, temp.Minute, temp.Second);
                    ai.End = valuee;
                    ai.ID = ds.Tables[0].Rows[i][7].ToString();
                    ai.RoomNo = assignCSR(ds.Tables[0].Rows[i][0].ToString());
                    ai.RecurrenceParentID = i.ToString();
                    ai.EmployeeID = ds.Tables[0].Rows[i][8].ToString();
                    sessApts.Add(ai);
                }

                if (sessApts == null)
                {
                    sessApts = new List<AppointmentInfo>();
                    HttpContext.Current.Session[AppointmentsKey] = sessApts;
                }
                return sessApts;
            }
        }

        protected void RadScheduler1_NavigationCommand(object sender, SchedulerNavigationCommandEventArgs e)
        {
            if (e.Command == SchedulerNavigationCommand.SwitchToTimelineView)
            {
                RadScheduler1.RowHeight = 50;

            }
            else
            {
                RadScheduler1.RowHeight = 20;
            }

        }


        private int assignCSR(string name)
        {
            switch (name)
            {
                case "Tony":
                    return 1;
                case "Sean":
                    return 2;
                case "Larry":
                    return 3;
                case "Jerry":
                    return 4;
                case "Jacquie":
                    return 5;
                default:
                    return 6;
            }
        }

        private List<RoomInfo> Rooms
        {
            get
            {
                List<RoomInfo> roomList = new List<RoomInfo>();
                roomList.Add(new RoomInfo(1, "Tony"));
                roomList.Add(new RoomInfo(2, "Sean"));
                roomList.Add(new RoomInfo(3, "Larry"));
                roomList.Add(new RoomInfo(4, "Jerry"));
                roomList.Add(new RoomInfo(5, "Jacquie"));
                roomList.Add(new RoomInfo(6, "Blaine"));
                return roomList;
            }
        }

        private AppointmentInfo FindById(string ID)
        {
            foreach (AppointmentInfo ai in Appointments)
            {
                if (ai.ID == ID)
                {
                    return ai;
                }
            }
            return null;
        }

        //protected void RadScheduler1_DataBound(object sender, EventArgs e)
        //{
        //    // Turn off the support for multiple resource values.
        //    foreach (ResourceType resType in RadScheduler1.ResourceTypes)
        //    {
        //        resType.AllowMultipleValues = false;
        //    }
        //}

        //protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)
        //{
        //    if (e.Appointment.RecurrenceState == RecurrenceState.Master || e.Appointment.RecurrenceState == RecurrenceState.Occurrence)
        //    {
        //        Panel recurrenceStateDiv = new Panel();
        //        recurrenceStateDiv.CssClass = "rsAptRecurrence";
        //        e.Container.Controls.AddAt(0, recurrenceStateDiv);
        //    }
        //    if (e.Appointment.RecurrenceState == RecurrenceState.Exception)
        //    {
        //        Panel recurrenceStateDiv = new Panel();
        //        recurrenceStateDiv.CssClass = "rsAptRecurrenceException";
        //        e.Container.Controls.AddAt(0, recurrenceStateDiv);
        //    }
        //}
        protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
        {
            Appointments.Add(new AppointmentInfo(e.Appointment));
        }
        protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
        {
            AppointmentInfo ai = FindById(e.ModifiedAppointment.ID.ToString());
            ai.CopyInfo(e.ModifiedAppointment);
        }
        protected void RadScheduler1_AppointmentDelete(object sender, AppointmentDeleteEventArgs e)
        {
            Appointments.Remove(FindById(e.Appointment.ID.ToString()));
        }


    }

     

     

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Web.UI;
    using System.Data.OleDb;
    using System.Data;

    /// <summary>
    /// Summary description for AppointmentInfo
    /// </summary>
    public class AppointmentInfo
       {
           private string id;
           private string subject;
           private DateTime start;
           private DateTime end;
           private string recurParentID;
           private string recurData;
           private int room;
           private string employeeID;

           public string EmployeeID
           {
               get { return employeeID; }
               set { employeeID = value; }
           }
           public string ID
           {
               get { return id; }
               set { id = value; }
           }
           public string Subject
           {
               get { return subject; }
               set { subject = value; }
           }
           public DateTime Start
           {
               get { return start; }
               set { start = value; }
           }
           public DateTime End
           {
               get { return end; }
               set { end = value; }
           }
           public string RecurrenceRule
           {
               get { return recurData; }
               set { recurData = value; }
           }
           public string RecurrenceParentID
           {
               get { return recurParentID; }
               set { recurParentID = value; }
           }
           public int RoomNo
           {
               get { return room; }
               set { room = value; }
           }
           private AppointmentInfo()
           {
               this.id = Guid.NewGuid().ToString();
           }

           public AppointmentInfo(string subject, DateTime start, DateTime end)
               : this()
           {
               this.subject = subject;
               this.start = start;
               this.end = end;
           }

           public AppointmentInfo(string subject)
               : this()
           {
               this.subject = subject;
           }
           public AppointmentInfo(Appointment source)
               : this()
           {
               CopyInfo(source);
           }
           public void CopyInfo(Appointment source)
           {
               subject = source.Subject;
               start = source.Start;
               end = source.End;
               recurData = source.RecurrenceRule;
               if (source.RecurrenceParentID != null)
                  recurParentID = source.RecurrenceParentID.ToString();
               Resource r = source.Resources.GetResourceByType("Room");
               if (r != null)
                   room = (int) r.Key;
           }

           

           public void getDaysActivityWarehouse()
           {
               OleDbConnection con = new OleDbConnection();
               OleDbDataAdapter da = default(OleDbDataAdapter);
               DataSet ds = new DataSet();
               //con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\\Program Files\\Mail-Shop\\MSApp2k.mdb";
               con.ConnectionString = "Provider=SQLOLEDB;Data Source=192.168.1.100,1433;Database=Mailshop2kSQL;Uid=sa;Pwd=1idrs!temp99;";
               con.Open();

               string sql = "SELECT tblEmployee.FirstName, tblJobCost.JobDate, tblJobCost.StartTime, tblJobCost.StopTime " +
                            "FROM (tblJobCostEmployee INNER JOIN tblJobCost ON tblJobCostEmployee.JobCostID = tblJobCost.JobCostID) INNER JOIN tblEmployee ON tblJobCostEmployee.EmployeeID = tblEmployee.EmployeeID " +
                            "WHERE (((tblJobCost.JobDate)='9/30/2015')) " +
                            "ORDER BY tblEmployee.FirstName;";
               da = new OleDbDataAdapter(sql, con);
               da.Fill(ds, "stats");
               con.Close();

          }



           class RoomInfo
           {
               private int id;
               private string name;
               public int RoomNo
               {
                   get { return id; }
               }
               public string RoomName
               {
                   get { return name; }
               }
               public RoomInfo(int id, string name)
               {
                   this.id = id;
                   this.name = name;
               }
           }
    }

     ​​

  2. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 08 Oct 2015 Link to this post

    Hello,

    I am attaching the code that worked correctly at my side.

    Hope this will help you solve the issue.

    Regards,
    Plamen
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top