|
With DB Visual ARCHITECT (DB-VA) you can develop quality ASP.NET Web Application much faster, better and cheaper. All DB-VA generated C# code, configuration files and persistent layer library are deployable to Internet Information Services (IIS). DB-VA generates all C# code for accessing database. You do not need to write SQL to insert, query, update or delete the record. All code you need to program is plain C# code (e.g. OrderDAO.Save(myOrder);). In this chapter we will use a simple "School System" application to show you how to generate C# code, configure your web application, and create/query/update/ delete objects. Again you do not need to write a single SQL statement for all above operations.
![]() |
|---|
| Figure 3.1 - The architenture of ASP .NET application with DB-VA Persistent Layer |
In this chapter:
You will develop a School System.
The School System provides the following functions:
Required Software:
Please open the SchoolSystem.vpp project file in the Chapter 3 School System.zip file. The project file contains the following diagrams. Please refer to the Designer Guide for details about how to draw class diagram and entity relationship diagram.
Class Diagram of School System:
![]() |
|---|
| Figure 3.2 - Class Diagram |
Entity Relationship Diagram of School System:
![]() |
|---|
| Figure 3.3 - Entity Relationship Diagram (ERD) |
Before writing code to develop the ASP.NET application, you need to:
The details of how to setup the environment to develop the ASP.NET application, please refer to Chapter 2 - Configuring the Source and Library in Visual Studio.
The school system provides separate register pages for teacher and student to enter their information. The register method of teacher and student method is the same, so we only demonstrate how to create the teacher and save to database.
![]() |
|---|
| Figure 3.4 - The RegisterUserComponent |
![]() |
|---|
| Figure 3.5 - The Web Form |
...}
Source Code : webschoolsystem\teacherReg.aspx.cs
Source Code : webschoolsystem\teacherReg.aspx.cs
Source Code : webschoolsystem\teacherReg.aspx.cs
Teacher lTeacher = TeacherFactory.CreateTeacher();
lTeacher.LoginID = userControl.LoginID;
lTeacher.Name = userControl.UserName;
lTeacher.Password = userControl.Password;
Source Code : webschoolsystem\teacherReg.aspx.cs
Source Code : webschoolsystem\teacherReg.aspx.cs
Source Code : webschoolsystem\teacherReg.aspx.cs
Console.WriteLine(ex.StackTrace);}
t.RollBack();
returnMsgLabel.Text = "Error to add a new teacher";
Source Code : webschoolsystem\teacherReg.aspx.cs
![]() |
|---|
| Figure 3.6 - Register on the page |
![]() |
|---|
| Figure 3.7 - The record is insert to the database |
You can retrieve the record in database as object. For example, you need to create the login function for the School System. It will request the user to input the user ID and password to login, the system retrieve the User object with the user id and compare the password to validate the user.
![]() |
|---|
| Figure 3.8 - Login page |
Object lObj = Session.Contents["user"];}
if (lObj != null)
{if (lObj is Teacher)}
{Response.Redirect("teacherPage.aspx", true);}
else if (lObj is Student)
{Response.Redirect("studentPage.aspx", true);}
Source Code : webschoolsystem\login.aspx.cs
Source Code : webschoolsystem\login.aspx.cs
Source Code : webschoolsystem\login.aspx.cs
if (lUser.Password == lPassword)
{Session.Add("user", lUser);}
redirectLoginedUser();
else
{returnMsgLabel.Text = "User ID or Password incorrect";}
Source Code : webschoolsystem\login.aspx.cs
You can modify the teacher information and update the record in database. You get the User object from the session and set the new values for the User object, finally call save() method to update the record in database.
![]() |
|---|
| Figure 3.9 - Teaching Page |
![]() | ![]() |
| Figure 3.10 - To modify the user information | |
Response.Redirect("login.aspx");}
school.SchoolSystemPersistentManager.Instance().GetSession().Lock(lObj, NHibernate.LockMode.None);}
((Teacher)user).Email = registerUserControl.Email;}
Source Code : webschoolsystem\login.aspx.cs
![]() |
|---|
| Figure 3.11 - The record in database are modified |
Teachers can create course for students to enroll and they can cancel courses in the system. They only need to click cancel hyperlink of the course then the course information will be deleted in the database and all the relationship with registered students will be removed.
![]() |
|---|
| Figure 3.12 - Delete record |
![]() |
|---|
| Figure 3.13 - Student Page |
![]() |
|---|
| Figure 3.14 - Teacher Page |
Course lCourse = CourseFactory.LoadCourseByORMID(int.Parse(delCourseID));
lCourse.DeleteAndDissociate();}
t.Commit();
|
|
|||||||