Presentation Layer (UI)
Presentation layer contains pages like .aspx or windows form where data is presented to the user or input is taken from the user.
Business Access Layer (BAL) or Business Logic Layer
BAL contains business logic, validations or calculations related with the data..
Data Access Layer (DAL)
DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc).
Designing 3-Tier Architecture
Data Access Layer (DAL) Code
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;/// <summary>/// Summary description for EmployeeDAL/// </summary>public class EmployeeDAL{string connStr = ConfigurationManager.ConnectionStrings["connectionstring"].ToString();public EmployeeDAL(){}public int Insert(string E_name, string E_address, int E_age){SqlConnection conn = new SqlConnection(connStr);conn.Open();SqlCommand dCmd = new SqlCommand("insert into EMP values(@name,@add,@age)", conn);try{dCmd.Parameters.AddWithValue("@name", E_name);dCmd.Parameters.AddWithValue("@add", E_address);dCmd.Parameters.AddWithValue("@age", E_age);return dCmd.ExecuteNonQuery();}catch{throw;}finally{dCmd.Dispose();conn.Close();conn.Dispose();}}}
Business Access Layer (BAL) Code
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;/// <summary>/// Summary description for EmployeeBAL/// </summary>public class EmployeeBAL{public EmployeeBAL(){//// TODO: Add constructor logic here//}public int Insert(string E_name, string E_address, int E_age){EmployeeDAL eDAL = new EmployeeDAL();try{return eDAL.Insert(E_name, E_address, E_age);}catch{throw;}finally{eDAL = null;}}}
Code for .cs file
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void Button1_Click(object sender, EventArgs e){//Lets validate the page firstif (!Page.IsValid)return;int intResult = 0;EmployeeBAL eBAL = new EmployeeBAL();// Instantiate the object we have to deal withstring name = txtname.Text;string address = txtadd.Text;int age = Int32.Parse(txtage.Text);try{intResult = eBAL.Insert(name, address, age);if (intResult > 0)lblmsg.Text = "New record inserted successfully.";elselblmsg.Text = "FirstName [<b>" + txtname.Text + "</b>]alredy exists, try another name";}catch (Exception ee){lblmsg.Text = ee.Message.ToString();}finally{eBAL = null;}}}
Code for Web.Config File
<?xml version="1.0"?><!--
Note: As an alternative to hand editing this file you can use theweb admin tool to configure settings for your application. Usethe Website->Asp.Net Configuration option in Visual Studio.A full list of settings and comments can be found inmachine.config.comments usually located in\Windows\Microsoft.Net\Framework\v2.x\Config--><configuration><appSettings/><connectionStrings><add name="ConnectionString" connectionString="Data Source=dell-pc;Initial Catalog=JavaTest;User Id=sa;Password=niitbpld95"/></connectionStrings><system.web><!--
Set compilation debug="true" to insert debuggingsymbols into the compiled page. Because thisaffects performance, set this value to true onlyduring development.--><compilation debug="true"/><!--
The <authentication> section enables configurationof the security authentication mode used byASP.NET to identify an incoming user.--><authentication mode="Windows"/><!--
The <customErrors> section enables configurationof what to do if/when an unhandled error occursduring the execution of a request. Specifically,it enables developers to configure html error pagesto be displayed in place of a error stack trace.<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"><error statusCode="403" redirect="NoAccess.htm" /><error statusCode="404" redirect="FileNotFound.htm" /></customErrors>--></system.web></configuration>
Presentation Layer
Database output:
Technorati Tags: ASP.Net
use EDM in this and u need only bussiness logic and Presentation and used LINQ also...
ReplyDeletetry this is to simple than preparing data layer
this is more prefered way in companies
Hello, all the time i used to check web site posts here early in the
ReplyDeletedaylight, since i like to gain knowledge of more and more.
Here is my web site; Solve Captchas