Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / XAML

Building OpenPOS: Part 4 – SalesModule (Part 1)

5.00/5 (1 vote)
1 Apr 2010CPOL 1  
Building OpenPOS: SalesModule (Part 1)

Let’s start implementing the SalesModule! This is a pretty big and complicated module and will most probably be split into multiple parts (and be refactored n times)! Before I can really start, let me show you my data model.

Everything revolves round a product.

C#
public class Product
{
    public Guid ID { get; set; }
    public string Refrence { get; set; }
    public string Name { get; set; }
    public string Barcode { get; set; }
    public double BuyPrice { get; set; }
    public double SellPrice { get; set; }

    public Guid CategoryID { get; set; }
    public Guid TaxID { get; set; }
}

Each Product can also belong to a category (used to filter products):

C#
public class Category
{
    public Guid ID { get; set; }
    public string Name { get; set; }
}

And a Tax type:

C#
public class Tax
{
    public Guid ID { get; set; }
    public string Name { get; set; }
    public double Rate { get; set; }
}

I also created a mocked repository to fetch the products:

C#
public interface IProductRepository
{
    Product[] GetProducts();
    Product GetProduct(Guid productID);
    Category[] GetCategories();
    Product[] GetProductsByCategory(Category category);
}

Currently only serving dummy data though!!!

One of the up front design decisions was to use the MVVM pattern. My SalesView_Main view has a ViewModel behind it that looks like this:

C#
public class SalesViewModel : INotifyPropertyChanged
{
    // Simplified version

    private readonly IProductRepository _productRepository;

    public List<Category> Categories { get; set; }
    public Category SelectedCategories { get; set; }
    public ObservableCollection<Product> Products { get; set; }
}

The UI binds to the collection of Categories, as the current item changes, re-creating the list of products to show! This creates the illusion of product filtering!

Here is the XAML:

XML
<ListBox ItemsSource="{Binding Categories}" 
         DisplayMemberPath="Name" 
         SelectedValue="{Binding SelectedCategories, Mode=TwoWay}" />

<ListBox ItemsSource="{Binding Products}" />

Here is a screen capture of all the products:

And here is the list filtered by hardware:

In the next part, I will cover how I did the adding of products into a current transaction!

Here is the latest version of OpenPOS source:

License

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