电子商务之Common类库分析(三)
首先介绍下公共对象类库下的公共对象类
这些对象的作用就是简化数据传递操作,因为它们能够包含数据,并且为该信息提供统一的封装方法。
ShoppingCartEntity(购物车)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ShoppingCartEntity
{
public int ShoppingCartID { set; get; }
public string CartGUID { set; get; }
public int Quantity { set; get; }
public int ProductID { set; get; }
public DateTime DateCreated { set; get; }
}
}
ProductEntity类
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ProductEntity
{
public int ProductID { set; get; }
public int ProductCategoryID { set; get; }
public ProductCategoryEntity ProductCategory { set; get; }
public string ProductName { set; get; }
public string ProductImageName { set; get; }
public string ProductDescription { set; get; }
public int Quantity { set; get; }
public Decimal ProductPrice { set; get; }
public ProductEntity()
{
this.ProductCategory = new ProductCategoryEntity();
}
}
}
ProductCategoryEntity(产品种类)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ProductCategoryEntity
{
public int ProductCategoryID { set; get; }
public string ProductCategoryName { set; get; }
}
}
OrdersEntity(订单)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class OrdersEntity
{
public int OrderID { set; get; }
public int EndUserID { set; get; }
public EndUserEntity EndUser { set; get; }
public string TransactionID { set; get; }
public DateTime OrderDate { set; get; }
public AddressEntity ShippingAddress { set; get; }
public int OrderStatusID { set; get; }
public Decimal ShippingTotal { set; get; }
public OrderDetailsEntity OrderDetails { set; get; }
public Decimal SubTotal { set; get; }
public Decimal OrderTotal { set; get; }
public Decimal Tax { set; get; }
public CreditCardEntity CreditCard { set; get; }
public DateTime ShipDate { set; get; }
public string TrackingNumber { set; get; }
public OrdersEntity()
{
this.EndUser = new EndUserEntity();
this.ShippingAddress = new AddressEntity();
this.CreditCard = new CreditCardEntity();
this.OrderDetails = new OrderDetailsEntity();
}
}
}
OrderDetailsEntity(详细订单)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class OrderDetailsEntity
{
public int OrderDetailID { set; get; }
public int OrderID { set; get; }
public int ProductID { set; get; }
public ProductEntity[] Products { set; get; }
public int Quantity { set; get; }
}
}
Enums类(用户类别)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Text;
namespace Shop.Common
{
public class Enums
{
public enum EndUserType
{
CUSTOMER = 1,
ADMINISTRATOR = 2
}
}
}
EndUserTypeEntity类(用户类别)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class EndUserTypeEntity
{
public int EndUserTypeID { set; get; }
public string EndUserName { set; get; }
}
}
EndUserEntity(用户)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
/// <summary>
/// 用户实体类
/// </summary>
public class EndUserEntity
{
public int EndUserID { get; set; }
public int EndUserTypeID { set; get; }
public string UserName { set; get; }
public AddressEntity UserAddress { set; get; }
public int AddressID { set; get; }
public ContactInformationEntity UserContactInformation { set; get; }
public int ContactInformationID { set; get; }
public string Password { set; get; }
public bool IsSubscribed { set; get; }
public EndUserEntity()
{
this.UserAddress = new AddressEntity();
this.UserContactInformation = new ContactInformationEntity();
}
}
}
CreditCardEntity类(信用卡)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class CreditCardEntity
{
public AddressEntity Address { set; get; }
public string CardType { set; get; }
public int ExpMonth { set; get; }
public int ExpYear { set; get; }
public string Number { set; get; }
public string SecurityCode { set; get; }
}
}
ContactInformationEntity类 (联系信息)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class ContactInformationEntity
{
public int ContactInformationID { set; get; }
public string Phone { set; get; }
public string Phone2 { set; get; }
public string Fax { set; get; }
public string Email { set; get; }
}
}
AddressEntity类 (用户地址信息)
![](https://i-blog.csdnimg.cn/blog_migrate/34031c708bfe702fe82d01ff5c6593aa.gif)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Shop.Common
{
public class CreditCardEntity
{
public AddressEntity Address { set; get; }
public string CardType { set; get; }
public int ExpMonth { set; get; }
public int ExpYear { set; get; }
public string Number { set; get; }
public string SecurityCode { set; get; }
public CreditCardEntity()
{
this.Address = new AddressEntity();
}
}
}
从上看出基本上一张数据库表对应一个公共对象类,相信大家一扫都能明白。
以前做法就是编写一个公共对象类紧接着将它和对数据库操作的类放在一起的,不像这个系统放在一起,另外我也是不会在公共对象类中使用另外一种公共数据类型的,你看这里EndUserEntity类引用了AddressEntity类和ContactInformationEntity类(这样还要注意编写构造函数,这里的类不是静态的所以要记得new一个,在构造函数中完成它),要是以前设计是不会放进去的,我会分别构造这三个类。我觉得这样只用一个类就涵盖了所有的数据很方便,但是数据类型很复杂,如果考虑到在客户端调用webservice存储数据肯定就复杂了,不知道json能不能传这样的复杂数据。反正这样设计可能使设计思路更清晰,代码简洁了。可以在这个类库下多加几个文件,一个文件中放入一个系统模块所需要的公共对象类,我想在扩展时候,思路更清晰了。
上面有一个地方要注意一下就是smallmoney数据类型在数据对象变为Decima,以前会用double.不知道Decima会不会比double好?
不知道大家的设计思路是怎样的,我希望大家说出自己的设计的思路,大家共同学习嘛,也希望高人指点。
同系列文章
- 电子商务之框架分析(一)
- 电子商务之数据库分析(二)
- 电子商务之Common类库分析(三)
- 电子商务之集成选项分析(四)
- 电子商务之数据存储流程(五)
- 电子商务之存储过程分析(六)
- 电子商务之数据访问层分析(七)
- 电子商务之购物车分析(八)
- 电子商务之表示层分析(九)