This is a migrated thread and some comments may be shown as answers.

Help: How to construct radscheduler programatically

0 Answers 69 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Mark de Torres
Top achievements
Rank 1
Mark de Torres asked on 29 Apr 2010, 02:05 PM

I am planning to construct Radscheduler in the "Class Detail Schedule" section. As you might can see from the code, other control is referencing user control. Is there anyway to build RadScheduler in the page without using user control. how it can be implemented and how to assign the datasource. thanks

 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DEET.StudentLearningProfile.CSharp.ClassLibrary;
using DEET.StudentLearningProfile.ViewPresenter.ClassManagement.Views;
using Microsoft.Practices.ObjectBuilder;
using NetTiers.Entities;
using Telerik.Web.UI;
using System.Globalization;
using System.Threading;

public partial class ClassManagement_Classes : Microsoft.Practices.CompositeWeb.Web.UI.Page,
                                             

DEET.StudentLearningProfile.ViewPresenter.ClassManagement.Views.IClasses
{
    #region Private members

    private ClassesPresenter presenter;

    #endregion

    [CreateNew]
    public ClassesPresenter Presenter
    {
        set
        {
           
            this.presenter = value;
            this.presenter.View = this;
        }
    }

    protected override void OnPreRender(EventArgs e)
    {
        //BuildSchedule();
        base.OnPreRender(e);
       
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            this.presenter.OnViewInitialized();
        }
        this.presenter.OnViewLoaded();
        BuildClass();
       
       
    }

    public List<ClassSchedulePeriod> ClassScheduleCollection
    {
        set
        {
            //RadScheduler1.DataSource = value;
        }
    }
    // Build class view regardless whether or not a schedule attached 
    public void BuildClass()
    {
        // Get all the class views associated with a given student ID
        // In here, class IDs will not be duplicated, it is one student ID to many class IDs relationship
        VList<NetTiers.Entities.VwStudentsByClass> data = presenter.GetAllClassesByStudentId();
        NetTiers.Services.SafeNameClassService classService = new NetTiers.Services.SafeNameClassService();

        // Get class IDs
        IList<long> classes = new List<long>();
        foreach (NetTiers.Entities.VwStudentsByClass aClass in data)
        {
            if (!classes.Contains(aClass.ClassId))
            {
                classes.Add(aClass.ClassId);
            }
        }

        Telerik.Web.UI.RadPanelBar panelBar = new Telerik.Web.UI.RadPanelBar();
        panelBar.Skin = "WebBlue";
        panelBar.ID = "panelBar";
        panelBar.Width = Unit.Percentage(97);

        foreach (long classId in classes)
        {
            // Going through one class at each loop

            // It is not necessary to retrieve the rows to tempData based on ClassId
            // Also it is not ncessary to calculate how many student groups a class has
            // However, here, it follows the coding style it already has
            /////////////////////////////////////////////////////////////////////////////////////////////
            VList<NetTiers.Entities.VwStudentsByClass> tempData = data.FindAll("ClassId", classId, true);
            IList<long> groups = new List<long>();

            // Find out how many student groups a class has
            foreach (NetTiers.Entities.VwStudentsByClass aClass in tempData)
            {
                if (!groups.Contains(aClass.StudentGroupId))
                {
                    groups.Add(aClass.StudentGroupId);               
                }
            }

            //
            if (groups.Count > 1)
            tempData = tempData.FindAll("StudentGroupId", groups[0], true);
          

            ////////////////////////////////////////////////////////////////////////////////////////////

 

            SafeNameClass currentClass = classService.GetByClassId(classId);
            classService.DeepLoad(currentClass);

            //modify the class name to set Uppercase letter
            CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
            TextInfo txtInfo = cultureInfo.TextInfo;

            RadPanelItem panelItem = new RadPanelItem(txtInfo.ToUpper(tempData[0].ClassName));
            panelItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold");
            panelItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontSize, "12px"); 
           

            // Expand the panel item
            panelItem.Expanded = false;
            panelItem.Value = "panelItem";
           

            System.Drawing.Color background = System.Drawing.Color.FromArgb(150, 120, 230);
           
            RadPanelItem classDetailsPanelItem = new RadPanelItem("Class Details");
            RadPanelItem classAssignmentPanelItem = new RadPanelItem("Class Assignment / Homework");
            RadPanelItem classNoticePanelItem = new RadPanelItem("Class Notices");
            RadPanelItem classSchedulePanelItem = new RadPanelItem("Class Schedule");
            RadPanelItem classDetailSchedulerPanelItem = new RadPanelItem("Class Detail Schedule");

            classDetailSchedulerPanelItem.BackColor = background;
            classDetailsPanelItem.BackColor = background;
            classNoticePanelItem.BackColor = background;
            classAssignmentPanelItem.BackColor = background;
            classSchedulePanelItem.BackColor = background;
            classDetailsPanelItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold");
            classSchedulePanelItem.Value = "template";

            ClassScheduleTemplate classScheduleTemp = new ClassScheduleTemplate();
           

classScheduleTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassSchedule.ascx"));

            ClassAssignmentTemplate classAssignmentTemp = new ClassAssignmentTemplate();
           

classAssignmentTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassAssignment.ascx"));

            ClassNoticeTemplate classNoticeTemp = new ClassNoticeTemplate();
           

classNoticeTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassNotices.ascx"));
           
            //ClassDetailsTemplate classDetailsTemp = new ClassDetailsTemplate();
           

//classDetailsTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassDetails.ascx"));
            //classDetailsTemp.ClassDetails(currentClass);

            classScheduleTemp.SetScheduleDataSource(presenter.GetClassScheduleByClassId(classId));
            classNoticeTemp.SetNoticesDataSource(presenter.GetClassNoticeByClassId(classId));
            classAssignmentTemp.SetAssignmentDataSource(presenter.GetAssignmentByClassId(classId));
            //this.presenter.GetTimetableDataSource((long)SessionObject.ManagedUserId);

            classAssignmentPanelItem.ItemTemplate = classAssignmentTemp;
            classSchedulePanelItem.ItemTemplate = classScheduleTemp;
            classNoticePanelItem.ItemTemplate = classNoticeTemp;
            //classDetailsPanelItem.ItemTemplate = classDetailsTemp;
            //classDetailSchedulerPanelItem.ItemTemplate = classScedulerViewTemp;

            //panelItem.Items.Add(classDetailsPanelItem);

            panelItem.Items.Add(classSchedulePanelItem);
            panelItem.Items.Add(classNoticePanelItem);
            panelItem.Items.Add(classAssignmentPanelItem);
            panelItem.Items.Add(classDetailSchedulerPanelItem);
            panelBar.Items.Add(panelItem);
        }

        ClassPlaceHolder.Controls.Add(panelBar);

    }

    // Build class view which has at least one schedule attached to it
    public void BuildSchedule()
    {
        // Not every class that a student belongs to has attached schedules.
        // Get all the ClassSchedule views associated with a given student ID
        // One class may have more than one schedule attached to it, so in this case, it considered as two different

views
        VList<NetTiers.Entities.VwStudentClassSchedule> data = presenter.GetClassByStudentId();
        NetTiers.Services.SafeNameClassService classService = new NetTiers.Services.SafeNameClassService();
       
        // Get class IDs, but only those classes have attached schedules
        // One class may have more than one attached schedule, this process will get rid of duplicates class IDs
        IList<long> classes = new List<long>();
        foreach(NetTiers.Entities.VwStudentClassSchedule schedule in data){
            if (!classes.Contains(schedule.ClassId))
            {
                classes.Add(schedule.ClassId);
            }
        }

        Telerik.Web.UI.RadPanelBar panelBar = new Telerik.Web.UI.RadPanelBar();
        panelBar.Skin = "WebBlue";
        panelBar.ID = "panelBar";
        panelBar.Width = Unit.Percentage(97);

        foreach (long classId in classes)
        {
            // Going through one class at each loop
            // In all the ClassSchedule views, extracting out the views associated with only the given class ID in

each loop
            //
            VList<NetTiers.Entities.VwStudentClassSchedule> tempData = data.FindAll("ClassId",classId,true);
            IList<long> groups = new List<long>();

            // Find out how many student groups a class has
            foreach (NetTiers.Entities.VwStudentClassSchedule schedule in tempData)
            {
                if (!groups.Contains(schedule.StudentGroupId))
                {
                    groups.Add(schedule.StudentGroupId);

                }
            }

            // Only get the first student group comes up
            if (groups.Count > 1)
            tempData = tempData.FindAll("StudentGroupId", groups[0], true);
          
            SafeNameClass currentClass = classService.GetByClassId(classId);
            classService.DeepLoad(currentClass);

            RadPanelItem panelItem = new RadPanelItem(tempData[0].ClassName);
           
            panelItem.Expanded = false;
            panelItem.Value = "panelItem";

            //System.Drawing.Color background = System.Drawing.Color.FromArgb(176, 196, 222);
            System.Drawing.Color background = System.Drawing.Color.FromArgb(150, 120, 230);
           
            RadPanelItem classDetailsPanelItem = new RadPanelItem("Class Details");
            RadPanelItem classAssignmentPanelItem = new RadPanelItem("Class Assignment / Homework");
            RadPanelItem classNoticePanelItem = new RadPanelItem("Class Notices");
            RadPanelItem classSchedulePanelItem = new RadPanelItem("Class Schedule");
            RadPanelItem classDetailSchedulerPanelItem = new RadPanelItem("Class Detail Schedule");

            classDetailSchedulerPanelItem.BackColor = background;
            classDetailsPanelItem.BackColor = background;
            classNoticePanelItem.BackColor = background;
            classAssignmentPanelItem.BackColor = background;
            classSchedulePanelItem.BackColor = background;
            classDetailsPanelItem.Attributes.CssStyle.Add(HtmlTextWriterStyle.FontWeight, "bold");
            classSchedulePanelItem.Value = "template";
           
            ClassScheduleTemplate classScheduleTemp = new ClassScheduleTemplate();
           

classScheduleTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassSchedule.ascx"));

            ClassAssignmentTemplate classAssignmentTemp = new ClassAssignmentTemplate();
           

classAssignmentTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassAssignment.ascx"));

            ClassNoticeTemplate classNoticeTemp = new ClassNoticeTemplate();
           

classNoticeTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassNotices.ascx"));

            //ClassDetailsTemplate classDetailsTemp = new ClassDetailsTemplate();
           

//classDetailsTemp.LoadUserControl(this.LoadControl("~/ClassManagement/Controls/StudentViewClassDetails.ascx"));
            //classDetailsTemp.ClassDetails(currentClass);

            //BuildClassScheduler();
           
            classScheduleTemp.SetScheduleDataSource(presenter.GetClassScheduleByClassId(classId));
            classNoticeTemp.SetNoticesDataSource(presenter.GetClassNoticeByClassId(classId));
            classAssignmentTemp.SetAssignmentDataSource(presenter.GetAssignmentByClassId(classId));
            //this.presenter.GetTimetableDataSource((long)SessionObject.ManagedUserId);

            classAssignmentPanelItem.ItemTemplate = classAssignmentTemp;
            classSchedulePanelItem.ItemTemplate = classScheduleTemp;
            classNoticePanelItem.ItemTemplate = classNoticeTemp;
            //classDetailsPanelItem.ItemTemplate = classDetailsTemp;
            //classDetailSchedulerPanelItem.ItemTemplate = classScedulerViewTemp;
            //panelItem.Items.Add(classDetailsPanelItem);
           
            panelItem.Items.Add(classNoticePanelItem);
            panelItem.Items.Add(classSchedulePanelItem);
            panelItem.Items.Add(classAssignmentPanelItem);
            panelItem.Items.Add(classDetailSchedulerPanelItem);

            panelBar.Items.Add(panelItem);
        }

        ClassPlaceHolder.Controls.Add(panelBar);
 
    }

    //public void BuildClassScheduler()
    //{
    //    RadScheduler clsScheduler = new RadScheduler();
    //    clsScheduler.DataSourceID = "";
    //    clsScheduler.DataStartField = "Start";
    //    clsScheduler.DataEndField = "End";
    //    clsScheduler.FirstDayOfWeek = DayOfWeek.Monday;
    //    clsScheduler.LastDayOfWeek = DayOfWeek.Sunday;
    //    clsScheduler.HoursPanelTimeFormat = "htt";
    //    clsScheduler.ValidationGroup="RadScheduler1";
    //    clsScheduler.DataSubjectField = "Subject";
    //    clsScheduler.DataRecurrenceField = "RecurrenceRule";
    //    clsScheduler.DataRecurrenceParentKeyField = "RecurrenceParentID";
    //    clsScheduler.Height = Unit.Pixel(600);
    //    clsScheduler.Width = Unit.Percentage(100);
    //    clsScheduler.SelectedView = SchedulerViewType.WeekView;
    //    clsScheduler.AllowDelete = false;
    //    clsScheduler.AllowEdit = false;
    //    clsScheduler.AllowInsert = false;
      

    //}
}

