ASP.NET开发电子商务网站学习经验


前些阵子照着《Pro ASP.NET 2.0 E-Commerce in C#2005》书编辑了一个商务系统网站,想总结一下学习到的所学的知识。

该网站具有一般商务网站的特征

这里先讲讲他的框架

数据访问层

用的的存储过程操作数据库的存储,有一个Shop.DataAccess类库专门(注意我这里将原文的命名空间改为shop了)

该类库使用了一个组件来封装对数据库的操作 为 Microsoft Data Access Application Block, 其实就是将SQLHelper.cs复制到该类下就行了,该类可以自动管理存储过程的连接,参数和名称。

类库下的DataAccessBase类是一个基类,该类库几乎所有的类都会继承它,有两个属性一个是存储过程,以及返回数据库的连接字符串

注意:这里是从web.config文件中获取与数据库连接的字符串,但是在类中无法引用到Configuration类,所以我们要额外的添加引用System.Configuration.dll程序集

以下为引用的内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Shop.DataAccess
{
    
public class DataAccessBase
    {
        
//存储过程的名称
        protected string StoredprocedureName { setget; }

        
//获得连接字符串
        protected string ConnectionString
        {
            
get
            {
                
return ConfigurationManager.ConnectionStrings["db_shopConnectionString"].ToString();
            }
        }
    }

}

类库中的StoreProcedure类

利用枚举存储编写的存储过程名称,这样便于更改及管理

但是对于存储过程很多,一个类来存储肯定显得不够,个人建议在细分,控制一个类中的存储过程不超过20个

例如:

StoreProcedure_User,StoreProcedure_Product,StoreProcedure_Orders

以下为引用的内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shop.DataAccess
{
    
public class StoredProcedure
    {
        
public enum Name
        {
            ProductByID_Select,
            Products_Select,
            Products_SelectSerach,
            ShoppingCart_Select,
            ShoppingCart_Insert,
            ShoppingCart_Update,
            ShoppingCart_Delete,
            EndUser_Insert,
            EndUserLogin_Select,
            Address_Select,
            ContactInformation_Select,
            AdminLogin_Select,
            Product_Insert,
            ProductCategory_Select,
            Product_Update,
            Orders_Select,
            OrderDetails_Select,
            OrderAll_Select,
            OrderStatus_Select,
            OrdersByID_Select,
            Orders_Update,
            ProductPromotion_Select
        }
    }
}


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3