Using the .Net Framework and Visual Studio .Net

I just completed the first full iteration of development on a project that I decided to implement using Microsoft’s .Net Platform. I designed it using an N-tier approach to see what advantages there are in using .Net as compared to Visual Basic 6. The application is a fairly straightforward client/server type application. It accesses a SQL Server database and uses the new Windows forms that are part of the .Net framework as its presentation tier. (These are visually the equivalent of VB 6 forms).

The application is spread out over 4 tiers.

  1. SQL Server Database
    This contains the actual data and all Stored Procedures, Triggers and Views that retrieve and update the data.
  2. A Windows Service that is running on another server.
    This service contains the DLL that actually performs all of the calls to the database and contains the classes for each type of object that the application uses. All database calls are performed using ADO.Net
  3. A Client side DLL.
    This DLL contains Client-side versions of the classes that the server contains. I pass these back and forth between the Client/Server. This DLL loads the data into the Windows forms with which the users interact.
  4. Windows Forms (.EXE)
    The actual User Interface of the application.

What I Learned

Building an application using Visual Studio .Net is a little different than Visual Studio 6, but if you’ve ever used Visual Interdev then it won’t take long to become accustomed to using Visual Studio. I decided to use VB.Net as the language of choice for this project. I could have used C# but the IDE is far superior in VB than it is for C#, so for now I choose VB.Net (although I do use components that are written in C# in this project).

VB.Net is now completely Object Oriented so the power of the language is much greater in .Net than in previous versions of Visual Basic. I can now do things using VB that previously would have required me to use Visual C++ to implement. VB.Net gives you true inheritance, which allows a developer to reuse and extend existing objects, saving a great amount of time coding the same types of objects over and over again. After I coded all of my Server side objects, I simply created the Client side versions using “Inherits” in the definition. Presto, I automatically had full access to all of the attributes and methods of the parent class.

The new Windows forms package is vastly different than the forms package that comes with Visual Studio 6. I have some O/O background from using Java, so the new syntax of VB.net and C# is no problem for me; however, the Windows forms package took me a bit of time to get used to. Here’s why. Everything in .Net is now an object, and therefore must be treated as such. A Windows form in VB 6 was not really considered an object, because the developer was blocked (shielded) from the underlying mechanisms of what was occurring inside of the form. In .Net, you are completely exposed to the form object, (it’s just another type of object) so there is endless customization and control exposed to the developer. The result - more power, but more responsibility…and more to learn.

The application I designed consists of 5 main forms

  1. A splash screen
  2. The main form of the application
  3. A secondary form for detail data
  4. A search form
  5. Crystal reports

When the application launches, I display the splash screen in its own thread, allowing the main form to load its data in the background. I do this using a Delegate, which is a new type of function call in .Net, similar to a Function pointer in C++. Try doing that in VB 6! So right off the bat I have real multithreading available to me. I implemented owner-drawn menus and toolbars for my forms (I created classes that extend the existing object types in the .Net framework and I then overrode the paint functions to meet my needs). Here I wanted to implement the XP style and look for the menus and the tool bar and that look doesn’t come right out of the box with Visual Studio .Net. In VB 6 I would have had to purchase a 3rd party implementation of these controls (Sheridan, Infragistics etc.) in order to accomplish this look. Now I can do it myself. There are also plenty of free examples on the internet of how to do this, which is where I acquired the original version of the classes that I am currently using. These components are mostly written in C#.

I also decided that I wanted to color code certain columns in my grids and add icons to certain columns, all using conditional logic. Once again I wrote my own classes that extended the existing column types and overrode the methods that I needed to change. This is not possible to do in VB 6. Again, I would have had to look to 3rd party components to accomplish this. A great advantage of this is that it’s completely reusable, so I can drop these menus, toolbars, or grid columns into any new project and I’m ready to go. Initially, it involves more work, but once complete you don’t have to do it again.

The main form was loaded and I decided to use a Dataset to house my data. This is new in .Net and is part of the ADO.Net package. A Dataset is basically an XML representation of data. It may contain multiple data tables, which may be joined by data relations. I filled my dataset with two data tables: a master table and a details table. I then bound the dataset to the controls on the form. In the past, data binding was frowned upon, since you needed to go through a data control that kept a constant open connection to your database, but now you can bind to a dataset and the dataset is completely cut off from its data source. It’s a disconnected model that takes some time to get used to, but once you do, you quickly see its advantages.

When data needs to be updated I send an instance of an object from my client side DLL to the server side DLL that resides in my Windows service. I accomplish this using the new .Net Remoting, which is the successor to DCOM. Web services are always in the forefront, but now Remoting is beginning to show its importance. I used TCP connections and a binary format for my objects. I serialized the object in the client side DLL and sent it to my Windows Service. There I de-serialized it back into its object type and passed its properties into parameters that I fed to a stored procedure that updates the database. The .Net framework makes all of this very easy as compared to VB 6. Prior to .Net, if I wanted to implement this type of distributed computing on a network I would have had to use MTS to house the Server side DLL. There is a learning curve that goes with it as well as a different way to write your objects that needs to be implemented in order for MTS to even work. I would have also had to write all of my own code to handle the Serialization issues for moving my objects between tiers. The .Net framework handles all of this for you. Mark a class with the attribute and send it through an object that is marked as inheriting “MarshalByObjectRef” and the framework does the work for you.

Next we move onto the issue of the Windows Service. Prior to .Net, I would have had to use Visual C++ to create a Windows service, but now it’s an included project type in Visual Studio .Net. There is a little work to get a Windows service up and running but it is trivial compared to doing it with C++.

Adding Crystal reports to my project was also a breeze. Crystal is now integrated into Visual Studio .Net so adding report capabilities is very easy.

In Summary

There is a learning curve to this as there would be with any development environment, but if you have any O/O background you should be able to get up and running fairly quickly. Developers who are primarily “scripters” will experience more difficulty changing the way they build applications.

Up front Design is now imperative! To properly design and code an object-oriented application, a design model is a must!

The Microsoft News groups saved me. The online documentation and the available books are high level. However, when you need specific advanced functionality you do need to dig deep to find it. This will change as the platform matures and the publishers have had some time to get some of these specific functionality books to market.

I now have full access to functionality that previously was only for the C++ programmers.

The .Net framework integrates very closely with the underlying Windows operating system, allowing the developer easy access to functionality that wasn’t always easy to implement (For example, logging entries to the Windows Event Log). Binary Encoding - need it? .Net has classes that will do this for you, it’s no longer necessary to write a lot of the plumbing code that you needed to write in VB 6 to implement or access functionality that is part of the Windows operating system. No more registering DLL’s - the XCopy functionality of .Net really works. For example, you now have the ability to copy a folder with an executable and any needed DLLs to function. All that is necessary is to copy that folder to your machine, make a shortcut to the .exe on your desktop and double click. As long as you have the .Net Framework installed on your machine, you are all set. If you need to change a DLL on your IIS Server, you may copy the new version over the old one; there is no need to shut down IIS any more just let it run. The .Net Framework will handle it for you!

The .Net framework now gives the developer more power, flexibility and ease of developing applications, and choices for implementing the actual applications when ready to deploy.