| Team Fly |
Page 535
The automated discount calculations impose another limitation on the design of the application's interface. The original NWOrders application allows you to switch tabs and select another customer even after adding detail lines to the order. We can't have this flexibility when the discount policy is based on the customer. To prevent users from selecting a new customer after having entered detail lines with discounts for another customer, we disable the Order Header tab. Another approach would be to allow users to select another customer and recalculate the
The Relations project
F IGURE 18.6 The Relations project displays sales data about each product.
When the application's form is loaded, all the data are loaded into the ProductSales DataSet. In a real application you should provide an interface that enables users to limit the selection. For example, select orders placed in a time interval, the orders of customers from a specific country, and so on. The tables of the Northwind database are very small and we've
| Team Fly |
| Team Fly |
Page 539
The listing is a bit lengthy because it calculates totals, formats the
1.
The detail lines that refer to the selected product are
DetailRows = _
ProductSales1.Order_Details.Select(''ProductID = " & productID)
The DetailRows array contains all the rows of the Order Details DataTable that refer to the product whose ID we passed to the Select method as argument.
2.
The program creates a new DataTable, the OrdersTable, with the same structure as the original Orders DataTable of the DataSet. This DataTable will store all the rows of the Orders DataTable that
For Each DetailRow In DetailRows
OrderRow = DetailRow.GetParentRow("OrdersOrder_Details")
OrdersTable.Rows.Add(OrderRow.ItemArray)
Next
3. The OrdersTable DataTable now contains the orders that include the product selected on the ListBox control. Another loop iterates through the rows of this DataTable and displays them on the ListView control. In addition, it keeps track of the number of orders placed by each customer and the total amount spent by each customer for the selected product.
4. To retrieve the customer name from each order, the program calls the FindByCustomerID method of the Customers DataTable, passing as argument the customer's ID with the following statements. The CustomerRow variable is of the ProductSales.CustomersRow type.
CustomerID = OrderRow.Item("CustomerID")
CustomerRow = _
ProductSales1.Customers.FindByCustomerID(CustomerID)
The remaining statements populate the ListView control, calculate the totals, and perform other straightforward
The Relations project
Figure 18.7 shows an application that maps more complicated relations on a ListView control. The Relations1 project maps the publishers of the Pubs database, along with their titles and each title's
| Team Fly |