1. Trang chủ
  2. » Công Nghệ Thông Tin

Visual Basic .NET at Work Building 10 Enterprise Projects phần 1 potx

52 186 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Visual Basic .NET at Work: Building 10 Enterprise Projects
Tác giả Tony Martin, Dominic Selly
Người hướng dẫn Robert Ipsen, Theresa Hudson, Angela Smith, Brian Snapp
Trường học John Wiley & Sons, Inc.
Thể loại sách
Năm xuất bản 2002
Thành phố New York
Định dạng
Số trang 52
Dung lượng 770,72 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

All the Installation Details 156Namespaces 156Assemblies 158Creating Installations with Visual Studio .NET 162 Project 5b: The Application Installation 176 Project 6: Web Portal with ASP

Trang 1

TE AM

Team-Fly®

Trang 2

Visual Basic NET

at Work: Building 10 Enterprise Projects

Tony Martin Dominic Selly

Wiley Computer Publishing

John Wiley & Sons, Inc.

Trang 3

Publisher: Robert Ipsen

Editor: Theresa Hudson

Managing Editor: Angela Smith

New Media Editor: Brian Snapp

Text Design & Composition: John Wiley Composition Services

Designations used by companies to distinguish their products are often claimed astrademarks In all instances where John Wiley & Sons, Inc., is aware of a claim, theproduct names appear in initial capital or ALL CAPITAL LETTERS Readers, however,should contact the appropriate companies for more complete information regardingtrademarks and registration

This book is printed on acid-free paper

Copyright © 2002 by Tony Martin All rights reserved

Published by John Wiley & Sons, Inc., New York

Published simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system or mitted in any form or by any means, electronic, mechanical, photocopying, recording,scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976United States Copyright Act, without either the prior written permission of the Pub-lisher, or authorization through payment of the appropriate per-copy fee to the Copy-right Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax(978) 750-4744 Requests to the Publisher for permission should be addressed to thePermissions Department, John Wiley & Sons, Inc., 605 Third Avenue, New York, NY10158-0012, (212) 850-6011, fax (212) 850-6008, E-Mail: PERMREQ @ WILEY.COM.This publication is designed to provide accurate and authoritative information in re-gard to the subject matter covered It is sold with the understanding that the pub-lisher is not engaged in professional services If professional advice or other expertassistance is required, the services of a competent professional person should besought

trans-Library of Congress Cataloging-in-Publication Data:

ISBN: 0-471-38631-6

Printed in the United States of America

10 9 8 7 6 5 4 3 2 1

Trang 4

To my friends

Trang 6

Getting Started xv

Project 2: Bug Tracking with ADO.NET 35

Contents

Trang 7

Project 3: Bug Reporting with Web Services 77

Project 4: Performance Testing with Remoting 119

vi Contents

Trang 8

All the Installation Details 156Namespaces 156Assemblies 158

Creating Installations with Visual Studio NET 162

Project 5b: The Application Installation 176

Project 6: Web Portal with ASP.NET 195

How Is ASP.NET Different from Traditional ASP? 198Example 205

Contents vii

Trang 9

Project 7: Schema Generator with XML 289

XML Technology 291

XML Schemas 295XML Namespaces 303

Project 8: User Authentication Login Screen 339

Forms Authentication and Authorization 344

Project 9: Employee Information System

How to Write a Mobile Web Application: An Overview 372

viii Contents

Trang 10

Preparing Your Development Environment 394

Part 2: The Mobile Web Application 401

Project 10: Employee Intranet with NET 419

Security 434

Trang 12

Thanks go out to many people on a project like this book I hardly know where tobegin I’ll start with Dominic I want to tell Dominic that he saved my at least 42 per-cent of my sanity by writing Project 6 Without his work and diligence, we wouldn’thave made it on time Besides, he’s an ASP.NET genius, wrote an ASP.NET trainingcourse that he now teaches around the country, and is one of the most immediately lik-able people on the planet Thanks, pal Give me a call when it’s time for that star party.

