- 热门文章:
- · 用C#实现无需iiS环境就可以执行aspx文件
- · 解决一个比较奇怪的NET问题的方法
- · asp.net datagrid如何在最后一行作求和:
- · HTTPBrowserCapabilities---在asp.net中显示浏览器属性
- · 将xml作为DataGrid 操作(Sort, Edit, Delete)
- · 使用net classes访问其他网站内容
- · 在asp.net中调用Excel 文件
- · 如何利用RowFilter 属性从一个dataset中创建两个不同的datagrid
- · 使用.NET访问Internet(5) Paul_Ni(原作)(补充)
- · 使用.NET访问Internet(5) Paul_Ni(原作)
- · 使用.NET访问Internet(4) Paul_Ni(原作)(补充)
- · 使用.NET访问 Internet(3) Paul_Ni(原作)
上一篇:ASP.NET移植须知 >>
深度剖析Duwamish 7.0 (1--数据结构)
1.结构概述
Duwamish 7.0 结构分为四个逻辑层:
Web 层
Web 层为客户端提供对应用程序的访问。这一层是作为 Duwamish.sln 解决方案文件中的 Web 项目实现的。Web 层由 ASP.NET Web 窗体和代码隐藏文件组成。Web 窗体只是用 HTML 提供用户操作,而代码隐藏文件实现各种控件的事件处理。
业务外观层
业务外观层为 Web 层提供处理帐户、类别浏览和购书的界面。这一层是作为 Duwamish.sln 解决方案文件中的 BusinessFacade 项目实现的。业务外观层用作隔离层,它将用户界面与各种业务功能的实现隔离开来。除了低级系统和支持功能之外,对数据库服务器的所有调用都是通过此程序集进行的。
业务规则层
业务规则层是作为 Duwamish.sln 解决方案文件中的 BusinessRules 项目实现的,它包含各种业务规则和逻辑的实现。业务规则完成如客户帐户和书籍订单的验证这样的任务。
数据访问层
数据访问层为业务规则层提供数据服务。这一层是作为 Duwamish.sln 解决方案文件中的 DataAccess 项目实现的。
在这里,对于Duwamish 7.0的分布式结构我就不再罗嗦了,MSDN写的绝对比我好..
下面就从数据访问层开始解剖,我单独提出Customer这一段进行程序讲解:
1.CustomerData.cs(数据层)
Code:
//----------------------------------------------------------------
// Copyright (C) 2000-2001 Microsoft Corporation
// All rights reserved.
//
// This source code is intended only as a supplement to Microsoft
// Development Tools and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
// FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------
namespace Duwamish7.Common.Data
{
using System;
using System.Data;
using System.Runtime.Serialization;
/// <summary>
/// A custom serializable dataset containing customer information.
/// <remarks>
/// This class is used to define the shape of CustomerData.
/// </remarks>
/// <remarks>
/// The serializale constructor allows objects of type CustomerData to be remoted.
/// </remarks>
/// </summary>
[SerializableAttribute]
public class CustomerData : DataSet
{
//
//Customer constants
//
/// <value>The constant used for Customers table. </value>
public const String CUSTOMERS_TABLE = "Customers";
/// <value>The constant used for Email field in the Customers table. </value>
public const String EMAIL_FIELD = "Email";
/// <value>The constant used for Name field in the Customers table. </value>
public const String NAME_FIELD = "Name";
/// <value>The constant used for Address field in the Customers table. </value>
public const String ADDRESS_FIELD = "Address";
/// <value>The constant used for Country field in the Customers table. </value>
public const String COUNTRY_FIELD = "Country";
/// <value>The constant used for Password field in the Customers table. </value>
public const String PASSWORD_FIELD = "Password";
/// <value>The constant used for PhoneNumber field in the Customers table. </value>
public const String PHONE_FIELD = "PhoneNumber";
/// <value>The constant used for Fax field in the Customers table. </value>
public const String FAX_FIELD = "Fax";
/// <value>The constant used for PKId field in the Customers table. </value>
public const String PKID_FIELD = "PKId";
//
// Error messages
//
/// <value>The constant used for row error when @#Email Not Unique@# field in CustomerData. </value>
public const String EMAIL_FIELD_NOT_UNIQUE = "Email Not Unique";
/// <value>The constant used for row error when @#Email Invalid Format@# field in CustomerData. </value>
public const String EMAIL_FIELD_INVALID_FORMAT = "Email Invalid Format";
/// <value>The constant used for row error when there is an @#Invalid Field@# in CustomerData. </value>
public const String INVALID_FIELD = "Invalid Field";
/// <value>The constant used for error when @#Invalid Fields@# exist in CustomerData. </value>
public const String INVALID_FIELDS = "Invalid Fields";
/// <summary>
/// Constructor to support serialization.
/// <remarks>Constructor that supports serialization.</remarks>
/// <param name="info">The SerializationInfo object to read from.</param>
/// <param name="context">Information on who is calling this method.</param>
/// </summary>
public CustomerData(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
/// <summary>
/// Constructor for CustomerData.
/// <remarks>Initialize a CustomerData instance by building the table schema.</remarks>
/// </summary>
public CustomerData()
{
//
// Create the tables in the dataset
//
BuildDataTables();
}
//----------------------------------------------------------------
// Sub BuildDataTables:
// Creates the following datatables: Customers
//----------------------------------------------------------------
private void BuildDataTables()
{
//
// Create the Customers table
//
DataTable table = new DataTable(CUSTOMERS_TABLE);
DataColumnCollection columns = table.Columns;
DataColumn Column = columns.Add(PKID_FIELD, typeof(System.Int32));
Column.AllowDBNull = false;
Column.AutoIncrement = true;
columns.Add(EMAIL_FIELD, typeof(System.String));
columns.Add(PASSWORD_FIELD, typeof(System.String));
columns.Add(NAME_FIELD, typeof(System.String));
columns.Add(ADDRESS_FIELD, typeof(System.String)).AllowDBNull= false;
columns.Add(COUNTRY_FIELD, typeof(System.String)).AllowDBNull= false;
columns.Add(PHONE_FIELD, typeof(System.String)).AllowDBNull= false;
columns.Add(FAX_FIELD, typeof(System.String));
this.Tables.Add(table);
}
} //class CustomerData
} //namespace Duwamish7.Common.Data
大家可以看到,这里的CustomerData类继承与DataSet,详细定义字段名称以及有可能产生的出错信息,
并同时绘制出一张空表格。
OK,这里的代码非常简单,大家一看应该就可以明白。代码的技巧性非常强,以后的数据访问、交换、传递全部通过这里进行。
私底下认为,采用这种方法有利于团队协作,代码编辑也很简单。
但是,微软自己也说过dataset的效率没有datareader高,而dataset的灵活性远远超过于datareader,真搞不懂MS在企业事例中为什么采用Dataset,也许只是让我们学习其中的思想吧。
过两天再和大家谈谈另一种方法,采用datareader,效率高点,但是代码太难看,难懂:(
下一篇:用C#实现无需iiS环境就可以执行aspx文件 >>
相关文章:
- · 使用.NET访问Internet(4) Paul_Ni(原作)
- · 使用.NET访问 Internet(2) Paul_Ni(原作)
- · 修改后的Whois查询程序
- · 使用.NET访问 Internet(1) Paul_Ni(原作)
- · 如何取得动态装载的WEB CONTROL的属性值?
- · POP3 Client as a C# Class(转自CodeProject)
- · 饼图的一种画法(转载自aspcool)
- · 精品:Asp3.0中email有效性验证
- · 使用Div加速页面的显示(原创)
- · Creating DataGrid Templated Columns Dynamically - Part I(转自Dotnettips)
- · 关于asp.net的代码重用
- · Getting Datagrid Columns Keypress,Keyup, Keydown and other events to Fire(一个很好的东西)
- · runat=server
- · 关于上下文(Context)/2(转MS)
- · 关于上下文(Context)/1(转MS)
- · 在.NET中使用静态变量来代替Application变量
- · ASP.NET窗体对话框的实现
- · 用.NET创建定时缓存
- · 将Session值储存于SQL Server中
- · ASP.NET中的事务处理和异常处理
- · ASP.NET Caching /2
- · 嘿,懒鬼!!其实MSDN阐述得真得不错哎,不知道你从哪来的资料
- · ASP.NET Caching /1
- · 绝对酷,如何解决asp.net中javascript脚本的问题(使用服务器控件执行客户端脚本)
- · 最佳ASP.NET编程习惯
- · 一次同时上传多个文件
- · 在datagrid中求和(vb.net,c#)
- · ASP.NET中利用SQLXML WEB服务访问XML数据(转)
- · 在DataGrid中经弹出窗口确认后执行操作(删除)。(附在DataGrid中修改,添加记录)详见代码!!
- · 在datagrid中放入一个DropDownList(忘了这个问题在那里看到的了CSDN or There)
- · 简单的动态加载用户控件的方法
- · 关于如何 确认删除的另外一个办法。
- · 掉掉注意了,如何动态加载用户控件(ascx)
- · 给大家一个新的加密方法,C#的。(国外的,只用于学习,支持中文)
- · TO feixr,DataGrid中的Radiobutton
- · 微软.NET战略和ASP.NET简介(1)
- · 微软.NET战略和ASP.NET简介(3)
- · 微软.NET战略和ASP.NET简介(2)
