Level C Walk-Through — Windows

   

This section describes how the Windows client of the Island Hopper News sample Level C works, including both what you see as a user and what happens behind the scenes. If possible, run the application as you read through this section, and look at the source code, which you'll find in Program Files\IslandHopper\ScenarioC\Source\VBClient\classifieds.vbg if you accepted the installation defaults. The source code for the server components is in Program Files\IslandHopper\ScenarioC\Source\Server_Components\Server_Components.vbg. For complete information on all the different parts of Level C, see Level C Specification in this chapter.

First Impressions

When you start the Windows client from the Start menu, you see what appears to be a single form with the caption "Island Hopper News."

This is actually an multiple-document interface (MDI) form, frmParentC, which calls a child, frmAccountingC, immediately. The child form contains the controls and background you see.

The main screen of the sample offers you the following six choices.

You can see how Level C of the sample expands upon Level A by including the concepts of customers and billing and the functions that go along with those concepts. Now that paying customers use the application, you need a way to maintain their records and match customers with payments. You also need a way to track what a customer owes for placing ads (invoices) and what a customer pays (payments).

For More Information   See Level A Walk-Through — Windows in this chapter for information on how the Windows version of Level A works.

The Ad Maintenance form changes slightly from Level A. Now you can retrieve ads by customer ID and customer e-mail. You can also search by customer last name.

Notice how the labels change color when you move the pointer over them. This is done by detecting the mouse move and changing the color of the labels. Look at the code for frmAccountingC and locate the Form_MouseMove and lblOption_MouseMove functions.

Maintaining Customer Records

Click Customer Maintenance to display the Customer Maintenance form, frmCustomerC. This form presents three options: you can add a new customer record to the database, update customer records, or delete a customer record from the database. You can use the customer in the following table to try out the search functions.

ID Name E-mail
11901 Masters, Steven someone@microsoft.com

How It's Done

All of these tasks are carried out by the bus_CustomerC component, which contains the business logic and subsequently creates data access objects, such as db_CustomerC, to perform the actual work with the database.

Inquiring About Invoices

Click Invoice Inquiry to display the Invoice Inquiry form, frmInvoiceC. With this form, you can retrieve invoices from the database by the invoice ID, the customer ID, or the customer e-mail address. You can also search for an invoice by customer last name. Invoices that match your search criteria are listed in a grid control at the bottom of the form. You can double-click any listed invoice to see detailed information about that invoice on the Invoice Details form, frmInvoiceDetailsC.

You can use the customer in the following table to try out the search functions.

ID Name E-mail
11901 Masters, Steven someone@microsoft.com

How It's Done

frmInvoiceC instantiates the bus_CustomerC component to retrieve the invoices from the database. The bus_CustomerC component in turn creates data access objects as needed.

Tracking Payments

Click Payments to display the Payments form, frmInputPaymentC. With this form, you can enter a payment for an invoice. You can retrieve customer information from the database using the customer ID or e-mail address. You can also search for a customer by last name.

You can use the customer in the following table to try out the search functions.

ID Name E-mail
11901 Masters, Steven someone@microsoft.com

How It's Done

The Payments form instantiates the bus_CustomerC component to handle retrieving customer information from the database. It also instantiates the bus_PaymentC component to handle adding payments to the database.

Retrieving Ads

Click Ad Maintenance to display the Ad Maintenance form, frmAdC. You can use this form to retrieve an ad from the database. You can search for a customer by last name without supplying any input. You can also retrieve ads by customer ID or customer e-mail address if you have that information. You can click Place Ads to place an ad, but you must supply a valid customer ID first.

You can use the customer in the following table to try out the search functions.

ID Name E-mail
11901 Masters, Steven someone@microsoft.com

The retrieved ads are displayed in an MSFlexGrid control. You can double-click on an ad to display the Ad Details form, frmAdDetailA. Clicking Place Ads also displays the Ad Details form.

How It's Done

This form, which is running on the client machine, instantiates the bus_CustomerC component on the server machine when it loads. When you fill in a customer ID or e-mail address and click Retrieve, the corresponding bus_CustomerC method (GetByID or GetByE-mail) is called. Both of these methods instantiate the db_CustomerC component to perform the actual retrieval.

Browsing Ads

Click Browse Ads to display the Browse Ads form, frmDisplayAdsC. This form consists of two parts: the list of categories on the left and the list of ads on the right. You click a category to see the ads in that category, and then click the title of an ad to see the text of the ad.

How It's Done

The list of categories is a standard ListBox control that is populated through a method called FillAdsByCategory. You can see this method if you look at the code for frmDisplayAdsC. The FillAdsByCategory method instantiates the db_CategoryC component to access the database and return a list of all the categories in the Categories table.

The list of ads is a WebBrowser control. The WebBrowser control is available with Internet Explorer 4.0 and later, and with it you can run Web pages as part of a Visual Basic form. The WebBrowser control locates the Web server and displays an Active Server Pages file, AdsList.asp, which contains the ads that apply to the category you selected. To see how this is done, look at the lstCategory_Click function in the code for frmDisplayAdsC.

Placing and Editing Ads

You can update, delete, or place new ads with the Ad Details form. These three modes are controlled by a set of option buttons in the upper left corner. The mode that is enabled when the form is displayed depends on how you got to the form. If you clicked Place Ads, the Ad Details form is displayed with the Place New Ad option selected. If you double-clicked an ad on the Ad Maintenance form, the Ad Details form is displayed with the Update option selected and the ad's information displayed.

How It's Done

When the Ad Details form is loaded, it instantiates the bus_AdC component, calls the FillCategory and FillDuration methods to populate the Category and Duration combo boxes, and clears all the text fields in preparation for your input. Then the form is activated. The activation code determines which option button should be enabled.

The FillDuration method simply uses the AddItem method to populate the Duration combo box. The FillCategory method instantiates the db_CategoryC component to access the database and retrieve the categories, and then uses the AddItem method to populate the combo box.

When the Ad Details form is activated, it calls the RetrieveAdByID subroutine to retrieve the ad from the database. RetrieveAdByID uses the GetByID method of bus_AdC to retrieve the ad information and populate the fields.