A mathematically incomprehensible amount of thanks, appreciations, and owedfavors go to Kathryn Malm She is the editor of this book She is smart, funny, encour-aging, and the primary reason you have this book in your hands now Without herefforts, I would have been committed by now Instead, I became committed to finish-ing the book She’s like that With an email or a short phone call she revitalized my zealand energy for this endeavor, and I enjoyed it a great deal because of her Many warmthanks to you She writes good well too!

Huge thanks to Yasser Shohoud at DevXpert (www.devxpert.com) Without the use

of his expertise, this book would have taken much longer He’s one of the smartest grammers I know, and I encourage anyone interested in XML, Web services, or NET tocheck out his company and the training he offers Thanks very much, buddy

pro-A big thank you to everyone, friends and family, who always asked how the bookwas doing while it was being written Whether you were genuinely interested or justbeing polite, it doesn’t matter That you thought to ask meant a lot to me The mostgenerous part of what you did was that you asked how the book was going, knowingfull well that I was actually going to tell you That’s the mark of true friendship Par-ticular thanks to Shilpa Kumbhar, who took an interest in doing some XML research I

am thankful for your help Sorry about all those OS reinstalls

Thanks a bunch to everyone at Best Software, Inc who put up with me during thewriting of this book They offered encouragement and asked about progress Specialthanks to Michael Ottomanelli for his sense of humor and flexibility that allowed me tofinish on time

Acknowledgments

Trang 13

Special thanks to my family: Mom, Lise, Wayne, Nico, Alex, Hannah, Poppop All ofyou helped me get through this in one way or another, either by encouragement, talk-ing with me about it, or just listening to me ramble I love you all.

I would like to send out a special thank you to Mike, Betsy, Maggie, Moxie, andSassy This crew gave me the much-needed breaks during the writing of this book thathelped keep me from going stir crazy You are two of the nicest people and three of thenicest dogs anyone would ever want to know

Warren, David, Susan, and Cheryl You are the best friends anyone could ask for.You have been the cause of more high points in my life than I can count, and you werethere for the low points We could easily make a television show about our friendship,except that we are the only ones who would laugh at the jokes

Thanks go out to Graham Chapman, John Cleese, Terry Gilliam, Eric Idle, TerryJones, and Michael Palin You helped get me through this book Thanks also for theyears of side-splitting laughter you’ve inflicted upon me and for making me walkaround all day quoting lines from your skits, films, songs, and books, which I’ll prob-ably be doing for the rest of my life, being laughed at, ostracized, and generally beaten

up I’ll get you for it

Finally, I’d like to thank my Dad Many times during the writing of this book, Iwould sit back and think about how you would handle one issue or another or justimagine that you were there to help me talk things out, and this helped a great deal.Thanks, and I hope you’re having a blast

xii Acknowledgments

Trang 14

Tony Martinhas been a programmer for about 20 years now He started in 1981 withsuch tools as CP/M and DOS He has been involved in many aspects of software devel-opment and has a special interest in software development process and user interfacedesign and construction However, like many programmers, he will do about anything

in which he can write code He works regularly with Visual Basic, C++, and VisualBasic NET and has the terribly unrealistic goal of someday understanding all 6,500classes in the NET framework By the time this happens, the framework will have irre-versibly changed and he’ll have to start over

There is more to Tony than just programming, and understanding his personality is

an important part of understanding his programming books Programming Tonyshares a brain with Artist Tony He draws, paints, writes fiction, but is mostly a pho-tographer He has a best friend who is a Border Terrier named Tirith that is layingupside down, feet in the air, and snoring as this is being written Friends, family, anddog are all extremely important parts of Tony’s life He sees possessions as a delusion,but as far as delusions go, he likes his camera equipment and his DVD collection

On a day when Tony is not programming, you are likely to find him rompingthrough the woods, hanging out with friends, reading a book, visiting family, or creat-ing some new work of art

