- •About the Authors
- •Contents at a Glance
- •Contents
- •Introduction
- •Goal of the Book
- •How to Use this Book
- •Introduction to the .NET Framework
- •Common Language Runtime (CLR)
- •Class Library
- •Assembly
- •Versioning
- •Exceptions
- •Threads
- •Delegates
- •Summary
- •Introduction to C#
- •Variables
- •Initializing Variables
- •Variable Modifiers
- •Variable Data Types
- •Types of Variables
- •Variable Scope
- •Types of Data Type Casting
- •Arrays
- •Strings
- •Initializing Strings
- •Working with Strings
- •Statements and Expressions
- •Types of Statements
- •Expressions
- •Summary
- •Classes
- •Declaring Classes
- •Inheritance
- •Constructors
- •Destructors
- •Methods
- •Declaring a Method
- •Calling a Method
- •Passing Parameters to Methods
- •Method Modifiers
- •Overloading a Method
- •Namespaces
- •Declaring Namespaces
- •Aliases
- •Structs
- •Enumerations
- •Interfaces
- •Writing, Compiling, and Executing
- •Writing a C# Program
- •Compiling a C# Program
- •Executing a C# Program
- •Summary
- •Arrays
- •Single-Dimensional Arrays
- •Multidimensional Arrays
- •Methods in Arrays
- •Collections
- •Creating Collections
- •Working with Collections
- •Indexers
- •Boxing and Unboxing
- •Preprocessor Directives
- •Summary
- •Attributes
- •Declaring Attributes
- •Attribute Class
- •Attribute Parameters
- •Default Attributes
- •Properties
- •Declaring Properties
- •Accessors
- •Types of Properties
- •Summary
- •Introduction to Threads
- •Creating Threads
- •Aborting Threads
- •Joining Threads
- •Suspending Threads
- •Making Threads Sleep
- •Thread States
- •Thread Priorities
- •Synchronization
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Primary and Foreign Keys
- •Referential Integrity
- •Normalization
- •Designing a Database
- •Low-Level Design
- •Construction
- •Integration and Testing
- •User Acceptance Testing
- •Implementation
- •Operations and Maintenance
- •Summary
- •Creating a New Project
- •Console Application
- •Windows Applications
- •Creating a Windows Application for the Customer Maintenance Project
- •Creating an Interface for Form1
- •Creating an Interface for WorkerForm
- •Creating an Interface for CustomerForm
- •Creating an Interface for ReportsForm
- •Creating an Interface for JobDetailsForm
- •Summary
- •Performing Validations
- •Identifying the Validation Mechanism
- •Using the ErrorProvider Control
- •Handling Exceptions
- •Using the try and catch Statements
- •Using the Debug and Trace Classes
- •Using the Debugging Features of Visual Studio .NET
- •Using the Task List
- •Summary
- •Creating Form1
- •Connecting WorkerForm to the Workers Table
- •Connecting CustomerForm to the tblCustomer Table
- •Connecting the JobDetails Form
- •to the tblJobDetails Table
- •Summary
- •Introduction to the Crystal Reports Designer Tool
- •Creating the Reports Form
- •Creating Crystal Reports
- •Creating the Windows Forms Viewer Control
- •Creating the Monthly Worker Report
- •Summary
- •Introduction to Deploying a Windows Application
- •Deployment Projects Available in Visual Studio .NET
- •Deployment Project Editors
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Populating the TreeView Control
- •Displaying Employee Codes in the TreeView Control
- •Event Handling
- •Displaying Employee Details in the ListView Control
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Adding the Programming Logic to the Application
- •Adding Code to the Form Load() Method
- •Adding Code to the OK Button
- •Adding Code to the Exit Button
- •Summary
- •The Created Event
- •Adding Code to the Created Event
- •Overview of XML
- •The XmlReader Class
- •The XmlWriter Class
- •Displaying Data in an XML Document
- •Displaying an Error Message in the Event Log
- •Displaying Event Entries from Event Viewer
- •Displaying Data from the Summary.xml Document in a Message Box
- •Summary
- •Airline Profile
- •Role of a Business Manager
- •Role of a Network Administrator
- •Role of a Line-of-Business Executive
- •Project Requirements
- •Creation and Deletion of User Accounts
- •Addition of Flight Details
- •Reservations
- •Cancellations
- •Query of Status
- •Confirmation of Tickets
- •Creation of Reports
- •Launch of Frequent Flier Programs
- •Summarizing the Tasks
- •Project Design
- •Database Design
- •Web Forms Design
- •Enabling Security with the Directory Structure
- •Summary
- •Getting Started with ASP.NET
- •Prerequisites for ASP.NET Applications
- •New Features in ASP.NET
- •Types of ASP.NET Applications
- •Exploring ASP.NET Web Applications
- •Introducing Web Forms
- •Web Form Server Controls
- •Configuring ASP.NET Applications
- •Configuring Security for ASP.NET Applications
- •Deploying ASP.NET Applications
- •Creating a Sample ASP.NET Application
- •Creating a New Project
- •Adding Controls to the Project
- •Coding the Application
- •Summary
- •Creating the Database Schema
- •Creating Database Tables
- •Managing Primary Keys and Relationships
- •Viewing the Database Schema
- •Designing Application Forms
- •Standardizing the Interface of the Application
- •Common Forms in the Application
- •Forms for Network Administrators
- •Forms for Business Managers
- •Forms for Line-of-Business Executives
- •Summary
- •The Default.aspx Form
- •The Logoff.aspx Form
- •The ManageUsers.aspx Form
- •The ManageDatabases.aspx Form
- •The ChangePassword.aspx Form
- •Restricting Access to Web Forms
- •The AddFl.aspx Form
- •The RequestID.aspx Form
- •The Reports.aspx Form
- •The FreqFl.aspx Form
- •Coding the Forms for LOB Executives
- •The CreateRes.aspx Form
- •The CancelRes.aspx Form
- •The QueryStat.aspx Form
- •The ConfirmRes.aspx Form
- •Summary
- •Designing the Form
- •The View New Flights Option
- •The View Ticket Status Option
- •The View Flight Status Option
- •The Confirm Reservation Option
- •Testing the Application
- •Summary
- •Locating Errors in Programs
- •Watch Window
- •Locals Window
- •Call Stack Window
- •Autos Window
- •Command Window
- •Testing the Application
- •Summary
- •Managing the Databases
- •Backing Up the SkyShark Airlines Databases
- •Exporting Data from Databases
- •Examining Database Logs
- •Scheduling Database Maintenance Tasks
- •Managing Internet Information Server
- •Configuring IIS Error Pages
- •Managing Web Server Log Files
- •Summary
- •Authentication Mechanisms
- •Securing a Web Site with IIS and ASP.NET
- •Configuring IIS Authentication
- •Configuring Authentication in ASP.NET
- •Securing SQL Server
- •Summary
- •Deployment Scenarios
- •Deployment Editors
- •Creating a Deployment Project
- •Adding the Output of SkySharkDeploy to the Deployment Project
- •Deploying the Project to a Web Server on Another Computer
- •Summary
- •Organization Profile
- •Project Requirements
- •Querying for Information about All Books
- •Querying for Information about Books Based on Criteria
- •Ordering a Book on the Web Site
- •Project Design
- •Database Design
- •Database Schema
- •Web Forms Design
- •Flowcharts for the Web Forms Modules
- •Summary
- •Introduction to ASP.NET Web Services
- •Web Service Architecture
- •Working of a Web Service
- •Technologies Used in Web Services
- •XML in a Web Service
- •WSDL in a Web Service
- •SOAP in a Web Service
- •UDDI in a Web Service
- •Web Services in the .NET Framework
- •The Default Code Generated for a Web Service
- •Testing the SampleWebService Web Service
- •Summary
- •Creating the SearchAll() Web Method
- •Creating the SrchISBN() Web Method
- •Creating the AcceptDetails() Web Method
- •Creating the GenerateOrder() Web Method
- •Testing the Web Service
- •Securing a Web Service
- •Summary
- •Creating the Web Forms for the Bookers Paradise Web Site
- •Adding Code to the Web Forms
- •Summary
- •Case Study
- •Project Life Cycle
- •Analyzing Requirements
- •High-Level Design
- •Low-Level Design
- •Summary
- •Overview of Mobile Applications
- •The Microsoft Mobile Internet Toolkit
- •Overview of WAP
- •The WAP Architecture
- •Overview of WML
- •The Mobile Web Form
- •The Design of the MobileTimeRetriever Application
- •Creating the Interface for the Mobile Web Forms
- •Adding Code to the MobileTimeRetriever Application
- •Summary
- •Creating the Forms Required for the MobileCallStatus Application
- •Creating the frmLogon Form
- •Creating the frmSelectOption Form
- •Creating the frmPending Form
- •Creating the frmUnattended Form
- •Adding Code to the Submit Button in the frmLogon Form
- •Adding Code to the Query Button in the frmSelectOption Form
- •Adding Code to the Mark checked as complete Button in the frmPending Form
- •Adding Code to the Back Button in the frmPending Form
- •Adding Code to the Accept checked call(s) Button in the frmUnattended Form
- •Adding Code to the Back Button in the frmUnattended Form
- •Summary
- •What Is COM?
- •Windows DNA
- •Microsoft Transaction Server (MTS)
- •.NET Interoperability
- •COM Interoperability
- •Messaging
- •Benefits of Message Queues
- •Limitations
- •Key Messaging Terms
- •Summary
- •Pointers
- •Declaring Pointers
- •Types of Code
- •Implementing Pointers
- •Using Pointers with Managed Code
- •Working with Pointers
- •Compiling Unsafe Code
- •Summary
- •Introduction to the Languages of Visual Studio .NET
- •Visual C# .NET
- •Visual Basic .NET
- •Visual C++ .NET
- •Overview of Visual Basic .NET
- •Abstraction
- •Encapsulation
- •Inheritance
- •Polymorphism
- •Components of Visual Basic .NET
- •Variables
- •Constants
- •Operators
- •Arrays
- •Collections
- •Procedures
- •Arguments
- •Functions
- •Adding Code to the Submit Button
- •Adding Code to the Exit Button
- •Summary
- •Introduction to Visual Studio .NET IDE
- •Menu Bar
- •Toolbars
- •Visual Studio .NET IDE Windows
- •Toolbox
- •The Task List Window
- •Managing Windows
- •Customizing Visual Studio .NET IDE
- •The Options Dialog Box
- •The Customize Dialog Box
- •Summary
- •Index
INTERACTING WITH A MICROSOFT WORD DOCUMENT |
Chapter 17 |
|
371 |
|
|
||||
|
|
|
|
|
You can store the data that you have retrieved from the cash memo document in an XML document. However, before storing the data in an XML document, you need to understand the basics of XML.
Overview of XML
XML (Extensible Markup Language) is a standard defined for W3C (World Wide Web Consortium) that you can use to store and display data in a structured format. The data in an XML document is displayed as plain text to provide you with a standard interface to display data across multiple platforms. Because of this, XML is extensively used to create applications that run on the Internet. To display data in an XML document, you use tags. You can now write a simple XML code that displays data in the Internet Explorer window. To create an XML document, type the following code in a Notepad file.
<?xml version=”1.0”?> <Students>
<Student>
< StudentId> St001 </StudentId> <LastName> Brown </LastName> <FirstName> George </FirstName>
</Student> <Student>
< StudentId> St002 </StudentId> <LastName> Floyd </LastName> <FirstName> Nancy </FirstName>
</Student> <Student>
< StudentId> St003 </StudentId> <LastName> Smith </LastName> <FirstName> James </FirstName>
</Student> </Students>
In the preceding code, the first line <?xml version= “1.0”?> is an XML declaration statement that is used to indicate to the browser that the document being processed is an XML document. The tag Student is used to denote an element
that contains StudentId, LastName, and FirstName as nodes.
372 Project 3 CREATING A CREATIVE LEARNING PROJECT
To view the output of the preceding code, save the Notepad file as Student.xml and open the file in Internet Explorer. Figure 17-3 shows the Student.xml file in Internet Explorer.
FIGURE 17-3 The Student.xml file in Internet Explorer
Visual Studio .NET provides you with several classes and APIs (application programming interfaces) that you can use to display and process data in an XML document.The following section discusses a few classes that you use to read and write data from an XML document.
The XmlReader Class
The XmlReader class is an abstract base class in the Visual Studio .NET base class library that allows you to access XML data. The XmlReader class lies in the System.Xml namespace and provides you with the ability to create a customized reader. In addition, the XmlReader class allows you to implement the functionality
of derived classes such as XmlTextReader, XmlValidatingReader, and Xml-
NodeReader. The XmlReader class provides several methods and properties to access data from XML documents.
INTERACTING WITH A MICROSOFT WORD DOCUMENT |
Chapter 17 |
373 |
|
|
|
|
|
The XmlWriter Class
The XmlWriter class is another abstract base class in the System.Xml namespace that allows you to write data to an XML document. You can use the XmlWriter class to create an interface for the XML documents. These XML documents are created using streams generated by the XmlWriter class and conform to the W3C and Namespace recommendations. The XmlWriter class implements the XmlTextWriter class. The XmlWriter class contains several methods and classes that you can use to write data to streams.
Displaying Data in an XML Document
Before writing the code to display data in an XML document, you should first see a sample XML document created by the Creative Learning application. Figure 17-4 shows the sample XML document.
FIGURE 17-4 Sample XML document
To display data in an XML document, you first need to create an object, xmlWrite, of the XmlTextWriter class in the System.Xml.XmlWriter class. After creating the xmlWrite object, you can use this object to write data to the XML document. The following section discusses how to add code to the XML document.
374 Project 3 CREATING A CREATIVE LEARNING PROJECT
Adding Code to the XML Document
To write data to the XML document, add the following code to the Created event.
XmlTextWriter xmlWrite; xmlWrite.Formatting=Formatting.Indented; xmlWrite.WriteDocType(“Sales”,null,null,null); xmlWrite.WriteComment(“Summary of sales at Creative Learning”); xmlWrite.WriteStartElement(“Sales”); xmlWrite.WriteStartElement(Convert.ToString(DateTime.Today)); xmlWrite.WriteElementString(“Memo”,strMemo); xmlWrite.WriteElementString(“Amount”,strAmount); xmlWrite.WriteEndElement();
xmlWrite.WriteEndElement();
The preceding code creates an object, xmlWrite, of the XmlTextWriter class.Then, the code uses the WriteDocType() method of the XmlTextWriter class to write the DOCTYPE declaration of the XML document. The WriteDocType() method takes four parameters.The first parameter specifies the name of the DOCTYPE, Sales, and is an essential parameter. However, the other three parameters are optional.
The DOCTYPE Declaration
The DOCTYPE declaration is used to specify DTD (Document Type Definition) for an XML document. DTD contains a set of rules that you can use to define the structure and logic of XML documents. You can create a document called a DTD document to store the set of rules for a specific XML document. The DTD documents contain rules that conform to W3C standards and are used to define the structure and syntax of the XML documents. In addition, the DTD documents contain the content and values allowed for an XML document as per W3C standards. The DTD document is a file with the extension .dtd.
When you create an XML document, the document is validated against the rules specified in the DTD document. To do this, you need to associate an XML document with a DTD document by using the DOCTYPE declaration. In addition to the name of the document, you can specify the root element of the document.
After discussing the DOCTYPE declaration statement, I will continue with the discussion of the code that is used to write data to the XML document. In addition to specifying a DOCTYPE for your XML document, you can add a com-
INTERACTING WITH A MICROSOFT WORD DOCUMENT |
Chapter 17 |
|
375 |
|
|
||||
|
|
|
|
|
ment to the XML document. To add a comment, you can use the WriteComment() method of the XmlTextWriter class. The WriteComment() method takes the text to be displayed in the form of a comment as a parameter.
After specifying the DOCTYPE and a comment to the XML document, you need to add data to the document.The data in an XML document is displayed in the form of elements and nodes. Each element that you specify is enclosed within tags. To specify the starting tag for an element, you use the WriteStartElement() method. The WriteStartElement() method is a void method in the XmlTextWriter class and is used to specify the starting tag for an element and associate the element with the given namespace. The WriteStartElement() method takes the name of the element as a parameter.
You can use the WriteStartElement() method to start two elements, Sales and current date. To specify the current date, use the DateTime struct in the System namespace. The Today property of the DateTime struct is used to retrieve the current date. The value returned by the Today property of the DateTime struct is converted to a string type value by using the ToString() method of the Convert class.
NOTE
The ToString() method is used to convert a 64-bit signed integer to its equivalent string type value represented by the System.String class in the specified base. The ToString() method is a method in the Convert class that lies in the System namespace.
Once you have added elements to your XML document, you can add nodes to the elements. To add nodes to the current date element, use the WriteElementString() method XmlWrite class. When you override the WriteElementString() method in a derived class, you can use it to create an element with the parameters that you specify. The WriteElementString() method takes the name of the element and its value as the parameter. You can use the WriteElementString() method to specify Memo and Amount as nodes in the current date element.
After adding data to the element, you need to close the element tag. You can do
this by using the WriteEndElement() method. The WriteEndElement() method is a void method in the XmlTextWriter class.
376 Project 3 CREATING A CREATIVE LEARNING PROJECT
TIP
You need to call the WriteEndElement() method of the XmlTextWriter class as many times as the number of elements in your XML document.This means that calling the WriteEndElement() method once will not close all the elements in the XML document.
You have created an object of the XmlTextWriter class xmlWrite. You have also used it to write the data to an XML document. However, until now, you have not specified the name of the XML document and the directory where the XML document needs to be stored. To do this, add the following statement to the Created event.The name of the file is specified as Summary.xml, and the destination directory is the directory specified in the txtDest text box.
xmlWrite= new XmlTextWriter(txtDest.Text + “Summary.xml”,null);
You can also use the Intended enum of the System.Xml.Formatting enum to format the data that is displayed in the XML document. The System.Xml.Formatting enum is used to specify the format settings for the objects of the System.Xml.XmlTextWriter class. Using the Intended enum enables you to display the data as per the
System.Xml.XmlTextWriter.Indentation and System.Xml.XmlTextWriter.IndentChar
settings. Figure 17-5 shows the XML document before you format the data in the document.
FIGURE 17-5 Data in the XML document without formatting