在C#中的BusinessLogic层中

时间:2010-03-10 14:55:47

标签: business-logic

现在,我编写了businessLogic层。

在这个项目中,Table的列名是:

Product,
UM,
ProductGroup,
ProductCode,
ProductName,
BuyingPrice,
SellingPrice,
IsActive,
IsDeleted

然后

我编写了存储过程,它们是:

1.  Product_SelectList
2.  Product_SelectByProduct
3.  Product_SelectByUM
4.  Product_SelectByProductType
5.  Product_SelectByProductGroup
6.  Product_Insert
7.  Prodct_Update
8.  Product_DeleteByProduct
9.  Product_DeleteUM
10. Product_DeleteByProductType
11. Product_DeleteByProductGroup

我在存储过程中编写了Product_SelectByProduct

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Product_SeleteByProduct]
@Product char(36)
AS
Begin
Select
Product,
UM,
ProductType,
ProductGroup,
ProductCode,
ProductName,
BuyingPrice,
SellingPrice,
IsActive,
IsDeleted
from Product
Where Product=@Product
End

我在businesslogic图层中写了Product_SelectByProduct

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections .ObjectModel ;
using System.Data ;

namespace Inventory.BusinessLogic
{
    public class ProductInfo
    {
        private string _product;
        public string Product
        {
            get { return _product; }
            set { _product = value; }
        }

        private string _uM;
        public string UM
        {
            get { return _uM; }
            set { _uM = value; }
        }

        private string _productType;
        public string ProductType
        {
            get { return _productType; }
            set { _productType = value; }
        }

        private string _productGroup;
        public string ProductGroup
        {
            get { return _productGroup; }
            set { _productGroup = value; }
        }

        private string _productCode;
        public string ProductCode
        {
            get { return _productCode; }
            set { _productCode = value; }
        }

        private string _productName;
        public string ProductName
        {
            get { return _productName; }
            set { _productName = value; }
        }

        private string _buyingPrice;
        public string BuyingPrice
        {
            get { return _buyingPrice; }
            set { _buyingPrice = value; }

        }

        private string _sellingPrice;
        public string SellingPrice
        {
            get { return _sellingPrice; }
            set { _sellingPrice = value; }
        }

        private Boolean _isActive;
        public Boolean IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }

        private Boolean _isDeleted;
        public Boolean IsDeleted
        {
            get { return _isDeleted; }
            set { _isDeleted = value; }
        }
    }


    public class ProductCollections : Collection<ProductInfo>
    { }

    public class ProductController
    {
        Inventory.DataAccess.ProductDataController dataAccess;

        public ProductController()
        {
            dataAccess = new Inventory.DataAccess.ProductDataController();
        }

        public void Insert(ProductInfo productInfo)
        {
            dataAccess.Insert(productInfo.Product, productInfo.UM, productInfo.ProductType,
                productInfo.ProductGroup, productInfo.ProductCode, productInfo.BuyingPrice, productInfo.ProductName,
                productInfo.SellingPrice, productInfo.IsActive, productInfo.IsDeleted);
        }

        public void Update(ProductInfo productInfo)
        {
            dataAccess.Update(productInfo.Product, productInfo.UM, productInfo.ProductType,
                productInfo.ProductGroup, productInfo.ProductCode, productInfo.BuyingPrice, productInfo.ProductName,
                productInfo.SellingPrice, productInfo.IsActive, productInfo.IsDeleted);
        }


        public void DeleteByProduct(string Product)
        {
            dataAccess.DelectByProduct(Product);
        }

        public void DeleteByProductType(string ProductType)
        {
            dataAccess.DeleteByProductType(ProductType);
        }

        public void DeleteByUM(string UM)
        {
            dataAccess.DeleteByUM(UM);
        }

        public void DeleteByProductGroup(string ProductGoup)
        {
            dataAccess.DeleteByProductGroup(ProductGoup);
        }


        public ProductInfo SeletcByProduct(string Product)
        {
            IDataReader Reader = dataAccess.SelectByProduct(Product);
            ProductInfo productInfo = new ProductInfo();

            if (Reader.Read())
            {
                productInfo.Product = Convert.ToString(Reader["Product"]);
                productInfo.UM = Convert.ToString(Reader["UM"]);
                productInfo.ProductType = Convert.ToString(Reader["ProductType"]);
                productInfo.ProductGroup = Convert.ToString(Reader["ProductGroup"]);
                productInfo.ProductCode = Convert.ToString(Reader["ProductCode"]);
                productInfo.ProductName = Convert.ToString(Reader["ProductName"]);
                productInfo.BuyingPrice = Convert.ToString(Reader["BuyingPrice"]);
                productInfo.SellingPrice = Convert.ToString(Reader["SellingPrice"]);
                productInfo.IsActive = Convert.ToBoolean(Reader["IsActive"]);
                productInfo.IsDeleted = Convert.ToBoolean(Reader["IsDeleted"]);

            }
            Reader.Close();
            return productInfo;
        }

现在,我想要Product_SelectByProductType

这是Product_SelectByProductType的存储过程

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER Procedure [dbo].[Product_SelectByProductType]
@ProductType char(36)
As
Begin
Select 
ProductType,
ProductTypeDescription,
IsActive,
IsDefault,
IsDeleted
from ProductType
Where ProductType=@ProductType
End

如何在C#

的businesslogic层中编写product_SelectByProductType

请帮帮我

1 个答案:

答案 0 :(得分:0)

这里有一个如何在C#中执行存储过程的示例 http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx