分享

中间层组件(1)

 悟静 2012-02-16

中间层组件(1)

这个示例的数据访问功能封装在中间层组件中,将数据库与网页区分开来。相关文件位于App_Code文件夹中的BLL及DAL这两个子文件夹中,BLL包含了业务逻辑类文件CategoryBLL.cs及LessonBLL.cs,数据访问的功能则位于DAL文件夹的LessonDAL.xsd数据集文件。我们从数据访问层的数据集开始,来看看中间层的内容。将LessonDAL.xsd打开,内容如下:

 

其中的两个TableAdapter包含了用来更新及回传数据表内容所需的SQL语句,它们的内容非常简单,提供相关的SELECT、INSERT及UPDATE等SQL语句,并且通过BLL文件夹里面的类进行引用与网页沟通。本书的前面章节已经针对这一部分进行了完整的说明。现在,我们进一步讨论BLL里面的两个类文件,CategoryBLL.cs及LessonBLL.cs。

CategoryBLL.cs这个文件负责提供所需的程序代码,引用数据访问层的TableAdapter,针对Category数据表内的数据进行访问,内容如下:

namespace Kangting.Learning.Bll
{
[System.ComponentModel.DataObject]
public class CategoryBLL
{
[System.ComponentModel.DataObjectMethodAttribute(
System.ComponentModel.DataObjectMethodType.Select)]
public LessonDAL.CategoryDataTable GetCategories()
{
LessonDALTableAdapters.CategoryTableAdapter categoryTA =
new LessonDALTableAdapters.CategoryTableAdapter();
LessonDAL.CategoryDataTable categoryDT =  
categoryTA.GetData();
return categoryDT;
}
[System.ComponentModel.DataObjectMethodAttribute(
System.ComponentModel.DataObjectMethodType.Select)]
public LessonDAL.CategoryDataTable GetCategories(int
categoryID)
{
      LessonDALTableAdapters.CategoryTableAdapter categoryTA =
new LessonDALTableAdapters.CategoryTableAdapter();
LessonDAL.CategoryDataTable categoryDT =
categoryTA.GetDataByCID(categoryID);
return categoryDT;
}
[System.ComponentModel.DataObjectMethodAttribute(
System.ComponentModel.DataObjectMethodType.Insert )]
public int AddCategory(int categoryID, string categoryTitle,
int categoryParent,
string categoryImgUrl, string categoryDesc)
{
LessonDALTableAdapters.CategoryTableAdapter categoryTA =
new LessonDALTableAdapters.CategoryTableAdapter();
int returnValue = categoryTA.Insert(categoryID,
categoryTitle,
categoryParent, categoryImgUrl, categoryDesc);
return returnValue;
}
[System.ComponentModel.DataObjectMethodAttribute(
System.ComponentModel.DataObjectMethodType.Update)]
public int UpdateCategoryByID(string categoryTitle,
int categoryParent,
string categoryImageUrl
string categoryDesc, int CategoryID)
{
CategoryDALTableAdapters.CategoryTableAdapter categoryTA =
new CategoryDALTableAdapters.CategoryTableAdapter();
int returnValue =
categoryTA.UpdateCategoryByID(categoryTitle,
categoryParent, categoryImageUrl,
categoryDesc, CategoryID);
return returnValue;
}
[System.ComponentModel.DataObjectMethodAttribute(
System.ComponentModel.DataObjectMethodType.Delete )]
public int DeleteCategory(int categoryID)
{
CategoryDALTableAdapters.CategoryTableAdapter categoryTA =  
new CategoryDALTableAdapters.CategoryTableAdapter();
int returnValue = categoryTA.Delete(categoryID);
return returnValue;
}
}
}
【责任编辑

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多