Dominic Selly is a Senior Software Engineer at Capella University (www.capella.edu),where courses are delivered entirely online Visit Capella and use the 2-Minute Advi-sor to see some of the earliest ASP.Net code to go into production Prior to Capella,Dominic was a Senior Software Engineer at Best Software where he led the data ser-vices tier working on their next generation Web-based accounting application

About the Authors

Trang 15

Dominic is also a trainer of developers He currently teaches the ASP.Net Bootcamp,which he developed (www.ASPDotNetBootCamp.com) Dominic also co-developed theWeb Application Development certificate program at George Washington University,where he was an instructor He has been a speaker at the SD and Connections confer-ences, and has been conducting trainings across the country for many years.

When he’s not coding or training, Dominic spends his time trying to master the perfect determinism of the game of billiards

xiv About the Authors

Trang 16

There’s no denying it Microsoft has turned the Windows software development munity on its ear with the NET initiative There have been debates and argumentsamong those who have firm opinions about whether NET is a good thing or a badthing The bad guys say that the changes are too big, too sweeping to be accepted Theycontend that the changes required are too great to adopt quickly and that they preventpeople from migrating their existing applications to the new technology They alsocomplain about the changes made to the Visual Basic language for the same reasons.These apprehensive people make good points It will be difficult if not impossible tomigrate large applications without redesigning and rewriting them However,redesign will be required anyway to take advantage of the new features and benefits ofthe framework and the language It will take significant amounts of time for engineers

com-to become proficient with the new language and framework The language changes arefundamental and the NET framework, with over 6,500 classes, is huge The effort will

be worth it, though The language is much more powerful and even safer to use It is

still fairly easy; just different The new capabilities are amazing and will start making

you think of new things to build Even the Visual Studio environment is vastlyimproved It’s as if they built everything they heard programmers complaining aboutfor the last three years

I can use myself as a good example of why NET and the changes to Visual Basic aregood things I was a little worried about NET at first I had been comfortable for yearswith VB, COM, DCOM, MTS, ASP, ADO, and all the other acrotechnologies (technolo-gies named with acronyms) Why bother changing to this radical new way of buildingsoftware? The promises were nice, but were they worth the work to get there? Duringthe course of learning and using NET and the new Visual Basic (VB), I realized that Iwas creating software that had advanced capabilities easily and swiftly Once I gotused to the language changes and the new way each technology worked, I realizedhow much programming power was at my disposal And I hadn’t even begun toscratch the surface of those 6,500 classes Programmers like myself who will be using

Getting Started

Trang 17

.NET will turn out applications that nobody has even thought of before, and the worldwill be astounded.

But the most compelling reason that I think of to recommend NET and Visual Basic.NET to other programmers is that after 20 years of programming, I thought I had seenabout everything Programming was still rewarding, but it was like doing anything for

20 years It’s hard to keep the subject lively and interesting After using NET for about

a month, I caught myself having fun again I was actually excited about the programs I

was writing and actually called friends to tell them about them It made me want to be

a teacher of NET and all it could do Mostly, I wanted to build more software, becauseideas came flooding into my head I will be busy for months with some of them.Obviously, you’ll have to make your own judgments about NET and its future Theindustry certainly has a lot to say For now, I’m having a blast and hope that this bookwill help you get to that place as well

What This Book Is About

We have all read books about new technology that go on for pages and pages aboutsomething or other, slipping you little code fragments as they go You’re always wait-ing for that big example, the payoff for having waded through explanations and the-ory And suddenly you come to the end of the chapter, having seen only a few trivialexamples of the technology’s use

These books give you something to think about, but more work to do before you canreally get started using what you have learned Seeing the technology in action is crit-ical to understanding how it works and is meant to be used You need substantialexamples to make this happen, examples that relate to the real world and tackle realproblems

