Monday, 7 January 2013

NTIRE


DATA OBJECT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DO
{
  public  class TAGGING_Category
    {
        public int Category_ID
        {
            get;
            set;
        }
        public string Category_Name
        {
            get;
            set;
        }
        public string Category_Description
        {
            get;
            set;
        }
        public int Parent_Category_ID
        {
            get;
            set;
        }
        public string Parent_Category_Name
        {
            get;
            set;
        }
        public string Created_On
        {
            get;
            set;
        }
        public int Created_By
        {
            get;
            set;
        }
        public string Modified_On
        {
            get;
            set;
        }
        public int Modified_By
        {
            get;
            set;
        }
        public bool Is_Active
        {
            get;
            set;
        }
        public bool Is_Deleted
        {
            get;
            set;
        }
        public string StoreName
        {
            get;
            set;
        }
        public string Description
        {
            get;
            set;
        }
        public DataTable StoreDetails
        {
            get;
            set;
        }
        public object Out { get; set; }
    }
}

DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swash.Objects;
using System.Data;
using System.Data.SqlClient;

namespace Swash.DataAccessLayer
{
    public partial class ERPDataAccess
    {
        public void InsertCategory(TAGGING_Category obj)
        {
          
            SqlCommand cm = new SqlCommand("Inventory.KC_InsertCategory");
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Category_Name", obj.Category_Name);
            cm.Parameters.AddWithValue("@Category_Description", obj.Category_Description);
            cm.Parameters.AddWithValue("@Parent_Category_ID",obj.Parent_Category_ID);
            cm.Parameters.AddWithValue("@Created_By", obj.Created_By);
            cm.Parameters.AddWithValue("@Mark", 1);
            ExecuteStoredProcedure(cm);
        }
        public void UpdateCategory(TAGGING_Category obj)
        {
            SqlCommand cm = new SqlCommand("Inventory.KC_InsertCategory");
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Category_ID", obj.Category_ID);
            cm.Parameters.AddWithValue("@Category_Name", obj.Category_Name);
            cm.Parameters.AddWithValue("@Category_Description", obj.Category_Description);
            cm.Parameters.AddWithValue("@Parent_Category_ID", obj.Parent_Category_ID);
            cm.Parameters.AddWithValue("@Modified_By", obj.Modified_By);
            cm.Parameters.AddWithValue("@Mark", 2);
            ExecuteStoredProcedure(cm);
        }
        public void DeleteCategory(TAGGING_Category obj)
        {
            SqlCommand cm = new SqlCommand("Inventory.KC_InsertCategory");
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Category_ID", obj.Category_ID);
            cm.Parameters.AddWithValue("@Modified_By", obj.Modified_By);
            cm.Parameters.AddWithValue("@Mark", 3);
            ExecuteStoredProcedure(cm);
        }
        public DataTable GetCategoryData()
        {
            SqlCommand cm = new SqlCommand("Inventory.KC_InsertCategory");
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Mark", 4);
            return ExecuteGetDataTable(cm);
        }
        public DataTable GetCategoryData1()
        {
            SqlCommand cm = new SqlCommand("Inventory.KC_InsertCategory");
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Mark", 5);
            return ExecuteGetDataTable(cm);
        }

    }
}

INTEGRATION
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swash.Objects;
using Swash.DataAccessLayer;
using System.Data;

namespace Swash.IntegrationLayer
{
    public partial class ERPIntegration
    {

        public static void InsertCategory(TAGGING_Category obj)
        {
            ERPDataAccess.GetInstance.InsertCategory(obj);
        }
        public static void UpdateCategory(TAGGING_Category obj)
        {
            ERPDataAccess.GetInstance.UpdateCategory(obj);
        }
        public static void DeleteCategory(TAGGING_Category obj)
        {
            ERPDataAccess.GetInstance.DeleteCategory(obj);
        }
        public static List<TAGGING_Category> GetCategoryData()
        {
            DataTable dt = new DataTable();
            dt.Clear();
            dt.Reset();
            dt = ERPDataAccess.GetInstance.GetCategoryData();
            List<TAGGING_Category> lis = new List<TAGGING_Category>();
            foreach (DataRow dr in dt.Rows)
            {
                TAGGING_Category obj = new TAGGING_Category();
                obj.Category_ID = Convert.ToInt32(dr["Category_ID"]);
                obj.Category_Name = dr["Category_Name"].ToString();
                obj.Category_Description = dr["Category_Description"].ToString();
                if (dr["Parent_Category_Name"].ToString() == "")
                    obj.Parent_Category_Name = "";
                else
                    obj.Parent_Category_Name = dr["Parent_Category_Name"].ToString();
                obj.Parent_Category_ID = Convert.ToInt32(dr["Parent_Category_ID"]);
                obj.Created_On = dr["Created_On"].ToString();
                obj.Created_By = Convert.ToInt32(dr["Created_By"]);
                if (dr["Modified_On"].ToString() != "")
                    obj.Modified_On = dr["Modified_On"].ToString();
                if (dr["Modified_By"].ToString() != "")
                    obj.Modified_By = Convert.ToInt32(dr["Modified_By"]);
                obj.Is_Active = Convert.ToBoolean(dr["Is_Active"].ToString());
                obj.Is_Deleted = Convert.ToBoolean(dr["Is_Deleted"].ToString());
                lis.Add(obj);
            }
            return lis;
        }
        public static List<TAGGING_Category> GetCategoryData1()
        {
            DataTable dt = new DataTable();
            dt.Clear();
            dt.Reset();
            dt = ERPDataAccess.GetInstance.GetCategoryData1();
            List<TAGGING_Category> lis = new List<TAGGING_Category>();
            foreach (DataRow dr in dt.Rows)
            {
                TAGGING_Category obj = new TAGGING_Category();
                obj.Category_ID = Convert.ToInt32(dr["Category_ID"]);
                obj.Category_Name = dr["Category_Name"].ToString();
                lis.Add(obj);
            }
            return lis;
        }
    }
}

