.NET Compact Framework 3.5 Data-Driven Applications Build robust and feature-rich mobile data-driven applications with the help of real-world examples Edmund Tan BIRMINGHAM - MUMBAI .NET Compact Framework 3.5 Data-Driven Applications Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2010 Production Reference: 1220410 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849690-10-2 www.packtpub.com Cover Image by Vinayak Chittar ([email protected]) [ FM- 2 ] Credits Author Editorial Team Leader Edmund Tan Gagandeep Singh Reviewer Project Team Leader Greg Yap Lata Basantani Acquisition Editor Project Coordinator David Barnes Srimoyee Ghoshal Development Editor Proofreader Rakesh Shejwal Sandra Hopper Technical Editors Graphics Neha Damle Geetanjali Sawant Rukhsana Khambatta Production Coordinator Shantanu Zagade Copy Editor Sanchari Mukherjee Cover Work Shantanu Zagade Indexer Monica Ajmera Mehta [ FM-3 ] About the Author Edmund Tan is the CTO and co-founder of a leading e-forms and workflow solution vendor based in Singapore. He holds more than eight years of experience building performance-critical .NET e-forms and workflow solutions for smart devices on top of Oracle and Microsoft SQL Server databases for large companies and governmental institutions located in Singapore and Malaysia. Edmund is also a regular public speaker at various conferences held in Singapore and Malaysia on the topic of on-the-go BPM (Business Process Management) hosted on smart device technologies. During his free time, Edmund works on trying to create machines capable of emulating human thought. My first and heartfelt word of thanks goes out to David Barnes without whom this book would not have been possible at all. I also thank James Lumsden for giving my e-mail a chance, Rakesh Shejwal and Greg, my long-time collaborator, for their always insightful edits, Srimoyee Ghoshal for keeping me on schedule, Lata Basantani, as well as everyone else involved in this book at Packt. I extend my gratitude to my parents, Laumee and Obagi, for their undying love and support, my aunt Laumar for instilling the bookworm in me, my wife Shen for keeping the beverages flowing, my kid Sophie simply for being the pride of my life, and, last but not least, my brother Edwin for his jokes during the really, really late hours of the night. [ FM- 4 ] About the Reviewer Greg Yap is a tech-savvy person who's always interested in the latest technology. He has worked on .NET since its first release. He has experience in developing software for small, medium, and enterprise-sized companies around the world and has worked on Microsoft technologies for a variety of platforms including the .NET Compact Framework. He is also well versed in the C# and VB.NET programming languages. I would like to thank my family, especially my understanding wife Jennie who's given me all the support and time I needed to review this great book. To my two kids—thank you! I'm glad that both of you have shown the patience I knew you would. My thanks also go out to my friend Edmund for having considered me as the technical reviewer for this book—I owe you a coffee! Last but not the least, I would like to thank Srimoyee Ghoshal for always being there to keep me on time and the remaining Packt Publishing team for giving me the opportunity to review this book. [ FM-5 ] Table of Contents Preface 1 Chapter 1: CRMLive.NET: An Overview 9 Tomorrow Inc. 10 The mobile sales force application 10 The mobile dashboard application 11 The mobile support case application 12 Data flow in CRMLive.NET 12 Deciding on the type of mobile application 13 Thin clients 13 Thick clients 14 Smart clients 14 Messaging 15 A brief summary 15 Defining the mobile sales force application 16 Capturing lead, opportunity, and customer information 17 Mobile screen design 18 Creating reusable controls 19 Maintaining global lists 19 Data retrieval and manipulation on the mobile device 20 Data transfer between multiple mobile devices 20 Task management 20 Full-text search functionality 21 Integrating with Windows Mobile and the hardware 22 Detect incoming phone calls and SMS 23 Integrating with the Windows Mobile Calendar and Contacts book 23 Data exchange using Bluetooth and IrDA 24 Capturing handwritten input 24 Data synchronization 25 Dual database support 25 Application maintenance and upgrades 25 Table of Contents Defining the mobile dashboard application 25 Using stateless web services as a data source 26 Rendering the dashboard 27 Road show revenue 27 Total monthly sales 28 Sales for last three months 28 Defining the mobile support case application 28 Building a messaging backbone with MSMQ 29 Summary 30 Chapter 2: Building the Data Tier 31 Designing the data tier 31 SQL Server CE 3.5 versus Oracle Lite 10g 32 Connecting the Windows Mobile emulator to ActiveSync 33 Setting up SQL Server Compact 3.5 35 Installing SQL Server CE on the development machine 35 Installing SQL Server CE on the Pocket PC device. 36 Setting up Oracle Lite 10g 37 Installing Oracle Lite 10g on the development machine 37 Installing Oracle Lite 10g on the Pocket PC device 38 Building the data tier 38 Building the CRMLiveFramework project 39 Defining the IDataLibPlugin interface 40 Building the Plugin Manager UI 43 An overview 44 Implementing the PluginCollection class 46 Implementing the PluginManager class 46 Creating the SalesForceApp project 50 Building the ConfigurePlugin form 50 Building the PluginsSetup form 54 Testing what you've built so far 58 Building the database plugins 59 Implementing the SQL Server CE Plugin 60 Storing DDL in the resource file 60 Building the plugin class 63 Connecting to SQL Server CE 64 Programmatically creating the SQL Server CE database 65 Testing what you've done so far 67 Browsing the SQL Server CE database with Query Analyzer 68 Retrieving data from SQL Server CE 70 Data manipulation in SQL Server CE 71 Dealing with GUID values in SQL Server CE 74 Implementing the Oracle Lite plugin 75 Storing DDL in the resource file 75 [ ii ] Table of Contents Building the plugin class 77 Connecting to Oracle Lite 77 Programmatically creating the Oracle Lite database 78 Browsing the Oracle Lite database with Msql 80 Retrieving data from Oracle Lite 81 Data manipulation in Oracle Lite 81 Dealing with GUID values in Oracle Lite 84 Summary 85 Chapter 3: Building the Mobile Sales Force Module 87 A brief walkthrough of what you will be building 88 Building a form navigation class 94 Building the main menu 96 Using Main() as the startup object 98 Creating the business objects to encapsulate your DataSets 100 Validating data in your business objects 108 Building the AccountViewer form 109 Data binding .NET controls to your business objects 111 Launching the AccountViewer form 111 Testing the AccountViewer form 114 Building the Tasks list 114 Populating the Tasks Datagrid control 115 Building the TaskDetailViewer form 116 Launching the TaskDetailViewer form 119 Testing the tasks list 120 Handling file attachments 120 Building a file manager class 121 Building the FileUpload user control 123 Building the FileDetailViewer form 126 Testing file upload functionality 128 Custom formatting and display in list controls 129 Building a collection sorter using the IComparer interface 130 Custom formatting and display in the list control 131 Using the History list control 135 Testing the History list control 136 Building the ProductList control 136 Using XML DOM to store and retrieve product selection 139 Using the ProductList control 141 Testing the ProductList control 142 Building a paged listing of accounts 142 Paging in SQL Server CE 143 Paging in Oracle Lite 146 [ iii ]