天天看點

.NET資料庫程式設計求索之路--4.使用ADO.NET實作(三層架構篇-使用Table傳遞資料)(2)

4.使用ADO.NET實作(三層架構篇-使用Table傳遞資料)(2)

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 }

OrderItem.cs

 8     public class OrderItem

11         public OrderItem()

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

 8     public class OrderState

10         public string Code { set; get; }

11         public string Name { set; get; }

12     }

13 }