The Baker’s Dozen: 13 Productivity Tips for Moving from VFP to .NET When Visual FoxPro developers take the plunge to learn .NET, the most common reaction is, “I could do such-and-such, this-and-that in VFP-how can I do it in .NET?” This special edition of The Baker’s Dozen will offer solutions for many of the typical challenges that VFP developers face when tackling .NET. I’ll start by covering .NET solution and project structures and an overview of the .NET Framework, and I’ll spend time showing how to use .NET reflection to do some of the things that VFP developers could accomplish with macro-expansion. Then I’ll cover different .NET features such as Generics, ASP.NET 2.0, and I’ll show how to create a reusable data access component. Finally, I’ll build the architecture for a set of reusable data maintenance classes in .NET. Beginning with the End in Mind I have the same goal in writing this article that I have in my Baker’s Dozen articles in CoDe Magazine: I’ll write a set of how-to tips that I would love to have read when I set out to learn a new technology or feature. I started developing software in 1987 and can honestly say that the transition from VFP to .NET was the most challenging (and also rewarding) endeavor of my career. | " | There is no one simple answer to the question of a .NET equivalent to VFP’s macro-but fortunately, the .NET Framework has a namespace called System.Reflection that provides developers with functions for run-time discovery.
| " |
In this article, I’ll cover the following: - Understanding .NET projects, solutions, and assemblies, and a quick language primer
- A quick tour through the common .NET Framework classes
- How to use reflection in place of the VFP macro
- Building a .NET data access class
- .NET Generics and anonymous methods in C#
- Some powerful features in ASP.NET 2.0 and AJAX
- The Baker’s Dozen Spotlight: building a reusable data maintenance form class (this covers the next four tips)
- Subclassing Windows Forms controls and implementing reusable data binding
- Building a data maintenance criteria container (UserControl)
- Building a data maintenance results container (UserControl)
- Building a data maintenance entry/edit container (UserControl)
- Working with data in DataSets using ADO.NET
At the end of this article, I’ll include a list of books, articles, and other resources that I recommend for further research. Watching My Language I wrote the example code in this article in C#. I prefer C# because I previously wrote C and C++. In most instances, developers can take the code in this article and port it to Visual Basic. However, Tip 5 contains code that uses anonymous methods, a new C# language feature with that doesn’t have a Visual Basic equivalent though it will be available in the next version. For that situation I’ll provide a workaround that works today. Less Talk, More Code I set a goal for this article to be short on talk and long on code. When I began the .NET learning curve, I got the most value out of books and articles that contained meaningful code samples. So for each tip, as much as possible, I’ll minimize the yakking and focus on the hacking. (There was a time when hacker meant something complimentary!) Tip 1: Understanding .NET Solutions, Projects, Assemblies, and References Let’s start by looking at the solution and project structure in Visual Studio 2005 for an actual .NET application. Figure 1 shows the complete solution for a demo .NET database application. A .NET solution is a collection of .NET projects. The .NET solution in Figure 1 consists of the following:  Figure 1: Solution structure.- Two solution folders, one for a framework of reusable classes (Common Ground Framework), and one for an actual demo application (Construction Demo).
- Subfolders to further categorize projects within a main folder.
- Under each solution you’ll see a series of .NET projects. Each project contains one or more related class files that compile to a single separate DLL. For instance, the project CGS.DataAccess contains a class file for basic data access functionality. The project compiles to CGS.DataAccess.DLL and can be used from other .NET projects.
- In addition, the project ConstructionDemo.Client.Winforms (in the folder structure Construction Demo…Client…Winforms) appears in bold, because I’ve defined it as the startup project. When I build this project, Visual Studio 2005 will create an executable file.
Many classes will refer to functions in base libraries, and will also inherit from previous classes in other .NET projects. In these situations, it is necessary to set add a reference to parent libraries. You can right-click on a project and select Add Reference from the short-cut menu (Figure 2).  Figure 2: Solution project options.In many instances you need to tell Visual Studio 2005 that some projects depend on others. You can also use the same short-cut menu (Figure 2) to establish project dependencies. For instance, project X may depend on projects A, B, and C. Figure 3 allows you to set the dependencies for any project in the solution.  Figure 3: Project dependencies. | & | | 
By: Kevin S Goff
Kevin S. Goff, a Microsoft MVP award recipient for 2007, is the founder and principal consultant of Common Ground Solutions, a consulting group that provides custom Web and desktop software solutions in .NET, VFP, SQL Server, and Crystal Reports. Kevin is the author of Pro VS 2005 Reporting using SQL Server and Crystal Reports, published by Apress. Kevin has been building software applications since 1988. He has received several awards from the U.S. Department of Agriculture for systems automation. He has also received special citations from Fortune 500 Companies for solutions that yielded six-figure returns on investment. He has worked in such industries as insurance, accounting, public health, real estate, publishing, advertising, manufacturing, finance, consumer packaged goods, and trade promotion. In addition, Kevin provides many forms of custom training. Contact Kevin at kgoff@commongroundsolutions.net
kgoff@commongroundsolutions.net | Fast Facts | | This article contains a number of .NET/C# code samples to show VFP developers how to do common tasks in .NET. | |
|