C#三层架构加工厂模式,在仅修改APP.CONFIG文件配置的情况下自由切换数据源。前台界面无感知。由于项目需要,时间比较紧,实现的界面比较简单。但三层架构和工厂模式均已实现。项目结构 资源目录
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Configuration;using window_oracle_dal;using window_sqlserver_dal;using window_sybase_dal;namespace Factory{ public class ifeng_fymc_factory { string databaseKey = ConfigurationManager.AppSettings["databaseKey"].ToString(); DataTable dt = new DataTable(); ifeng_fymc_oracle_dal ordal = new ifeng_fymc_oracle_dal(); ifeng_fymc_sqlserver_dal sqldal = new ifeng_fymc_sqlserver_dal(); ifeng_fymc_sybase_dal sydal = new ifeng_fymc_sybase_dal(); public DataTable GetFymc() { switch (databaseKey) { case "oracleConnection": dt = ordal.GetFymc(); break; case "sybaseConnection": dt = sydal.GetFymc(); break; case "sqlserverConnection": dt = sqldal.GetFymc(); break; case "mysqlConnection": //dt = sqldal.GetFymc(); break; default: break; } return dt; } }}
评论