Chapter 14 WCF Client WPF Implementation. Screen Layout



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

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

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

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

APPLICATION NOTE. Atmel AVR10006: XDK User Guide. Atmel Microcontrollers. Features. Description

Conexión SQL Server C#

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

A Step by Step Guide for Building an Ozeki VoIP SIP Softphone

Windows Presentation Foundation Tutorial 1

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

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

I A Form és a párbeszédablakok I.1. MessageBox osztály MessageBox.Show(szöveg[,cím[,gombok[,ikon[,defaultbutton]]]]);

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

WINDOWS PRESENTATION FOUNDATION LEKTION 3

Introduction to the BackgroundWorker Component in WPF

Introduction to C#, Visual Studio and Windows Presentation Foundation

How To Create A Database In Araba

Implementing a WCF Service in the Real World

Using ilove SharePoint Web Services Workflow Action

Web Services API Developer Guide

PROCEDURE INSERTION(NUM IN EMPLOYES.NUMEMP%TYPE, NOM VARCHAR2, PRENOM IN VARCHAR2, PPHOTO IN BLOB, SALAIRE IN NUMBER);

THE USE OF WPF FOR DEVELOPMENT OF INTERACTIVE GEOMETRY SOFTWARE

See the Developer s Getting Started Guide for an introduction to My Docs Online Secure File Delivery and how to use it programmatically.

Relationships in WPF Applications

Save Actions User Guide

Aucune validation n a été faite sur l exemple.

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

How to install and setup XLabs

Understanding In and Out of XAML in WPF

Software Engineering 1 EEL5881 Spring Homework - 2

2009 Tutorial (DB4O and Visual Studio 2008 Express)

Getting Started with Telerik Data Access. Contents

How To Develop A Mobile Application On Sybase Unwired Platform

Systems Programming & Scripting

Tutorial: Windows Mobile Application Development. Sybase Unwired Platform 2.1 ESD #2

İNTERNET TABANLI PROGRAMLAMA- 13.ders GRIDVIEW, DETAILSVIEW, ACCESSDATASOURCE NESNELERİ İLE BİLGİ GÖRÜNTÜLEME

webcrm API Getting Started

Introduction to Windows Presentation Foundation

