|
Home > Products > AspxFormsGen 2.0 > Tutorial > Professional Edition
AspxFormsGen Professional Tutorial
AspxFormsGen Professional Edition
- Let's us familiarize our self with the AdventureWorks Database. Open MS SQL Server 2005 Management Studio.
- Expand the databases node
-
Make sure you have the AdventureWorks database (figure 1.)
 (Figure 1)
-
Expand the Table node, notice that you have about 70 user tables (figure 2).
 (Figure 2)
- Note: The webforms that will be generated by AspxFormsGen will be based from these tables.
-
Now let's open the AspxFormsGen Application (figure 3). (Note that you don't need MS SQL Server 2005 Management Studio open to operate AspxFormsGen)
 (Figure 3 )
-
The first four textboxes (Server, Database, Username, Password) are needed to connect to the database. Here's a more detailed explanation:
- Server: The name of the server where your MS SQl Server 2005 is installed. For most parts, if your Database is installed locally (this is our recommendation for this tutorial), the server name would be localhost.
- Database: The name of the database that you want to make ASP.Net 2.0 webforms for, e.g. Northwind, Pubs, AdventureWorks.
- Username: The username for the database that you're trying to access. Note: For this tutorial, you need a username that has "sysadmin" priviledges in the database.
- Password: The password pair of the username above.
- Directory: This is the directory in your computer where the generated webforms will be written to. If the directory you specify does not exist, a folder for that directory will be created. If the directory you specify has files that have the same names as the files that will be created, your files will be overwritten without notice. Note: Make sure that you have "write" permissions to this directory.
- Language: The language where your webforms will be generated in. You have 2 options, C# 2.0 or VB.Net 2.0 (Visual Basic 8.0).
- Create Stored Procedures: When checked, generates Select, Insert, Update, and Delete stored procedures in the database. These stored procedures are automatically used as data sources for the generated data bound controls. When not checked, Ad Hoc SQL is generated in the web forms as data sources. Note: Generated stored procedures will overwrite existing stored procedures that has the same name, so make sure to use a stored procedure prefix that is different from the one that you're using now.
- Stored Proc Prefix: This is the prefix that is used when naming the generated stored procedures. E.g. "aspx_" will create as stored procedured named "aspx_StoredProcedureName". Note: We recommend that you use a prefix that is readily recognizable to you as one generated by AspxFormsGen.
- GridView Style: Generates a simple theme for the generated web forms based on the selected style. There are 8 styles to choose from.
- Fill out the Server. Since my server is local, "localhost" will do just fine.
- Fill out the Database name. Type "AdventureWorks".
- Fill out the Username. Use a user that has sysadmin rights. (Note: In figure 4 I'm using a user named "adventureworks" because I created a user in my local MS SQL Server 2005 named adventureworks). If you have an "sa" user then type this in.
- Fill out the Password. (Note: In figure 4, when I created a user in MS SQL Server 2005 named adventureworks, I assigned it a password "adventureworks"). If you're using the "sa" user, the password is probably blank.
- Used the default "C:\AspxFormsGen" as the Directory.
- Choose a Language. For this tutorial we're going to use VB (Short for Visual Basic 8.0).
- Leave the Create Stored Procedure checked.
- Leave the Stored Proc Prefix as is (_aspx).
-
Click Submit. AspxFormsGen will start generating the files and stored procedures (figure 4).
 (Figure 4)
-
Once webforms and stored procedures generation is complete, a message box will appear (figure 5). Click Ok. Then close AspxFormsGen by clicking the close button.
 (Figure 5)
-
Now go to the C:\AspxFormsGen directory. Notice that you have 845 objects in this directory (figure 6a). About
half of these objects are ASP.Net 2.0 Webforms (.aspx), and the other half are the respective
code files (.aspx.cs or .aspx.vb). A Web.Config file, a Theme folder, including a Stylesheet, and skin
files were generated. AspxFormsGen Professional generated regular unbound webforms. It
also generated bound webforms such as:
webforms with bound gridviews (with view details link - read only),
webforms with gridview for admin (with edit/delete links),
webforms with formview (read-only), webforms with formview for insert,
webforms with formview for update. It also created Stored procedures for:
Select All (column-by-column), Select by ID, Select for DropDownList data, Insert, Update, and Delete. About 392
stored procedures were created directly in the AdventureWorks database, in the SQL Server Management Studio,
in the Object Explorer under Programability, then Stored Procedure node (figure 6b).
 (Figure 6a)
 (Figure 6b)
- Let's create a website in Visual Studio 2005 that will contain all these generated webforms.
- Open MS Visual Studio 2005.
-
On the File Menu of Visual Studio 2005, click New Website (figure 7).
 (Figure 7)
-
On the new website window, choose ASP.Net Website, on the Location choose FileSystem (default) and then type in "C:\Inetpub\wwwroot\AdventureWorksVB"), select Visual Basic as the Language, then click ok (figure 8).
 (Figure 8)
-
Visual Studio 2005 will create a new website. On the solution explorer you will notice that
Visual Studio 2005 have created a "Default.aspx" file. Right click on it, then click Delete (figure 9).
 (Figure 9)
-
Let's leave the Visual Studio 2005 IDE and go back to our desktop. Open both directories
"C:\Inetpub\wwwroot\AdventureWorksVB" (directory for the newly created website) and
"C:\AspxFormsGen" (directory where AspxFormsGen generated all our unbound and bound webforms earlier) (figure 10).
 (Figure 10)
-
Highlight all the objects in "C:\AspxFormsGen" and then drag it to the "C:\Inetpub\wwwroot\AdventureWorksVB" directory (figure 11).
 (Figure 11)
