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));
}
}
}
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));
}
}
}