Add Item Sub Category
<%@ Page Title="Add New Sub Category" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Add_ItemSubCategory.aspx.cs" Inherits="Watson.Stock.Add_ItemSubCategory" %>
<%@ Register src="../UserControl/Notification.ascx" tagname="Notification" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
function ShowPopup(message) {
$(function () {
$("#dialog").dialog({
title: "Item Category Popup",
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
});
};
</script>
<div id="dialog" style="display: block" >
<asp:GridView ID="grdvwCat" runat="server" CssClass="gridview"
onselectedindexchanged="grdvwCat_SelectedIndexChanged"
onrowcreated="grdvwCat_RowCreated" onrowdatabound="grdvwCat_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<<<<<<< .mine
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
=======
>>>>>>> .r146
</div>
<div class="divTable">
<div class="divRow">
<div class="divColumn" style="width:100%;">
<uc1:Notification ID="Notification1" runat="server" />
</div>
</div>
</div>
<div class="divTable">
<br />
<div class="divRow" style="text-align:left">
<asp:Label ID="lblSubCatHeader" runat="server"
Text="Add New Sub Category" Font-Bold="True" Font-Size="20px"></asp:Label>
</div>
</div>
<asp:Panel ID="pnl_addItmSubCatgry" CssClass="paneldashbord" Width="94%" runat="server">
<div class="divTable">
<div class="divRow" style="width: 100%">
<div class="divColumn" style="width:10%">
<asp:Label ID="lblCatName" runat="server" Text="Name:"></asp:Label>
</div>
<div class="divColumn" style="width:30%">
<asp:TextBox ID="txtSubCatName" runat="server" Width="95%"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtSubCatName" ErrorMessage="*"
ValidationGroup="valgrpCat" ForeColor="Red" ToolTip="Name is required"><img
src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
<asp:Label ID="lblNamerror" runat="server" Text="Name is already exist"
Visible="False"></asp:Label>
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
<div class="divRow">
<div class="divRow">
<div class="divColumn" style="width:10%">
<asp:Label ID="Label1" runat="server" Text="Category"></asp:Label>
:</div>
<div class="divColumn" style="width:30%">
<asp:TextBox ID="txtCatName" runat="server" Width="95%" ReadOnly="True"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:Button ID="btnAddCat" runat="server" onclick="btnAddCat_Click" Text="--" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtCatName" ErrorMessage="*" ForeColor="Red"
ValidationGroup="valgrpCat" ToolTip="category is required"><img
src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
<asp:HiddenField ID="hdnfldCatId" runat="server" />
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
</div>
<div class="divRow" style="width: 100%">
<div class="divColumn" style="width:10%">
<asp:Label ID="lblCatDes" runat="server" Text="Description:"></asp:Label>
</div>
<div class="divColumn" style="width:30%">
<asp:TextBox ID="txtSubCatDes" runat="server" TextMode="MultiLine" Width="95%"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtSubCatDes" ErrorMessage="*"
ValidationGroup="valgrpCat" ForeColor="Red"
ToolTip="Description is required"><img
src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
<div class="divRow" style="height:120px">
</div>
<div class="divRow">
</div>
<div class="divRow" style="width: 100%">
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:30% ">
<div class="divColumn" style="width:40%; text-align:right;">
<asp:Button ID="btnSave" runat="server"
Text="Save" ValidationGroup="valgrpCat" onclick="btnSave_Click"
CssClass="btn_sav" />
</div>
<div class="divColumn" style="width:60%; text-align:right;">
<asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click"
Text="Cancel" CssClass="btn_cnl" />
</div>
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
</div>
</asp:Panel>
</asp:Content>
........................................................................................................................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DALWatsans;
namespace Watson.Stock
{
public partial class Add_ItemSubCategory : System.Web.UI.Page
{
public DALItem dalItem;
public Add_ItemSubCategory()
{
dalItem = new DALItem();
}
protected void Page_Load(object sender, EventArgs e)
{
Notification1.HideMessages();
//check session of catid and name
if (Session["catid"] != null && Session["catname"] != null)
{
txtCatName.Text = Session["catname"].ToString();
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("View_ItemSubCategory.aspx");
}
protected void btnSave_Click(object sender, EventArgs e)
{
string subcatname = txtSubCatName.Text.Trim();
int catid = Convert.ToInt32(hdnfldCatId.Value);
string subcatdes = txtSubCatDes.Text.Trim();
int result = dalItem.SetItemSubCategory(subcatname, catid, subcatdes);
if (result == 2)
{
Notification1.FindControl("noticmsg").Visible = true;
Label lblnotice = (Label)Notification1.FindControl("lblnotice");
lblnotice.Text = Common.Common.GerErrorMessage("DE-02");
Cleartxt();
}
else
{
lblNamerror.Visible = false;
Notification1.FindControl("sucmsg").Visible = true;
Label lblsuccess = (Label)Notification1.FindControl("lblsuccess");
lblsuccess.Text = Common.Common.GerErrorMessage("DE-00");
Cleartxt();
}
}
protected void btnAddCat_Click(object sender, EventArgs e)
{
//SetGridData();
//pnl_addItmSubCatgry.Visible = false;
//pnl_selectCategory.Visible = true;
DataSet dtst = dalItem.GetItemCategory();
grdvwCat.DataSource = dtst;
grdvwCat.DataBind();
string message = "Message from server side";
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
}
protected void SetGridData()
{
DataSet dtst = dalItem.GetItemCategory();
grdvwCat.DataSource = dtst;
grdvwCat.DataBind();
}
#region Clear all Text Box
/// <summary>
/// Clear all text fields .
/// Set Wizad active step as 0.
/// </summary>
private void Cleartxt()
{
foreach (Control cntrol in EnumerateControlsRecursive(Page))
{
if (cntrol is TextBox)
{
TextBox txt = (TextBox)cntrol;
txt.Text = string.Empty;
}
else if (cntrol is DropDownList)
{
DropDownList ddl = (DropDownList)cntrol;
ddl.SelectedIndex = 0;
}
}
}
/// <summary>
/// Recursive function for get controls
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
#endregion
protected void grdvwCat_SelectedIndexChanged(object sender, EventArgs e)
{
hdnfldCatId.Value = grdvwCat.SelectedRow.Cells[1].Text.ToString();
txtCatName.Text = grdvwCat.SelectedRow.Cells[2].Text.ToString();
//pnl_addItmSubCatgry.Visible = true;
//pnl_selectCategory.Visible = false;
}
protected void grdvwCat_RowCreated(object sender, GridViewRowEventArgs e)
{
}
protected void grdvwCat_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = "NEW TEXT";
}
}
}
<%@ Register src="../UserControl/Notification.ascx" tagname="Notification" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
function ShowPopup(message) {
$(function () {
$("#dialog").dialog({
title: "Item Category Popup",
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
});
};
</script>
<div id="dialog" style="display: block" >
<asp:GridView ID="grdvwCat" runat="server" CssClass="gridview"
onselectedindexchanged="grdvwCat_SelectedIndexChanged"
onrowcreated="grdvwCat_RowCreated" onrowdatabound="grdvwCat_RowDataBound">
<Columns>
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<<<<<<< .mine
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
=======
>>>>>>> .r146
</div>
<div class="divTable">
<div class="divRow">
<div class="divColumn" style="width:100%;">
<uc1:Notification ID="Notification1" runat="server" />
</div>
</div>
</div>
<div class="divTable">
<br />
<div class="divRow" style="text-align:left">
<asp:Label ID="lblSubCatHeader" runat="server"
Text="Add New Sub Category" Font-Bold="True" Font-Size="20px"></asp:Label>
</div>
</div>
<asp:Panel ID="pnl_addItmSubCatgry" CssClass="paneldashbord" Width="94%" runat="server">
<div class="divTable">
<div class="divRow" style="width: 100%">
<div class="divColumn" style="width:10%">
<asp:Label ID="lblCatName" runat="server" Text="Name:"></asp:Label>
</div>
<div class="divColumn" style="width:30%">
<asp:TextBox ID="txtSubCatName" runat="server" Width="95%"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtSubCatName" ErrorMessage="*"
ValidationGroup="valgrpCat" ForeColor="Red" ToolTip="Name is required"><img
src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
<asp:Label ID="lblNamerror" runat="server" Text="Name is already exist"
Visible="False"></asp:Label>
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
<div class="divRow">
<div class="divRow">
<div class="divColumn" style="width:10%">
<asp:Label ID="Label1" runat="server" Text="Category"></asp:Label>
:</div>
<div class="divColumn" style="width:30%">
<asp:TextBox ID="txtCatName" runat="server" Width="95%" ReadOnly="True"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:Button ID="btnAddCat" runat="server" onclick="btnAddCat_Click" Text="--" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtCatName" ErrorMessage="*" ForeColor="Red"
ValidationGroup="valgrpCat" ToolTip="category is required"><img
src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
<asp:HiddenField ID="hdnfldCatId" runat="server" />
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
</div>
<div class="divRow" style="width: 100%">
<div class="divColumn" style="width:10%">
<asp:Label ID="lblCatDes" runat="server" Text="Description:"></asp:Label>
</div>
<div class="divColumn" style="width:30%">
<asp:TextBox ID="txtSubCatDes" runat="server" TextMode="MultiLine" Width="95%"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtSubCatDes" ErrorMessage="*"
ValidationGroup="valgrpCat" ForeColor="Red"
ToolTip="Description is required"><img
src="../Images/exclamation.png" /></asp:RequiredFieldValidator>
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
<div class="divRow" style="height:120px">
</div>
<div class="divRow">
</div>
<div class="divRow" style="width: 100%">
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:30% ">
<div class="divColumn" style="width:40%; text-align:right;">
<asp:Button ID="btnSave" runat="server"
Text="Save" ValidationGroup="valgrpCat" onclick="btnSave_Click"
CssClass="btn_sav" />
</div>
<div class="divColumn" style="width:60%; text-align:right;">
<asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click"
Text="Cancel" CssClass="btn_cnl" />
</div>
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
<div class="divColumn" style="width:20%">
</div>
<div class="divColumn" style="width:10%">
</div>
</div>
</div>
</asp:Panel>
</asp:Content>
........................................................................................................................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DALWatsans;
namespace Watson.Stock
{
public partial class Add_ItemSubCategory : System.Web.UI.Page
{
public DALItem dalItem;
public Add_ItemSubCategory()
{
dalItem = new DALItem();
}
protected void Page_Load(object sender, EventArgs e)
{
Notification1.HideMessages();
//check session of catid and name
if (Session["catid"] != null && Session["catname"] != null)
{
txtCatName.Text = Session["catname"].ToString();
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("View_ItemSubCategory.aspx");
}
protected void btnSave_Click(object sender, EventArgs e)
{
string subcatname = txtSubCatName.Text.Trim();
int catid = Convert.ToInt32(hdnfldCatId.Value);
string subcatdes = txtSubCatDes.Text.Trim();
int result = dalItem.SetItemSubCategory(subcatname, catid, subcatdes);
if (result == 2)
{
Notification1.FindControl("noticmsg").Visible = true;
Label lblnotice = (Label)Notification1.FindControl("lblnotice");
lblnotice.Text = Common.Common.GerErrorMessage("DE-02");
Cleartxt();
}
else
{
lblNamerror.Visible = false;
Notification1.FindControl("sucmsg").Visible = true;
Label lblsuccess = (Label)Notification1.FindControl("lblsuccess");
lblsuccess.Text = Common.Common.GerErrorMessage("DE-00");
Cleartxt();
}
}
protected void btnAddCat_Click(object sender, EventArgs e)
{
//SetGridData();
//pnl_addItmSubCatgry.Visible = false;
//pnl_selectCategory.Visible = true;
DataSet dtst = dalItem.GetItemCategory();
grdvwCat.DataSource = dtst;
grdvwCat.DataBind();
string message = "Message from server side";
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "');", true);
}
protected void SetGridData()
{
DataSet dtst = dalItem.GetItemCategory();
grdvwCat.DataSource = dtst;
grdvwCat.DataBind();
}
#region Clear all Text Box
/// <summary>
/// Clear all text fields .
/// Set Wizad active step as 0.
/// </summary>
private void Cleartxt()
{
foreach (Control cntrol in EnumerateControlsRecursive(Page))
{
if (cntrol is TextBox)
{
TextBox txt = (TextBox)cntrol;
txt.Text = string.Empty;
}
else if (cntrol is DropDownList)
{
DropDownList ddl = (DropDownList)cntrol;
ddl.SelectedIndex = 0;
}
}
}
/// <summary>
/// Recursive function for get controls
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
#endregion
protected void grdvwCat_SelectedIndexChanged(object sender, EventArgs e)
{
hdnfldCatId.Value = grdvwCat.SelectedRow.Cells[1].Text.ToString();
txtCatName.Text = grdvwCat.SelectedRow.Cells[2].Text.ToString();
//pnl_addItmSubCatgry.Visible = true;
//pnl_selectCategory.Visible = false;
}
protected void grdvwCat_RowCreated(object sender, GridViewRowEventArgs e)
{
}
protected void grdvwCat_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow ||
e.Row.RowType == DataControlRowType.Header ||
e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = "NEW TEXT";
}
}
}