示例#1
0
        private XmlNode GetDBTypeNode(EnumDBType enuDbType)
        {
            string  dbtype = enuDbType.ToString();
            XmlNode node   = m_doc.SelectSingleNode(string.Format("//dbtype[@type='{0}']", dbtype));

            if (node == null)
            {
                m_doc.LoadXml($"<?xml version=\"1.0\" encoding=\"utf-8\" ?><dbTypes default=\"{enuDbType.ToString()}\"><dbtype></dbtype></dbTypes>");
                node = m_doc.SelectSingleNode("//dbtype");
                XmlAttribute attr = m_doc.CreateNode(XmlNodeType.Attribute, "type", string.Empty) as XmlAttribute;
                attr.Value = dbtype;

                node.Attributes.Append(attr);
                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "displaynull", string.Empty));
                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "userfieldname", string.Empty));
                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "traceuser", string.Empty));

                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "server", string.Empty));
                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "user", string.Empty));
                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "password", string.Empty));
                node.AppendChild(m_doc.CreateNode(XmlNodeType.Element, "dbname", string.Empty));



                node = m_doc.SelectSingleNode(string.Format("//dbtype[@type='{0}']", dbtype));
            }

            return(node);
        }
示例#2
0
        private Control GetPanelControl(EnumDBType enuDBType)
        {
            m_currentConfig   = ConfigService.CreateConfigModel(enuDBType);
            m_currentDBConfig = DBViewerConfig.Create(GetDBTypeNode(enuDBType));
            Control ctl = m_currentConfig.GetConfigPanel(m_currentDBConfig);

            return(ctl);
        }
示例#3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public DBSql(string strConnectionString, EnumDBType enumDBType)
        {
            _dbFactory = DBFactory.CreateInstance(enumDBType);

            // 设置连接字符串
            _DBConnectionString = strConnectionString;

            CreateConnection();
        }
示例#4
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public DBSql(string strConnectionString, EnumDBType enumDBType)
        {
            _dbFactory = DBFactory.CreateInstance(enumDBType);

            // 设置连接字符串
            _DBConnectionString = strConnectionString;

            CreateConnection();
        }
示例#5
0
        public static IDBConfig CreateConfigModel(EnumDBType dbType)
        {
            ModelInfo info = dicConfig[dbType];

            if (info != null)
            {
                return(info.CreateModel() as IDBConfig);
            }
            return(null);
        }
示例#6
0
        /// <summary>
        /// 获取SQL生成器
        /// </summary>
        /// <returns></returns>
        public static ISqlMaker GetSqlMaker(EnumDBType db_type)
        {
            switch (db_type)
            {
            case EnumDBType.MYSQL:
                return(new MysqlSqlMakerImpl());

            case EnumDBType.MSSQL:
                return(new MssqlSqlMakerImpl());

            default:
                return(null);
            }
        }
示例#7
0
        /// <summary>
        /// 创建客户端实现
        /// </summary>
        /// <param name="DBType"></param>
        /// <returns></returns>
        public DapperClient CreateClient(EnumDBType DBType)
        {
            var client = new DapperClient(new DBConnectionConfig {
            });

            var option = _optionsMonitor.Get(DBType.ToString()).DapperActions.FirstOrDefault();

            if (option != null)
            {
                option(client.CurrentConnectionConfig);
            }
            else
            {
                throw new ArgumentNullException(nameof(option));
            }
            return(client);
        }
示例#8
0
        /// <summary> 
        /// 建立Factory类实例 
        /// </summary> 
        /// <param name="enumDBType">数据库类型</param>
        /// <returns>Factory类实例</returns> 
        public static IDbFactory CreateInstance(EnumDBType enumDBType)
        {
            IDbFactory dbFactory = null;

            switch (enumDBType)
            {
                case EnumDBType.Sql:
                    dbFactory = new SqlFactory();
                    break;
                
                case EnumDBType.Access:
                    //dbFactory = new OleDbFactory();
                    break;
            }

            return dbFactory;
        }
示例#9
0
        /// <summary>
        /// 建立Factory类实例
        /// </summary>
        /// <param name="enumDBType">数据库类型</param>
        /// <returns>Factory类实例</returns>
        public static IDbFactory CreateInstance(EnumDBType enumDBType)
        {
            IDbFactory dbFactory = null;

            switch (enumDBType)
            {
            case EnumDBType.Sql:
                dbFactory = new SqlFactory();
                break;

            case EnumDBType.Access:
                //dbFactory = new OleDbFactory();
                break;
            }

            return(dbFactory);
        }
示例#10
0
 /// <summary>
 /// 获取数据库
 /// </summary>
 /// <param name="db_type">数据库类型</param>
 /// <param name="action_type">数据库作用类型</param>
 /// <returns></returns>
 public DBConfig Get(EnumDBType db_type, EnumDBActionType action_type)
 {
     return(DBList.FirstOrDefault(f => f.DbType == db_type && f.ActionType == action_type));
 }
        /// <summary>
        /// 添加服务到容器中
        /// </summary>
        /// <param name="services">服务容器</param>
        /// <param name="DBType">数据库类型</param>
        /// <param name="configureClient"></param>
        /// <returns></returns>
        public static IDapperFactoryBuilder AddDapper(this IServiceCollection services, EnumDBType DBType,
                                                      Action <DBConnectionConfig> configureClient)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (configureClient == null)
            {
                throw new ArgumentNullException(nameof(configureClient));
            }

            //services.AddLogging();
            //添加使用选项所需的服务。
            services.AddOptions();

            //将TService中指定类型的单例服务添加到指定的Microsoft.Extensions.DependencyInjection.IServiceCollection。
            services.AddSingleton <DefaultDapperFactory>();

            //将指定的服务添加为Microsoft.Extensions.DependencyInjection.服务寿命。单例
            //使用implementationFactory中指定的工厂的服务
            //如果服务类型尚未注册。
            services.TryAddSingleton <IDapperFactory>(serviceProvider => serviceProvider.GetRequiredService <DefaultDapperFactory>());

            var builder = new DefaultDapperFactoryBuilder(services, DBType);

            builder.ConfigureDapper(configureClient);
            return(builder);
        }
 /// <summary>
 /// 有参构造
 /// </summary>
 /// <param name="services"></param>
 /// <param name="DBType"></param>
 public DefaultDapperFactoryBuilder(IServiceCollection services, EnumDBType DBType)
 {
     Services = services;
     Name     = DBType.ToString();
 }