7.使用ADO.NET实现(工厂模式-实现多数据库切换)(4)
7.7 业务逻辑层HomeShop.BLL
OrderBiz.cs
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using HomeShop.Model;
7 using HomeShop.DALInterface;
8 using HomeShop.DALFactory;
9
10 namespace HomeShop.BLL
11 {
12 public class OrderBiz
13 {
14 private IOrderDAO dao;
15
16 public OrderBiz()
17 {
18 dao = (IOrderDAO)DataAccess.CreateDAO("OrderDAO");
19 }
20
21 public int Add(Order order)
22 {
23 return dao.Add(order);
24 }
25
26 public int Update(Order order)
27 {
28 return dao.Update(order);
29 }
30
31 public int Delete(int orderID)
32 {
33 return dao.Delete(orderID);
34 }
35
36 public List<Order> GetList()
37 {
38 return dao.GetList();
39 }
40
41 public List<Order> GetList(string customerName)
42 {
43 return dao.GetList(customerName);
44 }
45
46 public Order GetSingle(int orderID)
47 {
48 return dao.GetSingle(orderID);
49 }
50
51 }
52 }
OrderStateBiz.cs
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using HomeShop.Model;
7 using HomeShop.DALInterface;
8 using HomeShop.DALFactory;
9
10 namespace HomeShop.BLL
11 {
12 public class OrderStateBiz
13 {
14 private IOrderStateDAO dao;
15
16 public OrderStateBiz()
17 {
18 dao = (IOrderStateDAO)DataAccess.CreateDAO("OrderStateDAO");
19 }
20
21 public List<OrderState> GetList()
22 {
23 return dao.GetList();
24 }
25 }
26 }
7.7 界面层HomeShop.WinForm
App.config
1 <?xml version="1.0" encoding="utf-8" ?>
2 <configuration>
3 <connectionStrings>
4
5 <add name="HomeShop"
6 connectionString="Data Source=(local);Initial Catalog=HomeShop;Integrated Security=SSPI;" />
7 <!--
8 <add name="HomeShop"
9 connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=HomeShop.mdb;" />
10 -->
11 </connectionStrings>
12 <appSettings>
13
14 <add key="DAL" value="HomeShop.DALOfSql"/>
15 <!--
16 <add key="DAL" value="HomeShop.DALOfAccess"/>
17 -->
18 </appSettings>
19 </configuration>
为支持数据库切换,需要配置App.config文件,其它界面层代码同前。
(本章结束)
源码下载:/Files/SummerRain/NetDbDevRoad/7使用ADONET实现工厂模式DB切换.rar
数据下载:/Files/SummerRain/NetDbDevRoad/HomeShopDB.rar