public class DownloadLinktemplate : ITemplate
{
    HyperLink dwnLink = new HyperLink();

    #region ITemplate Members

    public void InstantiateIn(Control container)
    {
        dwnLink.ID = "downloadLink";
        container.Controls.Add(dwnLink);
    }

    #endregion
}

public class ClassNoticeTemplate : ITemplate
{
    RadGrid noticesGrid = new RadGrid();
    Control c;

    public void InstantiateIn(Control container)
    {
        container.Controls.Add(c);
      
    }

    public void LoadUserControl(Control c)
    {
        this.c = c;
    }

    public void SetNoticesDataSource(TList<NetTiers.Entities.ClassNotice> data)
    {
        ((RadGrid)c.FindControl("ClassNoticeGrid")).ItemDataBound += noticesGrid_ItemDataBound;
        ((RadGrid)c.FindControl("ClassNoticeGrid")).DataSource = data;

    }

    #region Grid Events

    void noticesGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            ClassNotice currentClass = (ClassNotice)e.Item.DataItem;
            //UserInfo currentUser = (UserInfo)Session[EnumSessionVariables.UserInfo.ToString()];

            //bind the client script for launching the download
            if (currentClass.AttachedItem != null)
            {
                ((HyperLink)e.Item.FindControl("downloadLink")).ToolTip = "Download Attached File";
                ((HyperLink)e.Item.FindControl("downloadLink")).NavigateUrl = "filedownload.txt?" +

"tab=Classes&Notice=true&key=" +
                    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ClassNoticeId"] +
                    "&studentid=" + SessionObject.ManagedUserId + "&Notice=yes";
               
            }
            else
            {
                HyperLink downloadLink = e.Item.FindControl("downloadLink") as HyperLink;
                downloadLink.ImageUrl = "~/RadControls/Grid/Skins/Cancel.gif";
                downloadLink.ToolTip = "No attachment to download";
                downloadLink.Enabled = false;
            }
        }
    }

    #endregion

}

