Relationships in WPF Applications

Similar documents
Microsoft Virtual Labs. Building Windows Presentation Foundation Applications - C# - Part 1

Windows Presentation Foundation Tutorial 1

1. WPF Tutorial Page 1 of 431 wpf-tutorial.com

STEP BY STEP to Build the Application 1. Start a. Open a MvvmLight (WPF4) application and name it MvvmControlChange.

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

Data Binding with WPF: Binding to XML

آموزش DataGrid در WPF به همراه صفحه بندي و جستجوي انتخابی. کلیک کن

WPF Viewer for Reporting Services 2008/2012 Getting Started

Introduction to the BackgroundWorker Component in WPF

This tutorial has been designed for all those readers who want to learn WPF and to apply it instantaneously in different type of applications.

Understanding In and Out of XAML in WPF

Windows Presentation Foundation (WPF) User Interfaces

Implementing multi-user multi-touch scenarios using WPF in Windows* 8 Desktop Apps

Introduction to C#, Visual Studio and Windows Presentation Foundation

Windows Presentation Foundation Using C#

ComponentOne. Windows for WPF

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Windows 10 Apps Development

wpf5concat Start Microsoft Visual Studio. File New Project WPF Application, Name= wpf5concat OK.

1. Create SQL Database in Visual Studio

ASP.NET Dynamic Data

Election 2012: Real- Time Monitoring of Election Results

WINDOWS PRESENTATION FOUNDATION LEKTION 3

Step 1: Download and install the CudaSign for Salesforce app

Microsoft Windows Apps Dev w/microsoft.net Framework 4.

User Guide for Video Conference. Using the Polycom RealPresence Application

ClientAce WPF Project Example

UniFinger Engine SDK Manual (sample) Version 3.0.0

Section 1: Ribbon Customization

Xamarin.Forms. Hands On

Microsoft Surface Lab #2: Surface Controls

Lab 8: ASP.NET 2.0 Configuration API and Health Monitoring

How to setup Outlook and Outlook Web Access (OWA) to give a send receipt and a read receipt (Options)

Sales Person Commission

Facilities and Safety How-To Guide: Accessing and Using Your UCF Webmail Account

Hands-On Lab. Client Workflow. Lab version: Last updated: 2/23/2011

MAKE A NEW SUBSITE 1. On the left navigation, click Site Contents (or Sites). Scroll down to subsites. Click new subsite.

Hands-On Lab. Building Applications in Silverlight 4 Module 8: Advanced OOB and MEF. Event Administrator Dashboard

טכנולוגיית WPF מספקת למפתחים מודל תכנות מאוחד לחוויית בניית יישומיי. ניהול התצוגה מתבצע בשפת הסימון Extensible Application Markup ) XAML

Telerik WPF Controls Tutorial

Understanding Junk filtering & Anti-Spam controls

Integrating InfoPath Forms. Paul Baker

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

Getting Started with Telerik Data Access. Contents

1. WPF Tutorial Page 1 of 359 wpf-tutorial.com

Database Linker Tutorial

AGENDA WINDOWS PRESENTATION FOUNDATION LEKTION 4. Statusbar Hyperlänkar WebBrowser TabControl Ribbon ListBox Data Template Resource Dictionary Style

Follow Up Pro Guide

Step by Step. Use the Cloud Login Website

How to Move Mail From Your Old POP Account To Exchange Using Outlook 2010

Organizing and Managing

Introduction to Unit Testing ---

Using WPF for Computer Graphics

Create PDF invoice in Windows Forms application. Written by Apitron Documentation Team

Quick Start Guide. Microsoft Access 2013 looks different from previous versions, so we created this guide to help you minimize the learning curve.

Access Tutorial 1 Creating a Database

Keep SQL Service Running On Replica Member While Replicating Data In Realtime

PDF for Windows Phone

Stored Documents and the FileCabinet

A Short Tutorial on Using Visio 2010 for Entity-Relationship Diagrams

Mahara: MyPortfolio. Create content Build pages Share. A user guide for beginners. What is Mahara?

Microsoft s Team Foundation Server (TFS) Canute Magalhaes Richland County (IT) SYSTEMS ANALYST / PROJECT LEAD 1

Working with IronPython and WPF

Windows Presentation Foundation: What, Why and When

Banner Relationship Management (BRM) Overview

Chapter 14 WCF Client WPF Implementation. Screen Layout

RightFax FaxUtil. Quick reference guide to getting started. Note: This document applies to OpenText RightFax version 10.0

Searching for jobs. The quick search provides a simple form on the home page that is quick to use at any stage.

Quick Start Guide. Microsoft Access 2013 looks different from previous versions, so we created this guide to help you minimize the learning curve.

webcrm API Getting Started