The purpose of this book is to teach through example, using complete solutions toreal problems that you as enterprise programmers need to deal with You’ll be taken on

a tour of the major NET technologies, seeing how each works and then workingthrough a complete program using that technology The chapters are really projects,complete programs that you can put to use in your own work or other programming.We’re covering a lot of material, but the project-oriented approach lets you tackle oneissue at a time

xvi Getting Started

Trang 18

Throughout the book will be assorted tips that will help you out with somethingspecific If there is anything important you should know about, it will be given in aSidebar for your reference.

Each chapter in this book is a project that focuses on a specific technology There are

10 projects all told Some build on previous projects, whereas others are completelystandalone I’ll let you know which is which They generally follow an order thatassumes you know the technologies in the previous projects, but not in the followingprojects Take a look at what each project is about:

Project 1: A WinForms Library. Take a tour of the new forms technology and see

how Microsoft has changed the way you will build standard Windows

applica-tions You’ll learn some advanced VB language features in the process, includinginheritance, inherited forms, overloaded and overridden methods, and creating

your own constructors When you’re done, you’ll have a class library of

stan-dard forms on which you can base your own applications

Project 2: Bug Tracking with ADO.NET. We’ll build a small bug-tracking

appli-cation using ADO.NET as our database interface You’ll see what the new

ADO.NET objects are like and how to use them I’ll show you how to use SQL

statements along with ADO.NET to perform all the primary database

opera-tions You will also see some ADO.NET data binding in action This project

makes use of Project 1

Project 3: Bug Reporting with Web Services. This project builds on Project 2 Wewill create a Web service that sits out on your Internet site and allows the users

of your programs to report bugs that they find in your software We’ll create a

client component that you can build into your own applications that provides

the interface your users can use to enter bug data It will then ship the bug off tothe Web service for storage The Web service does more as well, but we’ll save

that for the project The client portion of this project makes use of Project 1

Project 4: Application Performance Testing with NET Remoting. Remoting is

essentially Microsoft’s more flexible replacement for DCOM I’ll show you how

to create your own remote components, configure them to work over an HTTP

line, process requests, and ship results back We’ll build a component that logs

performance data from your own applications as they execute We’ll also create

a class for your own applications that will make it painless to instrument them

for performance testing You even get a fancy client program that will get

per-formance data from the remote component and analyze it for you

Project 5: Deployment Packages. Visual Studio NET has replaced the aging and

inadequate Package and Deployment Wizard with new deployment tools that

allow you to create truly professional installations We’ll create three different

types of deployments using these tools, resulting in deployment packages for

Projects 2 and 3 You may find yourself using these tools more often than your

complex third-party installation software

Project 6: A Web Portal with ASP.NET. This project will show you how to use

ASP.NET and its new capabilities to construct a complete company Web portal

You’ll find that ASP.NET is really a completely new way of building Web sites

Getting Started xvii

Trang 19

that are more capable, faster, and easier to construct This is a big project, somake some time for it.

Project 7: Schema Generator with XML. You can’t get through a day withouthearing about XML This project will show you how to make use of XML andXSD schemas to exchange data between disparate systems or even completelydifferent companies The project is a pair of programs, one for the provider ofdata and another for the consumer of the data The provider program generatesXML and XSD schemas from a database to pass to the consumer The consumerprogram reads XML and XSD schemas, validating the data against the schema

Project 8: User Authentication Login Screen. It is always difficult to approachthe topic of security It is complex, sometimes tedious, and often arcane Com-plete information about the topic seems to be difficult to locate This projectfocuses on ASP.NET Web security, and we’ll be creating a standard login screenyou can use on your Web applications We focus on forms security, but Win-dows security is even easier

Project 9: Employee Information System Using the Mobile Toolkit. This project explores the Microsoft Mobile Internet Toolkit This is an extension toASP.NET and Visual Studio NET that allows you to use VB to create Web sitesand applications for mobile devices, including Web-enabled cell phones We willactually build a small company intranet site that allows employees to accesscompany information through their cell phones They will have access to infor-mation such as company announcements, weather alerts, the next paid holiday,and a complete company phone list (which you can dial directly from your cellphone without punching in any numbers)

