Tuesday, October 22, 2013

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";
        }
    }
}

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
    }
}

Notification

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Notification.ascx.cs" Inherits="Watson.UserControl.Notification" %>
<div align="center">
    <div class="divTable">
     
        <div class="divRow" align="left">
            <div id="sucmsg" class="flash flash-success" runat="server">
                <asp:Label ID="lblsuccess" runat="server" Text="Label"></asp:Label>
            </div>
        </div>
        <div class="divRow" align="left">
            <!-- Success Flash Message -->
            <div id="msg" class="flash  flash-message" runat="server">
                <asp:Label ID="lblmessage" runat="server" Text="Label"></asp:Label>
            </div>
        </div>
        <div class="divRow" align="left">
            <div id="noticmsg" class="flash flash-notice" runat="server">
                <asp:Label ID="lblnotice" runat="server" Text="Label"></asp:Label>
            </div>
        </div>
        <div class="divRow" align="left">
            <div id="erormsg" class="flash flash-exclamation" runat="server">
                <asp:Label ID="lblerror" runat="server" Text="Label"></asp:Label>
            </div>
        </div>
    </div>
</div>
.................................................
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Watson.UserControl
{
    public partial class Notification : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region Hide Messages
        /// <summary>
        /// hide messages
        /// </summary>
        public void HideMessages()
        {

            sucmsg.Visible      = false;
            msg.Visible         = false;
            noticmsg.Visible    = false;
            erormsg.Visible = false;
        }
        #endregion
    }
}
...............css
.divTable
{
    width: 100%;
    display:block;
    margin-top:0px;
    max-width:100%;
           
   
}
.divRow
{
   width: 100%;
   display:block;
   padding-bottom:5px;
        
}
.divColumn
{
   float: left;
   width: 25%;
   display:block;
   text-align:left;
   padding-bottom:5px;
   min-height:30px;

}

ClearText

        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;
            }
        }

Stored Procedures

ALTER PROCEDURE [dbo].[usp_SetItemCategory]
    @ncName            nvarchar(100),
    @ncDesctiption  nvarchar(256)

       
AS
BEGIN
--Check to make sure the Name  does not already exist
    DECLARE @existing AS int = 0
    SELECT @existing=count(Name)
    FROM dbo.tbl_itemCategory
    WHERE Name=@ncName

    IF @existing > 0
    BEGIN
        RAISERROR ('Name is  already exists', 1, 1)
        RETURN 2
    END

    --Attempt insert
    INSERT INTO dbo.tbl_itemCategory
                (Name,
                 Desctiption,
                 Status)
            VALUES       
            (@ncName,
            @ncDesctiption,
            1)

            --check to see if insert occured
           --and return status
           IF @@ROWCOUNT = 1
                RETURN 1
           ELSE
                RETURN 0
        