1. La classe Connexion class Connexion {

Xamarin.Forms. Hands On

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

Introduction to Visual Studio and C#

How to create a SMTP plugin for ArGoSoft Mail Server,.NET edition (AMS.NET edition) using Visual Studio 2005

>

Aplicação ASP.NET MVC 4 Usando Banco de Dados

Mapping Specification for DWG/DXF (MSD) C#.NET Code Samples

CHAPTER 10: WEB SERVICES

Peer - to - Peer Networking

如 何 在 C#.2005 中 使 用 ICPDAS I/O Card 的 DLL 檔 案

Active Commerce Developer s Cookbook

USER GUIDE Appointment Manager

Capturx for SharePoint 2.0: Notification Workflows

J a v a Quiz (Unit 3, Test 0 Practice)

How To Design An Eprescription System

A PROJECT REPORT ON. SkyDrive. Submitted for the partial fulfillment of the requirement for the Award of the degree of MASTER OF COMPUTER APPLICATION

ADOBE READER AND ACROBAT

Windows Presentation Foundation Using C#

Comp151. Definitions & Declarations

Tutorial 1: M/M/n Service System Simulation Tutorial 2: M/M/n Simulation using Excel input file Tutorial 3: A Production/Inventory System Simulation

Save Actions User Guide

Working with IronPython and WPF

ASP.NET Dynamic Data

EMC Documentum Application Connectors Software Development Kit

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

WPF Shapes. WPF Shapes, Canvas, Dialogs 1

5 Airport. Chapter 5: Airport 49. Right-click on Data Connections, then select Add Connection.

Skyline Interactive Tool Support

Coding Standards for C#

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Security API Cookbook

ASP and ADO (assumes knowledge of ADO)

Token Payment Web Services

Using Windows Azure Mobile Services to Cloud-Enable your Windows Store Apps in C#

Windows Presentation Foundation (WPF) User Interfaces

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

Interaction Tracker Interaction Segments

Sample CSE8A midterm Multiple Choice (circle one)

Async startup WPF Application

BACKING UP A DATABASE

Filtered Views for Microsoft Dynamics CRM

NSPK Protocol Security Model Checking System Builder

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Qualtrics Single Sign-On Specification

Election 2012: Real- Time Monitoring of Election Results

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

The Fast Fourier Transform

SharePoint Integration

Getting Started with IVI Drivers

Fast JavaScript in V8. The V8 JavaScript Engine. ...well almost all boats. Never use with. Never use with part 2.

Important New Concepts in WPF

ADF Code Corner. 92. Caching ADF Web Service results for in-memory filtering. Abstract: twitter.com/adfcodecorner

Cello How-To Guide. Securing Data Access

Data Management Applications with Drupal as Your Framework

ComponentOne. Windows for WPF

T300 Acumatica Customization Platform

2. Modify default.aspx and about.aspx. Add some information about the web site.

Transcription:

Chapter 14 WCF Client WPF Implementation Screen Layout

Window1.xaml <Window x:class="chap14wcfclient.window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vc="clrnamespace:wpfcommonlib.valueconverters;assembly=wpfcommonlib" Title="Window1" Height="376" Width="496" Loaded="Window_Loaded"> <Window.Resources> <vc:currencyconverter x:key="currencyconverter"/> </Window.Resources> <Grid x:name="gridmain"> <StackPanel Name="stackPanel1" Height="27" VerticalAlignment="Top" Orientation="Horizontal"> <Label Height="28" Name="label1" Width="70">Customers:</Label> <ComboBox Name="_comboBoxCustomers" DisplayMemberPath="Name" SelectedValuePath="ContactID" Height="23" Width="151" SelectionChanged="_comboBoxCustomers_SelectionChanged" /> <TextBlock Height="28" Name="textBlock1" Width="74" /> <Button Height="23" Name="_buttonSave" Width="75" HorizontalAlignment="Right" Click="_buttonSave_Click">Save</Button> <StackPanel Margin="0,27,0,0" Name="stackPanel2" HorizontalAlignment="Left" Width="154" Height="125" VerticalAlignment="Top"> <Label Height="25" Name="label2" Width="154">Title:</Label> <Label Height="25" Name="label3" Width="156">FirstName:</Label> <Label Height="25" Name="label4" Width="156">LastName:</Label> <Label Height="25" Name="label5" Width="156">Notes:</Label> <Label Height="25" Name="label6" Width="156">Initial Date:</Label> <StackPanel Margin="154,27,0,0" Name="stackPanel3" Height="125" VerticalAlignment="Top" HorizontalAlignment="Left" Width="217"> <TextBox Height="25" Name="_textBoxTitle" Text="Binding Path=Title" Width="215" /> <TextBox Height="25" Name="_textBoxFirstName" Text="Binding Path=FirstName" Width="215" /> <TextBox Height="25" Name="_textBoxLastName" Text="Binding Path=LastName" Width="217" /> <TextBox Height="25" Name="_textBoxNotes" Text ="Binding Path=Notes" Width="215" /> <TextBox Height="25" Name="_textBoxInitialDate" Text="Binding Path=InitialDate, StringFormat=dd/MM/yyyy" Width="215" /> <StackPanel Margin="370,0,-1,186" Name="stackPanel4" Height="125" VerticalAlignment="Bottom"> <Button Height="23" Name="_newCustomer" Width="90" VerticalAlignment="Center" Click="_newCustomer_Click">New Customer</Button> <StackPanel Margin="0,152,0,0" Name="stackPanel5" Orientation="Horizontal" VerticalAlignment="Top"> <Label Height="102" Name="label7" Width="79" HorizontalAlignment="Left">Reservations:</Label> <ListBox Height="107" Name="_listBoxReservations" Width="208"> <ListBox.ItemTemplate>

<DataTemplate> <Border BorderThickness="2" CornerRadius="4" BorderBrush="Red"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> </Grid.RowDefinitions> <TextBlock Grid.ColumnSpan="2" FontWeight="Bold" Foreground="Blue" Text="Binding Path=ReservationDate, StringFormat=dd/MM/yyyy"/> <TextBlock Grid.Row="1" FontWeight="Bold" Text="StartDate :"/> <TextBlock Grid.Row="1" Grid.Column="1" Text="Binding Path=Trip.StartDate, StringFormat=dd/MM/yyyy"/> <TextBlock Grid.Row="2" FontWeight="Bold" Text="EndDate :"/> <TextBlock Grid.Row="2" Grid.Column="1" Text="Binding Path=Trip.EndDate, StringFormat=dd/MM/yyyy"/> <TextBlock Grid.Row="3" FontWeight="Bold" Text="Destination :"/> <TextBlock Grid.Row="3" Grid.Column="1" Text="Binding Path=Trip.Destination.DestinationName"/> </Grid> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <ComboBox Height="23" Name="_comboBoxTrips" Width="185" VerticalAlignment="Top" StaysOpenOnEdit="True"> <ComboBox.ItemTemplate> <DataTemplate> <Border BorderThickness="2" CornerRadius="4" BorderBrush="Blue" Width="200"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> </Grid.RowDefinitions>

<TextBlock FontWeight="Bold" Text="Destination: "/> <TextBlock Grid.Column="1" Text="Binding Path=Destination.DestinationName"/> <TextBlock Grid.Row="1" Text="StartDate: "/> <TextBlock Grid.Row="1" Grid.Column="1" Text="Binding Path=StartDate, StringFormat=dd/MM/yyyy "/> <TextBlock Grid.Row="2" Text="EndDate: "/> <TextBlock Grid.Row="2" Grid.Column="1" Text="Binding Path=EndDate, StringFormat=dd/MM/yyyy "/> <TextBlock Grid.Row="3" Text="Trip Cost: "/> <TextBlock Grid.Row="3" Grid.Column="1" Text="Binding Path=TripCostUSD, Converter=StaticResource CurrencyConverter"/> </Grid> </Border> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> <Button Height="23" HorizontalAlignment="Left" Margin="4,0,0,39" Name="_buttonAddReservation" VerticalAlignment="Bottom" Width="113" Click="_buttonAddReservation_Click">Add Reservation</Button> <Button Height="23" Margin="117,0,179,39" Name="_buttonDeleteReservation" VerticalAlignment="Bottom" Click="_buttonDeleteReservation_Click">Delete Selected Reservation</Button> </Grid> </Window> Window1.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Chap14WcfClient.BAWCFService; using WpfCommonLib.ValueConverters; namespace Chap14WcfClient /// <summary> /// Project : Programming Entity Framework (Julia Lerman) /// Author : Emmanuel Nuyttens /// Purpose : Errata on Chapter 14 - WPF Implementation. /// </summary> public partial class Window1 : Window

List<int> _resdeletelist; Customer _currentcustomer; public Window1() InitializeComponent(); private void Window_Loaded(object sender, RoutedEventArgs e) FillCombo(); private void FillCombo() var custtrips = GetCustsAndTrips(); this._comboboxcustomers.itemssource = custtrips.custs; this._comboboxtrips.itemssource = custtrips.trips; private void _comboboxcustomers_selectionchanged(object sender, SelectionChangedEventArgs e) if (_comboboxcustomers.selectedindex > -1 && _comboboxcustomers.selectedvalue!= null) _currentcustomer = GetCustomer((Int32)_comboBoxCustomers.SelectedValue); if (_currentcustomer!= null) this.datacontext = _currentcustomer; _resdeletelist = new List<int>(); this.showreservations(); private void ShowReservations() _listboxreservations.itemssource = null; if (_currentcustomer.reservations.count > 0) _listboxreservations.itemssource = _currentcustomer.reservations; private void _newcustomer_click(object sender, RoutedEventArgs e) _currentcustomer = new Customer(); _currentcustomer.timestamp = System.Text.Encoding.Default.GetBytes("0x123");

_currentcustomer.timestamp1 = System.Text.Encoding.Default.GetBytes("0x123"); _currentcustomer.reservations = new List<Reservation>(); this.datacontext = _currentcustomer; _resdeletelist = new List<int>(); ShowReservations(); private void _buttonaddreservation_click(object sender, RoutedEventArgs e) var seltrip = (Trip)_comboBoxTrips.SelectedItem; if (seltrip!= null) Reservation newres = new Reservation(); // get the trip + location newres.trip = seltrip; newres.tripdetails = seltrip.tripdetails; newres.reservationdate = System.DateTime.Now; newres.timestamp = System.Text.Encoding.Default.GetBytes("0x123"); _currentcustomer.reservations.add(newres); // Refresh the ListBox of the Reservations ShowReservations(); private void _buttondeletereservation_click(object sender, RoutedEventArgs e) if (_listboxreservations.selectedindex >= 0) // Add reservationid to the deletedlist Int32 id = (_listboxreservations.selecteditem as Reservation).ReservationID; _resdeletelist.add(id); // Find the reservation in the customer's reservations Reservation delres = _currentcustomer.reservations.where(r => r.reservationid == id).firstordefault(); if (delres!= null) _currentcustomer.reservations.remove(delres); ShowReservations(); private void _buttonsave_click(object sender, RoutedEventArgs e) var status = UpdateCustomer(); // in case of insert customer, new id of customer is returned if (string.isnullorempty(status) == false) // did the update return an id?

int newid = 0; if (int.tryparse(status, out newid)) _currentcustomer.contactid = newid; FillCombo(); _comboboxcustomers.selectedvalue = newid; #region WCF Service Related Data Loader and Data Persistance Methods private CustsandTrips GetCustsAndTrips() using (CustomerServiceClient proxy = new CustomerServiceClient()) return proxy.getcustsandtrips(); private Customer GetCustomer(int p_customerid) using (CustomerServiceClient proxy = new CustomerServiceClient()) return proxy.getcustomer(p_customerid); private string UpdateCustomer() string status = null; using (CustomerServiceClient proxy = new CustomerServiceClient()) if (_currentcustomer.contactid == 0) status = proxy.insertcustomer(_currentcustomer); else CusttoEdit custedit = new CusttoEdit(); custedit.customer = _currentcustomer; custedit.reservationstodelete = _resdeletelist; status = proxy.updatecustomer(custedit); return status; #endregion

CurrencyConverter using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Data; using System.Globalization; namespace WpfCommonLib.ValueConverters [ValueConversion(typeof(decimal),typeof(string))] public class CurrencyConverter : IValueConverter #region IValueConverter Members public object Convert(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) if (value!= null && value.tostring()!= string.empty) decimal money = Decimal.Parse(value.ToString()); return money.tostring("c",culture); return null; public object ConvertBack(object value, Type targettype, object parameter, System.Globalization.CultureInfo culture) string money = value.tostring(); decimal result; result)) if (Decimal.TryParse(money, NumberStyles.Any, null, out return result; return value; #endregion