7.使用ADO.NET实现(工厂模式-实现多数据库切换)(2)
7.3 数据访问层工厂HomeShop.DALFactory
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using System.Reflection;
7 using System.Configuration;
8
9 namespace HomeShop.DALFactory
10 {
11 public sealed class DataAccess
12 {
13 private static readonly string path = ConfigurationManager.AppSettings["DAL"];
14
15 private DataAccess() { }
16
17 public static Object CreateDAO(string className)
18 {
19 return Assembly.Load(path).CreateInstance(path + "." + className);
20 }
21 }
22 }
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using System.Reflection;
7 using System.Configuration;
8
9 namespace HomeShop.DALFactory
10 {
11 public sealed class DataAccess
12 {
13 private static readonly string path = ConfigurationManager.AppSettings["DAL"];
14
15 private DataAccess() { }
16
17 public static Object CreateDAO(string className)
18 {
19 return Assembly.Load(path).CreateInstance(path + "." + className);
20 }
21 }
22 }
7.4 数据访问层接口HomeShop.DALInterface
IOrderDAO.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using System.Data;
7 using HomeShop.Model;
8
9 namespace HomeShop.DALInterface
10 {
11 public interface IOrderDAO
12 {
13 int Add(Order order);
14 int Update(Order order);
15 int Delete(int orderID);
16 List<Order> GetList();
17 List<Order> GetList(string customerName);
18 Order GetSingle(int orderID);
19 }
20 }
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using System.Data;
7 using HomeShop.Model;
8
9 namespace HomeShop.DALInterface
10 {
11 public interface IOrderDAO
12 {
13 int Add(Order order);
14 int Update(Order order);
15 int Delete(int orderID);
16 List<Order> GetList();
17 List<Order> GetList(string customerName);
18 Order GetSingle(int orderID);
19 }
20 }
IOrderItemDAO.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using System.Data;
7 using HomeShop.Model;
8
9 namespace HomeShop.DALInterface
10 {
11 public interface IOrderItemDAO
12 {
13 List<OrderItem> GetList(int orderID);
14 }
15 }
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 //新添命名空间
6 using System.Data;
7 using HomeShop.Model;
8
9 namespace HomeShop.DALInterface
10 {
11 public interface IOrderItemDAO
12 {
13 List<OrderItem> GetList(int orderID);
14 }
15 }
IOrderStateDAO.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//新添命名空间
using System.Data;
using HomeShop.Model;
namespace HomeShop.DALInterface
{
public interface IOrderStateDAO
{
List<OrderState> GetList();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
//新添命名空间
using System.Data;
using HomeShop.Model;
namespace HomeShop.DALInterface
{
public interface IOrderStateDAO
{
List<OrderState> GetList();
}
}
源码下载:/Files/SummerRain/NetDbDevRoad/7使用ADONET实现工厂模式DB切换.rar
数据下载:/Files/SummerRain/NetDbDevRoad/HomeShopDB.rar