Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Calendar of Events in Windows Phone

0.00/5 (No votes)
15 Oct 2012 1  
Developing a Windows Phone app step by step

Introduction

Nowadays, most people always have busy days with a lot of meetings and a lot of work to do, and they must ensure that they don't forget any of them. So, why not help these people by providing an application that helps them manage all their events. As people may need this app anywhere and at anytime, it will be just great if they could get it with them in their pocket! So this app will be a Mobile app. And as we want to learn about the Microsoft's Mobile OS, we will use Windows Phone 7 as a platform.

Installing Tools

To develop applications in Windows Phone 7, you will need to have Visual Studio Express for Windows Phone which you can download from here, or if you have Visual Studio 2010 already installed on your computer, just install the WP7's SDK.

Building the Database

In WP7, you have to use the LINQ technology to manipulate your database. So we will need to add a reference to System.Data.Linq and to add the System.Linq using. We will reference our database by this:

ScheduleDataContext EventsDB = new ScheduleDataContext(@"isostore:/EventsDB.sdf"); 

So now we could manipulate our database as it is an object. To create it, just use the CreateDatabase() method:

if (EventsDB.DatabaseExists() == false)
    try
    {
        EventsDB.CreateDatabase();
    }
    catch (Exception exc) { return false;} 

As shown in the following picture, Intellisense provides all given methods with a little description.

It's good to program using the MVVM pattern. The Model here is the Event object. Because I will store it into the database, I have to specify the columns to use and their properties using annotations. The attribute that is started with [Column] will be stored in a column with his name.

[Table]
    public class Event
    {
        [Column(IsPrimaryKey = true)]
        public int EventID
        {
            get;
            set;
        }
        [Column(CanBeNull = false)]
        public string EventName
        {
            get;
            set;
        }
        [Column(CanBeNull = false)]
        public DateTime DateFrom
        {
            get;
            set;
        }
    }  

Then, to add an Event object to the table, just use InsertOnSubmit(Event) and SubmitChanges() methods.

EventsDB.Events.InsertOnSubmit(evnt);
EventsDB.SubmitChanges();  

Deleting an Event is also so simple. Consider using DeleteOnSubmit(Event) to delete and SubmitChanges() to save modification.

Here is an image that shows how Intellisense can help you.

Download the Full Project

You can download the full application code from MSDN.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here