Data Access Layer
------------------------
#region Brand
public static void InsertBrand(Brand cls)
{
// con = new SqlConnection(Connection.MyConnection());
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
cmd = new SqlCommand("InsertBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Brand_Name", cls.Brand_Name);
cmd.Parameters.AddWithValue("@Brand_Description", cls.Brand_Description);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static DataTable getAllBrand()
{
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
//con = new SqlConnection(Connection.MyConnection());
cmd = new SqlCommand("SelectBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter();
da.SelectCommand = cmd;
dt = new DataTable();
da.Fill(dt);
return dt;
}
public static void UpdateBrand(Brand c)
{
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
//con = new SqlConnection(Connection.MyConnection());
cmd = new SqlCommand("UpdateBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Brand_ID", c.Brand_ID);
cmd.Parameters.AddWithValue("@Brand_Name", c.Brand_Name);
cmd.Parameters.AddWithValue("@Brand_Description", c.Brand_Description);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteBrand(int cid)
{
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
cmd = new SqlCommand("DeleteBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Brand_ID", cid);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
#endregion
-------------------
Business Layer
-------------------------
#region Brand
public static void InsertBrand(Brand cls)
{
LessonPlanDataAccess.InsertBrand(cls);
}
public static List<Brand> getAllBrand()
{
List<Brand> BrandList = new List<Brand>();
DataTable dt = LessonPlanDataAccess.getAllBrand();
foreach (DataRow row in dt.Rows)
{
Brand c = new Brand();
c.Brand_ID = int.Parse(row["Brand_ID"].ToString());
c.Brand_Name = row["Brand_Name"].ToString();
c.Brand_Description = row["Brand_Description"].ToString();
BrandList.Add(c);
}
return BrandList;
}
public static void UpdateBrand(Brand c)
{
LessonPlanDataAccess.UpdateBrand(c);
}
public static void DeleteBrand(int cid)
{
LessonPlanDataAccess.DeleteBrand(cid);
}
#endregion
------------------------------------------
object layer
---------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Brand
/// </summary>
///
[Serializable]
public class Brand
{
public Brand()
{
//
// TODO: Add constructor logic here
//
}
public int Brand_ID
{
get;
set;
}
public string Brand_Name
{
get;
set;
}
public string Brand_Description
{
get;
set;
}
}-----------------------------------------
Design
----------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Brand.aspx.cs" Inherits="Projects_Brand" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="~/UserControl/U_Message.ascx" TagName="Message" TagPrefix="Mes"%>
<!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></title>
<style type="text/css">
.EmptyMessage
{
font-family: Arial;
color:Red;
font-size:16px;
font-weight:bold;
}
.TabStyle
{
height:460px;
overflow:inherit;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="TabStyle">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TabContainer ID="TabContainerBrand" runat="server" Style="height: auto; width: auto">
<asp:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" >Display</asp:LinkButton>
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Brand_ID" onrowcommand="GridView1_RowCommand"
onrowediting="GridView1_RowEditing" >
<Columns>
<asp:TemplateField HeaderText="BrandName">
<ItemTemplate>
<asp:LinkButton ID="ImgBtnEdit" runat="server" CausesValidation="false" ImageUrl="~/Images/edit.png"
CommandName="Edit" CommandArgument='<%# Eval("Brand_ID") %>' Text='<%# Eval("Brand_Name") %>'/></ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Description" DataField="Brand_Description">
</asp:BoundField>
</Columns>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="Tabpanel2" runat="server">
<HeaderTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">Entry</asp:LinkButton>
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="Panel2" runat="server">
<table class="style1">
<tr>
<td colspan="2">
Brand
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td style="text-align: right">
<asp:Label ID="Label1" runat="server" Text="Brand Name :"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtBrand" runat="server" Height="24px" Width="221px"></asp:TextBox>
<span class="EmptyMessage">
<asp:RequiredFieldValidator ID="req1" runat="server" ErrorMessage="Enter Brand Name"
ControlToValidate="TxtBrand" SetFocusOnError="true" ValidationGroup="1">*</asp:RequiredFieldValidator>
</span>
</td>
</tr>
<tr>
<td style="text-align: right" width="40%">
<asp:Label ID="Label2" runat="server" Text="Brand Description :"></asp:Label>
</td>
<td width="60%">
<asp:TextBox ID="TxtBrandDescription" runat="server" Height="24px" Width="221px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="BtnSave" runat="server" Text="Save" ValidationGroup="1" onclick="BtnSave_Click" />
<asp:Button ID="BtnCancel" runat="server" Text="Cancel"
onclick="BtnCancel_Click" />
</td
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
<Mes:Message ID="MessageID" runat="server" />
<asp:ValidationSummary ID="val1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="1" />
</div>
</form>
</body>
</html>
-------------------------------------------
C# Code
------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Projects_Brand : System.Web.UI.Page
{
#region Events
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillgrid();
}
}
protected void BtnSave_Click(object sender, EventArgs e)
{
if (BtnSave.Text == "Save")
{
if (TxtBrand.Text != "")
{
if (CheckDuplicate(TxtBrand.Text) == false)
{
Save();
fillgrid();
}
else
{
Message("Data Alredy Exists !");
}
}
}
else
{
if (CheckDuplicateForEdit(TxtBrand.Text) == false)
{
update();
fillgrid();
}
else
{
Message("Data Alredy Exists !");
}
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Reset();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
fillgrid();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
int catID = int.Parse(e.CommandArgument.ToString());
Session["PCID"] = catID;
Brand c = new Brand();
var catlist = from p in LessonPlanManagement.getAllBrand()
where p.Brand_ID == catID
select p;
if (catlist.ToList().Count > 0)
{
TabContainerBrand.ActiveTabIndex = 1;
Tabpanel2.Visible = true;
TxtBrand.Text = catlist.ToList()[0].Brand_Name.ToString();
TxtBrandDescription.Text = catlist.ToList()[0].Brand_Description.ToString();
BtnSave.Text = "Update";
BtnCancel.Text = "Delete";
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
e.Cancel = true;
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
if (BtnCancel.Text == "Cancel")
{
Reset();
}
else
{
Delete();
}
}
#endregion
#region Methods
private void Save()
{
Brand InsertBrand = new Brand();
if (Session["PCID"] != null)
{
if (TxtBrand.Text.Length > 0)
{
update();
Reset();
}
else
{
Message("Data Already Exists !");
}
}
else
{
if (TxtBrand.Text.Length > 0)
{
if (CheckDuplicate(TxtBrand.Text.Trim()) == false)
{
InsertBrand.Brand_Name = TxtBrand.Text;
//InsertCategory.Parent_Category_ID = int.Parse(DdlParentCategory.SelectedValue.ToString());
InsertBrand.Brand_Description = TxtBrandDescription.Text;
LessonPlanManagement.InsertBrand(InsertBrand);
Message("Data Inserted Successfully !");
Reset();
}
else
{
Message("Data Already Exists !");
}
TxtBrand.Focus();
}
}
}
private void update()
{
if (Session["PCID"].ToString() != null)
{
Brand updateBrand = new Brand();
updateBrand.Brand_ID = int.Parse(Session["PCID"].ToString());
updateBrand.Brand_Name = TxtBrand.Text.Trim();
updateBrand.Brand_Description = TxtBrandDescription.Text.Trim();
LessonPlanManagement.UpdateBrand(updateBrand);
Message("Data Updated Successfully !");
fillgrid();
}
}
private void Delete()
{
LessonPlanManagement.DeleteBrand(int.Parse(Session["PCID"].ToString()));
Message("Data Deleted Successfully !");
Reset();
Session["PCID"] = null;
fillgrid();
}
private bool CheckDuplicate(string BrandName)
{
bool ReturnValue = false;
List<Brand> CategoryList = new List<Brand>();
CategoryList = LessonPlanManagement.getAllBrand();
var lnqProject = from bus in CategoryList
where bus.Brand_Name.ToLower() == BrandName.ToLower()
select bus;
if (lnqProject.Count() > 0)
{
ReturnValue = true;
}
return ReturnValue;
}
private bool CheckDuplicateForEdit(string CategoryName)
{
bool ReturnValue = false;
List<Brand> BrandList = new List<Brand>();
BrandList = LessonPlanManagement.getAllBrand();
var lnqProject = from bus in BrandList
where bus.Brand_Name.ToLower() == CategoryName.ToLower() && bus.Brand_ID != int.Parse(Session["PCID"].ToString())
select bus;
if (lnqProject.Count() > 0)
{
ReturnValue = true;
}
return ReturnValue;
}
void Message(string msg)
{
UserControl_Message uc = (UserControl_Message)this.Page.FindControl("MessageID");
if (uc != null)
{
Label lb = (Label)uc.FindControl("LblModalMessage");
lb.Text = msg;
uc.Visible = true;
AjaxControlToolkit.ModalPopupExtender modal = (AjaxControlToolkit.ModalPopupExtender)uc.FindControl("modalMessage");
modal.Show();
}
}
private void Reset()
{
TxtBrand.Text = "";
TxtBrandDescription.Text = "";
}
public void fillgrid()
{
Brand cat = new Brand();
var lnqcatDetails = from c in LessonPlanManagement.getAllBrand()
select c;
if (lnqcatDetails.ToList().Count > 0)
{
GridView1.DataSource = lnqcatDetails.ToList();
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
#endregion
}
-------------------------------------------
Create Procedure [dbo].[InsertBrand]
(
@Brand_Name varchar(50),
@Brand_Description varchar(150)
)
AS
BEGIN
Insert into Brand (Brand_Name,Brand_Description)
Values
(@Brand_Name,@Brand_Description)
END
---------------------
Create Procedure [dbo].[UpdateBrand]
(
@Brand_ID int,
@Brand_Name varchar(50),
@Brand_Description varchar(100)
)
as begin
update Brand Set
Brand_Name=@Brand_Name,Brand_Description=@Brand_Description
where Brand_ID=@Brand_ID
end
-----------------------
ALTER PROCEDURE [dbo].[DeleteBrand]
(
@Brand_ID int
)
as
begin
Delete from Brand where Brand_ID=@Brand_ID
end
------------------
ALTER PROCEDURE [dbo].[SelectBrand]
as
begin
Select Brand_ID,Brand_Name,Brand_Description from Brand
end
--------------
------------------------
#region Brand
public static void InsertBrand(Brand cls)
{
// con = new SqlConnection(Connection.MyConnection());
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
cmd = new SqlCommand("InsertBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Brand_Name", cls.Brand_Name);
cmd.Parameters.AddWithValue("@Brand_Description", cls.Brand_Description);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static DataTable getAllBrand()
{
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
//con = new SqlConnection(Connection.MyConnection());
cmd = new SqlCommand("SelectBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter();
da.SelectCommand = cmd;
dt = new DataTable();
da.Fill(dt);
return dt;
}
public static void UpdateBrand(Brand c)
{
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
//con = new SqlConnection(Connection.MyConnection());
cmd = new SqlCommand("UpdateBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Brand_ID", c.Brand_ID);
cmd.Parameters.AddWithValue("@Brand_Name", c.Brand_Name);
cmd.Parameters.AddWithValue("@Brand_Description", c.Brand_Description);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
public static void DeleteBrand(int cid)
{
con = new SqlConnection("Server=USER-PC;Database=Emart4u;uid=sa;pwd=linku");
cmd = new SqlCommand("DeleteBrand", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Brand_ID", cid);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
#endregion
-------------------
Business Layer
-------------------------
#region Brand
public static void InsertBrand(Brand cls)
{
LessonPlanDataAccess.InsertBrand(cls);
}
public static List<Brand> getAllBrand()
{
List<Brand> BrandList = new List<Brand>();
DataTable dt = LessonPlanDataAccess.getAllBrand();
foreach (DataRow row in dt.Rows)
{
Brand c = new Brand();
c.Brand_ID = int.Parse(row["Brand_ID"].ToString());
c.Brand_Name = row["Brand_Name"].ToString();
c.Brand_Description = row["Brand_Description"].ToString();
BrandList.Add(c);
}
return BrandList;
}
public static void UpdateBrand(Brand c)
{
LessonPlanDataAccess.UpdateBrand(c);
}
public static void DeleteBrand(int cid)
{
LessonPlanDataAccess.DeleteBrand(cid);
}
#endregion
------------------------------------------
object layer
---------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Brand
/// </summary>
///
[Serializable]
public class Brand
{
public Brand()
{
//
// TODO: Add constructor logic here
//
}
public int Brand_ID
{
get;
set;
}
public string Brand_Name
{
get;
set;
}
public string Brand_Description
{
get;
set;
}
}-----------------------------------------
Design
----------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Brand.aspx.cs" Inherits="Projects_Brand" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="~/UserControl/U_Message.ascx" TagName="Message" TagPrefix="Mes"%>
<!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></title>
<style type="text/css">
.EmptyMessage
{
font-family: Arial;
color:Red;
font-size:16px;
font-weight:bold;
}
.TabStyle
{
height:460px;
overflow:inherit;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="TabStyle">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TabContainer ID="TabContainerBrand" runat="server" Style="height: auto; width: auto">
<asp:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" >Display</asp:LinkButton>
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Brand_ID" onrowcommand="GridView1_RowCommand"
onrowediting="GridView1_RowEditing" >
<Columns>
<asp:TemplateField HeaderText="BrandName">
<ItemTemplate>
<asp:LinkButton ID="ImgBtnEdit" runat="server" CausesValidation="false" ImageUrl="~/Images/edit.png"
CommandName="Edit" CommandArgument='<%# Eval("Brand_ID") %>' Text='<%# Eval("Brand_Name") %>'/></ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Description" DataField="Brand_Description">
</asp:BoundField>
</Columns>
</asp:GridView>
</asp:Panel>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="Tabpanel2" runat="server">
<HeaderTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">Entry</asp:LinkButton>
</HeaderTemplate>
<ContentTemplate>
<asp:Panel ID="Panel2" runat="server">
<table class="style1">
<tr>
<td colspan="2">
Brand
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td style="text-align: right">
<asp:Label ID="Label1" runat="server" Text="Brand Name :"></asp:Label>
</td>
<td>
<asp:TextBox ID="TxtBrand" runat="server" Height="24px" Width="221px"></asp:TextBox>
<span class="EmptyMessage">
<asp:RequiredFieldValidator ID="req1" runat="server" ErrorMessage="Enter Brand Name"
ControlToValidate="TxtBrand" SetFocusOnError="true" ValidationGroup="1">*</asp:RequiredFieldValidator>
</span>
</td>
</tr>
<tr>
<td style="text-align: right" width="40%">
<asp:Label ID="Label2" runat="server" Text="Brand Description :"></asp:Label>
</td>
<td width="60%">
<asp:TextBox ID="TxtBrandDescription" runat="server" Height="24px" Width="221px"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="BtnSave" runat="server" Text="Save" ValidationGroup="1" onclick="BtnSave_Click" />
<asp:Button ID="BtnCancel" runat="server" Text="Cancel"
onclick="BtnCancel_Click" />
</td
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
<Mes:Message ID="MessageID" runat="server" />
<asp:ValidationSummary ID="val1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="1" />
</div>
</form>
</body>
</html>
-------------------------------------------
C# Code
------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Projects_Brand : System.Web.UI.Page
{
#region Events
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillgrid();
}
}
protected void BtnSave_Click(object sender, EventArgs e)
{
if (BtnSave.Text == "Save")
{
if (TxtBrand.Text != "")
{
if (CheckDuplicate(TxtBrand.Text) == false)
{
Save();
fillgrid();
}
else
{
Message("Data Alredy Exists !");
}
}
}
else
{
if (CheckDuplicateForEdit(TxtBrand.Text) == false)
{
update();
fillgrid();
}
else
{
Message("Data Alredy Exists !");
}
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Reset();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
fillgrid();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
int catID = int.Parse(e.CommandArgument.ToString());
Session["PCID"] = catID;
Brand c = new Brand();
var catlist = from p in LessonPlanManagement.getAllBrand()
where p.Brand_ID == catID
select p;
if (catlist.ToList().Count > 0)
{
TabContainerBrand.ActiveTabIndex = 1;
Tabpanel2.Visible = true;
TxtBrand.Text = catlist.ToList()[0].Brand_Name.ToString();
TxtBrandDescription.Text = catlist.ToList()[0].Brand_Description.ToString();
BtnSave.Text = "Update";
BtnCancel.Text = "Delete";
}
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
e.Cancel = true;
}
protected void BtnCancel_Click(object sender, EventArgs e)
{
if (BtnCancel.Text == "Cancel")
{
Reset();
}
else
{
Delete();
}
}
#endregion
#region Methods
private void Save()
{
Brand InsertBrand = new Brand();
if (Session["PCID"] != null)
{
if (TxtBrand.Text.Length > 0)
{
update();
Reset();
}
else
{
Message("Data Already Exists !");
}
}
else
{
if (TxtBrand.Text.Length > 0)
{
if (CheckDuplicate(TxtBrand.Text.Trim()) == false)
{
InsertBrand.Brand_Name = TxtBrand.Text;
//InsertCategory.Parent_Category_ID = int.Parse(DdlParentCategory.SelectedValue.ToString());
InsertBrand.Brand_Description = TxtBrandDescription.Text;
LessonPlanManagement.InsertBrand(InsertBrand);
Message("Data Inserted Successfully !");
Reset();
}
else
{
Message("Data Already Exists !");
}
TxtBrand.Focus();
}
}
}
private void update()
{
if (Session["PCID"].ToString() != null)
{
Brand updateBrand = new Brand();
updateBrand.Brand_ID = int.Parse(Session["PCID"].ToString());
updateBrand.Brand_Name = TxtBrand.Text.Trim();
updateBrand.Brand_Description = TxtBrandDescription.Text.Trim();
LessonPlanManagement.UpdateBrand(updateBrand);
Message("Data Updated Successfully !");
fillgrid();
}
}
private void Delete()
{
LessonPlanManagement.DeleteBrand(int.Parse(Session["PCID"].ToString()));
Message("Data Deleted Successfully !");
Reset();
Session["PCID"] = null;
fillgrid();
}
private bool CheckDuplicate(string BrandName)
{
bool ReturnValue = false;
List<Brand> CategoryList = new List<Brand>();
CategoryList = LessonPlanManagement.getAllBrand();
var lnqProject = from bus in CategoryList
where bus.Brand_Name.ToLower() == BrandName.ToLower()
select bus;
if (lnqProject.Count() > 0)
{
ReturnValue = true;
}
return ReturnValue;
}
private bool CheckDuplicateForEdit(string CategoryName)
{
bool ReturnValue = false;
List<Brand> BrandList = new List<Brand>();
BrandList = LessonPlanManagement.getAllBrand();
var lnqProject = from bus in BrandList
where bus.Brand_Name.ToLower() == CategoryName.ToLower() && bus.Brand_ID != int.Parse(Session["PCID"].ToString())
select bus;
if (lnqProject.Count() > 0)
{
ReturnValue = true;
}
return ReturnValue;
}
void Message(string msg)
{
UserControl_Message uc = (UserControl_Message)this.Page.FindControl("MessageID");
if (uc != null)
{
Label lb = (Label)uc.FindControl("LblModalMessage");
lb.Text = msg;
uc.Visible = true;
AjaxControlToolkit.ModalPopupExtender modal = (AjaxControlToolkit.ModalPopupExtender)uc.FindControl("modalMessage");
modal.Show();
}
}
private void Reset()
{
TxtBrand.Text = "";
TxtBrandDescription.Text = "";
}
public void fillgrid()
{
Brand cat = new Brand();
var lnqcatDetails = from c in LessonPlanManagement.getAllBrand()
select c;
if (lnqcatDetails.ToList().Count > 0)
{
GridView1.DataSource = lnqcatDetails.ToList();
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
#endregion
}
-------------------------------------------
Create Procedure [dbo].[InsertBrand]
(
@Brand_Name varchar(50),
@Brand_Description varchar(150)
)
AS
BEGIN
Insert into Brand (Brand_Name,Brand_Description)
Values
(@Brand_Name,@Brand_Description)
END
---------------------
Create Procedure [dbo].[UpdateBrand]
(
@Brand_ID int,
@Brand_Name varchar(50),
@Brand_Description varchar(100)
)
as begin
update Brand Set
Brand_Name=@Brand_Name,Brand_Description=@Brand_Description
where Brand_ID=@Brand_ID
end
-----------------------
ALTER PROCEDURE [dbo].[DeleteBrand]
(
@Brand_ID int
)
as
begin
Delete from Brand where Brand_ID=@Brand_ID
end
------------------
ALTER PROCEDURE [dbo].[SelectBrand]
as
begin
Select Brand_ID,Brand_Name,Brand_Description from Brand
end
--------------