Tải bản đầy đủ (.pdf) (957 trang)

Microsoft C# Professional Projects docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.02 MB, 957 trang )

TEAMFLY






















































Team-Fly
®

C#
Professional Projects
This page intentionally left blank
Geetanjali Arora

Balasubramaniam
Aiaswamy
Nitin Pandey
WITH
C#
Professional Projects
Publisher:
Stacy L. Hiquet
Marketing Manager:
Heather Buzzingham
Managing Editor:
Sandy Doell
Editorial Assistant:
Margaret Bauer
Book Production Services:
Argosy
Cover Design:
Mike Tanamachi
©2002 by Premier Press, Inc.All rights reserved. No part of this book may
be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, recording, or by any information stor-
age or retrieval system without written permission from Premier Press,
except for the inclusion of brief quotations in a review.
The Premier Press logo, top edge printing, and related trade dress
are trademarks of Premier Press, Inc. and may not be used with-
out written permission. All other trademarks are the property of
their respective owners.
Important: Premier Press cannot provide software support. Please contact the
appropriate sof tware manufacturer’s technical support line or Web site for
assistance.

Premier Press and the author have attempted throughout this book to dis-
tinguish proprietary trademarks from descriptive terms by following the cap-
italization style used by the manufacturer.
Information contained in this book has been obtained by Premier Press from
sources believed to be reliable.However, because of the possibility of human
or mechanical error by our sources, Premier Press, or others, the Publisher
does not guarantee the accuracy, adequacy, or completeness of any informa-
tion and is not responsible for any errors or omissions or the results obtained
from use of such information. Readers should be particularly aware of the
fact that the Internet is an ever-changing entity. Some facts may have
changed since this book went to press.
ISBN: 1-931841-30-6
Library of Congress Catalog Card Number: 2001096998
Printed in the United States of America
02 03 04 05 06 RI 10 9 8 7 6 5 4 3 2 1
About NIIT
NIIT is a global IT solutions corporation with a presence in 38 countries. With its
unique business model and technology-creation capabilities, NIIT delivers software
and learning solutions to more than 1,000 clients across the world.
The success of NIIT’s training solutions lies in its unique approach to education.
NIIT’s Knowledge Solutions Business conceives, researches, and develops all of its
course material. A rigorous instructional design methodology is followed to create
engaging and compelling course content.
NIIT trains over 200,000 executives and learners each year in information technology
a reas using stand-up tra i n i n g, video-aided instru c t i on ,c omputer-based tra i n i n g
(CBT), and Internet-based training (IBT). NIIT has been featured in the Guinness
Book of World Records for the largest number of learners trained in one year!
NIIT has developed over 10,000 hours of instructor-led training (ILT) and over 3,000
hours of Internet-based training and computer-based training. IDC ranked NIIT
among the Top 15 IT training providers globally for the year 2000. Through the inno-

vative use of training methods and its commitment to research and development, NIIT
has been in the forefront of computer education and training for the past 20 years.
Quality has been the prime focus at NIIT. Most of the processes are ISO-9001 certi-
fied. It was the 12th company in the world to be assessed at Level 5 of SEI-CMM.
NIIT’s Content (Learning Material) Development facility is the first in the world to
be assessed at this highest maturity level. NIIT has strategic partnerships with compa-
nies such as Computer Associates, IBM, Microsoft, Oracle, and Sun Microsystems.
This page intentionally left blank
About the Authors
Geetanjali Arora is an instructional designer who has worked with the NIIT for
almost two years.She has done several projects with the NIIT that include instructor-
led training (ILT),computer-based training (CBT),and Web-based training (WBT).
She has written on both technical and non-technical subjects. At the NIIT,
Geentanjali’s responsibilities include scripting, construction, planning, and schedul-
ing. She has also provided training on NexGen and Dreamweaver.
Balasubramaniam Aiaswamy is a technical trainer and writer, an instructional
designer, a subject matter expert (SME), and an ID reviewer with NIIT’s Knowledge
Solutions Business division, which develops and reviews instructor-led training (ILT)
products for various software and technologies.These technologies include Microsoft
Visual InterDev 6.0, Microsoft Site Server 3.0 Commerce Edition, Microsoft Win-
dows CE, Java 2 Micro Edition (J2ME), networking concepts, the installation and
administration of a Layer 3 network, and Web security. He is both an MCSD and an
MCP in Windows NT. Balasubramaniam has experience in teaching career programs
at NIIT’s Career Education Group division. He has taught various technical subject
areas including networking essentials, SQL Server 7.0, Microsoft Windows NT
Server 4.0, Microsoft Visual Basic 6.0, Microsoft Visual C++ 4.0, Windows 32 API
programming, HTML, Java, Unix, C, and C++. He has also set up and managed labs
for students and administered Novell 3.11 and UNIX (SCO)–based networks.
Nitin Pandey works with NIIT as a subject matter expert (SME) for learning con-
tent developed on Microsoft technologies. Nitin has been involved in the develop-

