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 3

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 Database
You can create your compact database using either Visual Studio or SQL Server. For this example, you will create the tables you need using the built-in functionality of Visual Studio:

  1. Open your Server Explorer.
  2. Right-click the Data Connections item.
  3. Choose "Add Connection."
  4. Fill in the fields in the Add Connection dialog box (see Figure 3).
  5. Click the Create button.
  6. Fill in the fields in the "Create New SQL Server Compact Database" dialog box (see Figure 4) and click OK.
  7. Test your connection, and then click OK.
 
Figure 3. Creating a New Data Connection: Using the Add Connection dialog, specify the data source and connection properties.
 
Figure 4. Creating a New SQL Server Compact Database: Use the dialog shown in this figure to create a new SQL Server compact database.

With the database created, you can start creating the tables you need for the application by right-clicking the new data connection and choosing "Create table." For the mobile orders application, I created these tables: customer, order, orderitem, inventory, supplier, and manufacturer.

With the database structure in place, you can create strongly typed datasets by dragging each table from the server explorer to the dataset designer. The designer will create all the necessary code for you when you close it.

Windows Forms vs. Mobile Forms
Much of the mobile forms development is the same as Windows Forms; however, there are some distinct differences. These differences include:

  • Data binding
  • Data grid/custom controls
  • Events
  • Data entry
With Windows Forms, data binding is the accepted best practice; with mobile forms, manual binding is sometimes better. Manual binding is faster than the built-in data binding. Because you are typically dealing with only a handful of controls on any given form, the effort necessary to bind the controls to the data is more trouble than it is worth. However, standard data binding makes sense when you need:

  • Master/detail binding
  • Navigation
  • Currency Manager/BindingSource
Here's a sample of how the mobile orders project uses manual binding to populate the controls:

private void FillOrderHeaderControls( OrderDataSet.OrderRow dr) { this.txtCustomer.Text = dr.CustomerName; this.dtgOrderDate.Value = dr.OrderDate; } private void FillOrderItemControls( OrderItemDataSet.OrderItemRow dr) { this.txtManPartNo = _dr.ManPartNo; this.cboInventory.SelectedValue =_dr.fkInventory; this.txtQuantity.Text = (string)dr.quantity; this.txtPrice.Text = _dr.price; _dtItem.AddOrderItemRow(_dr); }

To gather control values to fill a row:

private void FillOrderHeaderRow() { _drOrder = _dtOrder.NewOrderRow(); _drOrder.fkCustomer = _cBiz.GetCustomerKey( this.txtCustomer.Text); _drOrder.OrderDate = this.dtgOrderDate.Value; _dtOrder.AddOrderRow(_drOrder); } private void FillOrderItemsRow() { _drItem = _dtItem.NewOrderItemRow(); _drItem.ManPartNo = _iBiz.GetManPartNo(value); _drItem.fkOrder = 0; _drItem.fkInventory = this.GetInventoryKey (this.cboInventory.Text); _drItem.Description = this.cboInventory.Text.Trim(); _drItem.quantity = (int)this.txtQuantity.Text; _drItem.price = (decimal)this.txtPrice.Text _dtItem.AddOrderItemRow(_drItem); }

One common question on the Compact Framework forum deals with adding custom controls to grid columns. Out of the box, the DataGrid control does not support custom columns without some extra work—unlike the regular framework DataGrid control.

With the release of .NET CF 2.0 SP1, the team exposed the DataGrid column's Paint method, which opens the opportunity for custom control creation. Due to the number of requests for help with this feature, they created a downloadable package that includes a number of useful controls, including the ComboBox, the CheckBbox, and a DateTimePicker. After you reference that library in your project, you can include custom columns with ease:



//TextBox Column DataGridCustomTextBoxColumn colOrdNo = new DataGridCustomTextBoxColumn(); colOrdNo.Owner = this.grdSearch; colOrdNo.HeaderText = "No"; colOrdNo.MappingName = "OrderNo"; colOrdNo.Alignment = HorizontalAlignment.Left; //CheckBox Colum DataGridCustomCheckBoxColumn colTaxable = new DataGridCustomCheckBoxColumn(); colTaxable.Owner = this.grdSearch; colTaxable.HeaderText = "Taxable"; colTaxable.MappingName = "Taxable"; colTaxable.Alignment = HorizontalAlignment.Center;

Mobile devices don't support easy data entry into form controls. For the most part, users have to enter text via a built-in hardware mini QWERTY keyboard or using a pop-up software keyboard called a SIP (software input panel). On older smart phones without the hardware keyboard, users must press the number keys on the keypad to enter text. Using any of these options, text entry is difficult, time consuming, and tedious. Therefore, a mobile forms designer must limit the amount of data entry required through the use of judiciously planned controls. Use drop-down lists pre-populated with the most common choices, check boxes, and lists to limit the amount of typing necessary.

Events are another place where mobile development is distinctly different from desktop applications. A typical Windows Form has more than 75 events; a mobile form has 23. A regular button has 60 events; a CF button has 11.

Because of this event disparity, you will need to put more thought into program flow and into creating and designing your mobile forms and projects than your Windows Forms applications.



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