Example #1
0
        private static string SelectNameFromID(long userID)
        {
            string appSetting  = Service.GetAppHelp().GetAppSetting("userdbname");
            string appSetting2 = Service.GetAppHelp().GetAppSetting("usernamefield");
            string appSetting3 = Service.GetAppHelp().GetAppSetting("useridfield");
            string appSetting4 = Service.GetAppHelp().GetAppSetting("tablename");
            DBEnum dbtype      = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string sqlstr      = string.Concat(new string[]
            {
                "select ",
                appSetting2,
                " from ",
                appSetting4,
                " where ",
                appSetting3,
                "=@userID and  state=0"
            });

            DbParameter[] dBParms = Service.GetIDBparm().GetDBParms(1);
            dBParms[0] = Service.GetIDBparm().GetDBParm("@userID", userID);
            string result = string.Empty;

            try
            {
                result = Service.GetSqlHelp().ExecuteScalar(dbtype, CommandType.Text, sqlstr, dBParms).ToString();
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@00000010", sQLandParstr, false);
            }
            return(result);
        }
Example #2
0
 public static SQLHelper GetSQLHelperInstance(DBEnum DbType, string args)
 {
     mysql = (SQLHelper)CacheHelper.GetCache(DbType.ToString().ToLower() + "_" + args);
     if (mysql == null)
     {
         //根据配置信息获取命名空间
         string DBNameSpace = CommonHelper.GetAppSetting("DBNameSpace");
         if (string.IsNullOrEmpty(DBNameSpace))
         {
             DBNameSpace = "WiteemFramework.DBWorks";
         }
         IEnumerable <Type> DBGroups  = null;
         Type[]             Assemblys = Assembly.GetExecutingAssembly().GetTypes();
         //返回命名空间的程序集
         DBGroups = Assemblys.Where(m => m.Namespace == DBNameSpace);
         foreach (Type item in DBGroups)
         {
             if (item.Name.ToLower() == DbType.ToString().ToLower())
             {
                 if (args == null)
                 {
                     mysql = (SQLHelper)Activator.CreateInstance(item);
                 }
                 else
                 {
                     mysql = (SQLHelper)Activator.CreateInstance(item, args);
                 }
                 CacheHelper.SetCache(DbType.ToString().ToLower() + "_" + args, mysql, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(10));
                 return(mysql);
             }
         }
         return(null);
     }
     return(mysql);
 }
Example #3
0
        public IDataReader ExecuteReader(DBEnum dbtype, CommandType commandtype, string sqlstr, params DbParameter[] parameterValues)
        {
            Database  database  = DatabaseFactory.CreateDatabase(dbtype.ToString());
            DbCommand dbCommand = this.PrepareCommand(database, commandtype, sqlstr, parameterValues);

            return(database.ExecuteReader(dbCommand));
        }
Example #4
0
        public static string GetSQLandParstr(DBEnum dbtype, string sqlstr, params DbParameter[] parameterValues)
        {
            string text = "";

            if (parameterValues != null)
            {
                for (int i = 0; i < parameterValues.Length; i++)
                {
                    DbParameter dbParameter = parameterValues[i];
                    if (dbParameter != null && dbParameter.Value != null)
                    {
                        text = string.Concat(new string[]
                        {
                            text,
                            dbParameter.ParameterName,
                            "=",
                            dbParameter.Value.ToString(),
                            ";"
                        });
                    }
                }
            }
            return(string.Concat(new string[]
            {
                dbtype.ToString(),
                ":",
                sqlstr,
                ";",
                text
            }));
        }
Example #5
0
        /// <summary>
        /// 查询列信息
        /// </summary>
        /// <param name="tablesName"></param>
        /// <returns></returns>
        public List <TableColumn> QueryColumn(DBInfoModel model, DBEnum dbenum)
        {
            DataTable table = new DataTable();

            if (dbenum == DBEnum.SqlServer)
            {
                //var table
            }
            else if (dbenum == DBEnum.MySQL)
            {
            }
            //var result = new SqlHelper(_connStr).ExecuteDataTable(sql, paramVal);

            //return (from DataRow row in result.Rows
            //        select new TableColumn
            //        {
            //            IsIdentity = Convert.ToBoolean(row["isidentity"]),
            //            IsKey = Convert.ToBoolean(row["iskey"]),
            //            IsNullable = Convert.ToBoolean(row["isnullable"]),
            //            Length = Convert.ToInt32(row["length"]),
            //            Name = row["name"].ToString(),
            //            Remark = row["remark"].ToString(),
            //            TableName = row["tablename"].ToString(),
            //            Type = row["type"].ToString()
            //        }).ToList();
            return(null);
        }
