ASP.NET 2.0数据操作之创建业务逻辑层
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-22
ing System.Configuration; 4using System.Web; 5using System.Web.Security; 6using System.Web.UI; 7using System.Web.UI.WebControls; 8using System.Web.UI.WebControls.WebParts; 9using System.Web.UI.HtmlControls; 10using NorthwindTableAdapters; 11 12[System.ComponentModel.DataObject] 13public class ProductsBLL 14{ 15 private ProductsTableAdapter _productsAdapter = null; 16 protected ProductsTableAdapter Adapter 17 { 18 get { 19 if (_productsAdapter == null) 20 _productsAdapter = new ProductsTableAdapter(); 21 22 return _productsAdapter; 23 } 24 } 25 26 27[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)] 28 public Northwind.ProductsDataTable GetProducts() 29 { 30 return Adapter.GetProducts(); 31 } 32 33 [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)] 34 public Northwind.ProductsDataTable GetProductByProductID(int productID) 35 { 36 return Adapter.GetProductByProductID(productID); 37 } 38 39[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)] 40 public Northwind.ProductsDataTable GetProductsByCategoryID(int categoryID) 41 { 42 return Adapter.GetProductsByCategoryID(categoryID); 43 } 44 45[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)] 46 public Northwind.ProductsDataTable GetProductsBySupplierID(int supplierID) 47 { 48 return Adapter.GetProductsBySupplierID(supplierID); 49 } 50 [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)] 51 public bool AddProduct(string productName, int? supplierID, int? categoryID, string quantityPerUnit, 52 decimal? unitPrice, short? unitsInStock, short? unitsOnOrder, short? reorderLevel, 53 bool discontinued) 54 { 55 // 新建一个ProductRow实例 56 Northwind.ProductsDataTable products = new Northwind.ProductsDataTable(); 57 Northwind.ProductsRow product = products.NewProductsRow(); 58 59 product.ProductName = productName; 60 if (supplierID == null) product.SetSupplierIDNull(); else product.SupplierID = supplierID.Value; 61 if (categoryID == null) product.SetCategoryIDNull(); else product.CategoryID = categoryID.Value; 62 if (quantityPerUnit == null) product.SetQuantityPerUnitNull(); else product.QuantityPerUnit = quantityPerUnit; 63 if (unitPrice == null) product.SetUnitPriceNull(); else product.UnitPrice = unitPrice.Value; 64 if (unitsInStock == null) product.SetUnitsInStockNull(); else product.UnitsInStock = unitsInStock.Value; 65 if (unitsOnOrder == null) product.SetUnitsOnOrderNull(); else product.UnitsOnOrder = unitsOnOrder.Value; 66 if (reorderLevel == null) product.SetReorderLevelNull(); else product.ReorderLevel = reorderLevel.Value; 67 product.Discontinued = discontinued; 68 69 // 添加新产品 70 products.AddProductsRow(product); 71 int rowsAffected = Adapter.Update(products); 72 73 // 如果刚好新增了一条记录,则返回true,否则返回false 74 ret |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: ASP.NET 2.0中创建内容页下一篇: ASP.NET 2.0中执行数据库操作命令之一
关于ASP.NET 2.0数据操作之创建业务逻辑层的所有评论