Tuesday, August 23, 2011

Sample Application On 3 -tier Architecture in asp.net c#

BLL.cs

using System;
using System.Collections.Generic;

using System.Web;


namespace _3_tier_Sample
{
    public class BLL
    {

        public string InsertUserDetails(Class1 objUserDetails)
        {
            DAL objUserDAL = new DAL();
            try
            {
                return objUserDAL.InsertUserInformation(objUserDetails);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objUserDAL = null;
            }
        }

    }
}
  

Class1.cs 

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;

namespace _3_tier_Sample
{
    public class Class1
    {
        #region Variables
        /// <summary>
        /// User Registration Variables
        /// </summary>
       
        private string _FirstName;
        private string _LastName;
        private string _Email;
        #endregion
        public string FirstName
        {
            get
            {
                return _FirstName;

            }
            set
            {
                _FirstName = value;
            }
        }

        public string LastName
        {
            get
            {
                return _LastName;

            }
            set
            {
                _LastName = value;
            }
        }


        public string Email
        {
            get
            {
                return _Email;
            }
            set
            {
                _Email = value;
            }
        }

    }
   

}





DAl.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

using System.Web;

namespace _3_tier_Sample
{
    public class DAL
    {
        //SQL Connection string
        string ConnectionString = ConfigurationManager.AppSettings["LocalConnection"].ToString();

        #region Insert User Details
        /// <summary>
        /// Insert Job Details
        /// </summary>
        /// <param name="objBELJobs"></param>
        /// <returns></returns>
        public string InsertUserInformation(Class1 objBELUserDetails)
        {
            SqlConnection con = new SqlConnection(ConnectionString);
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_userinformation", con);
            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
               
                cmd.Parameters.AddWithValue("@FirstName", objBELUserDetails.FirstName);
                cmd.Parameters.AddWithValue("@LastName", objBELUserDetails.LastName);
                cmd.Parameters.AddWithValue("@Email", objBELUserDetails.Email);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }
        #endregion
    }
}



Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _3_tier_Sample
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            string output = string.Empty;
            Class1 objClass  = new Class1();
            objClass.FirstName = txtfname.Text;
            objClass.LastName = txtlname.Text;
            objClass.Email = txtEmail.Text;
            BLL objBLL = new BLL();
            output = objBLL.
        }
    }
}