ment of WBTs and seminars for NIIT Online Ltd. and Microsoft. Nitin provides
technical support to the development teams, develops sample applications, and pro-
vides technical reviews of learning content.
This page intentionally left blank
Contents at a Glance
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi
Part I Introduction to C# . . . . . . . . . . . . . . . . . . . . . . 1
1 Overview of the .NET Framework . . . . . . . . . . . . . . . . . . . 3
2 C# Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Part II Handling Data . . . . . . . . . . . . . . . . . . . . . . . . 41
3 Components of C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4 More about Components . . . . . . . . . . . . . . . . . . . . . . . . . 67
5 Attributes and Properties. . . . . . . . . . . . . . . . . . . . . . . . . . 83
6 Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Part III Professional Project 1:
Creating a Customer Maintenance Project. . 109
7 Project Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
8 Windows Forms and Controls. . . . . . . . . . . . . . . . . . . . . 141
9 Validations and Exception Handling . . . . . . . . . . . . . . . . 175
10 Database Interaction Using ADO.NET . . . . . . . . . . . . . 197
11 Crystal Reports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
12 Deploying a Windows Application . . . . . . . . . . . . . . . . . 259
Part IV Professional Project 2: Creating the
Employee Records System (ERS) Project. . . 293
13 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 297
14 Implementing the Business Logic . . . . . . . . . . . . . . . . . . 311
Part V Professional Project 3:
Creating a Creative Learning Project . . . . . . 329
15 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 333
16 Implementing the Programming Logic . . . . . . . . . . . . . . 349

17 Interacting with a Microsoft Word
Document and Event Viewer . . . . . . . . . . . . . . . . . . . . . 365
Part VI Professional Project 4:
Creating an Airline Reservation Portal. . . . . 395
18 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 399
19 Basics of ASP.NET Web Applications. . . . . . . . . . . . . . . 429
20 Designing the Application. . . . . . . . . . . . . . . . . . . . . . . . 453
21 Implementing the Business Logic . . . . . . . . . . . . . . . . . . 483
22 Creating the Customer Transaction Portal. . . . . . . . . . . . 521
23 Debugging and Testing the Application. . . . . . . . . . . . . . 537
24 Administering the Application . . . . . . . . . . . . . . . . . . . . 551
25 Securing the Application . . . . . . . . . . . . . . . . . . . . . . . . . 567
26 Deploying the Application . . . . . . . . . . . . . . . . . . . . . . . 581
Part VII Professional Project 5:
Creating a Web Portal for a Bookstore . . . . 593
27 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 597
28 Exploring ASP.NET Web Services . . . . . . . . . . . . . . . . . 619
29 Developing Web Services . . . . . . . . . . . . . . . . . . . . . . . . 641
30 Developing Web Service Clients . . . . . . . . . . . . . . . . . . . 667
Part VIII Professional Project 6:
Creating a Mobile Application . . . . . . . . . . . 713
31 Project Case Study and Design . . . . . . . . . . . . . . . . . . . . 717
32 Basics of Mobile Applications . . . . . . . . . . . . . . . . . . . . . 727
33 Implementing the Business Logic . . . . . . . . . . . . . . . . . . 763
Part IX Beyond the Labs . . . . . . . . . . . . . . . . . . . . . 793
34 Advanced C# Concepts. . . . . . . . . . . . . . . . . . . . . . . . . . 795
Part X Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . 829
A Unsafe Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 831
B Introduction to Visual Basic .NET . . . . . . . . . . . . . . . . . 843
C Visual Studio.NET Integrated

Development Environment . . . . . . . . . . . . . . . . . . . . . . . 877
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
x Contents at a Glance
TEAMFLY






















































Team-Fly
®


Contents
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi
Goal of the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi
How to Use this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxii
PART I INTRODUCTION TO C# . . . . . . . . . . . . . . . . . 1
Chapter 1 Overview of the .NET Framework . . . . . . . . . . . 3
Introduction to the .NET Framework . . . . . . . . . . . . . . . . . . . . . . 4
Common Language Runtime (CLR) . . . . . . . . . . . . . . . . . . . . 6
Class Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Versioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
An Overview of .NET Framework Base Classes . . . . . . . . . . . . . 14
Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Chapter 2 C# Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Introduction to C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Initializing Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Variable Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Variable Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Types of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Types of Data Type Casting . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Initializing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Working with Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Statements and Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

Types of Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
PART II HANDLING DATA . . . . . . . . . . . . . . . . . . . . 41
Chapter 3 Components of C# . . . . . . . . . . . . . . . . . . . . . 43
Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Declaring Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Declaring a Method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Calling a Method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Passing Parameters to Methods . . . . . . . . . . . . . . . . . . . . . . . 52
Method Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Overloading a Method. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Declaring Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Accessing Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
xii Contents
Writing, Compiling, and Executing a C# Program. . . . . . . . . . . . 64
Writing a C# Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Compiling a C# Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Executing a C# Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Chapter 4 More about Components . . . . . . . . . . . . . . . . 67

Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Single-Dimensional Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Methods in Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Creating Collections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Working with Collections. . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Indexers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Boxing and Unboxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Preprocessor Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
#region and #endregion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
#define and #undef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
#if, #endif, #else, and #elif. . . . . . . . . . . . . . . . . . . . . . . . . . 80
#error and #warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Chapter 5 Attributes and Properties . . . . . . . . . . . . . . . 83
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Declaring Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Attribute Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Attribute Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Default Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Contents
xiii
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Declaring Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Accessors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Types of Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Chapter 6 Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Introduction to Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Creating Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Aborting Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Joining Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Suspending Threads. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Making Threads Sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Thread States. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Thread Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
PART III PROFESSIONAL PROJECT 1 . . . . . . . . . . . 109
Project 1 Creating a Customer Maintenance Project. . 111
Project 1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Chapter 7 Project Case Study . . . . . . . . . . . . . . . . . . . 113
Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Analyzing Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
High-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Primary and Foreign Keys . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Referential Integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
xiv Contents
Designing a Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Designing the Windows Forms
Used in Customer Maintenance Project . . . . . . . . . . . . . . . . 130
Low-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Integration and Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
User Acceptance Testing. . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Operations and Maintenance . . . . . . . . . . . . . . . . . . . . . . . . 138

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Chapter 8 Windows Forms and Controls. . . . . . . . . . . . 141
Introduction to Visual Studio .NET Projects. . . . . . . . . . . . . . . 142
Creating a New Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Console Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Windows Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Creating a Windows Application
for the Customer Maintenance Project. . . . . . . . . . . . . . . . . . . . 164
Creating an Interface for
Form1 . . . . . . . . . . . . . . . . . . . . . . . 165
Creating an Interface for
WorkerForm . . . . . . . . . . . . . . . . . . . 167
Creating an Interface for
CustomerForm . . . . . . . . . . . . . . . . . 168
Creating an Interface for
ReportsForm . . . . . . . . . . . . . . . . . . 170
Creating an Interface for
JobDetailsForm . . . . . . . . . . . . . . . 172
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Chapter 9 Validations and Exception Handling . . . . . . . 175
Performing Validations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Identifying the Validation Mechanism . . . . . . . . . . . . . . . . . 177
Using the
ErrorProvider Control . . . . . . . . . . . . . . . . . . . . . 183
Handling Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Using the
try and catch Statements . . . . . . . . . . . . . . . . . . . 187
Using the
Debug and Trace Classes . . . . . . . . . . . . . . . . . . . . 189
Contents

