views:

62

answers:

1

Hello, I am new to WPF, and I want to develop an application for Theater seating in WPF- c#.net. I did some research but i am lost as i do not know how each seat's data (sold or not, price, in which row) should be eventually bound to field in a table in SQL Express. Should i be using ObservableCollection to populate the contents of a Datatable in it? Also, should i be using a grid of buttons? or rectangles? How should i proceed if i want the front left and front right buttons to be inclined a bit instead of being horizontal? Should i be using a wrappanel if i want to have three areas for the seats? Left area, space for alter, middle area, space for alter and right area? If somebody can give me some hints for me to start, i will be more than glad. Thanks in advance...

A: 

You're asking a lot of questions at once, and it would be impossible for anyone to answer them all without writing your program for you, but I'll offer the high-level approach that I would take. You'll have to spend some time to dig into the details. Plenty of info on StackOverflow and otherwise to get help on these details.

Anyways-

Database, 3 tables

SeatStatus Table

  • ID, int, Primary Key
  • Name, string (e.g. Available, Sold, Broken)

PricePoint Table

  • ID, int, Primary Key
  • Name, string (e.g. Default, OnSale, Premium)
  • Price, float (e.g. 10.0, 8.0, 12.0)

Seat Table

  • ID, int, Primary Key
  • SeatStatusID, int, Foreign Key -> SeatStatus Table
  • PricePointID, int, Foreign Key -> PricePoint Table
  • Row, int
  • Column, int

Application Model

I would use Entity Framework 4 and generate your model from your TheaterSeating database. This will create Seat objects for you that automatically contain references to SeatStatus and PricePoint. Very slick.

Edit 1

Once you've created your model you will have an .edmx file that represents your data, and can read/write to your database easily. Assuming this file is called TheaterSeatingModel.edmx, the auto-generated classes will provide you with the means to call something along the lines of:

TheaterSeatingEntities entities = new TheaterSeatingEntities();

You now have access to your entire database, including:

entities.Seats
entities.PricePoints

etc.

You can use these classes as you would naturally expect, an example:

Seat seat = new Seat();
seat.Row = 10;
seat.Column = 5;
entities.Seats.Add(seat);
entities.SaveChanges();

Populate an ObservableCollection with these seats inside a class, and set your View's (the XAML control's) DataContext to this class.

public ObservableCollection<Seat> SeatCollection {get;set;}

public ViewModelConstructor()
{
   TheaterSeatingEntities entities = new TheaterSeatingEntities();
   SeatCollection = new ObservableCollection<Seat>(entities.Seats);
}

This will populate your collection with all the Seat objects.

A simple WPF binding to this collection would be something along the lines of:

<ListBox ItemsSource={Binding SeatCollection} />

UI

If it were me I would use a WPF ItemsControl whose ItemsSource is set to your ObservableCollection of Seats. Place this ItemsControl inside of a Canvas. The ItemsControl's ItemsControl.ItemTemplate control what each Seat will look like in your view. You can bind the ItemTemplates Canvas.Left and Canvas.Top to the Seat.Row and Seat.Column to place the seats in their appropriate positions on screen. You can make the template be a button, rectangle, image of a seat, anything. You can set up Styles and Triggers to make the Seat display differently depending on PricePoint, SeatStatus, etc.

I think WPF will be great for the project you're starting.

Good luck!

bufferz
Hello there, sorry for being so general in my question. But as all notions are new to me, i got quite lost ...In trying to find out how to bind the WPF controls with the database (to reflect updates, inserts and deletes)I got lost between ADO.NET EF, MVVM, ObservableCollection...Anyway thanks a million for your guidance.
yarojan77
No worries, I've been there many, many times. Just try to pick one thing and keep your head above water. In your case if you've already put together your database, I would start by generating some C# classes that represent your database using Entity Framework. This is quite straightforward to do, and requires no coding on your part for basic CRUD (CReate, Update, Delete) operations. See this page for doing so: http://www.asp.net/mvc/tutorials/creating-model-classes-with-the-entity-framework-cs Start with the "Creating the ADO.NET Entity Data Model" section.
bufferz
ok I got my ADO.NET Entity Data Model, thanks again for your guidance. Now how do i populate the observablecollection with the data of each entity? Any tutorial in C#.NET somewhere? it seems to be simple but i could not find an example...
yarojan77
I edited my response to answer your question. See Edit 1
bufferz