Learning Curve…

DevExpress Scheduler(ASPxScheduler) with CLSA…

Posted on: February 7, 2011

This article illustrates how to handle DevExpress Scheduler(ASPxScheduler) with  CLSA.

In this example, the ASPxSchedulerStorage component (which provides data for the ASPxScheduler control) is bound to ObjectDataSource  that gets data from CSLA classes , and CSLA classes are  configure with a SQLServer database that stores information about all appointments and resources.

Step -1 Use following sql script to generate two tables to persist appointments and resources data.


CREATE TABLE [dbo].[Appointments] ( [UniqueID] [int] IDENTITY (1, 1) NOT NULL ,

[Type] [int] NULL ,

[StartDate] [smalldatetime] NULL ,

[EndDate] [smalldatetime] NULL ,

[AllDay] [bit] NULL ,

[Subject] [nvarchar] (100) NULL ,

[Location] [nvarchar] (50) NULL ,

[Description] [ntext] NULL ,

[Status] [int] NULL ,

[Label] [int] NULL ,

[ResourceID] [int] NULL ,

[ReminderInfo] [ntext] NULL ,

[RecurrenceInfo] [ntext] NULL ,

[CustomField1] [ntext] NULL

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

CREATE TABLE [dbo].[Resources] (

[UniqueID] [int] IDENTITY (1, 1) NOT NULL ,

[ResourceID] [int] NOT NULL ,

[ResourceName] [nvarchar] (50) NULL ,

[Color] [int] NULL ,

[Image] [image] NULL ,

[CustomField1] [ntext] NULL

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[Appointments] WITH NOCHECK ADD

CONSTRAINT [PK_Appointments] PRIMARY KEY CLUSTERED

(

[UniqueID]

) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Resources] WITH NOCHECK ADD

CONSTRAINT [PK_Resources] PRIMARY KEY CLUSTERED

(

[UniqueID]

) ON [PRIMARY]

GO

Step -2 : Generate CSLA Editable classes (EditableRoot and EditableRootList ) with [dbo].[Appointments] table and ReadOnly Classes (ReadOnlyList and ReadOnlyRoot)  with [dbo].[Resources] table respectively.

Step -3 : Add one ASPxScheduler, two ObjectDataSource in a form .Configure ObjectDataSource  with created Classes  to get data from database. Map ASPxScheduler  with ObjectDataSource Data and then In code Behind you need to do some coding to insert , update and delete appointments.

See Below code:-

Design View :-

<%@ Page Title=”Scheduler With CSLA” Language=”C#” MasterPageFile=”~/Site.Master” AutoEventWireup=”true” CodeBehind=”DevExpressSchedulerCsla.aspx.cs” Inherits=”Option.DevExpressSchedulerCsla” %>

<%@ Register Assembly=”DevExpress.Web.ASPxScheduler.v10.2, Version=10.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a”

Namespace=”DevExpress.Web.ASPxScheduler” TagPrefix=”dxwschs” %>

<%@ Register Assembly=”DevExpress.XtraScheduler.v10.2.Core, Version=10.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a”

Namespace=”DevExpress.XtraScheduler” TagPrefix=”cc1″ %>

<asp:Content ID=”Content3″ ContentPlaceHolderID=”HeadContent” runat=”server”>

</asp:Content>

<asp:Content ID=”Content4″ ContentPlaceHolderID=”MainContent” runat=”server”>

<dxwschs:ASPxScheduler ID=”ASPxScheduler1″ runat=”server” ActiveViewType=”Month”

AppointmentDataSourceID=”ObjectDataSourceAppoitment” ResourceDataSourceID=”ObjectDataSourceResource”

ClientIDMode=”AutoID” OnAppointmentInserting=”ASPxScheduler1_AppointmentInserting”

OnAppointmentRowDeleting=”ASPxScheduler1_AppointmentRowDeleting” OnAppointmentRowUpdating=”ASPxScheduler1_AppointmentRowUpdating” Start=”2011-01-31″>

<Views>

<DayView Enabled=”false”>

<TimeRulers>

<cc1:TimeRuler />

</TimeRulers>

</DayView>

<WorkWeekView Enabled=”false”>

<TimeRulers>

<cc1:TimeRuler />

</TimeRulers>

</WorkWeekView>

<WeekView Enabled=”false”>

</WeekView>

<TimelineView Enabled=”false” />

<MonthView CompressWeekend=”False” >

</MonthView>

</Views>

<Storage EnableReminders=”false”>

<Appointments>

<Mappings AllDay=”AllDay” AppointmentId=”UniqueID” Description=”Description” End=”EndDate”

Label=”Label” Location=”Location” RecurrenceInfo=”RecurrenceInfo” ReminderInfo=”ReminderInfo”

ResourceId=”ResourceID” Start=”StartDate” Status=”Status” Subject=”Subject” Type=”Type” />

</Appointments>

<Resources>

<Mappings Caption=”ResourceName” Color=”Color” Image=”Image” ResourceId=”ResourceID” />

</Resources>

</Storage>

<OptionsView FirstDayOfWeek=”Monday” />

</dxwschs:ASPxScheduler>

<asp:ObjectDataSource ID=”ObjectDataSourceAppoitment” runat=”server” TypeName=”Library.AppointmentList”

SelectMethod=”GetAll”></asp:ObjectDataSource>

<asp:ObjectDataSource ID=”ObjectDataSourceResource” runat=”server” SelectMethod=”GetAll”

TypeName=”Library.ResourceInfoList”></asp:ObjectDataSource>

</asp:Content>

Code Behind:-

using System; using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Library;

using DevExpress.Web.ASPxScheduler;

using DevExpress.XtraScheduler;

using DevExpress.XtraScheduler.Xml;

namespace Option

{

public partial class DevExpressSchedulerCsla : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void ASPxScheduler1_AppointmentInserting(object sender, PersistentObjectCancelEventArgs e)

{

try

{

e.Cancel = true;

DevExpress.XtraScheduler.Appointment apt = (DevExpress.XtraScheduler.Appointment)e.Object;

Library.Appointment AddAppointment = Library.Appointment.NewAppointment();

AddAppointment.BeginEdit();

AddAppointment.AllDay = apt.AllDay;

AddAppointment.StartDate = apt.Start;

AddAppointment.EndDate = apt.End;

AddAppointment.Subject = apt.Subject;

AddAppointment.Description = apt.Description;

AddAppointment.Label = apt.LabelId;

AddAppointment.Location = apt.Location;

AddAppointment.Status = apt.StatusId;

if (apt.Reminder != null)

{

ReminderCollectionXmlPersistenceHelper helper = new ReminderCollectionXmlPersistenceHelper(apt, DateSavingType.UTC);

AddAppointment.ReminderInfo = helper.ToXml();

}

if (apt.RecurrenceInfo != null)

{

RecurrenceInfoXmlPersistenceHelper helper = new RecurrenceInfoXmlPersistenceHelper(apt.RecurrenceInfo, DateSavingType.UTC);

AddAppointment.RecurrenceInfo = helper.ToXml();

}

if (apt.ResourceIds != null)

{

DevExpress.XtraScheduler.Xml.AppointmentResourceIdCollectionXmlPersistenceHelper helper = new DevExpress.XtraScheduler.Xml.AppointmentResourceIdCollectionXmlPersistenceHelper(apt.ResourceIds);

string resourceIds = helper.ToXml();

helper = new DevExpress.XtraScheduler.Xml.AppointmentResourceIdCollectionXmlPersistenceHelper(new ResourceIdCollection());

ResourceIdCollection collection = helper.FromXml(resourceIds) as ResourceIdCollection;

int resId = 0;

foreach (object resourceId in collection)

{

resId = Convert.ToInt32(resourceId);

AddAppointment.ResourceID = resId;

}

}

AddAppointment.Type = (Int32)apt.Type;

AddAppointment.IsArchive = false;

AddAppointment.IsDeleted = false;

AddAppointment.ApplyEdit();

AddAppointment.Save();

ASPxSchedulerStorage storage = (ASPxSchedulerStorage)sender;

storage.RefreshData();

ASPxScheduler1.DataBind();

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

}

protected void ASPxScheduler1_AppointmentRowDeleting(object sender, ASPxSchedulerDataDeletingEventArgs e)

{

try

{

e.Cancel = true;

Int32 UniqueID = Convert.ToInt32(e.Keys[“UniqueID”]);

Library.Appointment.IsDeleteALLAppointment(false, UniqueID);

ASPxScheduler1.DataBind();

}

catch (Exception ex)

{

Response.Write(ex);

}

}

protected void ASPxScheduler1_AppointmentRowUpdating(object sender, ASPxSchedulerDataUpdatingEventArgs e)

{

try

{

e.Cancel = true;

Int32 UniqueID = Convert.ToInt32(e.Keys[“UniqueID”]);

if (UniqueID != 0)

{

Library.Appointment Updateppointment =   Library.Appointment.GetByUniqueID(UniqueID);

Updateppointment.BeginEdit();

Updateppointment.AllDay = Convert.ToBoolean(e.NewValues[“AllDay”]);

Updateppointment.StartDate = Convert.ToDateTime(e.NewValues[“StartDate”]);

Updateppointment.EndDate = Convert.ToDateTime(e.NewValues[“EndDate”]);

Updateppointment.Subject = Convert.ToString(e.NewValues[“Subject”]);

Updateppointment.Description = Convert.ToString(e.NewValues[“Description”]);

Updateppointment.Label = Convert.ToInt32(e.NewValues[“Label”]);

Updateppointment.Location = Convert.ToString(e.NewValues[“Location”]);

Updateppointment.Status = Convert.ToInt32(e.NewValues[“Status”]);

Updateppointment.Type = Convert.ToInt32(e.NewValues[“Type”]);

Updateppointment.IsArchive = false;

Updateppointment.IsDeleted = false;

Updateppointment.ApplyEdit();

Updateppointment.Save(true);

ASPxScheduler1.DataBind();

}

}

catch (Exception ex)

{

Response.Write(ex.Message);

}

}

}

}

Thats it.

View page in browser. You can see existing appointment s. You’re also able to create new appointments, or edit or delete existing ones, and all your changes will be automatically saved to the Database.

Enjoy Coding!!!

Advertisements

7 Responses to "DevExpress Scheduler(ASPxScheduler) with CLSA…"

What is “Library”? You refer to using Library; and Library.Appointment AddAppointment = Library.Appointment.NewAppointment();

Where do I add a reference to “Library”?

I have created three tier architecture for this , “Library” is a business logic layer where I have kept my csla classes.
If you are not following any architecture you can directly call newappointment function like this :

Appointment AddAppointment = Appointment.NewAppointment();

It will work .

Hello Nikhat,

I will definitely help me understand how to implement ObjectDataSource data binding of ASPxScheduler if I know what’s going on in Library.Appointment for a NewAppointment.
Could you please help me and others like me with code samples – even pseudo-code will be good enough.

Thank you so much.
Frank

Hi Frank,

In this case ‘Library’ is my BLL project name and ‘Appointment’ is CSLA entity root business class , which I have generated with the help of Codesmith tool.

Hope this will help you.Let me know If you need more info.

Regards,
Nikhat

Hi Nikhat,

Thank you for your prompt response. I am using NetTiers to generate my entity root business class. I am using my business classes instead of yours in the ObjectDataSourceAppointment TypeName and ObjectDataSourceResource TypeName – I am getting ‘[MissingMethodException: No parameterless constructor defined for this object.].
I must be missing something basic. Any idea what’s going on?

Also, SelectMethod = “GetAll” is returning a , correct?

Thank you for your help.

Regards,
Frank.

can u send me some sample code.then i can understand your issue better.

Hi, Please can you send me your code for your BL and DAL. This is exactly what I need. Looks awesome

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Author

Learning days (Calendar)

February 2011
M T W T F S S
« Jan   Mar »
 123456
78910111213
14151617181920
21222324252627
28  

Knowledge Bank (Archives)

I am on Twitter

Blog Stats

  • 507,854 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 43 other followers

%d bloggers like this: