文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>MVC三层架构

MVC三层架构

时间:2010-09-17  来源:eva.xiao

 

Entities_ItemCategoryInfo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Entities
{
    public class ItemCategoryInfo
    {
        private int _CategoryID;

        public int CategoryID
        {
            get { return _CategoryID; }
            set { _CategoryID = value; }
        }
        private string _CategoryName;

        public string CategoryName
        {
            get { return _CategoryName; }
            set { _CategoryName = value; }
        }
    }
}

 

Business_ItemCategoryBLL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DALC;

namespace Business
{
    public class ItemCategoryBLL
    {
        ItemCategoryDALC itemCategoryDALC = new ItemCategoryDALC();
        public List<ItemCategoryInfo> GetAllCategoryList()
        {
            return itemCategoryDALC.GetAllCategoryList();
        }
        public List<ItemCategoryInfo> GetCategoryList(string CategoryName)
        {
           return itemCategoryDALC.GetCategoryList(CategoryName);
        }
        public int InsertCategory(string CategoryName)
        {
            return itemCategoryDALC.InsertCategory(CategoryName);
        }
        public int UpdateCategory(string NewName, int CategoryID)
        {
            return itemCategoryDALC.UpdateCategory(NewName, CategoryID);
        }
        public int DeleteCategory(int CategoryID)
        {
            return itemCategoryDALC.DeleteCategory(CategoryID);
        }
    }
}

 

DALC_ItemCategoryDALC

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using System.Data.SqlClient;

namespace DALC
{
    public class ItemCategoryDALC
    {
        SqlConnection _con = new SqlConnection(@"Data Source=stkwx028\sqlexpress;Initial Catalog=WMDemo_JDE;Integrated Security=True");
        List<ItemCategoryInfo> ItemCategoryList = new List<ItemCategoryInfo>();
        public List<ItemCategoryInfo> GetAllCategoryList()//get all Category List
        {
            List<ItemCategoryInfo> CategoryList = new List<ItemCategoryInfo>();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = _con;
            cmd.CommandText = "SELECT CategoryID,CategoryName FROM ItemCategory";
            _con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    ItemCategoryInfo itemCategoryInfo = new ItemCategoryInfo();
                    itemCategoryInfo.CategoryID = Convert.ToInt32(reader["CategoryID"]);
                    itemCategoryInfo.CategoryName = reader["CategoryName"].ToString();
                    ItemCategoryList.Add(itemCategoryInfo);
                }
                if (reader != null)
                {
                    reader.Close();
                }
                _con.Close();
                return ItemCategoryList;
            }
            else
            {
                if (reader != null)
                {
                    reader.Close();
                }
                _con.Close();
                return null;
            }
        }
        public List<ItemCategoryInfo> GetCategoryList(string CategoryName)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = _con;
            cmd.CommandText = "SELECT * FROM ItemCategory" +
                              " WHERE CategoryName LIKE '%'+@CategoryName+'%'" +
                              " ORDER BY CategoryID";
            cmd.Parameters.AddWithValue("@CategoryName", CategoryName);
            _con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    ItemCategoryInfo itemCategoryInfo = new ItemCategoryInfo();
                    itemCategoryInfo.CategoryID = Convert.ToInt32(reader["CategoryID"]);
                    itemCategoryInfo.CategoryName = reader["CategoryName"].ToString();
                    ItemCategoryList.Add(itemCategoryInfo);
                }
                if (reader != null)
                {
                    reader.Close();
                }
                _con.Close();
                return ItemCategoryList;
            }
            else
            {
                if (reader != null)
                {
                    reader.Close();
                }
                _con.Close();
                return null;
            }
        }
        public int InsertCategory(string CategoryName)
        {
            ItemCategoryInfo itemCategoryInfo = new ItemCategoryInfo();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = _con;
            cmd.CommandText = "INSERT INTO ItemCategory(CategoryName)" +
                                               " VALUES(@CategoryName)";
            cmd.Parameters.AddWithValue("@CategoryName", CategoryName);
            _con.Open();
            int i = cmd.ExecuteNonQuery();
            _con.Close();
            return i;
        }
        public int UpdateCategory(string NewName,int CategoryID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = _con;
            cmd.CommandText = "UPDATE ItemCategory" +
                              " SET CategoryName=@NewName" +
                              " WHERE CategoryID=@CategoryID";
            cmd.Parameters.AddWithValue("@NewName", NewName);
            //cmd.Parameters.AddWithValue("@OldName", OldName);
            cmd.Parameters.AddWithValue("@CategoryID", CategoryID);
            _con.Open();
            int i = cmd.ExecuteNonQuery();
            _con.Close();
            return i;
        }
        public int DeleteCategory(int CategoryID)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = _con;
            cmd.CommandText = "DELETE FROM ItemCategory" +
                              " WHERE CategoryID=@CategoryID";
            cmd.Parameters.AddWithValue("@CategoryID", CategoryID);
            _con.Open();
            int i = cmd.ExecuteNonQuery();
            _con.Close();
            return i;
        }

    }
}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载