Add Item Category
<%@ Page Title="Add New Category" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Add_ItemCategory.aspx.cs" Inherits="Watson.Stock.add_ItemCategory" %>
<%@ 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">
<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="lblCathHeader" runat="server"
Text="Add New Category" Font-Bold="True" Font-Size="20px"></asp:Label>
</div>
</div>
<asp:Panel ID="pnl_addItmCatgry" 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="txtCatName" runat="server" Width="95%"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="reqfldNm" runat="server"
ControlToValidate="txtCatName" 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>
<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="txtCatDes" runat="server" Width="95%" TextMode="MultiLine"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtCatDes" ErrorMessage="*" ForeColor="Red"
ValidationGroup="valgrpCat" 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: 100px">
</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%">
<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click"
ValidationGroup="valgrpCat" CssClass="btn_sav" />
</div>
<div class="divColumn" style="width:60%">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn_cnl"
onclick="btnCancel_Click" />
</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 DALWatsans;
namespace Watson.Stock
{
public partial class add_ItemCategory : System.Web.UI.Page
{
#region Variables
public DALItem dalItem;
#endregion
#region Constructor
public add_ItemCategory()
{
dalItem = new DALItem();
}
#endregion
#region Page Load Event
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
Notification1.HideMessages();
}
#endregion
#region Save Button Click Event
/// <summary>
/// Save New Item Category Details
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string catname = txtCatName.Text.ToString();
string catdescription = txtCatDes.Text.ToString();
int result = dalItem.SetItemCategory(catname, catdescription);
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();
// Response.Redirect("View_ItemCategory.aspx");
}
}
catch (Exception ex)
{
Notification1.FindControl("erormsg").Visible = true;
Label lblerror = (Label)Notification1.FindControl("lblerror");
lblerror.Text = ex.ToString();
}
}
#endregion
#region Cancel Button Click Event
/// <summary>
/// Cancel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("View_ItemCategory.aspx");
}
#endregion
#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
}
}
<%@ 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">
<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="lblCathHeader" runat="server"
Text="Add New Category" Font-Bold="True" Font-Size="20px"></asp:Label>
</div>
</div>
<asp:Panel ID="pnl_addItmCatgry" 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="txtCatName" runat="server" Width="95%"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="reqfldNm" runat="server"
ControlToValidate="txtCatName" 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>
<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="txtCatDes" runat="server" Width="95%" TextMode="MultiLine"></asp:TextBox>
</div>
<div class="divColumn" style="width:20%">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtCatDes" ErrorMessage="*" ForeColor="Red"
ValidationGroup="valgrpCat" 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: 100px">
</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%">
<asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click"
ValidationGroup="valgrpCat" CssClass="btn_sav" />
</div>
<div class="divColumn" style="width:60%">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn_cnl"
onclick="btnCancel_Click" />
</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 DALWatsans;
namespace Watson.Stock
{
public partial class add_ItemCategory : System.Web.UI.Page
{
#region Variables
public DALItem dalItem;
#endregion
#region Constructor
public add_ItemCategory()
{
dalItem = new DALItem();
}
#endregion
#region Page Load Event
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
Notification1.HideMessages();
}
#endregion
#region Save Button Click Event
/// <summary>
/// Save New Item Category Details
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string catname = txtCatName.Text.ToString();
string catdescription = txtCatDes.Text.ToString();
int result = dalItem.SetItemCategory(catname, catdescription);
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();
// Response.Redirect("View_ItemCategory.aspx");
}
}
catch (Exception ex)
{
Notification1.FindControl("erormsg").Visible = true;
Label lblerror = (Label)Notification1.FindControl("lblerror");
lblerror.Text = ex.ToString();
}
}
#endregion
#region Cancel Button Click Event
/// <summary>
/// Cancel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("View_ItemCategory.aspx");
}
#endregion
#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
}
}
0 comments:
Post a Comment