Telerik Forums
UI for ASP.NET AJAX Forum
3 answers
2.6K+ views
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));
        }
    }
}
Rully
Top achievements
Rank 2
 answered on 08 Mar 2012
2 answers
98 views
Even after setting ExpandCollapseColumn display to false in my aspx page, there is no effect. is there a way to make the display false in css?
Steve
Top achievements
Rank 1
 answered on 08 Mar 2012
1 answer
56 views
I want to remove >> and << button in a rad calendar..
Shinu
Top achievements
Rank 2
 answered on 08 Mar 2012
2 answers
83 views

Import Problem On Primary key set table ,
Without primary set table data are saved without problem

Thanks,
Mohamed.
mohamed
Top achievements
Rank 1
 answered on 08 Mar 2012
2 answers
79 views
Hi all,

I want different colors for the headers of my hierarchical grid.How can I set the css for my requirement?

Thanks in advance.
Angella
Top achievements
Rank 1
 answered on 08 Mar 2012
2 answers
78 views
I have a Rad calendar in my page. On pressing the tab the control goes to calendar. I want to skip the calendar from gaining focus on pressing tab.

Any suggestion would be helpful.
Arun
Top achievements
Rank 1
 answered on 08 Mar 2012
1 answer
95 views
I am having a hard time figuring out how to turn SQL results into a RadChart.  I've tried numerous examples and code snippets in the "Getting Started" sections and others, but I still can't get it to do something simple.

Attached is a visual of what I am trying to accomplish.  All evidence is that RadChart should be able to handle this easily!  But I can't make sense of HOW.

On the left are the results from SQL. 

On the right is the simple chart as rendered in Excel.

Can someone point me to some good step-by-step instructions on how to make this happen?  (I know how to set up the SQL data source and bind the chart to the SQL Data Source, but once I get into the RadChart wizard or attempting to setup the series and items is where there's a mental disconnect.)

Suggestions are greatly appreciated!
Cartoon Head
Top achievements
Rank 1
 answered on 07 Mar 2012
2 answers
40 views
Dear friends,

I need help about radwindows. The code in attahed files worked for months until firefox 10.2 update. It is still working with ms internet explorer.

Issue is about web page -> open modal radwindow -> open another modal radwindow

I isolated the problem and added necessary information on pages. As I cannot attach rar files to message, I gave a link. Sorry for that. Also this problem is about multiple web pages, so I did not write code here in this message. Sorry about that.

I tried 2011q4 and 2012q1 telerik versions. aslo I tried 2012q1 hotfix228

Can you confirm this as a bug ? If so, is it about telerik or about firefox ? Can I do something to make this code work ?

www.karina-mira.org/test.rar
aykut
Top achievements
Rank 1
 answered on 07 Mar 2012
10 answers
263 views
as shown by many posts before, here's how i attach the key up events

function OnClientLoad(editor, args)
{
editor.attachEventHandler("onkeyup", handler);
}

function handler(eventArgs)
{
if (eventArgs.keyCode == "13") 

$telerik.cancelRawEvent(eventArgs); 
return;
}
... other stuff
}

I have tried it with other keystrokes and the cancelRawevent call can prevents those keystrokes, but not carriage return. Any ideas?
Alejandro
Top achievements
Rank 1
 answered on 07 Mar 2012
1 answer
63 views

Hello,

   Based on each high level directory in FileExplorer I have a set of permissions specific to the path that I set. Based on these permissions I either show or hide the related toolbar icons or gridContextMenu option. After the 2012 Q1 update, if I select any item other than a directory in the grid section, the open and copy options are the only options enabled, all others are disabled. Could this be related to the new cell/column selection feature?

Here is a portion of the code I use for the onClientFolderChange:

 

function OnClientFolderChange(fileExplorer, args) {
            //var loadingPanel = fileExplorer.get_ajaxLoadingPanel();
            var treeview = fileExplorer.get_tree();
            var selectedNode = treeview.get_selectedNode();
            var dirCurrent = fileExplorer.get_currentDirectory();
            var toolbar = fileExplorer.get_toolbar();
            //toolbar.get_element().style.display = "none";
            var GridContextMenu = fileExplorer.get_gridContextMenu();
            var grid = fileExplorer.get_grid();
            var windowManager = fileExplorer.get_windowManager();
            var dir = selectedNode.get_text();
            var nodeParent = selectedNode.get_parent();
            if (nodeParent != null) {
                var getNodeLevel = selectedNode.get_level();
                var thisNode = selectedNode;
                while (getNodeLevel != 0) {
                    if (getNodeLevel != 0) {
                        var parentDir = thisNode.get_parent();
                        dir = parentDir.get_text();
                        getNodeLevel = parentDir.get_level();
                        thisNode = parentDir;
                    }
                }
                // set permissions
                // createDir
                PageMethods.getPermission(dir, "createDir", function(response) {
                    //alert("dir: " + dir + " createDir response: " + response);
                    toolbar.trackChanges();
                    GridContextMenu.trackChanges();
                    var tbCreateDir = toolbar.findItemByValue("NewFolder");
                    var gcmCreateDir = GridContextMenu.findItemByValue("NewFolder");
                    if (response == "False") {
                        if (tbCreateDir != null) {
                            tbCreateDir.hide(0);
                        }
                        if (gcmCreateDir != null) {
                            gcmCreateDir.hide(0);
                        }
                    }
                    else if (response == "True") {
                        if (tbCreateDir != null) {
                            tbCreateDir.show();
                        }
                        if (gcmCreateDir != null) {
                            gcmCreateDir.show();
                        }
                    }
                    toolbar.commitChanges();
                    GridContextMenu.commitChanges();
                });
                // delete
                PageMethods.getPermission(dir, "delete", function(response) {
                    toolbar.trackChanges();
                    GridContextMenu.trackChanges();
                    var tbDelete = toolbar.findItemByValue("Delete");
                    var gcmDelete = GridContextMenu.findItemByValue("Delete");
                    if (response == "False") {
                        if (tbDelete != null) {
                            tbDelete.hide(0);
                        }
                        if (gcmDelete != null) {
                            gcmDelete.hide(0);
                        }
                    }
                    else if (response == "True") {
                        if (tbDelete != null) {
                            tbDelete.show();
                        }
                        if (gcmDelete != null) {
                            gcmDelete.show();
                        }
                    }
                    toolbar.commitChanges();
                    GridContextMenu.commitChanges();
                });

Thanks!

Jed
Jed
Top achievements
Rank 1
 answered on 07 Mar 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?