Thursday 17 September 2015

Registration,Login Page using 3 Tier Architecture - Asp.net

Login.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 67px;
        }
        .style3
        {
            width: 284px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <br />
        <br />
        <br />
        <br />
        <table class="style1">
<tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Name</td>
                <td>
                    <asp:textbox id="TextBox1" runat="server"></asp:textbox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
<tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Password</td>
                <td>
                    <asp:textbox id="TextBox2" runat="server"></asp:textbox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
<tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
<tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    <asp:button id="Button1" onclick="Button1_Click" runat="server" text="Login">
                </asp:button></td>
                <td>
                    &nbsp;</td>
            </tr>
</table>
</div>
</form>
</body>
</html>

Login.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BLL loginparameters = new BLL();
            loginparameters.Id = Convert.ToInt32(TextBox1.Text);
            loginparameters.Password = TextBox2.Text;

            BLL objUserBLL = new BLL();
            objUserBLL.validateloginBLL(loginparameters);
        }
    }
}

Register.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 113px;
        }
        .style3
        {
            width: 262px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
        <strong>
        Registration Page - 3 TIER</strong><br />
        <br />
        <table class="style1">
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Empid</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Name</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Salary</td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Password</td>
                <td>
                    <asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    Confirm Pwd</td>
                <td>
                    <asp:TextBox ID="TextBox5" runat="server" TextMode="Password"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Insert" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Register.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BLL objUserBEL = new BLL();
            objUserBEL.Id = Convert.ToInt32(TextBox1.Text);
            objUserBEL.Name = TextBox2.Text;
            objUserBEL.Salary = Convert.ToInt32(TextBox3.Text);
            objUserBEL.Password = TextBox4.Text;

            BLL objUserBLL = new BLL();
           objUserBLL.InsertUserDetails(objUserBEL);

           
           DAL da = new DAL();
            //  Response.Write("<script type=\"text/javascript\">alert('"+mess.ToString()+"');</script>");
        }

    }
}

BAL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace _3TierRegPaage
{
    public class BLL
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Salary { get; set; }
        public string Password { get; set; }

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

        public void validateloginBLL(BLL objUserDetails)
        {
            DAL objUserDAL = new DAL();
            try
            {
                objUserDAL.validateloginDLL(objUserDetails);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objUserDAL = null;
            }
        }
    }
}

DAL.cs

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

namespace _3TierRegPaage
{
    //string ConnectionString = ConfigurationManager.AppSettings["LocalConnection"].ToString();

    public class DAL
    {
        public void InsertUserInformation(BLL objBELUserDetails)
        {
            string msg;
            SqlConnection con = new SqlConnection(@"Data Source=GOKUL-PC\GOKULSQL;Initial Catalog=test;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into  tblEmployee (id,name,Salary,Password) values(@id,@name,@salary,@Password)", con);
            
            try
            {
                cmd.Parameters.AddWithValue("@id", objBELUserDetails.Id);
                cmd.Parameters.AddWithValue("@name", objBELUserDetails.Name);
                cmd.Parameters.AddWithValue("@salary", objBELUserDetails.Salary);
                cmd.Parameters.AddWithValue("@Password", objBELUserDetails.Password);
               
                cmd.ExecuteNonQuery();
                msg = "Registration Successful";
                messageshow(msg);
                con.Close();
                
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                messageshow(msg);
                
            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }

        public void validateloginDLL(BLL objBELUserDetails)
        {
            string msg;
            SqlConnection con = new SqlConnection(@"Data Source=GOKUL-PC\GOKULSQL;Initial Catalog=test;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT name,Password FROM tblEmployee where name=@name,password=@pwd", con);

            try
            {
                cmd.Parameters.AddWithValue("@name", objBELUserDetails.Name);
                cmd.Parameters.AddWithValue("@Password", objBELUserDetails.Password);
                SqlDataReader dr;
                dr= cmd.ExecuteReader();
                msg = "Registration Successful";
                messageshow(msg);
                con.Close();

            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                messageshow(msg);

            }
            finally
            {
                cmd.Dispose();
                con.Close();
                con.Dispose();
            }
        }

        public string messageshow(string msg)
        {
            return msg;
        }
    }
}

No comments:

Post a Comment