SummerRain

软件开发/信息安全
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

4.使用ADO.NET实现(三层架构篇-使用Table传递数据)(2)

作者:夏春涛 xchunta@163.com

转载请注明来源:http://www.cnblogs.com/SummerRain/archive/2012/07/25/2609132.html 

4.3 实体层HomeShop.Model

Order.cs

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace HomeShop.Model
 7 {
 8     public class Order
 9     {
10         //构造函数,初始化成员变量
11         public Order()
12         {
13             this.OrderID = 0;
14             this.OrderTime = DateTime.Now;
15             this.OrderStateCode = "1";
16             this.OrderItems = new List<OrderItem>();
17             this.CustomerAddress = "";
18             this.CustomerName = "";
19             this.CustomerPhoneNo = "";
20         }
21 
22         public int OrderID { setget; }
23         public DateTime OrderTime { setget; }
24         public string OrderStateCode{ setget; }
25         public string CustomerName{ setget; }
26         public string CustomerPhoneNo { setget; }
27         public string CustomerAddress { setget; }
28         
29         //计算字段
30         public decimal OrderTotal {
31             get
32             {
33                 decimal total = 0m;
34                 if (this.OrderItems != null)
35                 {
36                     foreach (OrderItem orderItem in this.OrderItems)
37                     {
38                         total += (decimal)orderItem.Subtotal;
39                     }
40                 }
41                 return total;
42             }
43         }
44 
45         //关联属性
46         public List<OrderItem> OrderItems { setget; }
47     }
48 }

 

OrderItem.cs

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace HomeShop.Model
 7 {
 8     public class OrderItem
 9     {
10         //构造函数,初始化成员变量
11         public OrderItem()
12         {
13             OrderItemID = 0;
14             OrderID = 0;
15             Product = "";
16             UnitPrice = 0m;
17             Quantity = 0;
18         }
19 
20         public int OrderItemID { setget; }
21         public int OrderID { setget; }
22         public string Product { setget; }
23         public decimal UnitPrice { setget; }
24         public int Quantity { setget; }
25 
26         //计算字段
27         public decimal Subtotal
28         {
29             get
30             {
31                 return (decimal)UnitPrice * Quantity;
32 
33             }
34         }
35     }
36 }

 

OrderState.cs

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace HomeShop.Model
 7 {
 8     public class OrderState
 9     {
10         public string Code { setget; }
11         public string Name { setget; }
12     }
13 }

 

 

数据库文件:/Files/SummerRain/NetDbDevRoad/HomeShopDB.rar

完整源代码:/Files/SummerRain/NetDbDevRoad/4使用ADONET实现三层架构Table.rar