END
..............................................................
  public int SetItemCategory(string name, string description)
        {

            int return_value = 0;
            SqlConnection Conn = DBConn.GetDbConnection();
            try
            {
               

                SqlCommand cmd = new SqlCommand("usp_SetItemCategory", Conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@ncName", name);
                cmd.Parameters.AddWithValue("@ncDesctiption", description);

                //get the return value from sp
                SqlParameter returnParam = new SqlParameter();
                returnParam.ParameterName = "returnValue";
                returnParam.Direction = ParameterDirection.ReturnValue;
                cmd.Parameters.Add(returnParam);

                cmd.ExecuteNonQuery();

                if (cmd.Parameters["returnValue"].Value.ToString() == "2")
                {
                    return_value = 2;
                }
                else if (cmd.Parameters["returnValue"].Value.ToString() == "1")
                {
                    return_value = 1;
                }


            }
            catch(Exception ex)
            {
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

           

                return return_value;
           

        }
...............................................Update Stored Procedure
ALTER PROCEDURE dbo.usp_UpdateItemCategory
    @inCatID        int,
    @ncName            nchar(100),
    @ncDesctiption  nchar(256)
AS
BEGIN
--Check to make sure the Name  does not already exist
    DECLARE @existing AS int = 0
    SELECT @existing=count(Name)
    FROM dbo.tbl_itemCategory
    WHERE Name=@ncName AND CatID!=@inCatID

    IF @existing > 0
    BEGIN
        RAISERROR ('Name is  already exists', 1, 1)
        RETURN 2
    END
    --attempt to update
    UPDATE tbl_itemCategory
    SET              
    Name =@ncName,
    Desctiption =@ncDesctiption
    WHERE(CatID=@inCatID)
       --and return status
          /* IF @@ROWCOUNT = 1
                RETURN 1
           ELSE
                RETURN 0*/
END
 

common.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

namespace Watson.Common
{
    public class Common
    {

        /// <summary>
        /// Read error message from error ID
        /// </summary>
        /// <param name="errorId"></param>
        /// <returns></returns>
        public static string GerErrorMessage(string errorId)
        {
            XmlDataDocument xmlDoc = new XmlDataDocument();
            string message = "Internal Error";
            string errorListFile = System.AppDomain.CurrentDomain.BaseDirectory + "ErrorList\\ErrorList.xml";

            xmlDoc.Load(errorListFile);

            XmlNodeList xmlList = xmlDoc.SelectNodes("root/ErroMessages/ErroMessage");

            if (xmlList != null)
            {
                foreach (XmlNode smsNode in xmlList)
                {
                    if (smsNode.SelectSingleNode("ErrorID").InnerText == errorId)
                    {

                        message = smsNode.SelectSingleNode("ErrorDescription").InnerText;
                        break;
                    }

                }
            }
            return message;
        }
    }
}

ErrorList.xml

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <ErroMessages>
    <!--Default error message-->

    <ErroMessage>
      <ErrorID>DE-00</ErrorID>
      <ErrorDescription>Successfully Save.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-01</ErrorID>
      <ErrorDescription>Unable to process.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-02</ErrorID>
      <ErrorDescription>Record already exists.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-03</ErrorID>
      <ErrorDescription>Unable to save.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-04</ErrorID>
      <ErrorDescription>Unable to update.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-05</ErrorID>
      <ErrorDescription>Successfully updated.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-06</ErrorID>
      <ErrorDescription>Unable to update,Record does not exists.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-07</ErrorID>
      <ErrorDescription>Successfully deleted.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-08</ErrorID>
      <ErrorDescription>Unable to delete,Record does not exists.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-09</ErrorID>
      <ErrorDescription>Unable to delete.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-10</ErrorID>
      <ErrorDescription>Server error.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-11</ErrorID>
      <ErrorDescription>Successfully activated.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-12</ErrorID>
      <ErrorDescription>Successfully inactivated.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>DE-13</ErrorID>
      <ErrorDescription>Successfully approved.</ErrorDescription>
    </ErroMessage>

    <!--Default error message-->

    <!--Customer error message-->
    <ErroMessage>
      <ErrorID>CU-01</ErrorID>
      <ErrorDescription>Invalid Customer.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>CU-02</ErrorID>
      <ErrorDescription>Contact Type alredy exist.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>CU-03</ErrorID>
      <ErrorDescription>Please add contact details.</ErrorDescription>
    </ErroMessage>
    <!--Customer error message-->

    <!--Transaction Type error message-->
    <ErroMessage>
      <ErrorID>TT-01</ErrorID>
      <ErrorDescription>No any transaction type.</ErrorDescription>
    </ErroMessage>
    <!--Transaction Type error message-->

    <!--Role error message-->
    <ErroMessage>
      <ErrorID>RM-01</ErrorID>
      <ErrorDescription>No any roles.</ErrorDescription>
    </ErroMessage>
    <!--Role error message-->

    <!--Limit variations error message-->
    <ErroMessage>
      <ErrorID>LV-01</ErrorID>
      <ErrorDescription>No any limit properties.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>LV-02</ErrorID>
      <ErrorDescription>Please select the limite code.</ErrorDescription>
    </ErroMessage>
    <!--Limit variations error message-->

    <!--Limit error message-->
    <ErroMessage>
      <ErrorID>LM-01</ErrorID>
      <ErrorDescription>No any limits.</ErrorDescription>
    </ErroMessage>
    <!--Limit error message-->

    <!--Funding source error message-->
    <ErroMessage>
      <ErrorID>FS-01</ErrorID>
      <ErrorDescription>No any funding sources.</ErrorDescription>
    </ErroMessage>
    <!--Funding source error message-->

    <!--Brand error message-->
    <ErroMessage>
      <ErrorID>BM-01</ErrorID>
      <ErrorDescription>No any Customer Segment.</ErrorDescription>
    </ErroMessage>
    <!--Brand error message-->

    <!--Agent error message-->
    <ErroMessage>
      <ErrorID>AM-01</ErrorID>
      <ErrorDescription>Please add contact details.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>AM-02</ErrorID>
      <ErrorDescription>Contact type alredy exists.</ErrorDescription>
    </ErroMessage>
    <!--Agent error message-->

    <!--Transaction template error message-->
    <ErroMessage>
      <ErrorID>TTe-01</ErrorID>
      <ErrorDescription>No any transaction templates.</ErrorDescription>
    </ErroMessage>
    <!--Transaction template error message-->

    <!--Transaction template attribute error message-->
    <ErroMessage>
      <ErrorID>TTA-01</ErrorID>
      <ErrorDescription>No any transaction template properties.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>TTA-02</ErrorID>
      <ErrorDescription>Please select the transaction template.</ErrorDescription>
    </ErroMessage>
    <!--Transaction template attribute error message-->

    <!--Customer type error message-->
    <ErroMessage>
      <ErrorID>CT-01</ErrorID>
      <ErrorDescription>No records available.</ErrorDescription>
    </ErroMessage>
    <!--Customer type error message-->

    <!--Brand assigned template error message-->
    <ErroMessage>
      <ErrorID>BAT-01</ErrorID>
      <ErrorDescription>No any brand templates.</ErrorDescription>
    </ErroMessage>
    <!--Brand assigned template error message-->

    <!--Fee template error message-->
    <ErroMessage>
      <ErrorID>FT-01</ErrorID>
      <ErrorDescription>No any fee templates.</ErrorDescription>
    </ErroMessage>
    <!--Fee template error message-->

    <!--Fee template Attribute error message-->
    <ErroMessage>
      <ErrorID>FTP-01</ErrorID>
      <ErrorDescription>No any fee template properties.</ErrorDescription>
    </ErroMessage>
    <!--Fee template Attribute error message-->

    <!--Slab template error message-->
    <ErroMessage>
      <ErrorID>ST-01</ErrorID>
      <ErrorDescription>No any slab templates.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>ST-01</ErrorID>
      <ErrorDescription>No any slab templates.</ErrorDescription>
    </ErroMessage>
    <!--Slab template error message-->

    <ErroMessage>
      <ErrorID>STA-01</ErrorID>
      <ErrorDescription>No any slab template properties.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>STA-02</ErrorID>
      <ErrorDescription>Invalid maximum value(maximum value should be greater than minimum value).</ErrorDescription>
    </ErroMessage>
    <!--Slab template error message-->

    <!--Tellers error message-->

    <ErroMessage>
      <ErrorID>BTA-01</ErrorID>
      <ErrorDescription>No any Teller properties.</ErrorDescription>
    </ErroMessage>


    <!--Teller error message-->

    <!--Admin creation error message-->
    <ErroMessage>
      <ErrorID>AC-01</ErrorID>
      <ErrorDescription>No any user detail.</ErrorDescription>
    </ErroMessage>
    <!--Admin creation error message-->

    <!--Agent creation error message-->
    <ErroMessage>
      <ErrorID>AGC-01</ErrorID>
      <ErrorDescription>No any detail.</ErrorDescription>
    </ErroMessage>
    <!--Agent creation error message-->

    <!--Commission-->
    <ErroMessage>
      <ErrorID>Com-01</ErrorID>
      <ErrorDescription>No any commission template.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>ComAtt-01</ErrorID>
      <ErrorDescription>No any commission template attribute.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>ComAtt-02</ErrorID>
      <ErrorDescription>Please select a commission template.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>ComAtt-03</ErrorID>
      <ErrorDescription>Total percentage should be 100.</ErrorDescription>

    </ErroMessage>

    <ErroMessage>
      <ErrorID>Tax-01</ErrorID>
      <ErrorDescription>No any tax template.</ErrorDescription>
    </ErroMessage>

    <!--File Upload-->
    <ErroMessage>
      <ErrorID>CFU-01</ErrorID>
      <ErrorDescription>File will be uploaded successfully.</ErrorDescription>
    </ErroMessage>
    <ErroMessage>
      <ErrorID>CFU-02</ErrorID>
      <ErrorDescription>Please select the file you need to upload.</ErrorDescription>
    </ErroMessage>
    <ErroMessage>
      <ErrorID>CFU-03</ErrorID>
      <ErrorDescription>Please select the correct file type.</ErrorDescription>
    </ErroMessage>
    <!--File Upload-->

    <!--Transaction History error message-->
    <ErroMessage>
      <ErrorID>TH-01</ErrorID>
      <ErrorDescription>No any transaction history records.</ErrorDescription>
    </ErroMessage>
    <!--Transaction History error message-->

    <!--Admin change password error message-->
    <ErroMessage>
      <ErrorID>ACP-01</ErrorID>
      <ErrorDescription>Your password has been successfully changed.</ErrorDescription>
    </ErroMessage>
    <!--Admin change password error message-->

    <!--teller error message-->

    <ErroMessage>
      <ErrorID>TM-01</ErrorID>
      <ErrorDescription>No any tellers.</ErrorDescription>
    </ErroMessage>

    <!-- teller error message -->

    <!--GL Accounts-->
    <ErroMessage>
      <ErrorID>GL-01</ErrorID>
      <ErrorDescription>No any GL Accounts.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>GM-01</ErrorID>
      <ErrorDescription>No any GL Mapping Details.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>GM-02</ErrorID>
      <ErrorDescription>Enter both debit and credit account.</ErrorDescription>
    </ErroMessage>

    <!--GL Accounts-->
    <ErroMessage>
      <ErrorID>RE-01</ErrorID>
      <ErrorDescription>No any detail found for this report.</ErrorDescription>
    </ErroMessage>

    <ErroMessage>
      <ErrorID>ufs-01</ErrorID>
      <ErrorDescription>No any funding source accounts for approval.</ErrorDescription>
    </ErroMessage>

  </ErroMessages>

</root>


Unhandle Exception with error Error.aspx and Application_Error

Error.aspx
    <form id="form1" runat="server">
    <div>
    <center>
  <div class="ContentHead">ERROR</div><br /><br />
  <asp:Label ID="Label_ErrorFrom" runat="server" Text="Label"></asp:Label><br /><br />
  <asp:Label ID="Label_ErrorMessage" runat="server" Text="Label"></asp:Label><br /><br />
</center>
    </div>
    </form>
..........
protected void Page_Load(object sender, EventArgs e)
        {
            Label_ErrorFrom.Text = Request["Err"].ToString();
            Label_ErrorMessage.Text = Request["InnerErr"].ToString();

        }

Global.asax
       void Application_Error(object sender, EventArgs e)
        {
            Exception myEx = Server.GetLastError();
            String RedirectUrlString = "~/Error.aspx?InnerErr=" +
                myEx.InnerException.Message.ToString() + "&Err=" + myEx.Message.ToString();
            Response.Redirect(RedirectUrlString);
            // Code that runs when an unhandled error occurs

        }

dal class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using System.Collections;


namespace DalLibrary
{
    public class DalPhone
    {
        /// <summary>
        /// get details of all phones
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllPhone()
        {
            using(SqlConnection conn=DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("usp_GetPhone", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    DataSet dtst = new DataSet();
                    adp.Fill(dtst);
                    return dtst;
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }

        /// <summary>
        /// get a phone details where by phone Id
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public DataSet GetPhoneById(ArrayList data)
        {
            using(SqlConnection conn=DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("sp", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@inId",data[0]);
                    SqlDataAdapter adp = new SqlDataAdapter(cmd);
                    DataSet dtst = new DataSet();
                    adp.Fill(dtst);
                    return dtst;
                }
                catch (Exception)
                {
                    throw;
                }
             
            }
        }

        /// <summary>
        /// insert a phone detail
        /// </summary>
        /// <param name="arrlst"></param>
        /// <returns></returns>
        public int SetPhoneData(ArrayList arrlst)
        {
            using(SqlConnection conn=DBConn.GetDbConnection())
            {
                try
                {
                    SqlCommand cmd = new SqlCommand("sp",conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@nvcName",arrlst[0]);
                    cmd.Parameters.AddWithValue("@inAge", arrlst[1]);

                    return cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public void SetPhoneData()
        {
            //throw new NotImplementedException();
            try
            {

            }
            catch (Exception)
            {
               
                throw;
            }
        }
    }
}

Popular Posts

Recent Posts

Text Widget

Powered by Blogger.

Find Us On Facebook

Flickr Images

Recent Posts

Video Of Day

Random Posts

Facebook

Random Posts

Advertising

Popular Posts