Exercises
421
}
class Order
{
public int OrderId { get; set; }
public Person Customer { get; set; }
public List<OrderItem> OrderItems { get; set; }
}
The programs Form_Load event handler
creates an array of
Order objects. The
program’s buttons, which are shown in
Figure 37-3, let the user display the data in
various ways although initially they don’t
contain any code. In Exercises 4 through 8,
you add that code to give the program
its features.
4. The CustomerOrders program creates several Order objects, but it doesn’t fill in those
objects’
TotalCosts properties. Use LINQ to do that. (Use a foreach loop to loop through
the objects. For each object, use a LINQ query to go through the order’s
OrderItems list and
select each
OrderItem’s UnitPrice times its Quantity. After you define the query, call its
Sum function to get the total cost for the order.)
5. Copy the program you built for Exercise 4 and add code behind the All Orders button.
That code should use a LINQ query to select the orders’ ID, customer name, and total costs.
Display the results in the
resultListBox by setting that control’s DataSource property to
the query.
6. Copy the program you built for Exercise 5 and add code behind the Order By Cost button.
That code should use a query similar to the one used by Exercise 5, but it should order the
results by cost so the orders with the largest costs are listed first.
7. Copy the program you built for Exercise 6 and add code behind the Customer button. That
code should use a LINQ query to list orders placed by the customer selected in the combo-
box. (Hint: Get the customer’s name from the combobox’s
Text property. If the name is
blank, exit the method without doing anything.)
8. Copy the program you built for Exercise 7 and add code behind the Greater Than button.
That code should use a LINQ query to list orders with total costs greater than the value
entered in the textbox.
You can download the solutions to these exercises from the book’s web page at
www.wrox.com or www.CSharpHelper.com/24hour.html. You can find those
solutions in the Lesson37 folder.
FIGURE 373
596906c37.indd 421 4/7/10 12:35:02 PM
Click here to Play
596906c37.indd 422 4/7/10 12:35:02 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.201.55