xv
Debugging the Customer Management Application . . . . . . . . . 190
Using the Debugging Features of Visual Studio .NET . . . . . 190
Using the Task List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Chapter 10 Database Interaction Using ADO.NET . . . . . . 197
Connecting Windows Forms to a Data Source
Using ADO.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Creating Form1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Connecting WorkerForm to the
Workers Table . . . . . . . . . . . 200
Connecting CustomerForm to the
tblCustomer Table . . . . . . 211
Connecting the JobDetails Form
to the
tblJobDetails Table . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Chapter 11 Crystal Reports . . . . . . . . . . . . . . . . . . . . . . 239
Introduction to the Crystal Reports Designer Tool. . . . . . . . . . . 240
Creating the Reports Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Creating Crystal Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Creating the Windows Forms Viewer Control . . . . . . . . . . . 248
Creating the Monthly Customer Visit Report . . . . . . . . . . . . . . 251
Creating the Monthly Balancing and Alignment Report . . . . . . 254
Creating the Monthly Worker Report . . . . . . . . . . . . . . . . . . . . 256
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Chapter 12 Deploying a Windows Application. . . . . . . . . 259
Introduction to Deploying a Windows Application . . . . . . . . . . 260
Deployment Projects Available in Visual Studio .NET . . . . . 261
Deployment Project Editors . . . . . . . . . . . . . . . . . . . . . . . . . 279

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
xvi Contents
PART IV PROFESSIONAL PROJECT 2 . . . . . . . . . . . 293
Project 2 Creating the Employee
Records System (ERS) Project. . . . . . . . . . . 295
Project 2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Chapter 13 Project Case Study and Design . . . . . . . . . . 297
Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Analyzing Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
High-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Low-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Chapter 14 Implementing the Business Logic. . . . . . . . . 311
Populating the TreeView Control . . . . . . . . . . . . . . . . . . . . . . . 312
Displaying Employee Codes in the TreeView Control . . . . . 313
Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Displaying Employee Details in the ListView Control . . . . . 318
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
PART V PROFESSIONAL PROJECT 3 . . . . . . . . . . . 329
Project 3 Creating a Creative Learning Project . . . . . . 331
Project 3 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
Contents
xvii
Chapter 15 Project Case Study and Design . . . . . . . . . . 333
Case Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Project Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Analyzing Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
High-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Low-Level Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Chapter 16 Implementing the Programming Logic . . . . . 349
Adding the Programming Logic to the Application . . . . . . . . . . 350
Adding Code to the Form
Load() Method . . . . . . . . . . . . . . 351
Adding Code to the OK Button. . . . . . . . . . . . . . . . . . . . . . 353
Adding Code to the Exit Button . . . . . . . . . . . . . . . . . . . . . 363
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Chapter 17 Interacting with a Microsoft Word
Document and Event Viewer . . . . . . . . . . . . 365
Interacting with a Microsoft Word Document. . . . . . . . . . . . . . 366
The
Created Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Adding Code to the
Created Event. . . . . . . . . . . . . . . . . . . . 367
Overview of XML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
The
XmlReader Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
The
XmlWriter Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Displaying Data in an XML Document . . . . . . . . . . . . . . . . 373
Displaying an Error Message in the Event Log. . . . . . . . . . . 377
Displaying Event Entries from Event Viewer . . . . . . . . . . . . 383
Displaying Data from the
Summary.xml
Document in a Message Box . . . . . . . . . . . . . . . . . . . . . . . . 385
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
xviii Contents
PART VI PROFESSIONAL PROJECT 4 . . . . . . . . . . . 395
Project 4 Creating an Airline Reservation Portal. . . . . 397

