首页 > 开发 > 综合 > 正文

深度剖析Duwamish 7.0 (1--数据结构)

2024-07-21 02:25:27
字体:
来源:转载
供稿:网友
不好意思啊,让大家久等了,第一次写这种文章,可能没有开心那么专业,废话少说,我们开始:

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,效率高点,但是代码太难看,难懂:(
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表