Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft CSharp Programming For The Absolute Beginner (2002) [eng].pdf
Скачиваний:
48
Добавлен:
16.08.2013
Размер:
15.71 Mб
Скачать

I then created a series of XML elements to hold the problem and its components. Next, I used the AppendChild() method of the various nodes to build the test and the first problem. Finally, I added some default text to each of the nodes. I then reset qNum to 0 and showed the initial question.

Summary

In this chapter you learned how C# can be used to create and explore XML documents. You have discovered the internal structure of XML documents, learned how to create an XML document in the IDE, and learned how to write a program that can navigate through any XML document. You have also learned how you can generate an XML document from scratch or add an element to an existing document.

Challenges

Modify the Adventure Kit game in Chapter 9 so that it uses XML data instead of object serialization to store the adventures.

Create an address book or another simple database, using XML technology.

Investigate existing XML technologies such as SMIL or SVG, and build a simple subset.

Create a new XML language to describe a type of data you frequently work with.

Use the XML skills you have learned to read an HTML or XML document and display selected information (perhaps it should switch to a larger font whenever your name is encountered in the document).

317

Chapter 11: Databases and ADO.NET: The Spy

Database

Overview

As you have grown more experienced in C#, you have seen the importance of data for creating interesting programs. Often you will find that you have a large amount of data that has already been generated in some sort of database management package, such as Access, Oracle, or SQL Server. C# provides a set of classes for working with existing databases. It also provides very handy tools for creating a database. In this chapter you will get exposure to the complex and powerful world of data manipulation and learn to

Build a simple database using the built−in data management tools

Create a form that uses data connections, data adapters, and data sets to access data

Use basic data normalization principles to design multi−table databases

Build relationships and views for managing complex databases

Connect to various types of databases and raw XML data as a data source

Update data on the fly

A Note about the CD−ROM

This chapter focuses on techniques for building databases on your own server. The examples in this chapter outline how I designed a data system on my own server, but the programs on the CD−ROM will not run unless you build the databases on your machine. In the event that you don’t want to build the database, I have included an Access database (spy.mdb) on the CD−ROM that you can connect to using the techniques outlined in the section, “Working with Other Databases.”

Introducing the SpyMaster Program

To illustrate the database generation features, you will build a simple database used to manage your international network of spies (you do have an international spy network, don’t you?).

The Spy Master program main screen is illustrated in Figure 11.1.

318

Figure 11.1: From this main screen you can achieve world dominance (or protect it from evil).

The main screen features familiar buttons that take you to other forms. To view your agents, click on the (what else?) View Agents button. You will see the form shown in Figure 11.2.

Figure 11.2: All the information regarding a spy is available on this form.

You can choose any agent in your roster from the drop−down list at the top of the form.

Because you are the spy master you also can change spy information at will, letting slip the dogs of international intrigue, as shown in Figure 11.3.

319

Figure 11.3: The edit agents screen is similar to the view agents screen, except that now you can change some of the data.

You can change a lot from the edit agent screen, but you can’t change everything from this screen, because designing daring missions of danger and creating specialties are different than manipulating your pawns on the grand chess table (evil laughter). There is a separate form for editing missions, shown in Figure 11.4.

Figure 11.4: Here the user can add and modify assignments in a grid.

Finally, you can add to the specialties your agents can pursue.

320

Соседние файлы в предмете Программирование на C++