Project 4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Chapter 18 Project Case Study and Design . . . . . . . . . . 399
Airline Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Role of a Business Manager . . . . . . . . . . . . . . . . . . . . . . . . . 401
Role of a Network Administrator . . . . . . . . . . . . . . . . . . . . . 402
Role of a Line-of-Business Executive . . . . . . . . . . . . . . . . . . 402
Project Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Creation and Deletion of User Accounts. . . . . . . . . . . . . . . . 403
Addition of Flight Details . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Reservations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Cancellations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Query of Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Confirmation of Tickets. . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Creation of Reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Launch of Frequent Flier Programs . . . . . . . . . . . . . . . . . . . 406
Summarizing the Tasks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Project Design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Database Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
Web Forms Design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Enabling Security with the Directory Structure. . . . . . . . . . . 425
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Chapter 19 Basics of ASP.NET Web Applications . . . . . . 429
Getting Started with ASP.NET. . . . . . . . . . . . . . . . . . . . . . . . . 430
Prerequisites for ASP.NET Applications. . . . . . . . . . . . . . . . 431
New Features in ASP.NET. . . . . . . . . . . . . . . . . . . . . . . . . . 431
Types of ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . 433
Contents
xix
Exploring ASP.NET Web Applications. . . . . . . . . . . . . . . . . . . 434
Introducing Web Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434

Web Form Server Controls. . . . . . . . . . . . . . . . . . . . . . . . . . 436
Configuring ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . 442
Configuring Security for ASP.NET Applications . . . . . . . . . 442
Deploying ASP.NET Applications. . . . . . . . . . . . . . . . . . . . 443
Creating a Sample ASP.NET Application . . . . . . . . . . . . . . . . . 443
Creating a New Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Adding Controls to the Project. . . . . . . . . . . . . . . . . . . . . . . 444
Coding the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
Chapter 20 Designing the Application . . . . . . . . . . . . . . 453
Creating the Database Schema . . . . . . . . . . . . . . . . . . . . . . . . . 454
Creating Database Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Managing Primary Keys and Relationships. . . . . . . . . . . . . . 460
Viewing the Database Schema . . . . . . . . . . . . . . . . . . . . . . . 464
Designing Application Forms . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Standardizing the Interface of the Application . . . . . . . . . . . 465
Common Forms in the Application . . . . . . . . . . . . . . . . . . . 465
Forms for Network Administrators. . . . . . . . . . . . . . . . . . . . 470
Forms for Business Managers . . . . . . . . . . . . . . . . . . . . . . . . 473
Forms for Line-of-Business Executives. . . . . . . . . . . . . . . . . 478
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
Chapter 21 Implementing the Business Logic. . . . . . . . . 483
Coding the Logon and Logoff Functionality . . . . . . . . . . . . . . . 484
The Default.aspx Form. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
The Logoff.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
xx Contents
TEAMFLY























































Team-Fly
®

Coding the Forms for Network Administrators . . . . . . . . . . . . . 490
The ManageUsers.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . 490
The ManageDatabases.aspx Form. . . . . . . . . . . . . . . . . . . . . 495
The ChangePassword.aspx Form . . . . . . . . . . . . . . . . . . . . . 498
Restricting Access to Web Forms . . . . . . . . . . . . . . . . . . . . . 498
Coding the Forms for Business Managers . . . . . . . . . . . . . . . . . 500
The AddFl.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500

The RequestID.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . 503
The Reports.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
The FreqFl.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Coding the Forms for LOB Executives . . . . . . . . . . . . . . . . . . . 508
The CreateRes.aspx Form. . . . . . . . . . . . . . . . . . . . . . . . . . . 508
The CancelRes.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . 514
The QueryStat.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . . 516
The ConfirmRes.aspx Form . . . . . . . . . . . . . . . . . . . . . . . . . 518
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
Chapter 22 Creating the Customer Transaction Portal . . 521
Designing the Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
The View New Flights Option. . . . . . . . . . . . . . . . . . . . . . . 525
The View Ticket Status Option . . . . . . . . . . . . . . . . . . . . . . 526
The View Flight Status Option . . . . . . . . . . . . . . . . . . . . . . 528
The Confirm Reservation Option. . . . . . . . . . . . . . . . . . . . . 529
Testing the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
Contents
xxi
Chapter 23 Debugging and Testing the Application. . . . . 537
Locating Errors in Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Watch Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Locals Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Call Stack Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Autos Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Command Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Testing the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Chapter 24 Administering the Application . . . . . . . . . . . 551
Managing the Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552