CACHE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swash.Objects;
using Swash.IntegrationLayer;

namespace Swash.CacheLayer
{
    public partial class ERPCache
    {
        public static void InsertCategory(TAGGING_Category obj)
        {
            ERPIntegration.InsertCategory(obj);
        }
        public static void UpdateCategory(TAGGING_Category obj)
        {
            ERPIntegration.UpdateCategory(obj);
        }
        public static void DeleteCategory(TAGGING_Category obj)
        {
            ERPIntegration.DeleteCategory(obj);
        }
        public static List<TAGGING_Category> GetCategoryData()
        {
            return ERPIntegration.GetCategoryData();
        }
        public static List<TAGGING_Category> GetCategoryData1()
        {
            return ERPIntegration.GetCategoryData1();
        }
    }
}

BO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swash.Objects;
using Swash.CacheLayer;

namespace Swash.BusinessLayer
{
    public partial class ERPManagement
    {

        public void InsertCategory(TAGGING_Category obj)
        {
            string Context = "ERPManagement.InsertCategory()";
            try
            {
                ERPCache.InsertCategory(obj);

            }
            catch (Exception ex)
            {
                throw (new Exception(Context, ex));
            }
        }
        public void UpdateCategory(TAGGING_Category obj)
        {
            string Context = "ERPManagement.UpdateCategory()";
            try
            {
                ERPCache.UpdateCategory(obj);

            }
            catch (Exception ex)
            {
                throw (new Exception(Context, ex));
            }
        }
        public void DeleteCategory(TAGGING_Category obj)
        {
            string Context = "ERPManagement.DeleteCategory()";
            try
            {
                ERPCache.DeleteCategory(obj);

            }
            catch (Exception ex)
            {
                throw (new Exception(Context, ex));
            }
        }
        public List<TAGGING_Category> GetCategoryData()
        {
            string Context = "ERPManagement.GetCategoryData()";
            try
            {
                return ERPCache.GetCategoryData();
            }
            catch (Exception ex)
            {
                throw (new Exception(Context, ex));
            }
        }
        public List<TAGGING_Category> GetCategoryData1()
        {
            string Context = "ERPManagement.GetCategoryData1()";
            try
            {
                return ERPCache.GetCategoryData1();
            }
            catch (Exception ex)
            {
                throw (new Exception(Context, ex));
            }
        }
    }
}

PROCEDURE
ALTER PROCEDURE  [Inventory].[KC_InsertCategory]
       (
       @Category_ID INT=null,
       @Category_Name VARCHAR(50)=null,
       @Category_Description VARCHAR(MAX)=null,
       @Parent_Category_ID INT=null,
       @Created_By   INT=null,
       @Modified_On DATETIME=null,
       @Modified_By INT=null,
       @Mark INT
       )
AS
BEGIN
        SET NOCOUNT ON
        
IF @Mark=1
   
       BEGIN
          DECLARE @chars NCHAR(36)
       SET @chars = N'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'


              DECLARE @result NCHAR(2)
              SET @result = SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
                                  + SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
                              -- + SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)
                              -- + SUBSTRING(@chars, CAST((RAND() * LEN(@chars)) AS INT) + 1, 1)

              --SELECT @result


       INSERT INTO Inventory.MST_Category
        (Category_Name,
        Category_Code,
        Category_Description,
        Parent_Category_ID,
        Created_By
       )
       VALUES
       (@Category_Name,
       @result,
        @Category_Description,
        @Parent_Category_ID,
        @Created_By
       )
        END
else if @Mark=2
        UPDATE Inventory.MST_Category
        SET
        Category_Name=@Category_Name,
        Category_Description=@Category_Description,
        Parent_Category_ID=@Parent_Category_ID,
        Modified_On=GETDATE(),
        Modified_By=@Modified_By
        WHERE Category_ID=@Category_ID
        
else if @Mark=3
     UPDATE Inventory.MST_Category
     SET
     Is_Active=0,
        Is_Deleted=1,
     Modified_On=GETDATE(),
     Modified_By=@Modified_By
     WHERE Category_ID=@Category_ID
 
else if @Mark=4

        WITH category1(Category_ID,Parent_Category_Name)
        AS
        (SELECT Category_ID,Category_Name
         FROM Inventory.MST_Category WHERE Is_Active=1 )
        
        SELECT a.Category_ID,Category_Name,Category_Description,Parent_Category_ID,b.Parent_Category_Name,
        CONVERT(VARCHAR,Created_On,103) Created_On,Created_By,
        CONVERT(VARCHAR,Modified_On,103) Modified_On,Modified_By,Is_Active,Is_Deleted
        FROM Inventory.MST_Category a
        LEFT OUTER JOIN category1 b
        ON a.Parent_Category_ID=b.Category_ID  WHERE Is_Active=1 AND Is_Deleted=0
        
else if @Mark=5

        SELECT Category_ID,Category_Name FROM Inventory.MST_Category  WHERE Is_Active=1 AND Is_Deleted=0 union select 00,'Select'  
        SET NOCOUNT OFF
        END
UI PAGE
 Swash.BusinessLayer.ERPManagement obj1 = new ERPManagement();
        TAGGING_Category obj = new TAGGING_Category();

No comments:

Post a Comment