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.
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 product
s):
public class Category
{
public Guid ID { get; set; }
public string Name { get; set; }
}
And a Tax
type:
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:
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:
public class SalesViewModel : INotifyPropertyChanged
{
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:
<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:
CodeProject