Click here to Skip to main content
15,886,689 members
Articles / Mobile Apps / Windows Phone 7
Tip/Trick

Calendar of Events in Windows Phone

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
15 Oct 2012CPOL2 min read 12.3K   2  
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:

C#
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:

C#
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.

Image 1

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.

C#
[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.

C#
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.

Image 2

Download the Full Project

You can download the full application code from MSDN.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Tunisia Tunisia
Software Engineerwho likes spending my free time developing open source .NET applications.
Mail : houssem.dellai@live.com
Phone : +216 29 903 563

Comments and Discussions

 
-- There are no messages in this forum --