Click here to Skip to main content
15,897,145 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
create an app_code

create two folders in it first folder named as business logic layer and second as data logic layer

create a class in each folders

under business logic layer

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
public class database
{
    public database()
    {
    }
    public int Load_Redirect()
    {
        businesslogic obj = new businesslogic();
        try
        {
            switch ((int)obj.Load().Rows[0][0])
            {
                case 1:
                    return 1;
                case 2:
                    return 2;
                case 3:
                    return 3;
                default:
                    return 0;
            }
        }
        catch (IndexOutOfRangeException ex)
        {
            return 0;
        }
        finally
        {
            obj = null;
        }
    }
}

under data logic layer
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI;
public class businesslogic
{
    SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True");
    public businesslogic()
    {
        con.Open();
    }
    public DataTable Load()
    {
        Page page = (Page)HttpContext.Current.Handler;
        TextBox tb1 = (TextBox)page.FindControl("TextBox1");
        TextBox tb2 = (TextBox)page.FindControl("TextBox2");
        string sql = string.Format("select r.rid from employee e  inner join specification1 r on r.eid =e.eid where uname='" + tb1.Text + "' and password='" + tb2.Text + "'");
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sql,con);
        try
        {
            da.Fill(ds, "d");
            return ds.Tables["d"];
        }
        catch (SqlException ex)
        {
            throw;
        }
        finally
        {
            ds.Dispose();
            da.Dispose();
            con.Close();
            con.Dispose();
        }
    }
}

in ur default page
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="uname"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Label ID="Label2" runat="server" Text="pass"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" />
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

c#
C#
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;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        database obj = new database();
        if((int)obj.Load_Redirect()==1)
            Response.Redirect("admin.aspx");
        else if((int)obj.Load_Redirect()==2)
            Response.Redirect("super.aspx");
        else if ((int)obj.Load_Redirect()==3)
            Response.Redirect("user.aspx");
        else
            Label3.Text="missmatch";
    }
}
Posted
Updated 23-Sep-12 21:31pm
v2
Comments
Rickin Kane 24-Sep-12 4:07am    
change the way you code ,you need how to do it much better way

1 solution

You have to extract the aspx textboxes out of the buisiness logic and pass it through parameters. Have you tried to use mvc and read a book about it? You will find very intresting the consept of isolation and how you can organise your code better for less maintanance time.

what was the question again?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900