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

Building OpenPOS: Part 8 – Windows 7 Love

0.00/5 (No votes)
12 Aug 2010 2  
Building OpenPOS - Windows 7 Love

OpenPOS is almost ready and I am very excited!!!

The first OFFICIAL version should be released by the end of the month, I am just busy finishing off some last touches… With that said, I do want to give a updated on the current status of the project and also give Windows 7 some love! I truly love Windows 7 and have been writing about using some of its features in the past… now it's time to put my money where my mouth is and use some of these.

In Part 3, I wrote about the navigation “framework” used in this project… I updated this “framework” to automatically add NavigationPoints to the JumpList. Let's re-cap:

To register a NavigationPoint

C#
_navigationService.RegisterNavigationPoint(
    new NavigationPoint() 
    { 
        Name = "Sales",
        Category = "Main",
        ShowInJumpList = true,
        Icon = "\\Images\\mycomputer.png"
    });

This will add a NavigationPoint to the Navigation pane.

If the ShowInJumpList is set to True, the NavigationPoint will also be added to the JumpList.

Let’s look at some of the implementation details… To make JumpList work, you need to ensure that only one instance of your application is running and that if a new instance is launched, it somehow sends the arguments passed into it all the way back to the original version already running (using some for of IPC). In my original series on the Anatomy of the Windows 7 taskbar, I used my Inter-process Mediator to facilitate this “process”. My Inter-process Mediator has some flaws though. :(

This being said, I decided to try out the SingleInstance implementation used in the FishBowl application.

“Fishbowl brings Facebook to your desktop.”

For their approach to work, I first needed to create a custom Main() method (I used approach 3 explained in this document).

C#
public static class OpenPOS_Main
{
    [STAThread]
    public static void Main()
    {
        if (SingleInstance.InitializeAsFirstInstance("OpenPOS"))
        {
            var application = new App();

            application.InitializeComponent();
            application.Run();

            // Allow single instance code to perform cleanup operations
            SingleInstance.Cleanup();
        }
    }
}

And wrap the normal Main() stuff in a SingleInstance.InitializeAsFirstInstance. This will ensure that the application will only really be started once. Once a second instance is created, an event will fire… We can handle this event then in our ShellViewModel.

C#
SingleInstance.SingleInstanceActivated += 
    new EventHandler<SingleInstanceEventArgs>(SingleInstance_SingleInstanceActivated);

In the SingleInstance_SingleInstanceActivated event handler, we can navigate to the new passed in “View”.

Ok, this is great but where do we create the JumpList? In WPF 4, the JumpList is built in, so we do not need the Windows® API Code Pack for Microsoft® .NET Framework any more… Now we can just do the following:

C#
var jl = JumpList.GetJumpList(Application.Current);

Which should return the current application’s JumpList… and add or remove any JumpTask. Here is the CreateJumpList method in my NavigationService:

C#
public void CreateJumpList()
{
    var jl = JumpList.GetJumpList(Application.Current);
    jl.JumpItems.Clear();
    for (int i = _navigationPoints.Count-1; i >= 0; i--)
    {
        var point = _navigationPoints[i];
        if (point.ShowInJumpList)
        {
            jl.JumpItems.Add(new JumpTask
                                    {
                                        Title = point.Name,
                                        CustomCategory = point.Category,
                                        IconResourceIndex = 0,
                                        IconResourcePath =
                                            Path.Combine
					(System.Environment.CurrentDirectory, 
					"OpenPOS.exe"),
                                        Arguments = point.CreateArg(),
                                        ApplicationPath =
                                            Path.Combine
					(System.Environment.CurrentDirectory, 
					"OpenPOS.exe")
                                    });
        }
    }
    jl.Apply();
}

We just loop through all the NavigationPoints and for each one that has the ShowInJumpList set to true will be added…

What is the current state of OpenPOS?

I have been hard at work finishing off some of the “normal” business requirements of a point of sale system. Here is a somewhat incomplete list of stuff I have done:

  • Implemented the Sales module
  • Implemented Ticket/Payment (Multi payment)
  • Users/Navigation plumming
  • Implemented Stock control (Stock can be added or removed)
  • Implemented reporting (Using Open-Source WPF Reporting Engine)
  • Cashup
  • Implemented basic Customer support
  • And much, much more…

Want to learn more?

The source is available on Codeplex.

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