---------------BE--------------
public class BEToday
{
public int Id {get; set;}
public string Name {get; set;}
public string Address {get; set;}
}
----------------Dal-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using BE_Today;
namespace DAL_Today
{
public class DALToday
{
private static string connect = MyConnectionString.path;
public List<BEToday> show()
{
List<BEToday> list=new List<BEToday>();
SqlConnection con= new SqlConnection(connect);
SqlCommand cmd=new SqlCommand(Myproc.Name.spshow.ToString(),con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BEToday be = new BEToday();
be.Id = Convert.ToInt32(sdr["Id"]);
be.Name=Convert.ToString(sdr["Name"]);
be.Address = Convert.ToString(sdr["Address"]);
list.Add(be);
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
return list;
}
public void insert( BEToday be)
{
SqlConnection con= new SqlConnection(connect);
SqlCommand cmd=new SqlCommand(Myproc.Name.spinsert.ToString(),con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
cmd.Parameters.AddWithValue("@Name",be.Name);
cmd.Parameters.AddWithValue("@Address",be.Address);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
}
public void update(BEToday be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(Myproc.Name.spupdate.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
cmd.Parameters.AddWithValue("@Name", be.Name);
cmd.Parameters.AddWithValue("@Address", be.Address);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
}
public void delte(BEToday be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(Myproc.Name.spdelete.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
}
------------------------bl--------------------
public List<BEToday> show()
{
return new DALToday().show();
}
public void insert(BEToday be)
{
new DALToday().insert(be);
}
public void update(BEToday be)
{
new DALToday().update(be);
}
public void delte(BEToday be)
{
new DALToday().delte(be);
}
-------------------test.aspx---------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="testasp.test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr >
<td colspan="2" align="center"><h1>Insert</h1></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtinsertname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtnsertaddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="Button1" runat="server" Text=" Save " OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<br />
<table class="auto-style1">
<tr >
<td colspan="2" align="center"><h1>update</h1></td>
</tr>
<tr>
<td><asp:Label ID="Label5" runat="server" Text="Select Value"></asp:Label></td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList></td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdatename" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdateaddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnUpdate" runat="server" Text=" Update " OnClick="btnUpdate_Click" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<br />
<table class="auto-style1">
<tr >
<td colspan="2" align="center"><h1>Delete</h1></td>
</tr>
<tr>
<td><asp:Label ID="Label6" runat="server" Text="Select Value"></asp:Label></td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"></asp:DropDownList></td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtdletename0" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtdeleteaddress0" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnDelete" runat="server" Text=" Delete " OnClick="btnDelete_Click" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br /> <br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
-----------------------------------test.aspx.cs-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BE_Today;
using BL_Today;
namespace testasp
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databnd();
dllupdate();
dlldelete();
}
}
public void databnd()
{
GridView1.DataSource = new BLToday().show();
GridView1.DataBind();
}
public void dllupdate()
{
DropDownList1.DataSource = new BLToday().show();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "----select----");
}
public void dlldelete()
{
DropDownList2.DataSource = new BLToday().show();
DropDownList2.DataTextField = "Name";
DropDownList2.DataValueField = "Id";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "----select----");
}
protected void Button1_Click(object sender, EventArgs e)
{
BEToday be = new BEToday();
be.Name = txtinsertname.Text;
be.Address = txtnsertaddress.Text;
new BLToday().insert(be);
databnd();
dllupdate();
dlldelete();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > 0)
{
var n = new BLToday().show().Single(id=>id.Id==Convert.ToInt32(DropDownList1.SelectedValue));
txtupdatename.Text = n.Name;
txtupdateaddress.Text = n.Address;
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
BEToday be = new BEToday();
be.Id=Convert.ToInt32(DropDownList1.SelectedValue);
be.Name=txtupdatename.Text;
be.Address=txtupdateaddress.Text;
new BLToday().update(be);
databnd();
dllupdate();
dlldelete();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedIndex > 0)
{
var n = new BLToday().show().Single(id => id.Id == Convert.ToInt32(DropDownList2.SelectedValue));
txtdletename0.Text = n.Name;
txtdeleteaddress0.Text = n.Address;
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
BEToday be = new BEToday();
be.Id = Convert.ToInt32(DropDownList2.SelectedValue);
new BLToday().delte(be);
databnd();
dllupdate();
dlldelete();
}
}
}
public class BEToday
{
public int Id {get; set;}
public string Name {get; set;}
public string Address {get; set;}
}
----------------Dal-----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using BE_Today;
namespace DAL_Today
{
public class DALToday
{
private static string connect = MyConnectionString.path;
public List<BEToday> show()
{
List<BEToday> list=new List<BEToday>();
SqlConnection con= new SqlConnection(connect);
SqlCommand cmd=new SqlCommand(Myproc.Name.spshow.ToString(),con);
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
BEToday be = new BEToday();
be.Id = Convert.ToInt32(sdr["Id"]);
be.Name=Convert.ToString(sdr["Name"]);
be.Address = Convert.ToString(sdr["Address"]);
list.Add(be);
}
}
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
return list;
}
public void insert( BEToday be)
{
SqlConnection con= new SqlConnection(connect);
SqlCommand cmd=new SqlCommand(Myproc.Name.spinsert.ToString(),con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
cmd.Parameters.AddWithValue("@Name",be.Name);
cmd.Parameters.AddWithValue("@Address",be.Address);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
}
public void update(BEToday be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(Myproc.Name.spupdate.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
cmd.Parameters.AddWithValue("@Name", be.Name);
cmd.Parameters.AddWithValue("@Address", be.Address);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
}
public void delte(BEToday be)
{
SqlConnection con = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(Myproc.Name.spdelete.ToString(), con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", be.Id);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
throw e;
}
finally
{
con.Close();
}
}
------------------------bl--------------------
public List<BEToday> show()
{
return new DALToday().show();
}
public void insert(BEToday be)
{
new DALToday().insert(be);
}
public void update(BEToday be)
{
new DALToday().update(be);
}
public void delte(BEToday be)
{
new DALToday().delte(be);
}
-------------------test.aspx---------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="testasp.test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr >
<td colspan="2" align="center"><h1>Insert</h1></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtinsertname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtnsertaddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="Button1" runat="server" Text=" Save " OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<br />
<table class="auto-style1">
<tr >
<td colspan="2" align="center"><h1>update</h1></td>
</tr>
<tr>
<td><asp:Label ID="Label5" runat="server" Text="Select Value"></asp:Label></td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList></td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdatename" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtupdateaddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnUpdate" runat="server" Text=" Update " OnClick="btnUpdate_Click" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br />
<br />
<table class="auto-style1">
<tr >
<td colspan="2" align="center"><h1>Delete</h1></td>
</tr>
<tr>
<td><asp:Label ID="Label6" runat="server" Text="Select Value"></asp:Label></td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"></asp:DropDownList></td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" runat="server" Text="Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtdletename0" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" runat="server" Text="Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtdeleteaddress0" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnDelete" runat="server" Text=" Delete " OnClick="btnDelete_Click" />
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<br /> <br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
-----------------------------------test.aspx.cs-------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BE_Today;
using BL_Today;
namespace testasp
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
databnd();
dllupdate();
dlldelete();
}
}
public void databnd()
{
GridView1.DataSource = new BLToday().show();
GridView1.DataBind();
}
public void dllupdate()
{
DropDownList1.DataSource = new BLToday().show();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Id";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, "----select----");
}
public void dlldelete()
{
DropDownList2.DataSource = new BLToday().show();
DropDownList2.DataTextField = "Name";
DropDownList2.DataValueField = "Id";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, "----select----");
}
protected void Button1_Click(object sender, EventArgs e)
{
BEToday be = new BEToday();
be.Name = txtinsertname.Text;
be.Address = txtnsertaddress.Text;
new BLToday().insert(be);
databnd();
dllupdate();
dlldelete();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > 0)
{
var n = new BLToday().show().Single(id=>id.Id==Convert.ToInt32(DropDownList1.SelectedValue));
txtupdatename.Text = n.Name;
txtupdateaddress.Text = n.Address;
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
BEToday be = new BEToday();
be.Id=Convert.ToInt32(DropDownList1.SelectedValue);
be.Name=txtupdatename.Text;
be.Address=txtupdateaddress.Text;
new BLToday().update(be);
databnd();
dllupdate();
dlldelete();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList2.SelectedIndex > 0)
{
var n = new BLToday().show().Single(id => id.Id == Convert.ToInt32(DropDownList2.SelectedValue));
txtdletename0.Text = n.Name;
txtdeleteaddress0.Text = n.Address;
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
BEToday be = new BEToday();
be.Id = Convert.ToInt32(DropDownList2.SelectedValue);
new BLToday().delte(be);
databnd();
dllupdate();
dlldelete();
}
}
}
No comments :
Post a Comment