Saturday, October 18, 2014

asp.net 3 tier architecture

Posted by Unknown  |  No comments


 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  

 here we are learing about 3-tier using vb.net (insert delete search and clear)  
 here i am explaing about :  
 1)how to insert and delete and search and clear  
 2)using 3-tier architecture  
 3)request and response also  
 4)BO,DAO,UI layers  
 5)using vb.net  
 step 1):  
 first you need to create Request and response  
 response(bo)  
 Public Class IDSRequest  
   Private slnoValue As String  
   Public Property slnno() As String  
     Get  
       Return insertValue  
     End Get  
     Set(ByVal value As String)  
       insertValue = value  
     End Set  
   End Property  
   Private empidValue As String  
   Public Property empid() As String  
     Get  
       Return deleteValue  
     End Get  
     Set(ByVal value As String)  
       deleteValue = value  
     End Set  
   End Property  
   Private empphValue As String  
   Public Property empno() As String  
     Get  
       Return searchValue  
     End Get  
     Set(ByVal value As String)  
       searchValue = value  
     End Set  
   End Property  
   Private empadressValue As String  
   Public Property empadress() As String  
     Get  
       Return clearValue  
     End Get  
     Set(ByVal value As String)  
       clearValue = value  
     End Set  
   End Property  
   Private insertValue As String  
   Public Property Insert() As String  
     Get  
       Return insertValue  
     End Get  
     Set(ByVal value As String)  
       insertValue = value  
     End Set  
   End Property  
   Private deleteValue As String  
   Public Property Delete() As String  
     Get  
       Return deleteValue  
     End Get  
     Set(ByVal value As String)  
       deleteValue = value  
     End Set  
   End Property  
   Private searchValue As String  
   Public Property Search() As String  
     Get  
       Return searchValue  
     End Get  
     Set(ByVal value As String)  
       searchValue = value  
     End Set  
   End Property  
   Private editValue As String  
   Public Property Edit() As String  
     Get  
       Return editValue  
     End Get  
     Set(ByVal value As String)  
       editValue = value  
     End Set  
   End Property  
   Private clearValue As String  
   Public Property Clear() As String  
     Get  
       Return clearValue  
     End Get  
     Set(ByVal value As String)  
       clearValue = value  
     End Set  
   End Property  
   Private showValue As String  
   Public Property Show() As String  
     Get  
       Return showValue  
     End Get  
     Set(ByVal value As String)  
       showValue = value  
     End Set  
   End Property  
 End Class  
 Response(bO)................  
 Public Class IDSResponse  
   Private dataTableValue As DataTable  
   Public Property DataDT() As DataTable  
     Get  
       Return dataTableValue  
     End Get  
     Set(ByVal value As DataTable)  
       dataTableValue = value  
     End Set  
   End Property  
   Private dtSearchValue As DataTable  
   Public Property DtSearch() As DataTable  
     Get  
       Return dtSearchValue  
     End Get  
     Set(ByVal value As DataTable)  
       dtSearchValue = value  
     End Set  
   End Property  
   Sub Write(ByVal p1 As String)  
     Throw New NotImplementedException  
   End Sub  
   Private dtdeleteValue As String  
   Public Property DtDelete() As String  
     Get  
       Return dtdeleteValue  
     End Get  
     Set(ByVal value As String)  
       dtdeleteValue = value  
     End Set  
   End Property  
   Private updateValue As String  
   Public Property Update() As String  
     Get  
       Return updateValue  
     End Get  
     Set(ByVal value As String)  
       updateValue = value  
     End Set  
   End Property  
   Private editValue As String  
   Public Property Edit() As String  
     Get  
       Return editValue  
     End Get  
     Set(ByVal value As String)  
       editValue = value  
     End Set  
   End Property  
   Private cancelValue As String  
   Public Property Cancel() As String  
     Get  
       Return cancelValue  
     End Get  
     Set(ByVal value As String)  
       cancelValue = value  
     End Set  
   End Property  
   Private showtableValue As String  
   Public Property ShowTableRecord() As String  
     Get  
       Return showtableValue  
     End Get  
     Set(ByVal value As String)  
       showtableValue = value  
     End Set  
   End Property  
 End Class  
 step 2):  
 -------  
 second you need to create DAO layer( data access layer)  
 DAO......................  
 Imports System  
 Imports System.Data  
 Imports System.Data.SqlClient  
 Imports BussinessEntites  
 Imports BussinessLayer  
 Public Class DAOClass  
   Public Shared Function insert(ByVal request As IDSRequest) As IDSResponse 'here parameters as REQUEST and returns as RESPONSE  
     Dim response = New IDSResponse()  
     Dim con As New SqlConnection()  
     Dim cmd As New SqlCommand()  
     Dim dt As New DataTable()  
     Dim da As New SqlDataAdapter  
     Dim connectionstring As String  
     connectionstring = "server=SSPLDEV9;database=testing;User ID =sa; password=svt123;integrated security=false"  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "Getemployeedetails"  
     cmd.CommandType = CommandType.StoredProcedure  
     cmd.Parameters.AddWithValue("@slnno", request.slnno)  
     cmd.Parameters.AddWithValue("@empid", request.empid)  
     cmd.Parameters.AddWithValue("@empno", request.empno)  
     cmd.Parameters.AddWithValue("@empadress", request.empadress)  
     cmd.Connection = con  
     cmd.ExecuteNonQuery()  
     cmd = New SqlCommand("select * from empdetails", con)  
     da.SelectCommand = cmd  
     da.Fill(dt)  
     response.DataDT = dt 'here the datatable response is sending to idsresponse  
     con.Close()  
     Return response  
   End Function  
   Public Shared Function Search(ByVal request As IDSRequest) As IDSResponse 'here parameters as REQUEST and returns as RESPONSE  
     Dim response = New IDSResponse()  
     Dim con As New SqlConnection()  
     Dim cmd As New SqlCommand()  
     Dim dt As New DataTable()  
     Dim da As New SqlDataAdapter  
     Dim connectionstring As String  
     connectionstring = "server=SSPLDEV9;database=testing;User ID =sa; password=svt123;integrated security=false"  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "SP_SEARCH"  
     cmd.CommandType = CommandType.StoredProcedure  
     cmd.Parameters.AddWithValue("@slnno", request.slnno)  
     cmd.Connection = con  
     da.SelectCommand = cmd  
     da.Fill(dt)  
     response.DtSearch = dt  
     cmd.ExecuteNonQuery()  
     con.Close()  
     Return response  
   End Function  
   Public Shared Function delete(ByVal request As IDSRequest) As IDSResponse 'here parameters as REQUEST and returns as RESPONSE  
     Dim response = New IDSResponse()  
     Dim con As New SqlConnection()  
     Dim cmd As New SqlCommand()  
     Dim dt As New DataTable()  
     Dim da As New SqlDataAdapter  
     Dim connectionstring As String  
     connectionstring = "server=SSPLDEV9;database=testing;User ID =sa; password=svt123;integrated security=false"  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "SP_DELETE"  
     cmd.CommandType = CommandType.StoredProcedure  
     cmd.Parameters.AddWithValue("@slnno", request.slnno)  
     cmd.Connection = con  
     cmd.ExecuteNonQuery()  
     cmd = New SqlCommand("select * from empdetails", con)  
     cmd.Connection = con  
     da.SelectCommand = cmd  
     da.Fill(dt)  
     response.DtDelete = dt.ToString()  
     con.Close()  
     Return response  
   End Function  
   Public Shared Function update(ByVal request As IDSRequest) As IDSResponse  
     Dim response = New IDSResponse()  
     Dim con As New SqlConnection()  
     Dim cmd As New SqlCommand()  
     Dim dt As New DataTable()  
     Dim da As New SqlDataAdapter  
     Dim connectionstring As String  
     connectionstring = "server=SSPLDEV9;database=testing;User ID =sa; password=svt123;integrated security=false"  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "SP_UPDATE"  
     cmd.CommandType = CommandType.StoredProcedure  
     cmd.Connection = con  
     cmd = New SqlCommand("select * from empdetails where slnno=@slnno, empid=@empid", con)  
     cmd.Connection = con  
     da.SelectCommand = cmd  
     da.Fill(dt)  
     response.DtSearch = dt  
     con.Close()  
     Return response  
   End Function  
   Public Shared Function showrecords(ByVal request As IDSRequest) As IDSResponse 'here parameters as REQUEST and returns as RESPONSE  
     Dim response = New IDSResponse()  
     Dim con As New SqlConnection()  
     Dim cmd As New SqlCommand()  
     Dim dt As New DataTable()  
     Dim da As New SqlDataAdapter  
     Dim connectionstring As String  
     connectionstring = "server=SSPLDEV9;database=testing;User ID =sa; password=svt123;integrated security=false"  
     con = New SqlConnection(connectionstring)  
     con.Open()  
     cmd.CommandText = "SHOW"  
     cmd.CommandType = CommandType.StoredProcedure  
     'cmd.Parameters.AddWithValue("@slnno", request.slnno)  
     'cmd.Parameters.AddWithValue("@empid", request.empid)  
     'cmd.Parameters.AddWithValue("@empno", request.empno)  
     'cmd.Parameters.AddWithValue("@empadress", request.empadress)  
     cmd.Connection = con  
     cmd.ExecuteNonQuery()  
     cmd = New SqlCommand("select * from empdetails", con)  
     da.SelectCommand = cmd  
     da.Fill(dt)  
     response.DataDT = dt 'here the datatable response is sending to idsresponse  
     con.Close()  
     Return response  
   End Function  
 End Class  
 step 3):  
 -------  
 you need to create User interface (UI) layer  
 Imports System  
 Imports System.Data  
 Imports System.Data.SqlClient  
 Imports BussinessEntites  
 Imports BussinessLayer  
 Imports ClassLibrary3  
 Partial Class Home_UI_  
   Inherits System.Web.UI.Page  
   Public Sub input()  
   End Sub  
   Protected Sub clearBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearBtn.Click  
     txtbxempid.Text = ""  
     txtbxempno.Text = ""  
     txtbxadress.Text = ""  
     txtbxslnno.Text = ""  
   End Sub  
   Protected Sub insertbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles insertbtn.Click  
     Try  
       Dim request = New IDSRequest()  
       request.slnno = txtbxslnno.Text  
       request.empid = txtbxempid.Text  
       request.empno = txtbxempno.Text  
       request.empadress = txtbxadress.Text  
       Dim Response = DAOClass.insert(request)  
       GridView1.DataSource = Response.DataDT  
       GridView1.DataBind()  
     Catch ex As Exception  
     End Try  
   End Sub  
   Protected Sub deletebtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles deletebtn.Click  
     Dim request = New IDSRequest()  
     request.slnno = txtbxsearch.Text  
     Dim Response = DAOClass.delete(request)  
     GridView1.DataSource = Response.DtSearch  
     GridView1.DataBind()  
     txtbxempid.Text = ""  
     txtbxempno.Text = ""  
     txtbxadress.Text = ""  
     txtbxslnno.Text = ""  
   End Sub  
   Protected Sub searchbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchbtn.Click  
     Try  
       Dim request = New IDSRequest()  
       request.slnno = txtbxsearch.Text  
       Dim Response = DAOClass.Search(request)  
       txtbxslnno.Text = Response.DtSearch.Rows(0).Item("slnno").ToString()  
       txtbxempid.Text = Response.DtSearch.Rows(0).Item("empid").ToString()  
       txtbxempno.Text = Response.DtSearch.Rows(0).Item("empno").ToString()  
       txtbxadress.Text = Response.DtSearch.Rows(0).Item("empaddress").ToString()  
       GridView1.DataSource = Response.DataDT  
       GridView1.DataBind()  
     Catch ex As Exception  
     End Try  
   End Sub  
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load  
     cancelbtn.Visible = False  
     updatebtn1.Visible = False  
   End Sub  
   Protected Sub cancelbtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cancelbtn.Click  
     cancelbtn.Visible = False  
     updatebtn1.Visible = False  
   End Sub  
   Protected Sub show_Click(ByVal sender As Object, ByVal e As EventArgs) Handles show.Click  
     Try  
       Dim request = New IDSRequest()  
       Dim Response = DAOClass.showrecords(request)  
       GridView1.DataSource = Response.DataDT  
       GridView1.DataBind()  
     Catch ex As Exception  
     End Try  
   End Sub  
   Protected Sub editbtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles editbtn.Click  
     If txtbxsearch.Text = "" Then  
       ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('first you can search your record in the search box');", True)  
     Else  
       cancelbtn.Visible = True  
       updatebtn1.Visible = True  
     End If  
   End Sub  
   Protected Sub updatebtn1_Click1(ByVal sender As Object, ByVal e As EventArgs) Handles updatebtn1.Click  
     Try  
       Dim request = New IDSRequest()  
       request.slnno = txtbxslnno.Text  
       request.empid = txtbxempid.Text  
       request.empno = txtbxempno.Text  
       request.empadress = txtbxadress.Text  
       Dim Response = DAOClass.update(request)  
       GridView1.DataSource = Response.DataDT  
       GridView1.DataBind()  
     Catch ex As Exception  
     End Try  
   End Sub  
 End Class  
 step4;)  
 finally you need to design just copy and paste in html (source view)  
  you can create the control as you like or what ever you want.  
 <%@ Page Language="VB" AutoEventWireup="false" Inherits="New_App.Home_UI_" Codebehind="Home(UI).aspx.vb" %>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">  
 <head runat="server">  
   <title>3tierIDS</title>  
   <style type="text/css">  
     #form1  
     {  
       height: 679px;  
       width: 984px;  
     }  
   </style>  
   <style type="text/css">  
   .blink  
   {  
     text-decoration:blink  
   }  
   </style>  
 </head>  
 <body>  
   <form id="form1" runat="server">  
   <div>  
   <marquee behavior="scroll" bgcolor="yellow" loop="-1" onmouseover="this.stop();" onmouseout="this.start();" style="height: 24px; width: 100%">Manupulation of data.</marquee></div>  
   &nbsp;<br />  
   <div>  
   <asp:LinkButton ID="lnkButton" runat="server" CssClass="blink">SoftVent</asp:LinkButton>  
   </div>  
   <br />  
   <br />  
   slnNO  
   <asp:TextBox ID="txtbxslnno" runat="server"></asp:TextBox>  
   <br />  
   empid:  
   <asp:TextBox ID="txtbxempid" runat="server"></asp:TextBox>  
   <br />  
   empph:<asp:TextBox ID="txtbxempno" runat="server"></asp:TextBox>  
   <br />  
   adress:<asp:TextBox ID="txtbxadress" runat="server"></asp:TextBox>  
   &nbsp;<asp:Button ID="show" runat="server" Height="26px" Text="ShowTableRecord"  
     Width="134px" />  
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; search here with slnNO&nbsp;  
   <asp:TextBox ID="txtbxsearch" runat="server"></asp:TextBox>  
   &nbsp;  
   <asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="146px">  
     <asp:ListItem>--SELECT--</asp:ListItem>  
     <asp:ListItem>Male</asp:ListItem>  
     <asp:ListItem>Female</asp:ListItem>  
   </asp:DropDownList>  
   <br />  
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
   <asp:Button ID="clearBtn" runat="server" Height="28px" Text="Clear"  
     Width="106px" onclick="clearBtn_Click" />  
   <asp:Button ID="insertbtn" runat="server" Height="28px" Text="insert"  
     Width="106px" />  
   <asp:Button ID="deletebtn" runat="server" Height="28px" Text="Delete"  
     Width="106px" />  
   <asp:Button ID="editbtn" runat="server" Height="28px" Text="edit"  
     Width="108px" />  
   &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;  
   <asp:Button ID="searchbtn" runat="server" Height="28px" Text="search"  
     Width="106px" />  
   &nbsp;<br />  
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
   <asp:Button ID="updatebtn1" runat="server" Text="update" />  
   <asp:Button ID="cancelbtn" runat="server" Text="cancel" />  
   <br />  
   <asp:GridView ID="GridView1" runat="server" CellPadding="4"  
     ForeColor="#333333" GridLines="None" Height="307px" Width="665px">  
     <AlternatingRowStyle BackColor="White" />  
     <Columns>  
       <asp:CheckBoxField />  
     </Columns>  
     <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />  
     <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />  
     <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />  
     <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />  
     <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />  
     <SortedAscendingCellStyle BackColor="#FDF5AC" />  
     <SortedAscendingHeaderStyle BackColor="#4D0000" />  
     <SortedDescendingCellStyle BackColor="#FCF6C0" />  
     <SortedDescendingHeaderStyle BackColor="#820000" />  
   </asp:GridView>  
   <asp:ListBox ID="ListBox1" runat="server" Height="106px" Width="669px">  
   </asp:ListBox>  
   </form>  
 </body>  
 </html>  

 if you want more related search please click here  
 please help to other  
 http://scriptquery.blogspot.in/  


11:31 PM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top