在 C# 的 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
如何在businesslogic中写product_SelectByProductType C# 层
请帮助我
Now, I wrote businessLogic layer.
In this project, Table's column name are:
Product,
UM,
ProductGroup,
ProductCode,
ProductName,
BuyingPrice,
SellingPrice,
IsActive,
IsDeleted
and then
I wrote stored procedures, they are:
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
I wrote Product_SelectByProduct in stored procedure
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
I wrote Product_SelectByProduct in the businesslogic layer
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;
}
Now, I would like to Product_SelectByProductType
this is Product_SelectByProductType's stored procedure
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
how to write product_SelectByProductType in businesslogic layer in C#
please, help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是如何在 C# 中执行存储过程的示例
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07。 ASPX
here an example of how to execute a store procedure in C#
http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson07.aspx