using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.Common; using HuizhongLibrary.Common.Configuration; namespace HuizhongLibrary.Data { public static class DatabaseFactory { public static Database CreateDatabase() { return CreateDatabase("ConnectionString"); } public static Database CreateDatabasel() { return CreateDatabase("BaseConnectionString"); } public static Database CreateDatabase(string name) { Database db = null; if (DataCache.ConfigCache.ContainsKey(name) == false) { ConfigurationSourceSection.GetConnection(name); } if (DataCache.ConfigCache.ContainsKey(name) == false) return null; string Namespace = DataCache.ConfigCache[name].Namespace; string ConnectionString = DataCache.ConfigCache[name].Value; if (string.IsNullOrEmpty(ConnectionString) == true) return null; if (Namespace == "System.Data.Oledb") { ConnectionString = CustomIO.AccessReplacePath(ConnectionString); } db = new Database(Namespace, ConnectionString); return db; } public static Database CreateDatabase2(string name) { Database db = null; if (DataCache.ConfigCache.ContainsKey(name) == false) { ConfigurationSourceSection.GetConnection2(name); } if (DataCache.ConfigCache.ContainsKey(name) == false) return null; string Namespace = DataCache.ConfigCache[name].Namespace; string ConnectionString = DataCache.ConfigCache[name].Value; if (string.IsNullOrEmpty(ConnectionString) == true) return null; if (Namespace == "System.Data.Oledb") { ConnectionString = CustomIO.AccessReplacePath(ConnectionString); } db = new Database(Namespace, ConnectionString); return db; } } }