Example #6
0
        public List <decimal> GetNewIDList(DBEnum dbtype, int count, string Tabelname)
        {
            string sqlstr = " update SYS_IDINCREASE set @keyvalue=keyvalue=keyvalue+" + count + " where tablename=@tablename";

            DbParameter[] dBParms = Service.GetIDBparm("sql").GetDBParms(2);
            dBParms[0] = Service.GetIDBparm("sql").GetDBParm("@tablename", Tabelname);
            dBParms[1] = Service.GetIDBparm("sql").GetDBParm("@keyvalue", DbType.Decimal, ParameterDirection.Output);
            try
            {
                Service.GetSqlHelp().ExecuteNonQuery(dbtype, CommandType.Text, sqlstr, dBParms);
            }
            catch (Exception ex)
            {
                string sQLandParstr = AppHelp.GetSQLandParstr(dbtype, sqlstr, dBParms);
                Service.GetExceptHelp().HandleExcept(ex, "@00000020", sQLandParstr, false);
            }
            List <decimal> list = new List <decimal>();
            decimal        num  = count - 1;

            while (num >= 0m)
            {
                decimal item = (decimal)dBParms[1].Value - num;
                list.Add(item);
                num = --num;
            }
            return(list);
        }
Example #7
0
        public bool ExecuteBulkCopy(DBEnum dbtype, DataTable dt, string db, DbTransaction dbt)
        {
            bool result;

            if (db == "sql")
            {
                SqlBulkCopy sqlBulkCopy;
                if (dbt != null)
                {
                    sqlBulkCopy = new SqlBulkCopy((SqlConnection)dbt.Connection, SqlBulkCopyOptions.CheckConstraints, (SqlTransaction)dbt);
                }
                else
                {
                    SqlConnection sqlConnection = (SqlConnection)DatabaseFactory.CreateDatabase(dbtype.ToString()).CreateConnection();
                    sqlBulkCopy = new SqlBulkCopy(sqlConnection.ConnectionString, SqlBulkCopyOptions.UseInternalTransaction);
                }
                sqlBulkCopy.DestinationTableName = dt.TableName;
                foreach (DataColumn dataColumn in dt.Columns)
                {
                    sqlBulkCopy.ColumnMappings.Add(dataColumn.ColumnName, dataColumn.ColumnName);
                }
                sqlBulkCopy.WriteToServer(dt);
                sqlBulkCopy.Close();
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Example #8
0
        public DbTransaction BeginTractionand(DBEnum dbtype)
        {
            DbConnection dbConnection = DatabaseFactory.CreateDatabase(dbtype.ToString()).CreateConnection();

            dbConnection.Open();
            return(dbConnection.BeginTransaction());
        }
Example #9
0
        public DataSet ExecuteQuery(CommandType commandType, DBEnum DBObject, params object[] QueryParameters)
        {
            DataSet ResultSet = null;

            //Setting Connection
            SqlDBConnection con = new SqlDBConnection(ConnectionString);

            con.GetConnection();

            try
            {
                //Setting Query
                string Query = GetQuery(DBObject);

                if (commandType == CommandType.StoredProcedure)
                {
                    ResultSet = SqlHelper.ExecuteDataset(con.GetConnection(), Query, SetParameters(QueryParameters));
                }
                else
                {
                    ResultSet = SqlHelper.ExecuteDataset(con.GetConnection(), commandType, Query);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.CloseConnection();
            }
            return(ResultSet);
        }
Example #10
0
        public DataSet ExecuteDataSet(DBEnum dbtype, CommandType commandtype, string sqlstr, int timeout, params DbParameter[] parameterValues)
        {
            Database  database  = DatabaseFactory.CreateDatabase(dbtype.ToString());
            DbCommand dbCommand = this.PrepareCommand(database, commandtype, sqlstr, timeout, parameterValues);

            return(database.ExecuteDataSet(dbCommand));
        }
Example #11
0
 /// <summary>
 /// 数据库类型,目前只支持SQL Server
 /// </summary>
 /// <param name="DBType">数据库类型</param>
 /// <param name="connString">数据库连接信息,为null,为系统级数据库连接</param>
 public DBAsser(DBEnum DBType = DBEnum.SqlServer, string connString = null)
 {
     ConnectionString = connString;
     if (DBType == DBEnum.SqlServer)//暂时只支持SQL Server数据库
     {
         m_DBAssesser = new SqlServerAssesser(ConnectionString);
     }
 }
Example #12
0
        private string GetQuery(DBEnum DBObject)
        {
            string query = "";

            if (DBObject == DBEnum.usp_Insert_Category)
            {
                query = "usp_Insert_Category";
            }
            else if (DBObject == DBEnum.usp_List_Category)
            {
                query = "usp_List_Category";
            }
            else if (DBObject == DBEnum.usp_Get_Category_By_Id)
            {
                query = "usp_Get_Category_By_Id";
            }
            else if (DBObject == DBEnum.usp_Delete_Category_By_Id)
            {
                query = "usp_Delete_Category_By_Id";
            }
            else if (DBObject == DBEnum.usp_Update_Category_By_Id)
            {
                query = "usp_Update_Category_By_Id";
            }
            else if (DBObject == DBEnum.usp_Insert_Product)
            {
                query = "usp_Insert_Product";
            }
            else if (DBObject == DBEnum.usp_List_Product)
            {
                query = "usp_List_Product";
            }
            else if (DBObject == DBEnum.usp_List_Product_By_UserId)
            {
                query = "usp_List_Product_By_UserId";
            }
            else if (DBObject == DBEnum.usp_Get_Product_By_Id)
            {
                query = "usp_Get_Product_By_Id";
            }
            else if (DBObject == DBEnum.usp_Delete_Product_By_Id)
            {
                query = "usp_Delete_Product_By_Id";
            }
            else if (DBObject == DBEnum.usp_Update_Product_By_Id)
            {
                query = "usp_Update_Product_By_Id";
            }
            else if (DBObject == DBEnum.usp_Insert_Logger)
            {
                query = "usp_Insert_Logger";
            }

            return(query);
        }
Example #13
0
        /// <summary>
        /// 查询列信息
        /// </summary>
        /// <param name="tablesName"></param>
        /// <returns></returns>
        public List <TableColumn> QueryColumn(DBInfoModel model, DBEnum dbenum)
        {
            DataTable table = new DataTable();

            if (dbenum == DBEnum.SqlServer)
            {
                //var table
            }
            else if (dbenum == DBEnum.MySQL)
            {
            }
            return(null);
        }
Example #14
0
        /// <summary>
        /// 客户端缓存操作对象
        /// </summary>
        public RedisClient GetClient(DBEnum _db)
        {
            if (_prcm == null)
            {
                CreateManager(writeServer, readServer);
            }
            RedisClient redisclient = _prcm.GetClient() as RedisClient;

            if (redisclient.Db != (int)_db)
            {
                redisclient.ChangeDb((int)_db);
            }
            return(redisclient);
        }
Example #15
0
 /// <summary>
 /// 获取数据库驱动名称
 /// </summary>
 /// <param name="dbEnum">连接类型枚举</param>
 /// <returns>string</returns>
 public static string GetProviderName(DBEnum dbEnum)
 {
     if (!dicConnectionString.ContainsKey(dbEnum.ToString() + "_ProviderName"))
     {
         string providerName = "MySql.Data.MySqlClient";
         string sqlType      = GetSQLType(dbEnum);
         if (sqlType.ToLower() == "MySQL".ToLower())
         {
             providerName = "MySql.Data.MySqlClient";
         }
         dicConnectionString.Add(dbEnum.ToString() + "_ProviderName", providerName);
     }
     return(dicConnectionString[dbEnum.ToString() + "_ProviderName"]);
 }
Example #16
0
        public int ExecuteNonQuery(DBEnum dbtype, DbTransaction dbTransaction, CommandType commandtype, string sqlstr, int timeout, params DbParameter[] parameterValues)
        {
            Database  database  = DatabaseFactory.CreateDatabase(dbtype.ToString());
            DbCommand dbCommand = this.PrepareCommand(database, commandtype, sqlstr, timeout, parameterValues);
            int       result;

            if (dbTransaction == null)
            {
                result = database.ExecuteNonQuery(dbCommand);
            }
            else
            {
                result = database.ExecuteNonQuery(dbCommand, dbTransaction);
            }
            return(result);
        }
Example #17
0
        public IDataReader ExecuteReader(DBEnum dbtype, DbTransaction dbTransaction, CommandType commandtype, string sqlstr, params DbParameter[] parameterValues)
        {
            Database    database  = DatabaseFactory.CreateDatabase(dbtype.ToString());
            DbCommand   dbCommand = this.PrepareCommand(database, commandtype, sqlstr, parameterValues);
            IDataReader result;

            if (dbTransaction == null)
            {
                result = database.ExecuteReader(dbCommand);
            }
            else
            {
                result = database.ExecuteReader(dbCommand, dbTransaction);
            }
            return(result);
        }
Example #18
0
        ///// <summary>
        ///// 获取连接字符串//无参构造函数
        ///// </summary>
        //public static string ConnectionString
        //{
        //    get
        //    {
        //        string _connectionString = ConfigurationManager.AppSettings["ConnectionString"];
        //        string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];//获取链接字符串是否是加密的
        //        if (ConStringEncrypt == "true")//如果是加密的就要对链接字符串进行解密
        //        {
        //            _connectionString = new DESHelper().Decrypt(_connectionString);
        //        }
        //        return _connectionString;
        //    }
        //}

        ///// <summary>
        ///// 得到web.config里配置项的数据库连接字符串。//有参构造函数,重写方法
        ///// </summary>
        ///// <param name="configName"></param>
        ///// <returns></returns>
        //public static string GetConnectionString(string configName)
        //{
        //    string connectionString = ConfigurationManager.AppSettings[configName];
        //    string ConStringEncrypt = ConfigurationManager.AppSettings["ConStringEncrypt"];
        //    if (ConStringEncrypt == "true")
        //    {
        //        connectionString =new DESHelper().Decrypt(connectionString);
        //    }
        //    return connectionString;
        //}
        #endregion

        /// <summary>
        /// 获取数据库类型
        /// </summary>
        /// <param name="dbEnum">连接类型枚举</param>
        /// <returns>string</returns>
        public static string GetSQLType(DBEnum dbEnum)
        {
            if (!dicConnectionString.ContainsKey(dbEnum.ToString() + "_SQLType"))
            {
                string configName = string.Empty;
                switch ((int)dbEnum)
                {
                case 0: configName = "OnlineMasterDBConfig"; break;

                default: configName = "OnlineSlaveDBConfig"; break;
                }
                string programFilesPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                string sqlType          = INIHelper.INIGetStringValue(programFilesPath + @"MyConfig.ini", configName, "SQLType", "MySQL");
                dicConnectionString.Add(dbEnum.ToString() + "_SQLType", sqlType);
            }
            return(dicConnectionString[dbEnum.ToString() + "_SQLType"]);
        }
Example #19
0
        public static DataSet ExeDataSetCache(DBEnum dbtype, CommandType commandtype, string sqlstr, int ExpiredSecond, params DbParameter[] parameterValues)
        {
            string  sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, parameterValues);
            DataSet data         = Service.GetCacheHelp().GetData <DataSet>(sQLandParstr);
            DataSet result;

            if (data != null)
            {
                result = data;
            }
            else
            {
                DataSet dataSet = Service.GetSqlHelp().ExecuteDataSet(dbtype, commandtype, sqlstr, parameterValues);
                Service.GetCacheHelp().AddAbsolute(sQLandParstr, dataSet, ExpiredSecond);
                result = dataSet;
            }
            return(result);
        }
Example #20
0
        public static long GetNewID(DBEnum dbtype, string Tabelname)
        {
            string sqlstr = "update IDIncrease set @keyvalue=keyvalue=keyvalue+1 where tablename=@tablename ";

            DbParameter[] dBParms = Service.GetIDBparm().GetDBParms(2);
            dBParms[0] = Service.GetIDBparm().GetDBParm("@tablename", Tabelname);
            dBParms[1] = Service.GetIDBparm().GetDBParm("@keyvalue", DbType.Int64, ParameterDirection.Output);
            try
            {
                Service.GetSqlHelp().ExecuteNonQuery(dbtype, CommandType.Text, sqlstr, dBParms);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, dBParms);
                Service.GetExceptHelp().HandleExcept(ex, "@00000020", sQLandParstr, false);
            }
            return((long)dBParms[1].Value);
        }
Example #21
0
        public static DataSet SelectStreet()
        {
            string  appSetting = Service.GetAppHelp().GetAppSetting("userdbname");
            DBEnum  dbtype     = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string  sqlstr     = "select B.ID,B.CountyID,B.Street,B.IfCod from Bas_Nation_AdministrativeRegion B  where  B.IfDel=0 ";
            DataSet result;

            try
            {
                result = Service.GetSqlHelp().ExecuteDataSet(dbtype, CommandType.Text, sqlstr);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@街道缓存", sQLandParstr, false);
                result = null;
            }
            return(result);
        }
Example #22
0
        public static DataSet SelectMenu()
        {
            string  appSetting = Service.GetAppHelp().GetAppSetting("userdbname");
            DBEnum  dbtype     = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string  sqlstr     = "select S.BarItemID,S.Caption,S.DllName,S.ImageName,S.ParentID,S.IsButton,S.ActionID from SYS_BarItem S  where 1=1 and BarItemID<>14 and BarItemID<>15  and NewOrOldFlag<>3 and IsEnable=1 order by ItemOrder ";
            DataSet result;

            try
            {
                result = Service.GetSqlHelp().ExecuteDataSet(dbtype, CommandType.Text, sqlstr);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@菜单缓存", sQLandParstr, false);
                result = null;
            }
            return(result);
        }
Example #23
0
        public static DataSet SelectEunm()
        {
            string  appSetting = Service.GetAppHelp().GetAppSetting("userdbname");
            DBEnum  dbtype     = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string  sqlstr     = "select B.ItemCode,B.ItemValue,B.OperTime,B.OperStatus,B.CodeDicName,B.CodeDicID,B.ifDel,B.ifModify,B.ElseValue from Bas_CodeTable B  where B.ifDel=0 ";
            DataSet result;

            try
            {
                result = Service.GetSqlHelp().ExecuteDataSet(dbtype, CommandType.Text, sqlstr);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@枚举缓存", sQLandParstr, false);
                result = null;
            }
            return(result);
        }
Example #24
0
        public static DataSet SelectStation()
        {
            string  appSetting = Service.GetAppHelp().GetAppSetting("userdbname");
            DBEnum  dbtype     = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string  sqlstr     = "select B.IFDaoFu,B.ifzhipiao,B.StationType,B.StationID,B.StationName,B.Telphone,B.MobilePhone,B.Address,B.BelongCenterID,B.BelongCenter,B.ProvinceID,B.ParentCode,B.ifIn,B.JoinUnitID,B.StationCityID from Bas_StationInformation B   ";
            DataSet result;

            try
            {
                result = Service.GetSqlHelp().ExecuteDataSet(dbtype, CommandType.Text, sqlstr);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@网点缓存", sQLandParstr, false);
                result = null;
            }
            return(result);
        }
Example #25
0
        public static DataSet SelectCity()
        {
            string  appSetting = Service.GetAppHelp().GetAppSetting("userdbname");
            DBEnum  dbtype     = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string  sqlstr     = "select  B.CityID,B.CityName,B.ProvinceID from Bas_Nation_City B where  B.IfDel=0 order by CityName ";
            DataSet result;

            try
            {
                result = Service.GetSqlHelp().ExecuteDataSet(dbtype, CommandType.Text, sqlstr);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@市缓存", sQLandParstr, false);
                result = null;
            }
            return(result);
        }
Example #26
0
        public static DataSet SelectAllUser()
        {
            string  appSetting = Service.GetAppHelp().GetAppSetting("userdbname");
            DBEnum  dbtype     = (DBEnum)Enum.Parse(typeof(DBEnum), appSetting);
            string  sqlstr     = " SELECT  t.[UserID],t.[Guid] FROM [SYS_User] t WHERE t.IfDel=0 ";
            DataSet result;

            try
            {
                result = Service.GetSqlHelp().ExecuteDataSet(dbtype, CommandType.Text, sqlstr);
            }
            catch (Exception ex)
            {
                string sQLandParstr = Tool.GetSQLandParstr(dbtype, sqlstr, new DbParameter[0]);
                Service.GetExceptHelp().HandleExcept(ex, "@用户缓存", sQLandParstr, false);
                result = null;
            }
            return(result);
        }
Example #27
0
        public object ExecuteScalar(DBEnum dbtype, DbTransaction dbTransaction, CommandType commandtype, string sqlstr, int timeout, params DbParameter[] parameterValues)
        {
            Database  database  = DatabaseFactory.CreateDatabase(dbtype.ToString());
            DbCommand dbCommand = this.PrepareCommand(database, commandtype, sqlstr, timeout, parameterValues);
            object    obj;

            if (dbTransaction == null)
            {
                obj = database.ExecuteScalar(dbCommand);
            }
            else
            {
                obj = database.ExecuteScalar(dbCommand, dbTransaction);
            }
            if (obj == DBNull.Value)
            {
                obj = null;
            }
            return(obj);
        }
Example #28
0
        /// <summary>
        /// 得到MyConfig.ini里配置项的数据库连接字符串。
        /// </summary>
        /// <param name="dbEnum"></param>
        /// <returns></returns>
        public static string GetConnectionStringFromINI(DBEnum dbEnum)
        {
            if (!dicConnectionString.ContainsKey(dbEnum.ToString()))
            {
                string configName = null;
                switch ((int)dbEnum)
                {
                case 0: configName = "OnlineMasterDBConfig"; break;

                default: configName = "OnlineSlaveDBConfig"; break;
                }
                string ProgramFilesPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                string server           = INIHelper.INIGetStringValue(ProgramFilesPath + @"MyConfig.ini", configName, "Server", "");
                string port             = INIHelper.INIGetStringValue(ProgramFilesPath + @"MyConfig.ini", configName, "Port", "");
                string database         = INIHelper.INIGetStringValue(ProgramFilesPath + @"MyConfig.ini", configName, "Database", "");
                string uid = INIHelper.INIGetStringValue(ProgramFilesPath + @"MyConfig.ini", configName, "Uid", "");
                string pwd = INIHelper.INIGetStringValue(ProgramFilesPath + @"MyConfig.ini", configName, "Pwd", "");
                dicConnectionString.Add(dbEnum.ToString(), "server=" + server + ";port=" + port + ";database=" + database + ";uid=" + uid + ";pwd=" + new DESHelper().Decrypt(pwd));
            }
            return(dicConnectionString[dbEnum.ToString()]);
        }
Example #29
0
        /// <summary>
        /// 获取数据库实现层
        /// </summary>
        /// <param name="dbEnum">连接类型枚举</param>
        /// <returns>string</returns>
        public static string GetAssemblyPath(DBEnum dbEnum)
        {
            if (!dicConnectionString.ContainsKey(dbEnum.ToString() + "_AssemblyPath"))
            {
                string configName   = string.Empty;
                string assemblyPath = string.Empty;
                switch ((int)dbEnum)
                {
                case 0: configName = "OnlineMasterDBConfig"; break;

                default: configName = "OnlineSlaveDBConfig"; break;
                }
                string ProgramFilesPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                assemblyPath = INIHelper.INIGetStringValue(ProgramFilesPath + @"MyConfig.ini", configName, "SQLDAL", "DSMTMALL.DB");
                string sqlType = GetSQLType(dbEnum);
                if (sqlType.ToLower() == "MySQL".ToLower())
                {
                    assemblyPath += ".MySQLDAL";
                }
                dicConnectionString.Add(dbEnum.ToString() + "_AssemblyPath", assemblyPath);
            }
            return(dicConnectionString[dbEnum.ToString() + "_AssemblyPath"]);
        }
Example #30
0
        /// <summary>
        /// 从xml文件获取redis配置信息
        /// </summary>
        /// <param name="path"></param>
        /// <param name="CacheName"></param>
        private void GetCacheConfig(CacheEnum CacheName)
        {
            XmlDocument xml = new XmlDocument();//声明xml

            xml.Load(AppDomain.CurrentDomain.BaseDirectory + XmlPath);
            XmlNodeList topM = xml.DocumentElement.ChildNodes;

            if (topM.Count < 0)
            {
                return;
            }
            foreach (XmlElement element in topM)
            {
                if (element.HasAttribute("Name") && element.Attributes["Name"].Value.ToLower() == CacheName.ToString().ToLower())
                {
                    IsTrue          = element.SelectSingleNode("IsTrue").InnerText.Trim().ToLower() == "true" ? true : false;
                    ReadServer      = element.SelectSingleNode("ReadServer").InnerText.Trim();
                    WriteServer     = element.SelectSingleNode("WriteServer").InnerText.Trim();;
                    RedisDB         = (DBEnum)Enum.Parse(typeof(DBEnum), element.SelectSingleNode("RedisDB").InnerText.Trim(), false);
                    RedisExpireTime = Convert.ToDateTime(element.SelectSingleNode("RedisExpireTime").InnerText.Trim()).Hour * 60 + Convert.ToDateTime(element.SelectSingleNode("RedisExpireTime").InnerText.Trim()).Minute;
                    IsCacheName     = CacheName;
                }
            }
        }