Tuesday, 8 November 2016

Three Tier Project Example:

3 Tier Project Example:

.Apx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RegistrationForm.aspx.cs"
    Inherits="JQery.RegistrationForm" %>

<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>
<html>
<head runat="server">
    <title>Untitled Page</title>

</head>

<script src="Js/jquery-1.8.2.js" type="text/javascript"></script>

<script src="Js/jquery-1.9.0.js" type="text/javascript"></script>

<script src="Js/jquery-1.9.0.min.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">
    $(function() {
        alert('Page Loading...');


    });
    //    $(document).ready(function() {
    //        $("#RegAccordion").accordion({
    //            heightStyle: "content",
    //            active: 0,
    //            collapsible: true
    //        });

    //    });

    function Alphabets(nkey) {
        var keyval
        if (navigator.appName == "Microsoft Internet Explorer") {
            keyval = window.event.keyCode;
        }
        //For A-Z
        if (keyval >= 65 && keyval <= 90) {
            return true;
        }
        //For a-z
        else if (keyval >= 97 && keyval <= 122) {
            return true;
        }
        else if (keyval == 32) {
            return true;
        }
        else {
            return false;
        }
    }
    function SaveData() {

        var obj = new Object();
        obj.name = $("#txtName").val();
        obj.gender = $("#ddlEdu option:selected").text();
        PageMethods.InsertValues(obj, onSucceess, onFailure);
        function onSucceess(a) {
            if (a = "Inserted Sucessfully") {
                alert('Inserted Sucessfully');
                return false;
            }
        }
        function onFailure() {
            alert(a);
            return false;
        }
        return false;
    }
</script>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="SM" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
    </div>
    <div>
        <h3>
            Registration Page
        </h3>
    </div>
    <div>
        <table>
            <tr>
                <td>
                    Name
                </td>
                <td>
                    <input id="txtName" type="text" title="Enter Name" onkeypress="return Alphabets(event);" />
                </td>
            </tr>
            <tr>
                <td>
                    Education
                </td>
                <td>
                    <select id="ddlEdu">
                        <option value="0">select</option>
                        <option value="1">MCA</option>
                        <option value="1">B-Tech</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    Gender
                </td>
                <td>
                    <input type="radio" name="gender" value="male">
                    Male<br>
                    <input type="radio" name="gender" value="female">
                    Female<br>
                    <input type="radio" name="gender" value="other">
                    Other
                </td>
            </tr>
            <tr>
                <td>
                    <button id="btnsave" title="Save" onclick="return SaveData();">
                        Save</button>
                </td>
                <td>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
 


.CS


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
//added
using BOLayer;
using BALayer;
using DALayer;
using System.Web.Services;

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

        }
        [WebMethod]
        public static string InsertValues(RegistrationBOL objRegistrationBOL)
        {
            try
            {
                RegistrationBAL objRegistrationBAL = new RegistrationBAL();
                return objRegistrationBAL.InsertValues(objRegistrationBOL);
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}



BAL:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BOLayer;
using DALayer;

namespace BALayer
{
    public class RegistrationBAL
    {
        RegistrationDAL objRegistrationDAL = new RegistrationDAL();
        public string InsertValues(RegistrationBOL objRegistrationBOL)
        {
            try
            {
            return objRegistrationDAL.InsertValues(objRegistrationBOL);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally { }
        }
    }
}



DAL:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BOLayer;
using System.Collections.Specialized;
using System.Configuration;
using System.Xml;
using System.Collections;


namespace DALayer
{
    public class RegistrationDAL
    {
        SqlConnection cs = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());

        public string InsertValues(RegistrationBOL objRegistrationBOL)
        {

            try
            {
                int i;
                SqlCommand cmd = new SqlCommand("Usp_RegistrationForm", cs);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name", objRegistrationBOL.name);
                cmd.Parameters.AddWithValue("@gender", objRegistrationBOL.gender);
                cs.Open();
                i = cmd.ExecuteNonQuery();
                cs.Close();
                if (i == 1)
                {
                    return "Inserted Sucessfully";
                }
                else
                {
                    return "Insert not Sucessfully";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}


BOL:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BOLayer
{
    public class RegistrationBOL
    {
        public string name { get; set; }
        public string gender { get; set; }
    }
}



This Is Complete 3 Tier Flow:









No comments:

Post a Comment