.NET数据库编程求索之路--4.使用ADO.NET实现(三层架构篇-使用Table传递数据)(2)
Posted on 2012-07-25 22:50 SummerRain 阅读(326) 评论(0) 编辑 收藏 举报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
分类:
.NET数据库编程求索之路
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架