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 { set; get; }
23 public DateTime OrderTime { set; get; }
24 public string OrderStateCode{ set; get; }
25 public string CustomerName{ set; get; }
26 public string CustomerPhoneNo { set; get; }
27 public string CustomerAddress { set; get; }
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 { set; get; }
47 }
48 }
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 { set; get; }
23 public DateTime OrderTime { set; get; }
24 public string OrderStateCode{ set; get; }
25 public string CustomerName{ set; get; }
26 public string CustomerPhoneNo { set; get; }
27 public string CustomerAddress { set; get; }
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 { set; get; }
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 { set; get; }
21 public int OrderID { set; get; }
22 public string Product { set; get; }
23 public decimal UnitPrice { set; get; }
24 public int Quantity { set; get; }
25
26 //计算字段
27 public decimal Subtotal
28 {
29 get
30 {
31 return (decimal)UnitPrice * Quantity;
32
33 }
34 }
35 }
36 }
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 { set; get; }
21 public int OrderID { set; get; }
22 public string Product { set; get; }
23 public decimal UnitPrice { set; get; }
24 public int Quantity { set; get; }
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 { set; get; }
11 public string Name { set; get; }
12 }
13 }
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 { set; get; }
11 public string Name { set; get; }
12 }
13 }
数据库文件:/Files/SummerRain/NetDbDevRoad/HomeShopDB.rar
完整源代码:/Files/SummerRain/NetDbDevRoad/4使用ADONET实现三层架构Table.rar