Visual basic NET powertools

1.2K 66 1
Visual basic NET powertools

Đ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

This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Cover Team Fly This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page iii Visual Basic™ Net Power Tools Evangelos Petroutsos and Richard Mansfield Team Fly This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page vii Acknowledgments WE WERE FORTUNATE TO have several smart, thoughtful editors assist us in polishing this manuscript First, we'd like to thank Development Editor Tom Cirtin He deserves credit for his discernment, and the high quality of his editing He's very good at dealing with his authors, and equally skilled at raising important questions and improving their chapters Technical Editor Greg Guntle carefully reviewed the manuscript and made many useful suggestions, caught a number of inconsistencies, and helped improve several code examples Production Editor Leslie Light ensured that this book moved smoothly through production and was most helpful with suggestions about the graphics, drawings, and screen shots Suzanne Goraj, copy editor, combed through every line of our text, making improvements throughout To all these, and the other good people at Sybex who contributed to this book, our thanks for the intelligence and care that they brought to this book In addition, the authors would like to give special thanks to their agents, Matt Wagner and David Fugate, of Waterside Productions, whose contributions to the authors' careers goes above and beyond the call of duty Team Fly This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page viii Contents at a Glance Introduction xix Chapter • Understanding the NET Framework Chapter • New Ways of Doing Traditional Jobs 23 Chapter • Serialization Techniques 59 Chapter • Leveraging Microsoft Office in Your Applications 93 Chapter • Understanding NET Security 119 Chapter • Encryption, Hashing, and Creating Keys 139 Chapter • Advanced Printing 159 Chapter • Upon Reflection 191 Chapter • Building Bug-Free and Robust Applications 215 Chapter 10 • Deploying Windows Applications 243 Chapter 11 • Building Data-Driven Web Applications 271 Chapter 12 • Peer-to-Peer Programming 289 Chapter 13 • Advanced Web Services 319 Chapter 14 • Building Asynchronous Applications with Message Queues 341 Chapter 15 • Practical ADO.NET 391 Chapter 16 • Building Middle-Tier Components 441 Chapter 17 • Exploring XML Techniques 475 Chapter 18 • Designing Data-Driven Windows Applications 505 Chapter 19 • Working with Regular Expressions 543 Chapter 20 • Advanced Graphics 589 Chapter 21 • Designing the User Interface 623 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Chapter 21 • Designing the User Interface 623 Chapter 22 • Using the NET Compact Framework and Its Emerging Technologies 643 Index 665 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page ix Contents Introduction Chapter • Understanding the NET Framework Why Read This Chapter xix Help! Grappling with Framework Class Descriptions The Hunt for a Grammar Why Two Ways? 10 About Constructors 10 Assemblies Three Ways 11 Understanding Data Types 11 About System.Object 12 MemberWiseClone 12 Equals 12 ReferenceEquals 13 The Main Point about Equality 14 GetHashCode 16 GetType 16 ToString 16 Strong Typing Weakens 17 Is Color a Data Type? 17 Exploiting the Framework 18 A Useful Class View Utility 20 A Brief Lexicon 21 Summary 22 Chapter • New Ways of Doing Traditional Jobs Clipboard Access 23 23 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Working with ''Control Arrays" Multiple Handles Using Arrays 27 28 Zero-Based Collections (Sometimes) 28 Initialization 30 Arrays of Objects 30 Array Search and Sort Methods 31 Customized Sorting 33 Many Properties and Methods 34 The Flexible ArrayList 35 Mass Manipulation 36 Data Binding 36 Enumerators 37 Using HashTables 37 New Date/Time Techniques 38 Adding Time Team Fly 24 39 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xix Introduction THIS BOOK ACTUALLY BEGAN in Athens, Greece in 1993 Evangelos Petroutsos wrote a very interesting outline, and several sample chapters, for a book about "fascinating and sophisticated things" you could with Visual Basic I agreed with my publisher that his ideas had potential, but Evangelos was a first-time author I had a track record, though, so the publisher said they'd invest in this "Power Toolkit" book if I agreed to co-author it Even a small book represents a $50,000 gamble for a publishing house, and this was a very large book I merrily agreed because I thought the topics were compelling—fractals, encryption, processing graphics, animated transitions, multimedia, manipulating color palettes, recursion, and other topics that were largely ignored by other VB books To our delight, the book became a runaway bestseller in 1995 Evidently many Visual Basic programmers were ready for a book about advanced, cutting-edge programming techniques In 2002, we decided to revisit this concept Nearly a decade has passed, and we now have what amounts to a brand new Visual Basic language: VB.NET We decided to follow the same path that we went down a decade ago: to explore aspects of VB.NET that have been largely ignored in other books, but are useful or interesting, or both Most of the topics covered ten years ago in the previous book are not repeated here—times have changed But we feel that the subjects explored in this new book are compelling in their own right Aesthetics Why would captivating topics be largely ignored in computer books? We think there are two primary reasons The first category of ignored topics is seen as "trivial" or "marginal." Put another way, these subjects involve aesthetics Programmers by and large prefer to consider themselves part of the scientific community, so examining such unscientific concepts as beauty or appearance seems to many programmers to be a step down Two of the chapters in this book, nonetheless, boldly explore aesthetic subjects Truth be told, programming is an art, not a science Some professors conjure up theoretical constructs and special terminology, but airy obfuscation and lofty-sounding jargon not, by themselves, create a science—and all too often actually inhibit rational discourse Studies have shown that the best programmers are frequently English or music majors Some of the best developers around today got into programming when they purchased their first Amiga computer—an early machine devoted to the creative side of computing And although academic programming is generally allied with mathematics departments, there is very little real relationship between This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xx math (or science) and programming—just as there is often very little relationship in general between many other academic studies and the real world Consider the primary current computer applications: word processing, database management, Internet communications, and spreadsheets Only spreadsheets have much at all to with math Programming can, of course, involve math, but it's rarely central to the programmer's task You could write an entire word processing program without even knowing long division, much less algebra or anything beyond And programming obviously isn't a science Science involves theorizing and controlled experimentation, behaviors rarely associated with programming Sure, there's a kind of experimental hacking that goes on while trying to fix bugs—but that's not scientific experimentation by any stretch of the imagination Debugging is much closer to searching for a lost set of keys than sending a kite up into a thunderstorm Programming is basically communication—albeit between humans and machines But it is a linguistic and expressive act It's not exactly rhetorical (we don't need to persuade the machines, at least not yet) But it's certainly descriptive, grammatical, and fundamentally communicative The two chapters in this book that some will consider ''unscientific" are Chapter 21, "Designing the User Interface," and Chapter 20, "Fractals: Infinity Made Visible." We agree But then we think the entire subject of programming is unscientific, and we're not bothered by that fact Complexity and the Avant-Garde Most of the remaining topics in this book fall into the second category: topics that are either too cutting-edge or too complex for inclusion in many books For example, not much is written about VB.NET's splendid and extensive security features—even though security is a primary ongoing challenge for the computing community Security-related VB.NET programming is avoided not because the programming involved is inherently difficult or novel, but rather because the concepts underlying cryptology and other aspects of security are fundamentally complex Many computer book authors simply don't know enough about encryption, for example, to explain its implementation in computer programming Fortunately, cryptology has long been a hobby of one of the authors of this book Other topics are perhaps too new to be widely understood or implemented Asynchronous programming, Web services, employing Office objects, using reflection, and the new NET Compact Framework (how to squeeze programming and I/O into the highly restrictive platform of small, portable devices such as PDAs and cell phones) all fall into this category This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Dealing with Logic Errors Summary Chapter 10 • Deploying Windows Applications Installing the NET Framework Runtime 241 243 244 XCopy Deployment 245 Internet Deployment 246 Preparing for Internet-Based Deployment 247 Deploying a Windows Application on a Web Server 249 Code Access Permissions 251 Running the Application 257 Downloading Assemblies on Demand 258 Deploying with Windows Installer Team Fly 237 259 Creating a Windows Installer Package 261 Using the File System Editor 263 Creating Shortcuts 266 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xiii The Registry Editor 267 Using the User Interface Editor 267 Summary Chapter 11 • Building Data-Driven Web Applications New Features in ASP.NET 270 271 271 Sending Entire Files 272 Using Server Controls 272 Displaying Data on a WebForm 273 The DataList, Repeater, and Templates 275 Using the DataGrid 276 Detecting Postback 281 Validation 282 Programmatic Validation 282 Validation Controls 283 Sending Graphics 286 Using HTML Controls 287 Summary 288 Chapter 12 • Peer-to-Peer Programming Internet Addressing Using Sockets 289 289 292 Using UDP Sockets 295 Using TCP Sockets 297 The TCPChat Application 300 The TCPChatServer Application 301 The TCPChatClient Application 305 Interacting with Web Resources 308 Downloading Documents with WebClient 311 Uploading Documents with WebClient 312 The WebRequest and WebResponse Classes 314 Summary 317 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Chapter 13 • Advanced Web Services What Are Web Services? Creating a Web Service Caching Web Service Data Team Fly 319 319 320 322 Consuming a Web Service 323 Preserving State 325 Using Session State 326 Making a Database Connection 326 Using the Pubs Sample Database 327 Getting an XML Dataset 327 Potential Problems with MSDE 329 Looking at the Results 329 Implementing WSDL 330 Viewing WSDL 331 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xiv SOAP Too 333 Complex Types 333 PortType 335 Seeing SOAP, WSDL, and the Reference Map 336 UDDI: The Registry 336 Testing a Published Web Service 337 Security Considerations 339 Summary 339 Chapter 14 • Building Asynchronous Applications with Message Queues Queues and Messages 341 342 Types of Queues 343 Creating New Queues 344 Administering Queues 345 The MessageQueue Class Exploring a Computer's Queues The Message Class 347 348 349 Message Properties 350 Creating and Sending Messages 352 Acknowledgments and Time-Outs 358 Requesting Message Acknowledgment 358 Processing Acknowledgment Messages 361 Fault Tolerance and Load Balancing 366 Transactional Messages 371 Processing Orders with Messages 373 Preparing Orders 375 Processing Orders 377 Message Queuing Triggers 382 Defining Rules 382 Defining Triggers 384 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com The ProcessOrders Console Application Summary Chapter 15 • Practical ADO.NET Accessing Databases 388 391 391 The Visual Database Tools 392 The Connection Class 402 The DataAdapter Class 404 The Command Class 409 Working with DataSets Team Fly 385 415 Accessing the DataSet's Tables 416 Working with Rows 417 Handling Null Values 418 Adding and Deleting Rows 419 Locating Rows 420 Navigating through a DataSet 421 Using DataViews 426 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xv Insert and Update Operations 428 Updating the Database with the DataAdapter 428 Handling Identity Columns 430 Performing Transactions with the DataAdapter 436 Summary Chapter 16 • Building Middle-Tier Components From Client/Server to Multiple Tiers 440 441 441 What Exactly Is a Business Rule? 443 Designing with Middle-Tier Components 445 Remoting the Business Logic 449 Converting the BusinessLayer Class to a Web Service 450 Converting the BusinessLayer to a Remote Service 458 Using COM Components with NET Clients 461 Using ActiveX Controls in NET 462 Using COM+ Applications in NET 465 The COMPlus Component 466 Exporting a Proxy and Testing It 467 Building Serviced Components with NET 468 Summary 473 Chapter 17 • Exploring XML Techniques Choosing SAX 475 Copying the Sample File 476 Using SAX 476 476 Deeper into DOM 478 Using Namespaces in XML 480 Explicit Declaration 480 Implicit Declaration 480 The Explosion of Schemes Understanding XSD 481 481 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Using XML Data Types Programmatic XML 487 Edit and Save 488 A Recursive Walk through the Nodes 491 XML and DataSets 493 Persisting with SOAP 495 Mixing and Matching Types 497 Deserialization Trapping 501 More Interchangeability 503 Summary 504 Chapter 18 • Designing Data-Driven Windows Applications Data Binding The NWProducts Application Team Fly 483 505 505 506 The Application's Interface 507 The Application's Architecture 508 The Application's Code 510 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xvi An Invoicing Application 516 The Application's Interface 516 The Application's Architecture 518 The Application's Code 525 Adding a Business Rule 532 The Relations Application 535 The Application's Architecture 535 The Application's Code 536 The Relations1 Project 539 Summary 542 Chapter 19 • Working with Regular Expressions Writing Regular Expressions The RegularExpressions Class 543 544 547 Using the Matches Method 550 Using the Match and NextMatch Methods 551 The Split Method 552 The Replace Method 552 The Elements of a Regular Expression 558 Characters and Metacharacters 558 Single Character Metacharacters 558 Ranges of Characters 559 White Space and Metacharacters 560 Quantifiers 560 Anchors 562 Escaping Metacharacters 563 Alternation 563 The RegExEditor Project 564 Advanced Topics in Regular Expressions 567 Grouping and Back-References 568 Regular Expressions with Multiple Captures 573 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Lookahead and Lookbehind Assertions 575 Advanced Replacement Operations 578 The RegularExpressions Project 579 The Visual grep Project 582 Summary 588 Chapter 20 • Advanced Graphics The PlotControl 589 The GraphicsPath Object 591 The Control's Members 591 Drawing the Grid 598 A Fractal Generator Team Fly 590 602 What Is a Fractal? 602 The Mandelbrot Set 607 The Julia Set 612 The Real Magic of Fractals 616 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xvii Complex Number Operations The Transformation z = z2 + c Summary Chapter 21 • Designing the User Interface Making Applications Look Reliable Windows Conventions 620 621 622 623 623 626 The Metallic Look 626 FontBold Off 627 Using a Sans-serif Typeface for Headlines 627 Choosing a Type Size 627 Layering 627 Adding Depth 627 Light from the Upper Left 628 Creating Zones 629 Framing 630 Metallic Shading 635 Sliding and Fading Transitions 636 Fade In, Fade Out 637 Sliding 640 Summary Chapter 22 • Using the NET Compact Framework and Its Emerging Technologies What's Eliminated? 641 643 644 Output Lite 644 Solving the Connectivity Problem 644 Using the Simulator 645 Understanding the Mobile Form 646 Navigating to a Second Form 646 More New Features New Technology, New Behaviors 647 648 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com The List Controls Team Fly 650 Mobile Security 652 Debugging via Tracing 654 Custom Tracing 655 Trace Information Sections 656 Providing Friendly Error Messages 656 Device Specificity 658 Using Emulators 660 Custom Device Emulators 660 The Visual Studio 2003 Pocket PC Emulator 661 New Technology, New Problems 662 Summary 663 Index 665 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xviii This page intentionally left blank Team Fly This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Team Fly Page xxii You'll find a variety of useful utilities throughout the book, including DES and RSA encryption systems in Chapter that you can plug into your projects to protect the privacy of any kind of data The chapter on Office automation, Chapter 4, demonstrates how to add a variety of utilities to your VB.NET programs: extracting statistical information such as word or paragraph counts; evaluating math expressions; spell checking; automatically retrieving email; filtering and displaying e-mail; searching directories and subdirectories for specific files; importing data from or exporting data to Word, Excel or Outlook; and sending faxes Chapter takes you on a tour of the Windows and NET multi-layered security maze—all the various secret keyholes and locks that must be correctly set before even a single function can execute You'll see how to manage code-based (.NET), role-based (Windows), and miscellaneous (IIS, database-specific, and so on) security systems Did you know that you can specify security with such great specificity that you can grant or deny permission for each individual procedure—or even for each individual line of code—within your VB.NET projects? Chapter explores the new technology called reflection with which you can extract information from self-describing assemblies (libraries of code that contain descriptions of their contents) You're shown how you can use this information in specialized, though practical, applications, and how you can even go so far as to emit (write code-generating code) Forms design is the topic of Chapter 21: What you can to make the appearance of your VB.NET programs more professional, polished, and ergonomic This chapter covers one of the most overlooked aspects of program design—the design itself properly so called, the actual look of the finished application on its surface—where your programming logic rises and becomes visible to your users Among the techniques explained in this chapter are light sources, metallic surfaces, fonts, layering, depth, framing, shading, gradients, and transitions In Chapters 11, 13, and 18 you'll find largely hype-free coverage of programming data-driven Web applications, Web services, and XML, respectively Although you will find a book on every aspect of ADO.NET in the market, we've included two chapters on the topic of database programming: an overview of the ADO.NET object model with simple examples and a chapter with practical data-driven applications One of the examples is an invoicing application, which is a fundamental component of every business Besides sending XML data to Japan, or exchanging data with a database residing on a satellite, a company may need to sell products and services, and for this you'll need a functional application for preparing orders and invoices It's a humble task, but too important to be skipped in a practical chapter on data-driven applications You have certainly read a lot about the middle tier of a data-driven application If you understand what a middle tier is, you can skip our discussion on developing middle-tier components If you need a simple example of a business rule, how to implement business rules as middle-tier components, and how to deploy middle-tier components so that you can change the business rule without touching the code of the application that has already been deployed to the users' workstations, then explore our examples in Chapters 16 and 18 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com We've also included a few useful tools, which you can use in your projects with little or no customization The PRNTextBox and PRNListView controls are enhanced versions of the TextBox and ListView controls that provide methods to print their contents Regular expressions are not the bread and butter of the typical VB developer, and this is the reason most books totally ignore this topic To demonstrate regular expressions in Chapter 19, we've included the RegExEditor: a simple text editor that allows you to search text files using general search patterns, such as e-mail addresses, dollar amounts, and so on In Chapter 20 we've included two graphics applications, one for plotting functions—a practical control you can use in any number-processing application—and a fractal application—a program that generates fascinating patterns for your amusement All of the utilities are available at www.sybex.com Team Fly This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com You are here: home We offer the only comprehensive approach to eBooks that integrates with the timehonored missions and methods of libraries and librarians Our vision is one of enhancing the role of librarians as stewards of knowledge, supporting their crucial role in serving millions of people every day who seek information home | search tools | reading room | help | jobs | log in © 2001 - 2004, netLibrary, a division of OCLC Online Computer Library Center, Inc All rights reserved privacy statement | terms of use ... like this: Visual Basic NET WAS not written by Visual Basic programmers The entire NET family of languages was created by C programmers C—and its cohort OOP—is an academic language Visual Basic is... the NET Framework VISUAL BASIC NET was not written by Visual Basic programmers The entire NET family of languages was created by C programmers C—and its cohort OOP—is an academic language Visual. .. Java, C#, and others) represent one great camp of programmers Visual Basic is the other camp However, NET is an attempt to merge Visual Basic with the C languages—while still retaining as much as

Ngày đăng: 25/03/2019, 15:05

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan