|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionAs a software developer and a geek before all, I dream that paper and pencil become useless by replacing them by their numeric counterpart. Obviously, we are far from this dream. However, with the advent of Pocket PC, and the Pocket Framework specifically, I've found a powerful tool in the pursuit of this dream. In my quest for the perfect project for the Code Project competition, I happened to find one of those little pieces of paper that my girlfriend uses, week after week, for her shopping list. Great! I've found my project, and also I've found a way that pencil and paper become useless. I'm going to build a Pocket PC application for shopping planning! This article is written as an extremely condensed analysis document. You will find information regarding the requirements, the user interface guideline, the system's design, and finally, a section where you will find implementation details about some of the most interesting parts of the code. TerminologyThe following terminology is used throughout the Shopping App discussions:
Background - The User RequirementsThe main challenge here with the shopping application was not really the code part, but the design part. Obviously, the goal was to build a funny application, but before all, a useful one that can really be integrated in day to day life. The requirements for the application can be summarized as:
The Shopping Application - User Interface GuidelineWhen the Shopping application opens, it displays a list of existing carts. The first time you open it, you face a blank screen. Available carts' list can be filtered to display carts that meet specific criteria based on the categories in which the cart belongs. To add a new cart, either click on the New icon, or select an existing cart in the list and click on the Clone icon to use the selected cart as a template for your new cart. Opening an existing cart can be achieved either by double clicking a cart in the list, or by selecting a cart in the list and clicking the Open icon. Figure 1 shows the initial screen with several carts that meet the current filter (Category = Grocery).
Figure 1: Starting screen for shopping application. Product DefinitionFigure 2 shows the Product definition screen. This is where the user defines the products needed when creating a new Cart. You access the product definition screen by clicking on the Option button, then selecting Manage/Product Editor menu. To add a new product, click the New button and enter the product's name in the text box. Optionally, you can specify a default unit for each product. Click the Add button to add the product. Changes are automatically saved as the window closes.
Figure 2: Product Definition screen. Unit DefinitionFigure 3 shows the Unit definition screen. This is where the user defines the product's units. You access the unit definition screen by clicking on the Option button, then selecting Manage/Unit Editor menu. To add a new unit, click the New button and enter the unit's name in the text box. Click the Add button to add the unit. Changes are automatically saved as the window closes.
Figure 3: Unit Definition screen. Using the Cart ScreenThe Cart screen is the numeric counterpart of a paper based shopping list. This screen presents the shopping list items with the following information: product's name, quantity, format, and notification icon (a note icon stands next to the product's name if there is a note associated with the entry). Cart's title and category can be changed on the Properties tab. The Plus and X icons are used to add and remove items in the list. Items can also be moved up and down on the list with the Up and Down arrow icons. The last icon is used to toggle the operating mode from shopping to editing. In shopping mode, an item can be set as checked by clicking on it with the stylet. While in shopping mode, it is not possible to add or remove an item. Changes are automatically saved as the window closes.
Figure 4: Cart screen. The Item EditorThis screen shows off when you click the Plus icon in the Cart screen, or when an existing item is double-clicked. To add a new item to the list, select a product from the list, specify the quantity, and optionally change the item's unit if it is not the correct one. The products list can be easily filtered by using the ToggleCategory button. When you click on a toggle category (Mno, for example), then only products beginning with the letter 'm' or greater are displayed. Clicking repetitively on a toggled category alternates the category's letters (Mno, mNo, mnO, Mno ...). The Notes tab contains a text area used to add a note to the item. As mentioned previously, when a note is attached to an item, an icon stands next to the item's name. Changes are saved with the Saved (green) button, while the Cancel (red) button is used to cancel changes.
Figure 5: Item Editor Screen. Design & ImplementationThe design follows the 2-tier architecture (user interface, business logic). The data-layer tier has been included in the business rule to simplify. The project has been divided into three assemblies:
The application's design is rather simple. The business rules consist in only six public classes.
User Controls and Double BufferingSeveral issues with the Compact Framework were raised during the coding of the Shopping application. However, the most obvious one is the fact that available user controls are very limited in terms of features and diversity. As an example, the I wrote 9 user controls and 2 supporting classes for this project. I will not go into the details of each control but I will pinpoint some of the most helpful tips to writing your own controls for the Compact Framework.
Implementing Custom sorting on ArrayList with IComparerOne of my favorite classes in the .NET framework is the In my case, I have created a custom comparer called public class ProductsComparer : IComparer
{
int IComparer.Compare(Object x, Object y)
{
return( (Product)x).Name.CompareTo( ((Product)y).Name);
}
}
And here is where I use this class to sort an // Note: mProducts is an ArrayList
IComparer myComparer = new ProductsComparer();
mProducts.Sort(myComparer);
Implementing the OnDoubleClick EventDo not search for the namespace McSoft.UILib
{
public delegate void DoubleClickEventHandler(object sender, EventArgs e);
public abstract class OwnerDrawnListView : McSoftControl
{
// Partial class implementation to demonstrate
// OnDoubleClick event, see class
// OwnerDrawnListView for full implementation
public event DoubleClickEventHandler OnDoubleClick;
private int previousClick = SystemInformation.DoubleClickTime + 1;
protected override OnClick(EventArgs e)
{
int now = System.Environment.TickCount;
if(now - previousClick <= System.information.DoubleClickTime)
if(OnDoubleClick != null) OnDoubleClick(this.selectedIndex, e);
previousClick = now;
base.onClick (e);
}
}
}
HistoryThis is release 1.0 of the application. Road Map
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||