Project 10: Employee Intranet with NET. This project brings together many ofthe technologies we learned in other projects to create a company intranet site

We have some nice features on this site, including the ability to view how muchvacation you have available and make vacation requests, enter and review sta-tus reports, and review and modify your personnel information We make use ofASP.NET, ADO.NET, Web security, and Web services for this project It should

be an exciting roundup of the technologies covered in other projects

Setting Up Your Workbench

You will need some background knowledge and a small pile of software tools to plete the projects in this book This section will detail exactly what those are

Trang 20

Other knowledge will be helpful, too Many of the projects use database access, sofamiliarity with SQL Server and SQL itself will be beneficial If you are familiar withASP development, Projects 6, 9, and 10 will go more smoothly This knowledge is notrequired, however You will pick up enough here to do the projects with relative ease.

If you want to test out Project 9, you’ll also need a Web-enabled cell phone or otherWeb-enabled portable device You can also use the Microsoft Mobile Emulator

Operating System

You will need at least Microsoft Windows 2000 to build these projects You can also useWindows XP Professional I used Windows 2000 for the entire process, and it workedbeautifully

Microsoft SQL Server 2000.This database is used for at least half the projects

You could use another database engine as well, such as Microsoft Access

You’ll just have to modify the code a little to do so (connection strings andthe ADO.NET DB objects created) It will be easier to just use SQL Server ifyou have it available

Internet Explorer 6.0.This should be installed for you when you install the dows Component Update portion of Visual Studio NET You will need it for allthe Web development projects

Win-Getting Started xix

Team-Fly®

Trang 21

Internet Information Server.Several projects make use of IIS If you’re using dows 2000, you might have to install it because it is an option in the setup This

http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/MSDN-FILES/027/001/516/msdncompositedoc.xml

Microsoft Mobile Explorer 3.0 or later.This is a cell phone simulator It is a Webbrowser that emulates the Web browsers found on most Web-enabled cellphones and other portable devices We use it in Project 9 as the test and debugexecution environment It is available for free download at Microsoft’s Web site.You can find it at http://msdn.microsoft.com/downloads/ From this page,you can search for MME, and you’ll jump right to it

What’s on the CD-ROM

The companion CD-ROM contains all the source code for every project in the book Italso includes any supporting files that might be needed, such as sample databases, dia-grams, or graphics files Anything you need for a project should be there This is a goodthing because you won’t want to create all your own sample data, for example It ismuch easier to import it right into SQL Server

The CD-ROM is organized by project There is a directory at the root called Projects.Underneath that is a folder for each project in the book that contains all the files foreach project For example, all the source for project 2 is located at:

\Projects\Project 2

The Web Site

A Web site was created for this book to keep you posted on any changes, to let youknow about new developments, and to provide additional related information youmight find interesting or useful It will also be hosting some of the Web-based projectsfrom the book that you can play around with in a production environment Stop byand poke around for a while at http://www.wiley.com/compbooks/martin

xx Getting Started

Trang 22

Time to Embark

You should have all you need to get started with the projects right away As long asyour development environment is configured properly and your tools are installed,any of the projects can be built If you’re a free spirit, go ahead and jump around If not,the projects work very well in order

The projects in this book are calling to you Build them and enhance them, makingthem your own You have your road map and requirements for your workbench Allthe tools should be ready to go The first project will help you get your feet wet andlearn a few new things about the VB language capabilities Dive into the rest at yourleisure, but if you’re anything like me, you’ll be devouring them The book will guideyou through the forest of new technologies, making sure you’re not embarking up thewrong tree

Sorry I couldn’t help it Have fun!

Getting Started xxi

Trang 24

