多层结构+存储过程应用的记录!采用Duwamish7的方法!
2004-11-26 18:07
399 查看
Asp.Net 多层结构,使用不带参数存储过程的简单例子。
给小安同学学习一下多层结构的应用和使用存储过程的方法,仿照Duwamish7的方式,以下只列出了主要的实现代码,命名空间引用等其他内容没有列出,可以跟我索取这个简单的例子!如果兄弟也是刚转到.Net上来,而且想采用多层结构来入门,研究研究这个倒会有点帮助的嘛!我觉得多层结构对于.Net来说并未有助于提高性能,倒是真麻烦。优点嘛,google上写的多的是!
高手就不用看了,有时间的话教教我喽,hoho……
![](http://www.cnblogs.com/Emoticons/QQ/49.gif)
*********************************************************************
共用:Common
商务层:BusinessFacade
数据层:DataAccess
表示层:Web
*********************************************************************
** 存储过程:
*********************************************************************
CREATE PROCEDURE GetCategories
AS
SELECT
NodeId, ParentId, NodeName, OrderId, Menu, Url
FROM News_Categories
ORDER BY OrderId
RETURN 0
GO
*********************************************************************
** Common
** namespace Test.Common.Data
*********************************************************************
public class NewsCategoryData : DataSet
{
public const String NEWS_CATEGORIES_TABLE = "News_Categories";
public const String NODE_ID_FIELD = "NodeId";
//省略相同部分
public NewsCategoryData()
{
//
// Create the tables in the dataset
//
BuildDataTables();
}
private void BuildDataTables()
{
//
// Create the Categories table
// 好象Petshop里也是用如下方法,确实不错!
//
DataTable table = new DataTable(NEWS_CATEGORIES_TABLE);
DataColumnCollection columns = table.Columns;
columns.Add(NODE_ID_FIELD, typeof(System.Int32));
columns.Add(PARENT_ID_FIELD, typeof(System.Int32));
columns.Add(NODE_NAME_FIELD, typeof(System.String));
columns.Add(ORDER_ID_FIELD, typeof(System.Int32));
columns.Add(MENU_FIELD, typeof(System.String));
columns.Add(URL_FIELD, typeof(System.String));
this.Tables.Add(table);
}
}
*********************************************************************
** DataAccess
** 使用不带参数的存储过程的例子
** namespace Test.DataAccess
*********************************************************************
public class NewsCategories
{
private SqlDataAdapter dsCommand;
public NewsCategories()
{
//
// TODO: 在此处添加构造函数逻辑
//
dsCommand = new SqlDataAdapter();
//
// 获取数据库链接
//
dsCommand.SelectCommand = new SqlCommand();
string ConnStr = ConfigurationSettings.AppSettings["ConnectionString"];
dsCommand.SelectCommand.Connection = new SqlConnection(ConnStr);
dsCommand.TableMappings.Add("Table", NewsCategoryData.NEWS_CATEGORIES_TABLE);
}
// Duwamish7中使用的是带参数的存储过程
public NewsCategoryData GetNewsCategories()
{
return FillNewsCategoryData("GetNewsCategories");
}
private NewsCategoryData FillNewsCategoryData(String commandText)
{
NewsCategoryData data = new NewsCategoryData();
SqlCommand command = dsCommand.SelectCommand;
command.CommandText = commandText;
command.CommandType = CommandType.StoredProcedure;
dsCommand.Fill(data);
return data;
}
}
*********************************************************************
** BusinessFacade
** namespace Test.BusinessFacade
*********************************************************************
public class ProductSystem
{
public NewsCategoryData GetNewsCategories()
{
NewsCategories accessNewsCategories = new NewsCategories();
return accessNewsCategories.GetNewsCategories();
}
}
*********************************************************************
** Web 层
** namespace Test.Web.manage
*********************************************************************
private void Page_Load(object sender, System.EventArgs e)
{
//
NewsCategoryData NewscategorySet;
ProductSystem productSystem;
DataView categoryView;
productSystem = new ProductSystem();
NewscategorySet = productSystem.GetNewsCategories();
categoryView = NewscategorySet.Tables[NewsCategoryData.NEWS_CATEGORIES_TABLE].DefaultView;
DataGrid1.DataSource=categoryView;
DataGrid1.DataBind();
}
*********************************************************************
给小安同学学习一下多层结构的应用和使用存储过程的方法,仿照Duwamish7的方式,以下只列出了主要的实现代码,命名空间引用等其他内容没有列出,可以跟我索取这个简单的例子!如果兄弟也是刚转到.Net上来,而且想采用多层结构来入门,研究研究这个倒会有点帮助的嘛!我觉得多层结构对于.Net来说并未有助于提高性能,倒是真麻烦。优点嘛,google上写的多的是!
高手就不用看了,有时间的话教教我喽,hoho……
![](http://www.cnblogs.com/Emoticons/QQ/49.gif)
*********************************************************************
共用:Common
商务层:BusinessFacade
数据层:DataAccess
表示层:Web
*********************************************************************
** 存储过程:
*********************************************************************
CREATE PROCEDURE GetCategories
AS
SELECT
NodeId, ParentId, NodeName, OrderId, Menu, Url
FROM News_Categories
ORDER BY OrderId
RETURN 0
GO
*********************************************************************
** Common
** namespace Test.Common.Data
*********************************************************************
public class NewsCategoryData : DataSet
{
public const String NEWS_CATEGORIES_TABLE = "News_Categories";
public const String NODE_ID_FIELD = "NodeId";
//省略相同部分
public NewsCategoryData()
{
//
// Create the tables in the dataset
//
BuildDataTables();
}
private void BuildDataTables()
{
//
// Create the Categories table
// 好象Petshop里也是用如下方法,确实不错!
//
DataTable table = new DataTable(NEWS_CATEGORIES_TABLE);
DataColumnCollection columns = table.Columns;
columns.Add(NODE_ID_FIELD, typeof(System.Int32));
columns.Add(PARENT_ID_FIELD, typeof(System.Int32));
columns.Add(NODE_NAME_FIELD, typeof(System.String));
columns.Add(ORDER_ID_FIELD, typeof(System.Int32));
columns.Add(MENU_FIELD, typeof(System.String));
columns.Add(URL_FIELD, typeof(System.String));
this.Tables.Add(table);
}
}
*********************************************************************
** DataAccess
** 使用不带参数的存储过程的例子
** namespace Test.DataAccess
*********************************************************************
public class NewsCategories
{
private SqlDataAdapter dsCommand;
public NewsCategories()
{
//
// TODO: 在此处添加构造函数逻辑
//
dsCommand = new SqlDataAdapter();
//
// 获取数据库链接
//
dsCommand.SelectCommand = new SqlCommand();
string ConnStr = ConfigurationSettings.AppSettings["ConnectionString"];
dsCommand.SelectCommand.Connection = new SqlConnection(ConnStr);
dsCommand.TableMappings.Add("Table", NewsCategoryData.NEWS_CATEGORIES_TABLE);
}
// Duwamish7中使用的是带参数的存储过程
public NewsCategoryData GetNewsCategories()
{
return FillNewsCategoryData("GetNewsCategories");
}
private NewsCategoryData FillNewsCategoryData(String commandText)
{
NewsCategoryData data = new NewsCategoryData();
SqlCommand command = dsCommand.SelectCommand;
command.CommandText = commandText;
command.CommandType = CommandType.StoredProcedure;
dsCommand.Fill(data);
return data;
}
}
*********************************************************************
** BusinessFacade
** namespace Test.BusinessFacade
*********************************************************************
public class ProductSystem
{
public NewsCategoryData GetNewsCategories()
{
NewsCategories accessNewsCategories = new NewsCategories();
return accessNewsCategories.GetNewsCategories();
}
}
*********************************************************************
** Web 层
** namespace Test.Web.manage
*********************************************************************
private void Page_Load(object sender, System.EventArgs e)
{
//
NewsCategoryData NewscategorySet;
ProductSystem productSystem;
DataView categoryView;
productSystem = new ProductSystem();
NewscategorySet = productSystem.GetNewsCategories();
categoryView = NewscategorySet.Tables[NewsCategoryData.NEWS_CATEGORIES_TABLE].DefaultView;
DataGrid1.DataSource=categoryView;
DataGrid1.DataBind();
}
*********************************************************************
相关文章推荐
- 身体好比什么都强 [唱片]
- 由触摸屏所联想到的软件界面设计
- 个性化CSDN blog的相关文章收集
- DEC的历史
- arcims开发经验总结(4) (arcIMS 客户端 连接器的选择)
- 设计模式-行为模式
- 还有一种情况会出现 ORA-00942:table or view does not exist
- Oracle: 删除当前用户的所有对象(表、视图、触发器、存储过程、函数)
- 全排列的泛型算法的简单实现
- 页面无刷新多框联动代码
- “Coding在西元前”——写给所有热爱C++的朋友
- 冥想
- 期货市场入门指南
- JBOSS jBPM 工作流管理系统简介
- 在Flash中使用XPath
- 利率期货
- 工作一个月了
- 真的是恋上你了
- 工作一个月了
- 一篇支持盗版的非常有力度的文章