- •About the Authors
- •Contents at a Glance
- •Contents
- •Introduction
- •Goal of the Book
- •How to Use this Book
- •Introduction to the .NET Framework
- •Common Language Runtime (CLR)
- •Class Library
- •Assembly
- •Versioning
- •Exceptions
- •Threads
- •Delegates
- •Summary
- •Introduction to C#
- •Variables
- •Initializing Variables
- •Variable Modifiers
- •Variable Data Types
- •Types of Variables
- •Variable Scope
- •Types of Data Type Casting
- •Arrays
- •Strings
- •Initializing Strings
- •Working with Strings
- •Statements and Expressions
- •Types of Statements
- •Expressions
- •Summary
- •Classes
- •Declaring Classes
- •Inheritance
- •Constructors
- •Destructors
- •Methods
- •Declaring a Method
- •Calling a Method
- •Passing Parameters to Methods
- •Method Modifiers
- •Overloading a Method
- •Namespaces
- •Declaring Namespaces
- •Aliases
- •Structs
- •Enumerations
- •Interfaces
- •Writing, Compiling, and Executing
- •Writing a C# Program
- •Compiling a C# Program
- •Executing a C# Program
- •Summary
- •Arrays
- •Single-Dimensional Arrays
- •Multidimensional Arrays
- •Methods in Arrays
- •Collections
- •Creating Collections
- •Working with Collections
- •Indexers
- •Boxing and Unboxing
- •Preprocessor Directives
- •Summary
- •Attributes
- •Declaring Attributes
- •Attribute Class
- •Attribute Parameters
- •Default Attributes
- •Properties
- •Declaring Properties
- •Accessors
- •Types of Properties
- •Summary
- •Introduction to Threads
- •Creating Threads
- •Aborting Threads
- •Joining Threads
- •Suspending Threads
- •Making Threads Sleep
- •Thread States
- •Thread Priorities
- •Synchronization
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Primary and Foreign Keys
- •Referential Integrity
- •Normalization
- •Designing a Database
- •Low-Level Design
- •Construction
- •Integration and Testing
- •User Acceptance Testing
- •Implementation
- •Operations and Maintenance
- •Summary
- •Creating a New Project
- •Console Application
- •Windows Applications
- •Creating a Windows Application for the Customer Maintenance Project
- •Creating an Interface for Form1
- •Creating an Interface for WorkerForm
- •Creating an Interface for CustomerForm
- •Creating an Interface for ReportsForm
- •Creating an Interface for JobDetailsForm
- •Summary
- •Performing Validations
- •Identifying the Validation Mechanism
- •Using the ErrorProvider Control
- •Handling Exceptions
- •Using the try and catch Statements
- •Using the Debug and Trace Classes
- •Using the Debugging Features of Visual Studio .NET
- •Using the Task List
- •Summary
- •Creating Form1
- •Connecting WorkerForm to the Workers Table
- •Connecting CustomerForm to the tblCustomer Table
- •Connecting the JobDetails Form
- •to the tblJobDetails Table
- •Summary
- •Introduction to the Crystal Reports Designer Tool
- •Creating the Reports Form
- •Creating Crystal Reports
- •Creating the Windows Forms Viewer Control
- •Creating the Monthly Worker Report
- •Summary
- •Introduction to Deploying a Windows Application
- •Deployment Projects Available in Visual Studio .NET
- •Deployment Project Editors
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Populating the TreeView Control
- •Displaying Employee Codes in the TreeView Control
- •Event Handling
- •Displaying Employee Details in the ListView Control
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Adding the Programming Logic to the Application
- •Adding Code to the Form Load() Method
- •Adding Code to the OK Button
- •Adding Code to the Exit Button
- •Summary
- •The Created Event
- •Adding Code to the Created Event
- •Overview of XML
- •The XmlReader Class
- •The XmlWriter Class
- •Displaying Data in an XML Document
- •Displaying an Error Message in the Event Log
- •Displaying Event Entries from Event Viewer
- •Displaying Data from the Summary.xml Document in a Message Box
- •Summary
- •Airline Profile
- •Role of a Business Manager
- •Role of a Network Administrator
- •Role of a Line-of-Business Executive
- •Project Requirements
- •Creation and Deletion of User Accounts
- •Addition of Flight Details
- •Reservations
- •Cancellations
- •Query of Status
- •Confirmation of Tickets
- •Creation of Reports
- •Launch of Frequent Flier Programs
- •Summarizing the Tasks
- •Project Design
- •Database Design
- •Web Forms Design
- •Enabling Security with the Directory Structure
- •Summary
- •Getting Started with ASP.NET
- •Prerequisites for ASP.NET Applications
- •New Features in ASP.NET
- •Types of ASP.NET Applications
- •Exploring ASP.NET Web Applications
- •Introducing Web Forms
- •Web Form Server Controls
- •Configuring ASP.NET Applications
- •Configuring Security for ASP.NET Applications
- •Deploying ASP.NET Applications
- •Creating a Sample ASP.NET Application
- •Creating a New Project
- •Adding Controls to the Project
- •Coding the Application
- •Summary
- •Creating the Database Schema
- •Creating Database Tables
- •Managing Primary Keys and Relationships
- •Viewing the Database Schema
- •Designing Application Forms
- •Standardizing the Interface of the Application
- •Common Forms in the Application
- •Forms for Network Administrators
- •Forms for Business Managers
- •Forms for Line-of-Business Executives
- •Summary
- •The Default.aspx Form
- •The Logoff.aspx Form
- •The ManageUsers.aspx Form
- •The ManageDatabases.aspx Form
- •The ChangePassword.aspx Form
- •Restricting Access to Web Forms
- •The AddFl.aspx Form
- •The RequestID.aspx Form
- •The Reports.aspx Form
- •The FreqFl.aspx Form
- •Coding the Forms for LOB Executives
- •The CreateRes.aspx Form
- •The CancelRes.aspx Form
- •The QueryStat.aspx Form
- •The ConfirmRes.aspx Form
- •Summary
- •Designing the Form
- •The View New Flights Option
- •The View Ticket Status Option
- •The View Flight Status Option
- •The Confirm Reservation Option
- •Testing the Application
- •Summary
- •Locating Errors in Programs
- •Watch Window
- •Locals Window
- •Call Stack Window
- •Autos Window
- •Command Window
- •Testing the Application
- •Summary
- •Managing the Databases
- •Backing Up the SkyShark Airlines Databases
- •Exporting Data from Databases
- •Examining Database Logs
- •Scheduling Database Maintenance Tasks
- •Managing Internet Information Server
- •Configuring IIS Error Pages
- •Managing Web Server Log Files
- •Summary
- •Authentication Mechanisms
- •Securing a Web Site with IIS and ASP.NET
- •Configuring IIS Authentication
- •Configuring Authentication in ASP.NET
- •Securing SQL Server
- •Summary
- •Deployment Scenarios
- •Deployment Editors
- •Creating a Deployment Project
- •Adding the Output of SkySharkDeploy to the Deployment Project
- •Deploying the Project to a Web Server on Another Computer
- •Summary
- •Organization Profile
- •Project Requirements
- •Querying for Information about All Books
- •Querying for Information about Books Based on Criteria
- •Ordering a Book on the Web Site
- •Project Design
- •Database Design
- •Database Schema
- •Web Forms Design
- •Flowcharts for the Web Forms Modules
- •Summary
- •Introduction to ASP.NET Web Services
- •Web Service Architecture
- •Working of a Web Service
- •Technologies Used in Web Services
- •XML in a Web Service
- •WSDL in a Web Service
- •SOAP in a Web Service
- •UDDI in a Web Service
- •Web Services in the .NET Framework
- •The Default Code Generated for a Web Service
- •Testing the SampleWebService Web Service
- •Summary
- •Creating the SearchAll() Web Method
- •Creating the SrchISBN() Web Method
- •Creating the AcceptDetails() Web Method
- •Creating the GenerateOrder() Web Method
- •Testing the Web Service
- •Securing a Web Service
- •Summary
- •Creating the Web Forms for the Bookers Paradise Web Site
- •Adding Code to the Web Forms
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Overview of Mobile Applications
- •The Microsoft Mobile Internet Toolkit
- •Overview of WAP
- •The WAP Architecture
- •Overview of WML
- •The Mobile Web Form
- •The Design of the MobileTimeRetriever Application
- •Creating the Interface for the Mobile Web Forms
- •Adding Code to the MobileTimeRetriever Application
- •Summary
- •Creating the Forms Required for the MobileCallStatus Application
- •Creating the frmLogon Form
- •Creating the frmSelectOption Form
- •Creating the frmPending Form
- •Creating the frmUnattended Form
- •Adding Code to the Submit Button in the frmLogon Form
- •Adding Code to the Query Button in the frmSelectOption Form
- •Adding Code to the Mark checked as complete Button in the frmPending Form
- •Adding Code to the Back Button in the frmPending Form
- •Adding Code to the Accept checked call(s) Button in the frmUnattended Form
- •Adding Code to the Back Button in the frmUnattended Form
- •Summary
- •What Is COM?
- •Windows DNA
- •Microsoft Transaction Server (MTS)
- •.NET Interoperability
- •COM Interoperability
- •Messaging
- •Benefits of Message Queues
- •Limitations
- •Key Messaging Terms
- •Summary
- •Pointers
- •Declaring Pointers
- •Types of Code
- •Implementing Pointers
- •Using Pointers with Managed Code
- •Working with Pointers
- •Compiling Unsafe Code
- •Summary
- •Introduction to the Languages of Visual Studio .NET
- •Visual C# .NET
- •Visual Basic .NET
- •Visual C++ .NET
- •Overview of Visual Basic .NET
- •Abstraction
- •Encapsulation
- •Inheritance
- •Polymorphism
- •Components of Visual Basic .NET
- •Variables
- •Constants
- •Operators
- •Arrays
- •Collections
- •Procedures
- •Arguments
- •Functions
- •Adding Code to the Submit Button
- •Adding Code to the Exit Button
- •Summary
- •Introduction to Visual Studio .NET IDE
- •Menu Bar
- •Toolbars
- •Visual Studio .NET IDE Windows
- •Toolbox
- •The Task List Window
- •Managing Windows
- •Customizing Visual Studio .NET IDE
- •The Options Dialog Box
- •The Customize Dialog Box
- •Summary
- •Index
BASICS OF MOBILE APPLICATIONS |
Chapter 32 |
751 |
|
|
|
|
|
You have learned about various controls that can be used in a mobile Web application. You can now use this knowledge to create the mobile Web forms required for a MobileTimeRetriever application.
Creating the Interface for the Mobile Web Forms
The MobileTimeRetriever application contains two forms, frmOptions and frmResult. Figure 32-16 shows the interface of the frmOptions form.
FIGURE 32-16 The interface of the frmOptions form
As you can see, the frmOptions form contains three Label controls, one Command control, and one SelectionList control. To add these controls to the form, drag the controls from the mobile Web forms control toolbox to the form and change the following properties of the controls.
Label1
ID: lblCurrentTime
Text: The current time in New York is:
Font:
Bold: True
752 Project 6 CREATING A MOBILE APPLICATION
Label2
ID: lblCurTime
Text: Label
Label3
ID: lblRegion
Text: Select a new location below:
Font:
Bold: True
Command1
ID: cmdFindTime
Text: Find Time
SelectionList
ID: lstLocations
Items: The items to be added in the SelectionList control are displayed
in Table 32-1.
Table 32-1 Items to Be Added to the SelectionList Control
ItemText |
Value |
Selected |
London |
1 |
Checked |
Moscow |
2 |
Unchecked |
Bangkok |
3 |
Unchecked |
Singapore |
4 |
Unchecked |
Sydney |
5 |
Unchecked |
|
|
|
BASICS OF MOBILE APPLICATIONS |
Chapter 32 |
753 |
|
|
|
|
|
In the General tab of the lstLocations Properties dialog box, change the following properties:
Select Type: DropDown
Rows: 4
After creating the interface for the frmOptions form, create the interface for the frmResult form. Figure 32-17 shows the interface for the frmResult form.
FIGURE 32-17 The frmResult form
The frmResult form contains three Label controls and one Command control. Change the following properties of the controls:
Label1
ID: lblSelLoc
Text: You selected:
754 Project 6 CREATING A MOBILE APPLICATION
Label2
ID: lblTime
Text: Time:
Font:
Bold: True
Label3
ID: lblOrgLoc
Text: (as of EST)
Command1
ID: cmdBack
Text: Back
After creating the interface, add code to the controls in the MobileTimeRetriever application.
Adding Code to the MobileTimeRetriever Application
Once you have added the controls to the form,Visual Studio .NET automatically creates the declaration statements for the controls. However, to make the controls functional, you need to add code to the Click events of the Command controls.
Adding Code to the cmdFindTime Command Control
When a user selects the location from a lstLocations SelectionList control and clicks on the cmdFindTime Command control, the application displays the current time in the selected location. To do this, add the following code to the Click event of the cmdFindTime Command control.
private void cmdFindTime_Click(object sender, System.EventArgs e)
{
DateTime currentTime= DateTime.Now; TimeSpan timeDiff=new TimeSpan(0,0,0); switch (lstLocations.Selection.Value)
BASICS OF MOBILE APPLICATIONS |
Chapter 32 |
755 |
|
|
|
|
|
{
case “1”:
timeDiff=new TimeSpan(5,0,0); break;
case “2”:
timeDiff=new TimeSpan(8,0,0); break;
case “3”:
timeDiff=new TimeSpan(12,0,0); break;
case “4”:
timeDiff=new TimeSpan(13,0,0); break;
case “5”:
timeDiff=new TimeSpan(15,0,0); break;
}
DateTime newTime=currentTime.Add(timeDiff); lblSelLoc.Text=”You selected: “ + lstLocations.Selection.Text;
lblTime.Text=”Time at the selected location:” + Convert.ToString(newTime); lblOrgLoc.Text=”(as of “ + DateTime.Now + “ EST)”;
ActiveForm=frmResult;
}
The previous code creates a variable, currentTime, of the struct DateTime in the System namespace. It then uses the Now property of the struct DateTime to retrieve the current date and time on the computer. The value returned by the Now property is stored in the currentTime variable. The code then creates an instance, timeDiff, of the TimeSpan struct in the System namespace. The TimeSpan struct is used to represent a time interval. Next, a switch case is used to trap the value selected by the user in the SelectionList control. To do this, the Value property of the MobileListItem class is used.
Then, the instance of the TimeSpan struct is used to find the time for different locations. The difference between the time in New York and the selected city is passed as a parameter to timeDiff. For example, the difference between the time in New York and London is five hours.Therefore, this time difference in hours is passed as a parameter to the default constructor of timeDiff. Similarly, the time
756 Project 6 CREATING A MOBILE APPLICATION
difference between other cities is passed to timeDiff for different cases of the switch statement.
The code then creates another variable of the DateTime struct, newTime. Then, the Add() method of the DateTime class is used to add the value stored in timeDiff to the value stored in the currentTime variable. The result is then stored in the newTime variable, which is then converted to a string and displayed in the lblTime Label control. The location selected by the user is displayed in the lblSelLoc Label control. The time at the original location, New York, is displayed in the lblOrgLoc Label control. Finally, the code makes the frmResult form active. Figure 32-18 shows the frmOptions form at run time.
FIGURE 32-18 The frmOptions form at run time
When the user clicks on the Find Time button, the frmResult form becomes active. Figure 32-19 shows the frmResult form at run time.
BASICS OF MOBILE APPLICATIONS |
Chapter 32 |
757 |
|
|
|
|
|
FIGURE 32-19 The frmResult form at run time
To return to the frmOptions form from the frmResult form, the user needs to click on the Back button. The following section discusses how to add code to the Back button.
Adding Code to the cmdBack Command Control
When a user clicks on the Back button, the frmOptions form becomes active. To do this, add the following code to the Click event of the cmdBack Command control.
private void cmdBack_Click(object sender, System.EventArgs e)
{
ActiveForm=frmOptions;
}
The preceding code uses the ActiveForm property to set the frmOptions form as active. The entire code of the application is as shown below.
using System;
using System.Collections;
using System.ComponentModel;
758 |
Project 6 |
|
CREATING A MOBILE APPLICATION |
|||||
|
|
|
|
|
|
|
||
|
using System.Data; |
|
|
|
|
|||
|
using System.Drawing; |
|
|
|
|
|||
|
using System.Web; |
|
|
|
|
|||
|
using System.Web.Mobile; |
|
|
|
|
|||
|
using System.Web.SessionState; |
|
|
|
|
|||
|
using System.Web.UI; |
|
|
|
|
|||
|
using System.Web.UI.MobileControls; |
|
Y |
|||||
|
using System.Web.UI.WebControls; |
|
|
|||||
|
|
L |
||||||
|
using System.Web.UI.HtmlControls; |
|||||||
|
F |
|
||||||
|
using System.Xml; |
|
|
|||||
|
M |
|
|
|||||
|
namespace MobileTimeRetriever |
|
|
|||||
|
|
|
|
|
||||
|
{ |
|
|
|
|
|
|
|
|
|
public class MobileWebForm1 : System.Web.UI.MobileControls.MobilePage |
||||||
|
|
{ |
|
E |
|
|
|
|
|
|
|
protected |
T |
|
|
|
lblCurrentTime; |
|
|
|
System.Web.UI.MobileControls.Label |
|||||
|
|
|
protected System.Web.UI.MobileControls.LabelA |
lblRegion; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.SelectionList lstLocations; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.Command cmdFindTime; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.Label lblSelLoc; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.Label lblTime; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.Command cmdBack; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.Label |
lblCurTime; |
|||
|
|
|
protected System.Web.UI.MobileControls.Form |
frmOptions; |
||||
|
|
|
protected |
System.Web.UI.MobileControls.Form |
frmResult; |
|||
|
|
|
protected |
System.Web.UI.MobileControls.Label lblOrgLoc; |
private void Page_Load(object sender, System.EventArgs e)
{
ActiveForm=frmOptions; lblCurTime.Text=Convert.ToString(DateTime.Now);
}
private void cmdFindTime_Click(object sender, System.EventArgs e)
{
DateTime currentTime= DateTime.Now; TimeSpan timeDiff=new TimeSpan(0,0,0); switch (lstLocations.Selection.Value)
Team-Fly®
BASICS OF MOBILE APPLICATIONS |
Chapter 32 |
759 |
|
|
|
|
|
{
case “1”:
timeDiff=new TimeSpan(5,0,0); break;
case “2”:
timeDiff=new TimeSpan(8,0,0); break;
case “3”:
timeDiff=new TimeSpan(12,0,0); break;
case “4”:
timeDiff=new TimeSpan(13,0,0); break;
case “5”:
timeDiff=new TimeSpan(15,0,0); break;
}
DateTime newTime=currentTime.Add(timeDiff); lblSelLoc.Text=”You selected: “ + lstLocations.Selection.Text;
lblTime.Text=”Time at the selected location:” + Convert.ToString(newTime); lblOrgLoc.Text=”(as of “ + DateTime.Now + “ EST)”;
ActiveForm=frmResult;
}
private void cmdBack_Click(object sender, System.EventArgs e)
{
ActiveForm=frmOptions;
}
}
}
In Figures 32-18 and 32-19, you saw the forms in Internet Explorer. To have an idea of the look of the forms in a mobile device, you can view the output of the application in a WAP device emulator. To view the output of the application in an emulator, you need to install the emulator and the WAP gateway. After installing the emulator and the gateway, you need to perform the following steps to view the output in the emulator:
1. On the View menu, point to the Mobile Explorer Browser option.
760Project 6 CREATING A MOBILE APPLICATION
2.In the displayed list, select the Show Browser option.
3.Type the URL address of the mobile Web page in the Address box of the emulator and then press the Enter key.
The output is shown in the emulator. Figure 32-20 shows the frmOptions form in an emulator.
FIGURE 32-20 The frmOptions form in an emulator
Figure 32-21 shows the frmResult form in the emulator.