Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Getting Started with Windows Mobile Development : Page 4

Although the Compact Framework is roughly one-third the size of the regular .NET Framework, it provides all of the requisite functionality to create powerful mobile applications.


advertisement
Creating the Order Form
The order form example shows the primary techniques you'll use when creating mobile application forms. Remember that form real estate is minimal, and that form factor changes (differing devices) can affect your layout and data entry. You solve this problem by using a TabControl or panel on each form as a container for the objects within it. With a TabControl, you effectively extend screen space by adding tab pages and more controls as needed.

The order form in the next example will let users:

  • Search for an order
  • View a specific order
  • Edit a selected order
  • Delete a selected order
  • Add a new order
To create the form design, I dragged a TabControl from the ToolBox, and then added controls to the TabPages to display what I wanted. New forms added to the project initially have an empty MainMenu control. To create your menu actions, simply click the menu bar (see Figure 5) and type. You can add as many menu items horizontally and vertically as you need. Figure 6 and Figure 7 show the completed order form with its TabControl in place and the MainMenu items added.

 
Figure 5. Creating Menus: New forms have an empty MainMenu control to which you add items by clicking the menu bar and typing the item names.
 
Figure 6. Search Tab: When users click the Search tab, they can select a customer and a date range for which to search.
 
Figure 7. The View Order Tab: Selecting an order in the main grid and clicking the View Order tab displays the selected order in detail mode.

To search for a given order, you will use the customer key and a date range. I've set the default date range to the hundred year period from 1950-2050. The code for the search is as follows (in this example, _rowNumber is set in a method that determines the row number of the selected DataGrid row in a grid hit method):

private void SearchMenuItem_Click( object sender, EventArgs e) { OrderBiz biz = new OrderBiz(); _dtOrder = biz.Find( this.cboCustomer.Text.Trim(), this.dtgStartDate.Value, this.dtgEndDate.Value); this.grdSearch.Select(_rowNumber); if (_dtOrder.Rows.Count > 0) { this.ViewMenuItem.Enabled = true; this.DeleteMenuItem.Enabled = true; } }

In this code sample, you make a call to the order business object to perform the search and return a strongly typed dataset containing the matching orders. The business object's Find() method is shown here:

public OrderDataSet.OrderDataTable Find( string customerName, DateTime startDate, DateTime endDate) { OrderDataSet.OrderDataTable dt = new OrderDataSet.OrderDataTable(); OrderTableAdapter ta = new OrderTableAdapter(); if (customerName.Equals("ANY")) { customerName = string.Empty; } ta.FillBy(dt, startDate, endDate, "%"+customerName+"%"); return dt; }

The main form's grid then displays the orders returned by the search. By selecting an item in this grid and pressing the View menu item, the selected order and its order items will be displayed in the view mode (on the View Order tab). The view mode displays the order's subtotal, tax, and total, which requires an instance of the inventory business object in addition to the order and order item business objects (see Listing 1 and Listing 2 respectively).

Another item to consider is data entry in your forms. If your target device supports both a hardware QWERTY keyboard and a SIP, you need to worry about the SIP, because when users display the SIP, it might cover up the entry-field text boxes when users enable it, preventing users from being able to see the text they're entering. When that's a possibility, you need to trap an event and resize your TabControl so no fields get covered.

The SIP includes a property called VisibleDesktop, which lets you know how much real estate is visible after the SIP is open. If necessary, the device will add scroll bars to the TabControl so that you can enter text into all available fields. Here's the code:



private void inputPanel_EnabledChanged( object sender, EventArgs e) { if (inputPanel.Enabled) { //get the height of the TabControl _originalHeight = this.tcTab.Height; //adjust the TabControl for the SIP's space this.tcTab.Height = inputPanel.VisibleDesktop.Height; } else { this.tcTab.Height = _originalHeight; this.tcTab.Dock = DockStyle.Fill; } }



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date