public class ClassAssignmentTemplate : ITemplate
{
    RadGrid assignmentGrid = new RadGrid();
    Control c;

    public void InstantiateIn(Control container)
    {
        container.Controls.Add(c);

    }

    public void LoadUserControl(Control c)
    {
        this.c = c;
    }

    public void SetAssignmentDataSource(TList<NetTiers.Entities.ClassAssignment> data)
    {
        ((RadGrid)c.FindControl("ClassAssignmentGrid")).ItemDataBound += classAssignmentGrid_ItemDataBound;
        ((RadGrid)c.FindControl("ClassAssignmentGrid")).DataSource = data;
    }

    #region Grid Events

    void classAssignmentGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            ClassAssignment currentClass = (ClassAssignment)e.Item.DataItem;
            //UserInfo currentUser = (UserInfo)Session[EnumSessionVariables.UserInfo.ToString()];

            //bind the client script for launching the download
            if (currentClass.Attachment != null)
            {
                ((HyperLink)e.Item.FindControl("downloadLink")).ToolTip = "Download Attached File";
                ((HyperLink)e.Item.FindControl("downloadLink")).NavigateUrl = "filedownload.txt?" +

"tab=Classes&Assignment=true&key=" +
                    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["AssignmentId"] +
                    "&studentid=" + SessionObject.ManagedUserId;
               
            }
            else
            {
                HyperLink downloadLink = e.Item.FindControl("downloadLink") as HyperLink;
                downloadLink.ImageUrl = "~/RadControls/Grid/Skins/Cancel.gif";
                downloadLink.ToolTip = "No attachment to download";
                downloadLink.Enabled = false;
            }
        }
    }
    #endregion

}