-
Let's go back to the Visual Studio IDE. Right click on the website project "C:\...\AdventureWorksVB" in the solution explorer, then click Add Existing Item...(figure 12).
 (Figure 12)
-
In the Add Existing Item window, select all objects except the App_Data folder, including the Themes folder. Then click the Add button (figure 13).
 (Figure 13)
-
In the solution explorer you will notice that you have 6 webforms per table in your database and their respective codefiles. E.g. for the Person.Address table
the following have been created: AddressFormView.aspx, AddressFormViewAdd.aspx, AddressFormViewEdit.aspx, AddressGrid.aspx,
AddressGridAdmin.aspx, AddressWebform.aspx.
Plus 1 html file (Default.htm), a Web.Config file, a MasterPage.master file, an ASP .Net Themes folder which includes a
SkinFile.skin, and StyleSheet.css files were added to your website. Right click on the "Defautl.htm" file,
then click Set As Start Page (figure 14).
 (Figure 14)
-
You may notice that the Themes folder does not show in the solution explorer. In the solution explorer,
right click on the "C:\...\AdventureWorksVB\" project, then click Refresh Folder. (figure 15).
 (Figure 15)
- Let's run the website by hitting the F5 function key on your keyboard.
-
Now that your website is finally running you will notice that AspxFormsGen Professional generated
70 unbound webforms, and 350 bound webforms for the AdventureWorks database. These webforms are shown as links
in the Default.htm page. (figure 16).
 (Figure 16)
-
Things to notice:
- The webforms are categorized into: Regular Webforms, Regular Gridviews, Regular FormViews,
Administration Gridviews, Administration FormViews (Add Record), and Administration FormViews (Update Record).
- The Default.htm file or the list of Webforms has a neat and simple style applied to it.
Here's a definition of the generated webform categories:
- Regular Weforms: Unbound webforms except for the DropDownList control in it.
-
Regular Gridviews: Bound read-only webforms. When you click any of the Regular GridView webforms,
then on the gridview there's a link, "View Details". When you click this link, it goes
to the respective Regular FormView webform.
-
Regular FormViews: Bound read-only webforms. This is where the "View Details" link goes to from the respective Regular Gridview.
-
Administration Gridviews: Bound webforms. The webforms contain a gridview with an "Edit" and "Delete"
links. The Edit link goes to the respective Administration FormView (Update Record) webform. The Delete link
deletes the current record if there are no explicit relationships to other tables. It also contains a link
"Add New Record", whick links to the respective Administration FormView (Add Record) webform.
-
Administration FormViews -- Add Record: Bound webforms. This is where the "Add New Record" link goes to from the respective Administration Gridview.
-
Administration FormViews -- Update Record: Bound webforms. This is where the "Edit" link goes to from the respective Administration Gridview.
-
Let's examine one of the unbound webforms. Scroll down the page and navigate to the "ProductWebform.aspx", under the regular webforms. Things to note: (figure 17).
- This webform is generated based on the Production.Product table of the AdventureWorks table.
- Each column in the Production.Product table is shown on this webform.
- The webform contains both RequiredFieldValidators and CompareValidators (for date and numbers).
- The ForeignKey columns are pre-populated with data from their respective Foreign Key Table, e.g. Product Model ID.
- Column names are used as control titles and are nicely separated with spaces, e.g. the SizeUnitMeasureCode (or if you have a column that's named: SIZE_MEASURE_UNIT_CODE, size_measure_unit_code, or [Size Measure Unit Code]) is shown as Size Unit Measure Code.
- The webform controls are unbound (except the DropDownList controls therefore, it won't do anything other than validate your inputs. Check the other generated bound webforms to see the difference.
- A simple style for the page is implemented based on the generated StyleSheet.css.
 (Figure 17)
-
Close the web browser and let's examine the generated code. Double-click
ProductWebform.aspx in the solution explorer. Things to notice:
- MaxLength is added to string column data types, e.g. Size has a MaxLength.
- RequiredFieldValidators are added to None-nullable columns.
- CompareValidators are added to Date and number columns.
- Only the DropDownlist controls are data-bound
- DropDownlist controls are used for columns that has explicit foreign relations with another table.
- The DropDownlist controls are bound using SqlDataSource control.
- SqlDataSource controls retrieves data for the DropDownlist using Stored Procedures
(the AspxFormsGen Professional also gives you the option to create
Ad-Hoc SQL in webforms instead of stored procedures).
- SqlDataSource references the generated Web.Config file for the connection strings.
-
Let's look at the CodeFile for ProductWebform.aspx. Go back to the solution explorer,
then right click on the ProductWebform.aspx, click "View Code". Things to notice:
-
Now let's look at one of the generated stored procedures. Open MS SQL Server 2005
Management Studio. Expand the AdventureWorks database node. Then expand the
Programmability node. Now expand the Stored Procedures node. There are approximately
400 stored procedures that was generated by AspxFormsGen Professional. Drill down to
the "aspx_UpdateContact" stored procedure. Right click on it, then choose modify. The
stored procedure will come up in a query window (figure 18)
 (Figure 18)
-
Things to note:
-
Correctly determines data types. Also knows when to use
User-defined types. E.g. @NameStyle namestyle, namestyle is a user-defined type.
- Determines nullable values. E.g. @Title nvarchar(8) = null.
- Uses both the table owner and table name, E.g. [Person].[Contact]
-
Determines primary key(s). E.g. WHERE [ContactID] = @ContactID. Note: if this
table has multiple primary keys, this will be reflected in the WHERE clause.
- Just a regular (Update) stored procedure, no fancy SQL programming to learn.
- You can go ahead and examine the rest of the bound webforms that was generated by the Standard Edition.
- You're done.
|
|