예제 #1
0
        /// <summary>
        /// 获取数据库
        /// </summary>
        /// <param name="_constr"></param>
        private void GetDB(string _constr = "")
        {
            DBEntity info = null;

            if (lst != null)
            {
                if (string.IsNullOrEmpty(_constr))
                {
                    info = lst.Where(x => x.isdefault == "1").FirstOrDefault();
                }
                else
                {
                    info = lst.Where(x => x.name == _constr).FirstOrDefault();
                }
            }
            if (info != null)
            {
                switch (info.dbtype)
                {
                case "sqlserver":
                    Db = GetClient(info.value, SqlSugar.DbType.SqlServer);
                    break;

                case "mysql":
                    Db = GetClient(info.value, SqlSugar.DbType.MySql);
                    break;

                case "oracle":
                    Db = GetClient(info.value, SqlSugar.DbType.Oracle);
                    break;
                }
            }
            else
            {
                throw new Exception("数据库获取失败");
            }
        }
예제 #2
0
        /// <summary>
        /// 获取数据库配置文件信息,若数据库文件发生变更,需重新启动程序
        /// </summary>
        /// <returns></returns>
        public static List <DBEntity> GetDBS()
        {
            if (lst == null || lst.Count == 0)
            {
                lst = new List <DBEntity>();
                DBEntity    info       = null;
                string      configPath = AppDomain.CurrentDomain.BaseDirectory + "/Database.config";
                XmlDocument xml        = new XmlDocument();
                xml.Load(configPath);
                XmlNodeList NodeList = xml.SelectNodes("/DBS/DB");
                for (int i = 0; i < NodeList.Count; i++)
                {
                    info           = new DBEntity();
                    info.name      = NodeList[i].Attributes["name"].Value;
                    info.value     = NodeList[i].Attributes["value"].Value;
                    info.dbtype    = NodeList[i].Attributes["dbtype"].Value;
                    info.isdefault = NodeList[i].Attributes["isdefault"].Value;
                    info.dbName    = NodeList[i].Attributes["dbName"].Value;
                    lst.Add(info);
                }
            }

            return(lst);
        }