public class ClassScheduleTemplate : ITemplate
{

    #region ITemplate Members
    RadGrid scheduleGrid = new RadGrid();
    Control userControl;

    public void LoadUserControl(Control c)
    {
        userControl = c;
    }

    public void InstantiateIn(Control container)
    {
        container.Controls.Add(userControl);
    }

    public void SetScheduleDataSource(TList<NetTiers.Entities.ClassSchedule> data)
    {
        ((RadGrid)userControl.FindControl("ClassScheduleGrid")).DataSource = data;
        ((RadGrid)userControl.FindControl("ClassScheduleGrid")).ItemDataBound += new

GridItemEventHandler(classScheduleGrid_ItemDataBound);
    }

    void classScheduleGrid_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            ClassSchedule currentClass = (ClassSchedule)e.Item.DataItem;
            //UserInfo currentUser = (UserInfo)Session[EnumSessionVariables.UserInfo.ToString()];

            //bind the client script for launching the download
            if (currentClass.Attachment != null)
            {
                ((HyperLink)e.Item.FindControl("downloadLink")).ToolTip = "Download Attached File";
                ((HyperLink)e.Item.FindControl("downloadLink")).NavigateUrl = "filedownload.txt?" +

"tab=Classes&Schedule=true&key=" +
                    e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ClassTimeId"] +
                    "&studentid=" + SessionObject.ManagedUserId +"&Schedule=yes";

            }
            else
            {
                HyperLink downloadLink = e.Item.FindControl("downloadLink") as HyperLink;
                downloadLink.ImageUrl = "~/RadControls/Grid/Skins/Cancel.gif";
                downloadLink.ToolTip = "No attachment to download";
                downloadLink.Enabled = false;
            }
        }

    }

    #endregion

}

public class ClassDetailsTemplate : ITemplate
{
    TextBox classOwner = new TextBox();
    LinkButton sharedresource = new LinkButton();
    TextBox classDescription = new TextBox();
    Label description = new Label();
    Label owner = new Label();

    Control c;

    public void InstantiateIn(Control container)
    {

        container.Controls.Add(c);

    }

    public void LoadUserControl(Control c)
    {
        this.c = c;
    }

    public void ClassDetails(SafeNameClass currentClass)
    {
        ((TextBox)c.FindControl("txtClassdescription")).Text = currentClass.ClassDescription;
        ((TextBox)c.FindControl("txtClassOwner")).Text = string.Format("{0} {1}",

currentClass.UserCreatedSource.FirstName, currentClass.UserCreatedSource.Surname);
        if (currentClass.ResourceSiteUrl == null)
        {
            ((HyperLink)c.FindControl("resourceSiteLnk")).Visible = false;
        }
        else
        {
            ((HyperLink)c.FindControl("resourceSiteLnk")).NavigateUrl = currentClass.ResourceSiteUrl;
        }
    }

}

 

 

No answers yet. Maybe you can help?

Tags
Scheduler
Asked by
Mark de Torres
Top achievements
Rank 1
Share this question
or