.NET
  Home arrow .NET arrow Page 4 - The Basics
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

The Basics
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 19
    2005-04-06

    Table of Contents:
  • The Basics
  • Modeling a Logon Process
  • Coding Conventions
  • Generating the VB .NET Code for the Logon Class
  • Generating the C# Code for the Logon Class
  • ER and ORM Diagrams
  • Generating the Database
  • Reverse Engineering a Database

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Basics - Generating the VB .NET Code for the Logon Class


    (Page 4 of 8 )

    Now that you’ve created the skeleton model for the Logon class, it’s time to see the actual code that VEA generates from the model, which is what it’s ultimately all about—generating and maintaining the code for your application. Exercise 1-5 shows how to generate the VB .NET code.

    EXERCISE 1-5

    1. Select the Logon class.

    2. Select UML -> Code -> Generate. This brings up the Generate dialog box.

    3. Make sure Visual Basic is selected in the Target language list.

    4. Select the Logon class in the Select classes for code generation tree view.

    5. Select the location you want the generated output placed in by typing the path in the Location text box or by browsing to the location after clicking the Browse button. Save the output with this name and path for easy access in later exercises: \EDWVSNETUMLMSF\Chapter 01\VB .NET\ TopPackage\Logon.vb. The Generate dialog box should now look like Figure 1-6. Note that when you select the VB .NET folder, VEA assumes the Top Package folder underneath it.


    Figure 1-6.  The Generate dialog box

       6.  Click OK. You might be prompted to create a nonexistent folder.
            If so, click Yes.


    NOTE The Top Package subfolder comes from the Model Explorer, which is usually shown on the left side of the Visio workspace, as you can see in Figure 1-7. We won’t be covering packages now, but a UML package in VEA resembles a namespace in .NET (that is, a logical grouping).

    In Figure 1-6, you can see the code-generation options for the Logon class in the Generate dialog box. Once you click OK in the Generate dialog box, the code is generated and output to the specified location. The Output window shows if any errors were encountered during the code generation.


    In Figure 1-7, you can see the Top Package UML package selected in the Model Explorer. You can give your package any name by double-clicking the package. This will bring up the UML Package Properties dialog box.


    Figure 1-7.  The Model Explorer with Top Package selected

    Figure 1-8 shows the Output window after the VB .NET code is generated for the Logon class. In our case, there weren’t any semantic errors.


    Figure 1-8.  The Output window showing semantic errors after code generation


    NOTE Semantic errors are programmatic errors such as incompatible data types. If you pick a data type as the return type for an operation that’s not supported in the target programming language, you’ll see a semantic error in the Output window.

    Now let’s take a look at the generated code. Go to the output location you specified in the Generate dialog box and double-click the Logon.vb file. If your VS .NET installation is working properly, and you haven’t specified that VS .NET should open the last loaded solution when opening,3 the code file is opened in the VS .NET IDE, and it should look similar to the one shown in Figure 1-9.


    Figure 1-9.  The generated VB .NET code for the Logon class

    Figure 1-9 shows the generated output for the Logon class from the UML model as VB .NET code. If you’re familiar with VB .NET or even VB, there shouldn’t be any surprises in the generated code. However, we’ll just run through the code listing, pointing out what the various code lines correspond to in the UML model:

    • Lines 4 and 15 define the class boundary.

    • Lines 6 and 8 are the two class attributes or member variables.

    • Lines 10 through 13 are the Logon procedure, declared as a Function, because you specified a return type (Boolean). The two input parameters have been declared with ByVal, which effectively means they’re input parameters, because changes to the values of a parameter declared with ByVal won’t be reflected in the caller of the operation.


    TIP To turn on line numbers in Visual Studio, select Tools -> Options - 
    > Text Editor/Basic and check the Line Numbers option.

    We’re aware this isn’t a lot of code, and that for such a small class it would be easier to create it the normal way. However, many useful applications do start out as small, simple, and unplanned applications, don’t they?

    Creating the C# Class

    You’ve created the VB .NET class, and since the content of the C# class is the same, you need to change only a few things in the class model. The differences are the data types you used for the attributes and the operation and the target programming language. Exercise 1-6 demonstrates how to change from VB .NET to C#.

    EXERCISE 1-6

    1. Open the previously saved Logon.vsd UML model in VEA (if it isn’t already open).

    2. Open the UML Class Properties dialog box for the Logon class.

    3. Select the Code Generation Options category from the Categories list.

    4. Select C# from the Target language list.

       5.  Click OK.


    Now you’ve changed the target programming language, but didn’t we just state that you need to change the data types for the new target programming language? Yes, we did. However, the data types chosen for the VB .NET class were common type system (CTS) compatible, meaning they exist in all .NET programming languages. Well, this isn’t quite true, but for data exchange between classes in different .NET languages to work, the exposed data types must be CTS compatible. You used the Boolean and String VB .NET data types, and they certainly have counterparts in C#. Generally, you won’t find a problem when going from VB .NET to C#. A problem is more likely to arise when you go in the other direction—if you select an unsigned data type in C# and want the corresponding data type in VB .NET. VB .NET doesn’t directly handle unsigned data types;4 therefore, VEA won’t be able to convert those data types for you.

    If you feel confident that you can generate the C# code for the Logon class now, feel free to jump to the next section. However, for the purpose of having two different models saved in different locations and with the correct data types, follow along with Exercise 1-7.

    EXERCISE 1-7

    1. Open the UML Class Properties dialog box for the Logon class.

    2. Select the Attributes category from the Categories list.

    3. Select C#::string from the Type list for the m_userID and m_password attributes.

    4. Select the Operations category from the Categories list.

    5. Select C#::bool from the Return Type list for the Logon operation.

    6. Click the Properties button while the Logon operation is selected to show the UML Operations dialog box.

    7. Select the Parameters category from the Categories list.

    8. Select C#::string from the Type list for the userID and password parameters.

       9.  Click OK twice.


    The changes you’ve made to the Logon class should now be reflected on the diagram. Save the new model to this name and path for easy access in later exercises and chapters: \EDWVSNETUMLMSF\Chapter 01\C#\Logon.vsd.

    This article is excerpted from Enterprise Development with Visual Studio .NET, UML, and MSF by John Erik Hansen and Carsten Thomsen (Apress, 2004; ISBN 1590590422). Check it out at your favorite bookstore today. Buy this book now.

    More .NET Articles
    More By Apress Publishing


     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT