15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Course order application ❘ 1375<br />

private void AddListItem(LabelIdMapping labelIdMapping)<br />

{<br />

listOrders.Items.Add(labelIdMapping);<br />

}<br />

The ListBox control contains elements of the LabelIdMapping class. This class is used to display the labels<br />

of the messages in the list box, but to keep the ID of the message hidden. The ID of the message can be used<br />

to read the message at a later time:<br />

private class LabelIdMapping<br />

{<br />

public string Label { get; set; }<br />

public string Id { get; set; }<br />

}<br />

public override string ToString()<br />

{<br />

return Label;<br />

}<br />

The ListBox control has the SelectedIndexChanged event associated with the method<br />

listOrders_SelectionChanged(). This method gets the LabelIdMapping object from the current<br />

selection, <strong>and</strong> uses the ID to peek at the message once more with the PeekById() method. Then the content<br />

of the message is displayed in the TextBox control. Because by default the priority of the message is not<br />

read, the property MessageReadPropertyFilter must be set to receive the Priority:<br />

private void listOrders_SelectionChanged(object sender,<br />

RoutedEventArgs e)<br />

{<br />

LabelIdMapping labelId = listOrders.SelectedItem as LabelIdMapping;<br />

if (labelId == null)<br />

return;<br />

orderQueue.MessageReadPropertyFilter.Priority = true;<br />

Message message = orderQueue.PeekById(labelId.Id);<br />

CourseOrder order = message.Body as CourseOrder;<br />

if (order != null)<br />

{<br />

textCourse.Text = order.Course.Title;<br />

textCompany.Text = order.Customer.Company;<br />

textContact.Text = order.Customer.Contact;<br />

buttonProcessOrder.IsEnabled = true;<br />

}<br />

if (message.Priority > MessagePriority.Normal)<br />

{<br />

labelPriority.Visibility = Visibility.Visible;<br />

}<br />

else<br />

{<br />

labelPriority.Visibility = Visibility.Hidden;<br />

}<br />

}<br />

else<br />

{<br />

MessageBox.Show("The selected item is not a course order",<br />

"Course Order Receiver", MessageBoxButton.OK,<br />

MessageBoxImage.Warning);<br />

}<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!