If you are an enterprise software engineer, writing applications for your company, youknow that time is the one luxury that is most in demand Everyone wants a specialapplication completed yesterday and thinks his or hers is more important than all theothers in your hopper Shaving time off the top of all your projects could go a long waytoward making your life easier and your internal customers happier If we could writethe common functionality once and use it for all of our upcoming projects, we mightjust achieve this

In addition, we rarely have time to give thought to usability and consistency.Because our time is in high demand, we need to concentrate on functionality Often weend up with applications that are inconsistent and look very different, making it diffi-cult for our customers to move easily from one to the other However, if we couldinvest the time once to build in usability and consistency and then make use of thatwork on all our future projects, well, that would be a wise investment indeed

THE PROBLEM:

We need to create all kinds of enterprise applications for our company, and they all need

a similar look and feel and similar features and capabilities However, we’d like to create

the common functionality once and use it for all applications from then on.

THE SOLUTION:

Build a WinForms library containing common functionality and style that we can use as a

starting point for all our future applications.

A WinForms Library

P R O J E C T

1

Trang 25

The Project

We will design and build a set of NET WinForms classes using Visual Basic NET thatwill encapsulate all the look, functionality, and consistency we need for our enterpriseapplications There are six classes, or forms, in our collection, which you can use as astarting point for any future applications It’s easy to use, easy to add to your projects,and if we’re careful, will even cut out a fair chunk of your development time

You could certainly use trusty Visual Basic 6.0 to build a set of windows that you canload into your projects However, using Visual Basic NET and the NET Frameworkmakes this job a whole lot easier One of the best things is being able to inherit func-tionality from other forms For example, in this project we will be starting out with abase form that will contain some common functionality If you want to create a newform with that same functionality, you can inherit your new form from the base formand get all that common functionality for free Inheritance will save us time, both increating the derived forms and when maintaining them in the future

This project consists of six WinForms classes that we will create, followed by a simple test driver form We’ll be following these basic steps:

1 Create the base form from which the other forms will be derived It will

contain common functionality that all our forms will need and use

2 Create the frmDialog class This will form the basis of any dialog box we

need to create

3 Create the frmMsgBox class We will use this as a replacement for the Visual

Basic MsgBox functionality

4 Create the frmWizard window class This can be used as the basis for any

wizard dialogs we need in our application

5 Create the frmApp window class This can be used as the main window of

any SDI application we want to create

6 Create the frmAbout class We can use this as our application’s About Box.

This has been designed for use with only a single line of code

7 Detail how to base your own projects on these window classes You can

include the forms in your projects, or use a class library that includes the forms.You’ll see how to do both

8 Create the test driver form that will allow us to test out the forms This will

also demonstrate how each should be used in code

You Will Need

Visual Basic NET

A basic knowledge of Visual Basic NET and WinForms

2 Project 1

Trang 26

Let’s Start the Project

If we were using Visual Basic 6.0 for this project, the whole idea of classes would noteven enter the picture We’d build a few forms, write a little code, and be done with it.Visual Basic NET, as it does with almost every aspect of writing software, changes thegame completely All forms are now created as classes And, with the addition of trueinheritance and other object-oriented features, we can really add some power to ourforms and the code we write On the other hand, we also need to spend a little moretime thinking about our design before we sit down to write code

To develop a useful collection of windows as well as gain the most benefit fromVisual Basic NET’s new features, we need to think at least a little bit about our needsand how to satisfy them with a decent design The hierarchy of classes in this project isfairly simple but illustrates some of the benefits of a class hierarchy Figure 1.1 showsthe class organization

Features of the Design

Our design incorporates a few interesting features that bear discussion Some arerelated to the way the classes are designed, and some relate to the usability of the endresult

Figure 1.1 Class organization.

frmBase frmDialog

frmAppfrmMsgBoxfrmAbout

frmWizard

A WinForms Library 3

Ngày đăng: 14/08/2014, 01:20

TỪ KHÓA LIÊN QUAN