Backing Up the SkyShark Airlines Databases . . . . . . . . . . . . 553
Exporting Data from Databases . . . . . . . . . . . . . . . . . . . . . . 555
Examining Database Logs . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Scheduling Database Maintenance Tasks . . . . . . . . . . . . . . . 558
Managing Internet Information Server . . . . . . . . . . . . . . . . . . . 560
Configuring IIS Error Pages. . . . . . . . . . . . . . . . . . . . . . . . . 560
Managing Web Server Log Files . . . . . . . . . . . . . . . . . . . . . 563
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
Chapter 25 Securing the Application . . . . . . . . . . . . . . . 567
Security in ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . 568
Authentication Mechanisms. . . . . . . . . . . . . . . . . . . . . . . . . 568
Securing a Web Site with IIS and ASP.NET . . . . . . . . . . . . 570
Enabling Authentication in SkyShark Airlines. . . . . . . . . . . . . . 571
Configuring IIS Authentication . . . . . . . . . . . . . . . . . . . . . . 571
Configuring Authentication in ASP.NET. . . . . . . . . . . . . . . 573
Securing SQL Ser ver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
xxii Contents
Chapter 26 Deploying the Application . . . . . . . . . . . . . . 581
Deployment Scenarios. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
Deployment Editors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Deploying the SkyShark Airlines Application . . . . . . . . . . . . . . 586
Creating a Deployment Project. . . . . . . . . . . . . . . . . . . . . . . 587
Adding the Output of SkySharkDeploy
to the Deployment Project . . . . . . . . . . . . . . . . . . . . . . . . . . 589
Deploying the Project to a Web Server
on Another Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
PART VII PROFESSIONAL PROJECT 5 . . . . . . . . . . . 593
Project 5 Creating a Web Portal for a Bookstore . . . . 595

Project 5 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
Chapter 27 Project Case Study and Design . . . . . . . . . . 597
Organization Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Project Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Querying for Information about All Books. . . . . . . . . . . . . . 600
Querying for Information about Books Based on Criteria. . . 601
Ordering a Book on the Web Site. . . . . . . . . . . . . . . . . . . . . 602
Project Design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
Database Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
Database Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Web Forms Design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
Flowcharts for the Web Forms Modules. . . . . . . . . . . . . . . . 616
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
Contents
xxiii
Chapter 28 Exploring ASP.NET Web Services . . . . . . . . . 619
Introduction to ASP.NET Web Services . . . . . . . . . . . . . . . . . . 621
Web Service Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
Working of a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Technologies Used in Web Services . . . . . . . . . . . . . . . . . . . . . . 625
XML in a Web Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
WSDL in a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
SOAP in a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
UDDI in a Web Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
Web Services in the .NET Framework . . . . . . . . . . . . . . . . . . . 628
Creating a Simple Web Service in the .NET Framework . . . . . . 632
The Default Code Generated for a Web Service. . . . . . . . . . 633
Creating a Web Method
in the SampleWebService Web Service. . . . . . . . . . . . . . . . . 635
Testing the SampleWebService Web Service. . . . . . . . . . . . . 638

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
Chapter 29 Developing Web Services. . . . . . . . . . . . . . . 641
Creating a Web Service for Deepthoughts Publications . . . . . . . 642
Creating the
SearchAll() Web Method . . . . . . . . . . . . . . . . 645
Creating the
SrchISBN() Web Method . . . . . . . . . . . . . . . . . 647
Creating the
AcceptDetails() Web Method . . . . . . . . . . . . . 650
Creating the
GenerateOrder() Web Method . . . . . . . . . . . . . 653
Testing the Web Service. . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
Securing a Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
xxiv Contents

×