HttpContext.Current.Session is null in class MyDbSchedulerProvider

4 posts, 0 answers
  1. Khi
    Khi avatar
    2 posts
    Member since:
    Jan 2011

    Posted 26 Jan 2011 Link to this post

    I'm using The Q3 2010 Scheduler control with a Web Service data source, in  class MyDbSchedulerProvider
     public override IEnumerable<Appointment> GetAppointments(RadScheduler owner)
     {
          User objUser = (User)HttpContext.Current.Session["User"];
    }

    in function GetAppointments i'm use object HttpContext.Current.Session, Minor run all good when !isPosback, but when my execute event Update then HttpContext.Current.Session is null.
    please help me.
    thanks!



    using System;
    using System.Collections.Generic;
    using System.Data.Common;
    using System.Data.SqlClient;
    using Telerik.Web.UI;
    using WebLibs;
    using System.Data;
    using EWorking.Scheduler;
    using EWorking.CRM;
    using HRMS.Utility;
    using System.Web;
    using System.Web.Services;
    using System.Web.SessionState;

    namespace EWorking.Scheduler
    {
        public class MyDbSchedulerProvider : DbSchedulerProviderBase  
        {
            private string strUsername = string.Empty;

            public string Username
            {
                get { return strUsername; }
                set { strUsername = value; }
            }

            private IDictionary<int, Resource> _teachers;
            private IDictionary<int, Resource> _students;

            private IDictionary<int, Resource> Teachers
            {
                get
                {
                    if (_teachers == null)
                    {
                        _teachers = new Dictionary<int, Resource>();
                        foreach (Resource teacher in LoadTeachers())
                        {
                            _teachers.Add((int)teacher.Key, teacher);
                        }
                    }

                    return _teachers;
                }
            }

            private IDictionary<int, Resource> Students
            {
                get
                {
                    _students = new Dictionary<int, Resource>();
                    foreach (Resource student in LoadStudents())
                    {
                        _students.Add((int)student.Key, student);
                    }

                    return _students;
                }
            }

            public MyDbSchedulerProvider()
            {
            }

            public MyDbSchedulerProvider(string strUser)
            {
                Username = strUser;
            }

            public override IEnumerable<Appointment> GetAppointments(RadScheduler owner)
            {
                List<Appointment> appointments = new List<Appointment>();
                IData objData = new IData();
                try
                {
                    objData.Connect();
                    SCHAppointment objApp = new SCHAppointment();
                    objApp.DataObject = objData;
                    int intStatus = 1;
                    if (HttpContext.Current.Session["MD_Scheduler_Status"] != null)
                        intStatus = Convert.ToInt16(HttpContext.Current.Session["MD_Scheduler_Status"]);
                    IDataReader objReader = objApp.GetList(Username, intStatus, "");
                    owner.Culture = ResxManager.CurrentCultureInfo;
                    using (IDataReader reader = objReader)
                    {
                        while (reader.Read())
                        {
                            Appointment apt = owner.CreateAppointment();
                            apt.Owner = owner;
                            apt.ID = reader["AppID"];
                            apt.Subject = Convert.ToString(reader["Subject"]);
                            apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader["Start"]), DateTimeKind.Utc);
                            apt.End = DateTime.SpecifyKind(Convert.ToDateTime(reader["End"]), DateTimeKind.Utc);
                            apt.RecurrenceRule = Convert.ToString(reader["RecurrenceRule"]);
                            apt.RecurrenceParentID = reader["RecurrenceParentId"] == DBNull.Value ? null : reader["RecurrenceParentId"];

                            if (apt.RecurrenceParentID != null)
                            {
                                apt.RecurrenceState = RecurrenceState.Exception;
                            }
                            else
                                if (apt.RecurrenceRule != string.Empty)
                                {
                                    apt.RecurrenceState = RecurrenceState.Master;
                                }
                            //apt.BackColor = System.Drawing.Color.Red;
                            //apt.BorderColor = System.Drawing.Color.Blue;

                            //apt.ForeColor = System.Drawing.Color.Red;
                            //apt.Owner.Height = System.Web.UI.WebControls.Unit.Pixel(100);

                            //LoadResources(apt);
                            appointments.Add(apt);
                        }
                    }
                }
                catch
                {
                }
                finally
                {
                    objData.DeConnect();
                }
                return appointments;
            }

            public void UpdateFull(int intAppID, string strSubject, DateTime dtmStart, DateTime dtmEnd, string strRecurrenceRule, int intRecurrenceParentID, bool bolShareAll, string strPlace, int intProcess, int intPriority, int intType, bool bolGroup, string strOwnerUsername, string strObjectName, int intAccountID, string strLstContact, int intEntityID, int intOwner, bool bolExistCRM, string strUserShare, int intMaxUserShare)
            {
                string str = Username;
                MySchedulerInfo objS = new MySchedulerInfo();
                
                IDbTransaction objTran = null;
                IData objData = new IData();
                SCHAppointment objMain = new SCHAppointment();
                try
                {

                    objData.Connect();
                    WebLibs.User objUser = (WebLibs.User)HttpContext.Current.Session["User"];
                    objMain.AppID = intAppID;
                    if (objMain.LoadByPrimaryKeys())
                    {
                        objMain.Subject = strSubject;
                        objMain.Start = dtmStart;
                        objMain.End = dtmEnd;
                        objMain.RecurrenceRule = strRecurrenceRule;
                        objMain.RecurrenceParentID = intRecurrenceParentID;

                        objTran = objData.GetConnection().BeginTransaction();
                        objData.Transaction = objTran;
                        objMain.DataObject = objData;
                        objMain.Username = objUser.strUsername;
                        objMain.IsShareAll = bolShareAll;
                        objMain.UserShare = strUserShare;
                        objMain.MaxUsesrShare = intMaxUserShare;
                        objMain.Place = strPlace;
                        if (intProcess > 0)
                            objMain.ProgressID = intProcess;

                        objMain.PriorityID = intPriority;
                        objMain.AppType = intType;
                        if (bolExistCRM && intEntityID > 0)
                        {
                            CRMENTITIES objEntity = new CRMENTITIES();
                            objEntity.DataObject = objData;
                            objEntity.CREATEDUSER = objUser.strUsername;
                            if (!bolGroup)
                            {
                                GlobalFunction objFun = new GlobalFunction();
                                if (strOwnerUsername != "")
                                    objEntity.OWNERID = Convert.ToInt32(objFun.GetUserInfo(strOwnerUsername).Rows[0]["UserID"]);
                            }
                            else
                                if (intOwner > 0)
                                    objEntity.OWNERID = intOwner;

                            objEntity.MODULEID = CRMENTITIES.Activity;
                            objMain.EntityID = Convert.ToInt32(objEntity.Insert());
                            CRMRELATEDLIST objRELATEDLIST = new CRMRELATEDLIST();
                            objRELATEDLIST.DataObject = objData;
                            if (strObjectName != "")
                            {
                                objMain.RELATEDENTITYID = intAccountID;
                                objMain.RELATEDENTITYNAME = strObjectName;
                            }
                            string[] arrContact = strLstContact.Split(',');
                            for (int i = 0; i < arrContact.Length; i++)
                            {
                                objRELATEDLIST.ENTITYID = objMain.EntityID;
                                objRELATEDLIST.RELATEDENTITYID = Convert.ToInt32(arrContact[i]);
                                objRELATEDLIST.Insert();
                            }
                            objRELATEDLIST.ENTITYID = objMain.EntityID;
                            objRELATEDLIST.RELATEDENTITYID = intEntityID;
                            objRELATEDLIST.Insert();
                        }
                        objMain.Update();
                        if (!AddGuest(intAppID, objData, objMain.IsShareAll, objMain.UserShare, objMain.MaxUsesrShare))
                        {
                            objTran.Rollback();
                            return;
                        }
                        objTran.Commit();
                    }
                }
                catch
                {
                    objTran.Rollback();
                }
                finally
                {
                    objData.DeConnect();
                }
                //Cache.Remove("Widget_Scheduler_" + User.strUsername);
            }   

            private string LoadShare(int intAppID)
            {
                string strResult = "";
                try
                {
                    SCHAppointmentShare objAppShare = new SCHAppointmentShare();
                    DataTable dt = new DataTable();
                    dt = objAppShare.GetByID(intAppID);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        strResult += "<div><input checked='checked' type='checkbox' name='chkUserSharer' value='" + dt.Rows[i]["Username"] + "' />" + dt.Rows[i]["Username"] + " - " + dt.Rows[i]["Fullname"] + "</div>";
                    }
                }
                catch (Exception objEx)
                {
                    new SystemMessage("L?i khi l?y danh sách User du?c share!", "", "Controls_MD_Scheduler_Appointment.LoadShare(int intAppID)<br />ERROR: " + objEx.ToString());
                }
                return strResult;
            }
            public string[] GetData(int intAppID, bool ExistCRM)
            {
                string[] arrResult = new string[13];
                try
                {
                    SCHAppointment objMain = new SCHAppointment();
                    objMain.AppID = intAppID;

                    if (objMain.LoadByPrimaryKeys())
                    {
                        //LoadDiscuss(objMain.AppID);
                        //LoadInfoUser(objMain.AppID);
                        arrResult[0] = objMain.IsShareAll.ToString().ToLower();
                        arrResult[1] = objMain.Place;
                        if (objMain.ProgressID > 0)
                            arrResult[2] = objMain.ProgressID.ToString();
                        if (objMain.PriorityID > 0)
                            arrResult[3] = objMain.PriorityID.ToString();
                        if (objMain.AppType > 0)
                        {
                            arrResult[4] = objMain.AppType.ToString();
                        }

                        if (objMain.EntityID > 0 && ExistCRM)
                        {
                            CRMENTITIES objEntity = new CRMENTITIES();
                            objEntity.ENTITYID = objMain.EntityID;
                            if (objEntity.LoadByPrimaryKeys())
                            {
                                arrResult[11] = objEntity.UserType.ToString();
                                if (objEntity.UserType)
                                    arrResult[7] = objEntity.OWNERID.ToString();
                                else
                                {
                                    arrResult[5] = objEntity.Username;
                                    arrResult[6] = objEntity.Fullname;
                                }
                            }
                            CRMRELATEDLIST objRELATEDLIST = new CRMRELATEDLIST();
                            DataTable dtContactList = objRELATEDLIST.GetRelatedList(objMain.EntityID, CRMENTITIES.Contact);
                            for (int i = 0; i < dtContactList.Rows.Count; i++)
                            {
                                //if (lstContact.Items.FindByValue(dtContactList.Rows[i]["ContactID"].ToString()) == null && lstContact.Items.FindByValue(intEntityID.ToString()) == null)
                                //    lstContact.Items.Add(new ListItem(dtContactList.Rows[i]["Firstname"] + " " + dtContactList.Rows[i]["Lastname"], dtContactList.Rows[i]["ContactID"].ToString()));
                            }
                            arrResult[8] = objMain.RELATEDENTITYNAME;//objectName
                            arrResult[9] = objMain.RELATEDENTITYID.ToString();//EntityID
                            objEntity = new CRMENTITIES();
                            objEntity.ENTITYID = objMain.RELATEDENTITYID;
                            if (objEntity.LoadByPrimaryKeys())
                                arrResult[10] = objEntity.MODULEID.ToString();//ddlObject
                        }
                        arrResult[12] = LoadShare(objMain.AppID);

                        //if (drw.Length > 0)
                        //{
                        //    if (Convert.ToBoolean(drw[0]["IsShared"]))
                        //    {
                        //        string strDivButtonID = rsdMain.ClientID + "_Form_UpdateButton";
                        //        ScriptManager.RegisterStartupScript(Page, typeof(string), "", "document.getElementById('" + strDivButtonID + "').style.display = 'none';", true);
                        //        Page.ClientScript.RegisterStartupScript(typeof(string), "CloseButtonPanel", "document.getElementById('" + strDivButtonID + "').style.display = 'none';", true);
                        //        isShare = 1;
                        //        pnlProgress.Enabled = false;
                        //    }
                        //    else
                        //    {
                        //        isShare = 0;
                        //        pnlProgress.Enabled = true;
                        //    }
                        //    ScriptManager.RegisterStartupScript(Page, typeof(string), "toggleAll", "toggleAll('" + isShare + "')", true);
                        //    updProgress.Update();
                        //}
                    }
                }
                catch
                {
                }
                return arrResult;
            }
            public static void UpdateUserShareData(string strUser, bool IsChecked)
            {
                if (HttpContext.Current.Session["SCH_UserShareData"] != null)
                {
                    DataTable dt = (DataTable)HttpContext.Current.Session["SCH_UserShareData"];
                    DataRow[] arr = dt.Select("[Tên TK]='" + strUser + "'");
                    if (arr.Length > 0)
                        arr[0]["Checked"] = IsChecked;
                    HttpContext.Current.Session["SCH_UserShareData"] = dt;
                }
            }
            public void InsertFull(string strSubject, DateTime dtmStart, DateTime dtmEnd, string strRecurrenceRule, int intRecurrenceParentID, bool bolShareAll, string strPlace, int intProcess, int intPriority, int intType, bool bolGroup, string strOwnerUsername, string strObjectName, int intAccountID, string strLstContact, int intEntityID, int intOwner, bool bolExistCRM, string strUserShare, int intMaxUserShare)
            {
                string str = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();

                IDbTransaction objTran = null;
                IData objData = new IData();
                SCHAppointment objMain = new SCHAppointment();
                try
                {
                    objData.Connect();
                    WebLibs.User objUser = (WebLibs.User)HttpContext.Current.Session["User"];

                    objMain.Subject = strSubject;
                    //objMain.Start = dtmStart.AddHours(intTimeZone);
                    //objMain.End = dtmEnd.AddHours(intTimeZone);
                    objMain.Start = dtmStart;
                    objMain.End = dtmEnd;
                    objMain.RecurrenceRule = strRecurrenceRule;
                    objMain.RecurrenceParentID = intRecurrenceParentID;

                    objTran = objData.GetConnection().BeginTransaction();
                    objData.Transaction = objTran;
                    objMain.DataObject = objData;
                    objMain.Username = objUser.strUsername;
                    objMain.IsShareAll = bolShareAll;
                    objMain.UserShare = strUserShare;
                    objMain.MaxUsesrShare = intMaxUserShare;
                    objMain.Place = strPlace;
                    if (intProcess > 0)
                        objMain.ProgressID = intProcess;

                    objMain.PriorityID = intPriority;
                    objMain.AppType = intType;
                    if (bolExistCRM && intEntityID > 0)
                    {
                        CRMENTITIES objEntity = new CRMENTITIES();
                        objEntity.DataObject = objData;
                        objEntity.CREATEDUSER = objUser.strUsername;
                        if (!bolGroup)
                        {
                            GlobalFunction objFun = new GlobalFunction();
                            if (strOwnerUsername != "")
                                objEntity.OWNERID = Convert.ToInt32(objFun.GetUserInfo(strOwnerUsername).Rows[0]["UserID"]);
                        }
                        else
                            if (intOwner > 0)
                                objEntity.OWNERID = intOwner;

                        objEntity.MODULEID = CRMENTITIES.Activity;
                        objMain.EntityID = Convert.ToInt32(objEntity.Insert());
                        CRMRELATEDLIST objRELATEDLIST = new CRMRELATEDLIST();
                        objRELATEDLIST.DataObject = objData;
                        if (strObjectName != "")
                        {
                            objMain.RELATEDENTITYID = intAccountID;
                            objMain.RELATEDENTITYNAME = strObjectName;
                        }
                        string[] arrContact = strLstContact.Split(',');
                        for (int i = 0; i < arrContact.Length; i++)
                        {
                            objRELATEDLIST.ENTITYID = objMain.EntityID;
                            objRELATEDLIST.RELATEDENTITYID = Convert.ToInt32(arrContact[i]);
                            objRELATEDLIST.Insert();
                        }
                        objRELATEDLIST.ENTITYID = objMain.EntityID;
                        objRELATEDLIST.RELATEDENTITYID = intEntityID;
                        objRELATEDLIST.Insert();
                    }
                    int intResult = Convert.ToInt32(objMain.Insert());
                    if (intResult > 0)
                    {
                        if (!AddGuest(intResult, objData, objMain.IsShareAll, objMain.UserShare, objMain.MaxUsesrShare))
                        {
                            objTran.Rollback();
                            return;
                        }
                    }
                    objTran.Commit();
                }
                catch
                {
                    objTran.Rollback();
                }
                finally
                {
                    objData.DeConnect();
                }
                //Cache.Remove("Widget_Scheduler_" + User.strUsername);
            }
            public static void DeleteFull(int intAppID)
            {
                try
                {
                    SCHAppointment objMain = new SCHAppointment();
                    objMain.AppID = intAppID;
                    WebLibs.User objUser = (WebLibs.User)HttpContext.Current.Session["User"];
                    if (objMain.LoadByPrimaryKeys())
                        if (objMain.Username != objUser.strUsername)
                        {
                            SCHAppointmentShare objShare = new SCHAppointmentShare();
                            objShare.AppID = intAppID;
                            objShare.Username = objUser.strUsername;
                            objShare.Delete();

                        }
                        else
                            objMain.Delete();
                }
                catch (Exception objEx)
                {
                    new SystemMessage("L?i khi xoá s? ki?n!", "", "Controls_MD_Scheduler_Appointment.DoDelete(int intAppID)<br />ERROR: " + objEx.ToString());
                }
            }

            public override void Insert(RadScheduler owner, Appointment appointment)
            {
                //if (!PersistChanges)
                //{
                //    return;
                //}
                //if (appointment.Start > appointment.End)
                //{
                //    return;
                //}
                //if (appointment.Subject.Length < 1)
                //{
                //    return;
                //}

                //IDbTransaction objTran = null;
                //IData objData = new IData();
                //SCHAppointment objMain = new SCHAppointment();
                //try
                //{
                //    objData.Connect();
                //    WebLibs.User objUser = (WebLibs.User)HttpContext.Current.Session["User"];
                //    objTran = objData.GetConnection().BeginTransaction();
                //    objData.Transaction = objTran;
                //    objMain = (SCHAppointment)HttpContext.Current.Session["Appointment_Data"];
                //    objMain.DataObject = objData;

                //    objMain.Subject = appointment.Subject;
                //    objMain.Start = appointment.Start;
                //    objMain.End = appointment.End;
                //    objMain.RecurrenceRule = appointment.RecurrenceRule;
                //    objMain.RecurrenceParentID = Convert.ToInt32(appointment.RecurrenceParentID);

                //    int intResult = Convert.ToInt32(objMain.Insert());
                //    if (intResult > 0)
                //    {
                //        if (!AddGuest(intResult, objData, objMain.IsShareAll, objMain.UserShare, objMain.MaxUsesrShare))
                //        {
                //            objTran.Rollback();
                //            return;
                //        }
                //    }

                //    objTran.Commit();
                //}
                //catch
                //{
                //    objTran.Rollback();
                //}
                //finally
                //{
                //    objData.DeConnect();
                //}
            }
            /// <summary>
            /// Thêm ngu?i chia s? 1 s? ki?n
            /// </summary>
            /// <param name="intAppID"></param>
            private bool AddGuest(int intAppID, IData objData, bool bolShareAll, string strListUserGroup, int intMaxSharedUser)
            {
                SCHAppointmentShare objAppShare = new SCHAppointmentShare();
                objAppShare.DataObject = objData;
                try
                {
                    objAppShare.AppID = intAppID;
                    objAppShare.DeleteAll();
                }
                catch
                { }
                if (!bolShareAll)
                {
                    int iCountUser = 0;
                    string[] arrUserGroup = strListUserGroup.Split(',');
                    iCountUser = arrUserGroup.Length;

                    if (bolShareAll || iCountUser <= intMaxSharedUser)
                    {
                        if (arrUserGroup != null)
                        {
                            foreach (string strItem in arrUserGroup)
                            {
                                if (strItem != "")
                                {
                                    objAppShare.AppID = intAppID;
                                    objAppShare.Username = strItem;
                                    if (!objAppShare.LoadByPrimaryKeys())
                                        objAppShare.Insert();
                                }
                            }
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                return true;
            }


            public override void Update(RadScheduler owner, Appointment appointment)
            {
                //if (!PersistChanges)
                //{
                //    return;
                //}
                //if (appointment.Start > appointment.End)
                //{
                //    return;
                //}
                //if (appointment.Subject.Length < 1)
                //{
                //    return;
                //}

                //IDbTransaction objTran = null;
                //IData objData = new IData();
                //SCHAppointment objMain = new SCHAppointment();
                //try
                //{
                //    objData.Connect();
                //    WebLibs.User objUser = (WebLibs.User)HttpContext.Current.Session["User"];
                //    objTran = objData.GetConnection().BeginTransaction();
                //    objData.Transaction = objTran;
                //    objMain = (SCHAppointment)HttpContext.Current.Session["Appointment_Data"];
                //    objMain.DataObject = objData;

                //    objMain.Subject = appointment.Subject;
                //    objMain.Start = appointment.Start;
                //    objMain.End = appointment.End;
                //    objMain.RecurrenceRule = appointment.RecurrenceRule;
                //    objMain.RecurrenceParentID = Convert.ToInt32(appointment.RecurrenceParentID);

                //    int intResult = Convert.ToInt32(objMain.Update());
                //    if (intResult > 0)
                //    {
                //        if (!AddGuest(intResult, objData, objMain.IsShareAll, objMain.UserShare, objMain.MaxUsesrShare))
                //        {
                //            objTran.Rollback();
                //            return;
                //        }
                //    }

                //    objTran.Commit();
                //}
                //catch
                //{
                //    objTran.Rollback();
                //}
                //finally
                //{
                //    objData.DeConnect();
                //}
            }

            public override void Delete(RadScheduler owner, Appointment appointmentToDelete)
            {
                if (!PersistChanges)
                {
                    return;
                }
                try
                {
                    SCHAppointment objMain = new SCHAppointment();
                    objMain.AppID = Convert.ToInt32(appointmentToDelete.ID);
                    WebLibs.User objUser = (WebLibs.User)HttpContext.Current.Session["User"];
                    if (objMain.LoadByPrimaryKeys())
                        if (objMain.Username != objUser.strUsername)
                        {
                            SCHAppointmentShare objShare = new SCHAppointmentShare();
                            objShare.AppID = Convert.ToInt32(appointmentToDelete.ID);
                            objShare.Username = objUser.strUsername;
                            objShare.Delete();

                        }
                        else
                            objMain.Delete();
                }
                catch (Exception objEx)
                {
                    new SystemMessage("L?i khi xoá s? ki?n!", "", "Controls_MD_Scheduler_Appointment.DoDelete(int intAppID)<br />ERROR: " + objEx.ToString());
                }
            }

            public override IEnumerable<ResourceType> GetResourceTypes(RadScheduler owner)
            {
                ResourceType[] resourceTypes = new ResourceType[2];
                resourceTypes[0] = new ResourceType("Teacher", false);
                resourceTypes[1] = new ResourceType("Student", true);

                return resourceTypes;
            }

            public override IEnumerable<Resource> GetResourcesByType(RadScheduler owner, string resourceType)
            {
                switch (resourceType)
                {
                    case "Teacher":
                        return Teachers.Values;

                    case "Student":
                        return Students.Values;

                    default:
                        throw new InvalidOperationException("Unknown resource type: " + resourceType);
                }
            }

            private void LoadResources(Appointment apt)
            {
                using (DbConnection conn = OpenConnection())
                {
                    DbCommand cmd = DbFactory.CreateCommand();
                    cmd.Connection = conn;

                    cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID));
                    cmd.CommandText = "SELECT [TeacherID] FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID AND [TeacherID] IS NOT NULL";
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            Resource teacher = Teachers[Convert.ToInt32(reader["TeacherID"])];
                            apt.Resources.Add(teacher);
                        }
                    }

                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID));
                    cmd.CommandText = "SELECT [StudentID] FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID";
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Resource student = Students[Convert.ToInt32(reader["StudentID"])];
                            apt.Resources.Add(student);
                        }
                    }
                }
            }

            private IEnumerable<Resource> LoadTeachers()
            {
                List<Resource> resources = new List<Resource>();

                //IData objData = new IData();
                //try
                //{
                //    objData.Connect();
                //    objData.CreateNewStoredProcedure("SCH_Appointment_Get");
                //    objData.AddParameter("@strUsername", "administrator");
                //    objData.AddParameter("@intViewOption", 1);
                //    IDataReader reader = objData.ExecStoreToDataReader();

                //    while (reader.Read())
                //    {
                //        Resource res = new Resource();
                //        res.Type = "Teacher";
                //        res.Key = reader["AppID"];
                //        res.Text = Convert.ToString(reader["subject"]);
                //        //res.Attributes["Phone"] = Convert.ToString(reader["Phone"]);
                //        resources.Add(res);
                //    }
                //}
                //catch
                //{
                //}
                //finally
                //{
                //    objData.DeConnect();
                //}

                //using (DbConnection conn = OpenConnection())
                //{
                //    DbCommand cmd = DbFactory.CreateCommand();
                //    cmd.Connection = conn;
                //    cmd.CommandText = "SELECT [TeacherID], [Name], [Phone] FROM [DbProvider_Teachers]";

                //    using (DbDataReader reader = cmd.ExecuteReader())
                //    {
                //        while (reader.Read())
                //        {
                //            Resource res = new Resource();
                //            res.Type = "Teacher";
                //            res.Key = reader["TeacherID"];
                //            res.Text = Convert.ToString(reader["Name"]);
                //            res.Attributes["Phone"] = Convert.ToString(reader["Phone"]);
                //            resources.Add(res);
                //        }
                //    }
                //}

                return resources;
            }

            private IEnumerable<Resource> LoadStudents()
            {
                List<Resource> resources = new List<Resource>();
                //IData objData = new IData();
                //try
                //{
                //    objData.Connect();
                //    objData.CreateNewStoredProcedure("SCH_Appointment_Get");
                //    objData.AddParameter("@strUsername", "administrator");
                //    objData.AddParameter("@intViewOption", 1);
                //    IDataReader reader = objData.ExecStoreToDataReader();

                //    while (reader.Read())
                //    {
                //        Resource res = new Resource();
                //        res.Type = "Teacher";
                //        res.Key = reader["AppID"];
                //        res.Text = Convert.ToString(reader["subject"]);
                //        //res.Attributes["Phone"] = Convert.ToString(reader["Phone"]);
                //        resources.Add(res);
                //    }
                //}
                //catch
                //{
                //}
                //finally
                //{
                //    objData.DeConnect();
                //}
                //using (DbConnection conn = OpenConnection())
                //{
                //    DbCommand cmd = DbFactory.CreateCommand();
                //    cmd.Connection = conn;
                //    cmd.CommandText = "SELECT [StudentID], [Name] FROM [DbProvider_Students]";

                //    using (DbDataReader reader = cmd.ExecuteReader())
                //    {
                //        while (reader.Read())
                //        {
                //            Resource res = new Resource();
                //            res.Type = "Student";
                //            res.Key = reader["StudentID"];
                //            res.Text = Convert.ToString(reader["Name"]);
                //            resources.Add(res);
                //        }
                //    }
                //}

                return resources;
            }

            private void FillClassStudents(Appointment appointment, DbCommand cmd, object classId)
            {
                foreach (Resource student in appointment.Resources.GetResourcesByType("Student"))
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(CreateParameter("@ClassID", classId));
                    cmd.Parameters.Add(CreateParameter("@StudentID", student.Key));

                    cmd.CommandText = "INSERT INTO [DbProvider_ClassStudents] ([ClassID], [StudentID]) VALUES (@ClassID, @StudentID)";
                    cmd.ExecuteNonQuery();
                }
            }

            private void ClearClassStudents(object classId, DbCommand cmd)
            {
                cmd.Parameters.Clear();
                cmd.Parameters.Add(CreateParameter("@ClassID", classId));
                cmd.CommandText = "DELETE FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID";
                cmd.ExecuteNonQuery();
            }

            private void PopulateAppointmentParameters(DbCommand cmd, Appointment apt)
            {
                cmd.Parameters.Add(CreateParameter("@Subject", apt.Subject));
                cmd.Parameters.Add(CreateParameter("@Start", apt.Start));
                cmd.Parameters.Add(CreateParameter("@End", apt.End));

                Resource teacher = apt.Resources.GetResourceByType("Teacher");
                object teacherId = null;
                if (teacher != null)
                {
                    teacherId = teacher.Key;
                }
                cmd.Parameters.Add(CreateParameter("@TeacherID", teacherId));

                string rrule = null;
                if (apt.RecurrenceRule != string.Empty)
                {
                    rrule = apt.RecurrenceRule;
                }
                cmd.Parameters.Add(CreateParameter("@RecurrenceRule", rrule));

                object parentId = null;
                if (apt.RecurrenceParentID != null)
                {
                    parentId = apt.RecurrenceParentID;
                }
                cmd.Parameters.Add(CreateParameter("@RecurrenceParentId", parentId));
            }
        }
    }
  2. Maxime Gaudreault Proulx
    Maxime Gaudreault Proulx avatar
    3 posts
    Member since:
    Dec 2009

    Posted 02 Jun 2011 Link to this post

    I'm having the same problem too, does anybody have a solution for this? In my case the HttpContext.Current is null. 
    Thanks
  3. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 08 Jun 2011 Link to this post

    Hi Maxime and Khi,

    Although this question is not related to our controls but to ASP.NET please try to implement IRequiresSessionState interface and let me know how it goes.

    http://msdn2.microsoft.com/en-us/lib...sionstate.aspx


    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.

  4. Rully
    Rully avatar
    1 posts
    Member since:
    Jun 2009

    Posted 08 Mar 2012 Link to this post

    Hi,

    Has anyone managed to fix their issue with HttpContext.Current.Session being null/empty when it's accessed from the Scheduler Web Service?

    I've ensured that my web service method enables session, and I've also ensured the IRequiresSessionState interface is implemented on the web service.

    Here is the modified sample code that I found from other thread in Telerik Forum:

    Ref: http://www.telerik.com/community/code-library/aspnet-ajax/scheduler/filter-appointments-by-sending-additional-information-to-the-web-service-and-the-provider.aspx

    RadSchedulerForm.aspx
    <%@ Page Language="VB" AutoEventWireup="true" Inherits="SchedulerDbProvider.RadSchedulerWebForm" Codebehind="RadSchedulerWebForm.aspx.vb" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            </Scripts>
        </telerik:RadScriptManager>
      
        <script type="text/javascript">
     
            var teacherID = "all";
     
            function OnClientSelectedIndexChanged(sender, args) {
                teacherID = args.get_item().get_value();
                var scheduler = $find('<%=RadScheduler1.ClientID %>');
                scheduler.rebind();
            }
     
            function OnClientAppointmentsPopulating(sender, eventArgs) {
                eventArgs.get_schedulerInfo().TeacherID = teacherID;
            }
        </script>
        <p>
            Filter appointments by teacher (resource):
        </p>
        <p>
            <telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
                <Items>
                    <telerik:RadComboBoxItem Text="All" Value="all" />
                    <telerik:RadComboBoxItem Text="Teacher 1" Value="1" />
                    <telerik:RadComboBoxItem Text="Teacher 2" Value="2" />
                </Items>
            </telerik:RadComboBox>
        </p>
        <telerik:RadScheduler ID="RadScheduler1" runat="server" OnClientAppointmentsPopulating="OnClientAppointmentsPopulating"
            AppointmentStyleMode="Default" SelectedView="WeekView" SelectedDate="2011-01-21"
            Width="600px">
            <WebServiceSettings Path="SchedulerWebService.asmx" ResourcePopulationMode="ServerSide" />
            <ResourceStyles>
                <telerik:ResourceStyleMapping Type="Teacher" Key="1" BackColor="Orange" />
                <telerik:ResourceStyleMapping Type="Teacher" Key="2" BackColor="Aqua" />
            </ResourceStyles>
        </telerik:RadScheduler>
        </form>
    </body>
    </html>

    RadSchedulerWebForm.aspx.vb
    Imports System
    Imports System.Web.UI
    Imports Telerik.Web.UI
    Imports System.Net
    Imports System.Web
    Imports System.Web.Security
     
    Partial Class RadSchedulerWebForm
        Inherits System.Web.UI.Page
     
        Protected Sub RadScheduler1_ResourcesPopulating(sender As Object, e As Telerik.Web.UI.ResourcesPopulatingEventArgs) Handles RadScheduler1.ResourcesPopulating
     
            Dim cookie As HttpCookie = FormsAuthentication.GetAuthCookie(HttpContext.Current.User.Identity.Name, False)
            Dim cookieHeader As String = String.Format("{0}={1}", cookie.Name, cookie.Value)
            e.Headers.Add(HttpRequestHeader.Cookie, cookieHeader)
     
            Session.Add("connectionString", ConfigurationManager.ConnectionStrings("TelerikVSXConnectionString").ConnectionString)
     
        End Sub
     
    End Class

    SchedulerWebService.asmx.vb
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports Telerik.Web.UI
    Imports System.Data.Common
     
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class SchedulerWebService
        Inherits System.Web.Services.WebService
         Implements IRequiresSessionState

        Private _controller As WebServiceAppointmentController
        'private MySchedulerInfo localSchedulerInfo;
        Private _provider As MyDbSchedulerProvider
        Private ReadOnly Property Provider() As MyDbSchedulerProvider
            Get
                If _provider Is Nothing Then
                    Dim connString As String = String.Empty
     
                    If HttpContext.Current.Session.Count > 0 AndAlso Not String.IsNullOrEmpty(HttpContext.Current.Session.Item("connectionString").ToString()) Then
                        connString = HttpContext.Current.Session.Item("connectionString").ToString()
                    End If
     
                    Dim factory = DbProviderFactories.GetFactory("System.Data.SqlClient")
                    _provider = New MyDbSchedulerProvider() With { _
                     .ConnectionString = connString, _
                     .DbFactory = factory, _
                     .PersistChanges = True _
                    }
                End If
                Return _provider
            End Get
        End Property
     
        ''' <summary>
        ''' The WebServiceAppointmentController class is used as a facade to the SchedulerProvider.
        ''' </summary>
        Private ReadOnly Property Controller() As WebServiceAppointmentController
            Get
                If _controller Is Nothing Then
                    _controller = New WebServiceAppointmentController(Provider)
                End If
     
                Return _controller
            End Get
        End Property
     
        <WebMethod(EnableSession:=True)> _
        Public Function GetAppointments(ByVal schedulerInfo As MySchedulerInfo) As IEnumerable(Of AppointmentData)
            Return Controller.GetAppointments(schedulerInfo)
        End Function
     
        <WebMethod(EnableSession:=True)> _
        Public Function InsertAppointment(ByVal schedulerInfo As MySchedulerInfo, ByVal appointmentData As AppointmentData) As IEnumerable(Of AppointmentData)
            Return Controller.InsertAppointment(schedulerInfo, appointmentData)
        End Function
     
        <WebMethod(EnableSession:=True)> _
        Public Function UpdateAppointment(ByVal schedulerInfo As MySchedulerInfo, ByVal appointmentData As AppointmentData) As IEnumerable(Of AppointmentData)
            Return Controller.UpdateAppointment(schedulerInfo, appointmentData)
        End Function
     
        <WebMethod(EnableSession:=True)> _
        Public Function CreateRecurrenceException(ByVal schedulerInfo As MySchedulerInfo, ByVal recurrenceExceptionData As AppointmentData) As IEnumerable(Of AppointmentData)
            Return Controller.CreateRecurrenceException(schedulerInfo, recurrenceExceptionData)
        End Function
     
        <WebMethod(EnableSession:=True)> _
        Public Function RemoveRecurrenceExceptions(ByVal schedulerInfo As SchedulerInfo, ByVal masterAppointmentData As AppointmentData) As IEnumerable(Of AppointmentData)
            Return Controller.RemoveRecurrenceExceptions(schedulerInfo, masterAppointmentData)
        End Function
     
        <WebMethod(EnableSession:=True)> _
        Public Function DeleteAppointment(ByVal schedulerInfo As MySchedulerInfo, ByVal appointmentData As AppointmentData, ByVal deleteSeries As Boolean) As IEnumerable(Of AppointmentData)
            Return Controller.DeleteAppointment(schedulerInfo, appointmentData, deleteSeries)
        End Function
     
        <WebMethod(EnableSession:=True)> _
        Public Function GetResources(ByVal schedulerInfo As MySchedulerInfo) As IEnumerable(Of ResourceData)
            Return Controller.GetResources(schedulerInfo)
        End Function
     
    End Class

    MyDbSchedulerProvider.vb
    Imports System
    Imports System.Collections.Generic
    Imports System.Data.Common
    Imports System.Data.SqlClient
    Imports Telerik.Web.UI
     
    Public Class MyDbSchedulerProvider
        Inherits DbSchedulerProviderBase
       
        Private _teachers As IDictionary(Of Integer, Resource)
        Private _students As IDictionary(Of Integer, Resource)
     
        Private ReadOnly Property Teachers() As IDictionary(Of Integer, Resource)
            Get
                If _teachers Is Nothing Then
                    _teachers = New Dictionary(Of Integer, Resource)()
                    For Each teacher As Resource In LoadTeachers()
                        _teachers.Add(CInt(teacher.Key), teacher)
                    Next
                End If
     
                Return _teachers
            End Get
        End Property
     
        Private ReadOnly Property Students() As IDictionary(Of Integer, Resource)
            Get
                _students = New Dictionary(Of Integer, Resource)()
                For Each student As Resource In LoadStudents()
                    _students.Add(CInt(student.Key), student)
                Next
     
                Return _students
            End Get
        End Property
     
        Public Overrides Function GetAppointments(ByVal shedulerInfo As ISchedulerInfo) As IEnumerable(Of Appointment)
            Dim myInfo = TryCast(shedulerInfo, MySchedulerInfo)
            Dim teacherID As String = myInfo.TeacherID
     
            Dim appointments As New List(Of Appointment)()
     
            Using conn As DbConnection = OpenConnection()
                Dim cmd As DbCommand = DbFactory.CreateCommand()
                cmd.Connection = conn
                cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId], [Reminder] FROM [DbProvider_Classes]"
     
                If teacherID <> "all" Then
                    cmd.CommandText += "WHERE TeacherID = " + teacherID
                End If
     
                Using reader As DbDataReader = cmd.ExecuteReader()
                    While reader.Read()
                        Dim apt As New Appointment()
                        'apt.Owner = owner;
                        apt.ID = reader("ClassID")
                        apt.Subject = Convert.ToString(reader("Subject"))
                        apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader("Start")), DateTimeKind.Utc)
                        apt.[End] = DateTime.SpecifyKind(Convert.ToDateTime(reader("End")), DateTimeKind.Utc)
                        apt.RecurrenceRule = Convert.ToString(reader("RecurrenceRule"))
                        apt.RecurrenceParentID = If(reader("RecurrenceParentId") Is DBNull.Value, Nothing, reader("RecurrenceParentId"))
     
                        If Not reader("Reminder") Is DBNull.Value Then
                            Dim reminders As IList(Of Reminder) = Reminder.TryParse(Convert.ToString(reader("Reminder")))
                            If reminders IsNot Nothing Then
                                apt.Reminders.AddRange(reminders)
                            End If
                        End If
     
                        If apt.RecurrenceParentID IsNot Nothing Then
                            apt.RecurrenceState = RecurrenceState.Exception
                        ElseIf apt.RecurrenceRule <> String.Empty Then
                            apt.RecurrenceState = RecurrenceState.Master
                        End If
     
                        LoadResources(apt)
                        appointments.Add(apt)
                    End While
                End Using
            End Using
     
            Return appointments
        End Function
     
        Public Overrides Sub Insert(ByVal schedulerInfo As ISchedulerInfo, ByVal appointmentToInsert As Appointment)
            If Not PersistChanges Then
                Return
            End If
     
            Using conn As DbConnection = OpenConnection()
                Using tran As DbTransaction = conn.BeginTransaction()
                    Dim cmd As DbCommand = DbFactory.CreateCommand()
                    cmd.Connection = conn
                    cmd.Transaction = tran
     
                    PopulateAppointmentParameters(cmd, appointmentToInsert)
     
                    cmd.CommandText = vbTab & "INSERT" & vbTab & "INTO [DbProvider_Classes]" & vbCr & vbLf & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "([Subject], [Start], [End], [TeacherID]," & vbCr & vbLf & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "[RecurrenceRule], [RecurrenceParentID], [Reminder])" & vbCr & vbLf & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "VALUES" & vbTab & "(@Subject, @Start, @End, @TeacherID," & vbCr & vbLf & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "@RecurrenceRule, @RecurrenceParentID, @Reminder)"
     
                    If TypeOf DbFactory Is SqlClientFactory Then
                        cmd.CommandText += Environment.NewLine + "SELECT SCOPE_IDENTITY()"
                    Else
                        cmd.ExecuteNonQuery()
     
                        cmd.CommandText = "SELECT @@IDENTITY"
                    End If
                    Dim identity As Integer = Convert.ToInt32(cmd.ExecuteScalar())
     
                    FillClassStudents(appointmentToInsert, cmd, identity)
     
                    tran.Commit()
                End Using
            End Using
        End Sub
     
        Public Overrides Sub Update(ByVal schedulerInfo As ISchedulerInfo, ByVal appointmentToUpdate As Appointment)
            If Not PersistChanges Then
                Return
            End If
     
            Using conn As DbConnection = OpenConnection()
                Using tran As DbTransaction = conn.BeginTransaction()
                    Dim cmd As DbCommand = DbFactory.CreateCommand()
                    cmd.Connection = conn
                    cmd.Transaction = tran
     
                    PopulateAppointmentParameters(cmd, appointmentToUpdate)
     
                    cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToUpdate.ID))
                    cmd.CommandText = "UPDATE [DbProvider_Classes] SET [Subject] = @Subject, [Start] = @Start, [End] = @End, [TeacherID] = @TeacherID, [RecurrenceRule] = @RecurrenceRule, [RecurrenceParentID] = @RecurrenceParentID WHERE [ClassID] = @ClassID"
                    cmd.ExecuteNonQuery()
     
                    ClearClassStudents(appointmentToUpdate.ID, cmd)
     
                    FillClassStudents(appointmentToUpdate, cmd, appointmentToUpdate.ID)
     
                    tran.Commit()
                End Using
            End Using
        End Sub
     
        Public Overrides Sub Delete(ByVal schedulerInfo As ISchedulerInfo, ByVal appointmentToDelete As Appointment)
            If Not PersistChanges Then
                Return
            End If
     
            Using conn As DbConnection = OpenConnection()
                Dim cmd As DbCommand = DbFactory.CreateCommand()
                cmd.Connection = conn
     
                Using tran As DbTransaction = conn.BeginTransaction()
                    cmd.Transaction = tran
     
                    ClearClassStudents(appointmentToDelete.ID, cmd)
     
                    cmd.Parameters.Clear()
                    cmd.Parameters.Add(CreateParameter("@ClassID", appointmentToDelete.ID))
                    cmd.CommandText = "DELETE FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID"
                    cmd.ExecuteNonQuery()
     
                    tran.Commit()
                End Using
            End Using
        End Sub
     
        Public Overrides Function GetResources(ByVal schedulerInfo As ISchedulerInfo) As IDictionary(Of ResourceType, IEnumerable(Of Resource))
     
            Dim resCollection As New Dictionary(Of ResourceType, IEnumerable(Of Resource))()
            resCollection.Add(New ResourceType("Teacher", False), Teachers.Values)
            resCollection.Add(New ResourceType("Student", True), Students.Values)
     
            Return resCollection
        End Function
     
        Private Sub LoadResources(ByVal apt As Appointment)
            Using conn As DbConnection = OpenConnection()
                Dim cmd As DbCommand = DbFactory.CreateCommand()
                cmd.Connection = conn
     
                cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID))
                cmd.CommandText = "SELECT [TeacherID] FROM [DbProvider_Classes] WHERE [ClassID] = @ClassID AND [TeacherID] IS NOT NULL"
                Using reader As DbDataReader = cmd.ExecuteReader()
                    If reader.Read() Then
                        Dim teacher As Resource = Teachers(Convert.ToInt32(reader("TeacherID")))
                        apt.Resources.Add(teacher)
                    End If
                End Using
     
                cmd.Parameters.Clear()
                cmd.Parameters.Add(CreateParameter("@ClassID", apt.ID))
                cmd.CommandText = "SELECT [StudentID] FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID"
                Using reader As DbDataReader = cmd.ExecuteReader()
                    While reader.Read()
                        Dim student As Resource = Students(Convert.ToInt32(reader("StudentID")))
                        apt.Resources.Add(student)
                    End While
                End Using
            End Using
        End Sub
     
        Private Function LoadTeachers() As IEnumerable(Of Resource)
            Dim resources As New List(Of Resource)()
     
            Using conn As DbConnection = OpenConnection()
                Dim cmd As DbCommand = DbFactory.CreateCommand()
                cmd.Connection = conn
                cmd.CommandText = "SELECT [TeacherID], [Name], [Phone] FROM [DbProvider_Teachers]"
     
                Using reader As DbDataReader = cmd.ExecuteReader()
                    While reader.Read()
                        Dim res As New Resource()
                        res.Type = "Teacher"
                        res.Key = reader("TeacherID")
                        res.Text = Convert.ToString(reader("Name"))
                        res.Attributes("Phone") = Convert.ToString(reader("Phone"))
                        resources.Add(res)
                    End While
                End Using
            End Using
     
            Return resources
        End Function
     
        Private Function LoadStudents() As IEnumerable(Of Resource)
            Dim resources As New List(Of Resource)()
     
            Using conn As DbConnection = OpenConnection()
                Dim cmd As DbCommand = DbFactory.CreateCommand()
                cmd.Connection = conn
                cmd.CommandText = "SELECT [StudentID], [Name] FROM [DbProvider_Students]"
     
                Using reader As DbDataReader = cmd.ExecuteReader()
                    While reader.Read()
                        Dim res As New Resource()
                        res.Type = "Student"
                        res.Key = reader("StudentID")
                        res.Text = Convert.ToString(reader("Name"))
                        resources.Add(res)
                    End While
                End Using
            End Using
     
            Return resources
        End Function
     
        Private Sub FillClassStudents(ByVal appointment As Appointment, ByVal cmd As DbCommand, ByVal classId As Object)
            For Each student As Resource In appointment.Resources.GetResourcesByType("Student")
                cmd.Parameters.Clear()
                cmd.Parameters.Add(CreateParameter("@ClassID", classId))
                cmd.Parameters.Add(CreateParameter("@StudentID", student.Key))
     
                cmd.CommandText = "INSERT INTO [DbProvider_ClassStudents] ([ClassID], [StudentID]) VALUES (@ClassID, @StudentID)"
                cmd.ExecuteNonQuery()
            Next
        End Sub
     
        Private Sub ClearClassStudents(ByVal classId As Object, ByVal cmd As DbCommand)
            cmd.Parameters.Clear()
            cmd.Parameters.Add(CreateParameter("@ClassID", classId))
            cmd.CommandText = "DELETE FROM [DbProvider_ClassStudents] WHERE [ClassID] = @ClassID"
            cmd.ExecuteNonQuery()
        End Sub
     
        Private Sub PopulateAppointmentParameters(ByVal cmd As DbCommand, ByVal apt As Appointment)
            cmd.Parameters.Add(CreateParameter("@Subject", apt.Subject))
            cmd.Parameters.Add(CreateParameter("@Start", apt.Start))
            cmd.Parameters.Add(CreateParameter("@End", apt.[End]))
     
            Dim teacher As Resource = apt.Resources.GetResourceByType("Teacher")
            Dim teacherId As Object = Nothing
            If teacher IsNot Nothing Then
                teacherId = teacher.Key
            End If
            cmd.Parameters.Add(CreateParameter("@TeacherID", teacherId))
     
            Dim rrule As String = Nothing
            If apt.RecurrenceRule <> String.Empty Then
                rrule = apt.RecurrenceRule
            End If
            cmd.Parameters.Add(CreateParameter("@RecurrenceRule", rrule))
     
            Dim parentId As Object = Nothing
            If apt.RecurrenceParentID IsNot Nothing Then
                parentId = apt.RecurrenceParentID
            End If
            cmd.Parameters.Add(CreateParameter("@RecurrenceParentId", parentId))
     
            cmd.Parameters.Add(CreateParameter("@Reminder", apt.Reminders.ToString()))
        End Sub
    End Class

    MySchedulerInfo.vb
    Imports Telerik.Web.UI
     
    Public Class MySchedulerInfo
        Inherits SchedulerInfo
        Public Property TeacherID() As String
            Get
                Return m_TeacherID
            End Get
            Set(ByVal value As String)
                m_TeacherID = value
            End Set
        End Property
        Private m_TeacherID As String
        Public Sub New(ByVal baseInfo As ISchedulerInfo, ByVal teacherID__1 As String)
            MyBase.New(baseInfo)
            TeacherID = teacherID__1
        End Sub
     
        Public Sub New()
        End Sub
    End Class
Back to Top