ONLINE QUICK REFERENCE CARD ENDNOTE

How to Login Username Password:

Visual Studio 2008 Express Editions

Contents. Introduction. Chapter 1 Some Hot Tips to Get You Started. Chapter 2 Tips on Working with Strings and Arrays..

WPF Learner s Guide to Head First C#

KEYBOARD SHORTCUTS. Note: Keyboard shortcuts may be different for the same icon depending upon the SAP screen you are in.

Why the need for set of rules in Microsoft Outlook?

WCF Service Creation With C#

8 CREATING FORM WITH FORM WIZARD AND FORM DESIGNER

An Introduction to the Windows Presentation Foundation with the Model-View-ViewModel

A SharePoint Developer Introduction. Hands-On Lab. Lab Manual SPCHOL306 Using Silverlight with the Client Object Model VB

Async startup WPF Application

Customer Relations Management

Mapping to the Windows Presentation Framework

SMS for Outlook. Installation, Configuration and Usage Guide

Visual Basic and OPC All versions of Kepware OPC Servers 10/23/03

>

In this tutorial I will be uploading multiple images to my ftp folder on my ktools site, and then add them using manager.

Visual Basic Programming. An Introduction

Enhanced Attendance Reporting for SmartLock Pro Plus OPERATOR GUIDE

- First Steps. Introduction Creating a new testsuite Blocks and libraries Creating your first (compound) block...

ios 9 Accessibility Switch Control - The Missing User Guide Updated 09/15/15

Einführung in die Windows Store App Entwicklung mit C# und XAML. Modul 2 Datenbindung und Zugriff auf das lokale Dateisystem

MAIL MERGE TUTORIAL. (For Microsoft Word on PC)

Transcription:

Chapter 15 Relationships in WPF Applications Table of Contents Chapter 15... 15-1 Relationships in WPF Applications... 15-1 One-To-Many Combo Box to List Box... 15-1 One-To-Many Relationships using Properties... 15-5 One-To-Many Relationships using Lazy-Loading... 15-7 Chapter Index... 15-10 At some point you will need to work with relationships between tables. This chapter will help you with working with relationships in a WPF application. One-To-Many Combo Box to List Box In this sample you will use the PDSASamples database that comes with Haystack to display all Order Line Items for a specific Order. You will place a Combo Box and a List Box control on a WPF Window and hook them together with an ObjectDataProvider. Your final version will look Figure 1.

Figure 1: Selecting Line Items for an Order Create a new project in Haystack. Check the Generate Foreign Key Methods. Open the Customer table and Save Table Info. This will also create the OrderHeader and OrderLineItem classes Generate all tables. Create a new WPF Application. Add the appropriate Haystack DLLs. Add the generated code and an App.Config file from one of the WPF folders. On the MainWindow.xaml add a TextBlock Set the Text property to Orders Add a ComboBox control to the right of the TextBlock. Add a ListView below the TextBlock and ComboBox Go to the XAML view of MainWindow and in the <Window element add the following XAML namespaces. NOTE: Use whatever namespaces you used when generating the classes with Haystack. The namespace I used was Sample.Project. xmlns:mgr="clr-namespace:sample.project.datalayer" xmlns:entity="clr-namespace:sample.project.entitylayer" Add a <Window.Resources> element just below the <Window > and before the <Grid> element: 15-2 Haystack Code Generator for.net

<Window.Resources> <ObjectDataProvider x:key="odporders" ObjectType="x:Type mgr:orderheadermanager" MethodName=" BuildCollection " /> <ObjectDataProvider x:key="odplineitems" ObjectType="x:Type mgr:orderlineitemmanager" MethodName="GetOrderLineItemsByFK_OrdersEntity"> <ObjectDataProvider.MethodParameters> <entity:orderheader /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> Build the Project. Click once on the ComboBox control to give it focus and bring up the Properties window. Click on the Advanced Properties (the little box) on the ItemsSource property and select Apply Data Binding as shown in Figure 2. Figure 2: Apply a data binding to Combo Box Select StaticResource Window.Resources odporders from the list as shown in Figure 3. Haystack Code Generator for.net 15-3

Figure 3: Select the odporders Object Data Provider Click off this window to set the binding. While still in the Properties Window for the ComboBox select the DisplayMemberPath property and type in OrderDate as shown in Figure 4. Figure 4: Set the DisplayMemberPath to the property you wish to display in the ComboBox If you run the project right now you should see data in the combo box. Now, let s hook up the list box to display the line items. In the ComboBox you will need to write the following XAML between the <ComboBox > and the </ComboBox> tags. If the </ComboBox> ending tag is not there, you will need to create it. 15-4 Haystack Code Generator for.net

