Registration form in Asp.Net / C#.Net winforms using 3-tier architecture
In previous posts , i have given a example for simple registration form in asp.net . And now i am extending the same example to 3-tier. As almost everyone knows what is 3-tier architecture, so here i am not going to write much about 3-tier architecture. If you are not aware of 3-tier architecture, you can search on google. So here we will see registration form in Asp.Net / C#.Net winforms using 3-tier architecture.
In this article, we are not only doing 3-tier architecture example but we also see how the same coding can be used for both Asp.Net and Windows application.
In 3-tier Architecture, we divide our project coding in 3 layers,
1) Presentation Layer
2) Business Logic Layer / Business Access layer
3) Data Access layer
So i have taken my asp.net project architecture as shown in figure below .
In App_Code folder, i have added 3 folders that you can see in image above, they are BEL_FILES, BLL_FILES, DAL_FILES.
Below is the screen shot of registration form designed
The Asp.Net controls used in screen designing are:
Label control
Textbox control
Checkbox control
Radio button list control
Fileupload control
Button control
Required Field validator (for all required fields)
Regular expression validator (for validating email,mobile)
compare validator (to compare password with confirm password field)
The Database table structure is like this
Query to create table :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
CREATE TABLE [dbo].[RegisterEmp]( [UserName] [varchar](50) NOT NULL, [Email] [nvarchar](50) NOT NULL primary key, [Password] [nvarchar](50) NULL, [Gender] [varchar](50) NULL, [DOB] [varchar](50) NULL, [Mobile] [varchar](50) NULL, [Physical] [varchar](50) NULL, [Country] [varchar](50) NULL, [City] [varchar](50) NULL, [Address] [varchar](500) NULL, [FileName] [varchar](500) NULL, [FileData] [varbinary](max) NULL ON [PRIMARY]) |
BEL_FILES contains classes defined for entities, as here we are doing employee registration form , of-course there should be a class Employee.
Employee Class will have all the required properties and methods related to employee.
The Employee Class Code is like this :
The BLL_FILES folder (which is considered as Business Logic layer) contains all the class files required for implementing logic.
Here I have BLL class and the logic code required for registering an employee is all done here.
DAL_FILES contains all the required classes of Data Access Layer.
It Contains the methods to do all the required query operations with database.
Here the DAL class is present in DAL_FILES, and its code is given below.
And finally the Submit button_Click code for the registration form is in Asp.Net is like this :
The one of the major advantages of 3-tier / n-tier architecture is code re-usability.
You can use the same code in windows forms Application, just the validation part and some of the button click code may change, and the remaining code will remain same.
I have used the same code with Registration form in Windows Forms Application, the screenshot is given below.
Labels
Textboxes
Radio buttons
Date Time Picker
Checkbox
DropdownList
Groupbox
Listbox
Buttons
Error Provider
Timer Control
The project architecture of my windows forms application is shown in figure below
Here the Submit button click code in windows forms Application is like this :
I have designed these projects especially for beginners, and tried my best to cover all the needed controls, logic and validation part and made it more clear and useful.
I hope beginners will find this useful. For beginners, i will recommend to download the full Source code of the projects both (asp.net and winforms Application) from the links provided below.
Note: Here after downloading the source code, for windows application you need to create table in your sql server database and should change the connection string in DAL Class. The sql query to create table is also provided with the source code.