<ComboBox.SelectedValue> <Binding Source="StaticResource odplineitems" Path="MethodParameters[0]" BindsDirectlyToSource="True" UpdateSourceTrigger="PropertyChanged" /> </ComboBox.SelectedValue> Data and Manager Classes Click on the List Box control to give it focus. In the Properties Window select ItemsSource and click on the Advanced Properties box to Apply a Data Binding. Choose the odplineitems as shown in Figure 5. Figure 5: Select the odplineitems Object Data Provider Run the application and you should be able to select an order and see the ToString() representation of the line items for that order (Figure 1). Feel free to fix up the ListBox to look like however you want. One-To-Many Relationships using Properties You can create one-to-many relationships by doing just a little manual adding of properties and methods to your generated classes. In this sample you will use the PDSASamples database that comes with Haystack to add an Orders collection to the Customer entity object. Create a new project in Haystack Check the Generate Foreign Key Methods Haystack Code Generator for.net 15-5

Open the Customer table and Save Table Info Open the OrderHeader table and Save Table Info Generate both tables Using the WPF Template Project add your generated code to this project Open Customer.cs Add the following property C# public OrderHeaderCollection Orders get; set; Visual Basic Public Property Orders As OrderHeaderCollection Open CustomerManager.cs Add the following method: C# public OrderHeaderCollection GetOrdersForCustomer(int customerid) OrderHeaderManager mgr = new OrderHeaderManager(); mgr.entity.customerid = customerid; // Get Orders this.entity.orders = mgr.getorderheadersbycustomerid(); return mgr.getorderheadersbycustomerid(); Visual Basic Public Function GetOrdersForCustomer(customerId As Integer) _ As OrderHeaderCollection Dim mgr As New OrderHeaderManager() mgr.entity.customerid = customerid Me.Entity.Orders = mgr.getorderheadersbycustomerid() Return mgr.getorderheadersbycustomerid() End Function Open Main.xaml Delete the sample user control Add a Button and set the Name to btnload and the Content to Load Double click and write the following code: 15-6 Haystack Code Generator for.net

C# private void btnload_click(object sender, RoutedEventArgs e) CustomerManager mgr = new CustomerManager(); mgr.dataobject.loadbypk(1); mgr.getordersforcustomer(mgr.entity.customerid); System.Diagnostics.Debugger.Break(); Visual Basic Private Sub btnload_click(sender As Object, e As RoutedEventArgs) _ Handles btnload.click Dim mgr As New CustomerManager() mgr.dataobject.loadbypk(1) mgr.getordersforcustomer(mgr.entity.customerid) System.Diagnostics.Debugger.Break() End Sub Set a break point on the last line of this event procedure and run the app to see your orders loaded for this customer. One-To-Many Relationships using Lazy- Loading If you do not care about coupling between your Data Layer (Manager classes) and your Entity Layer (Entity classes) you can employ lazy loading of your Orders property. Modify the Orders property you created in Customer.cs to look like the following: Haystack Code Generator for.net 15-7

C# private OrderHeaderCollection _Orders = null; public OrderHeaderCollection Orders get if (_Orders == null) CustomerManager mgr = new CustomerManager(); _Orders = mgr.getordersforcustomer(this.customerid); return _Orders; set _Orders = value; Visual Basic Private _Orders As OrderHeaderCollection = Nothing Public Property Orders() As OrderHeaderCollection Get If _Orders Is Nothing Then Dim mgr As New CustomerManager() _Orders = mgr.getordersforcustomer(me.customerid) End If Return _Orders End Get Set _Orders = value End Set End Property The above code will now load Orders when you first access the Orders property. Open Main.xaml again Add another button to try out lazy loading. Set the Name to btnlazyload and the Content Lazy Load. 15-8 Haystack Code Generator for.net

C# private void btnlazyload_click(object sender, RoutedEventArgs e) CustomerManager mgr = new CustomerManager(); mgr.dataobject.loadbypk(1); MessageBox.Show(mgr.Entity.Orders.Count.ToString()); Visual Basic Private Sub btnlazyload_click(sender As Object, _ e As RoutedEventArgs) Dim mgr As New CustomerManager() mgr.dataobject.loadbypk(1) MessageBox.Show(mgr.Entity.Orders.Count.ToString()) End Sub Run the application to see the count of the orders displayed. You can step through the code to watch it load the orders. Haystack Code Generator for.net 15-9

Summary In this chapter you learned how to create relationships between tables in Haystack using WPF. Chapter Index L Lazy Loading, 15-7 O ObjectDataProvider in WPF, 15-1 One-To-Many Combo Box to List Box, 15-1 One-To-Many Relationships, 15-1 Lazy Loading, 15-7 WPF, 15-1 One-To-Many Relationships using Properties, 15-5 W WPF One-To-Many, 15-1 15-10 Haystack Code Generator for.net