Exemple #1
0
        /// <summary>
        /// 普通无分页查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static List <T> GetEntitiesListByDB <T>(string sql)
        {
            IRDBHelper helper = null;
            List <T>   list   = new List <T>();

            try
            {
                string strCon = ManageConfig.instance.GetConnectionStrings("SHHConnection");
                helper = RDBFactory.CreateDbHelper(strCon, DatabaseType.MSSQL);
                DataTable dataTable = helper.ExecuteDatatable("table", sql, true);
                list = TBToList.ToList <T>(dataTable);
                return(list);
            }
            catch (Exception ex)
            {
                LogAPI.Debug(ex);
                return(list);
            }
            finally
            {
                if (helper != null)
                {
                    helper.DisConnect();
                    helper = null;
                }
            }
        }
Exemple #2
0
        public static int ExecuteSQL(string sql)
        {
            IRDBHelper helper = null;

            try
            {
                string strCon = ManageConfig.instance.GetConnectionStrings("SHHConnection");
                helper = RDBFactory.CreateDbHelper(strCon, DatabaseType.Oracle);
                int count = helper.ExecuteNonQuery(sql, CommandType.Text);
                if (count > 0)
                {
                    helper.Commit();
                }
                return(count);
            }
            catch (Exception ex)
            {
                LogAPI.Debug(ex);
                return(0);
            }
            finally
            {
                if (helper != null)
                {
                    helper.DisConnect();
                    helper = null;
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///  RDBHelper 查询分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql">sql语句</param>
        /// <param name="skip">页数</param>
        /// <param name="take">每页显示条数</param>
        /// <param name="count">总数</param>
        /// <returns></returns>
        public static List <T> GetEntitiesListByDB <T>(string sql, int skip, int take, out int count)
        {
            IRDBHelper helper = null;
            List <T>   list   = new List <T>();

            try
            {
                string strCon = ManageConfig.instance.GetConnectionStrings("SHHConnection");
                helper = RDBFactory.CreateDbHelper(strCon, DatabaseType.MSSQL);
                if (helper != null)
                {
                    string    countSQL = string.Format("select count(1) as NUM from({0})", sql);
                    DataTable dt       = helper.ExecuteDatatable("table", countSQL, true);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        count = int.Parse(dt.Rows[0]["NUM"].ToString());
                    }
                    else
                    {
                        count = 0;
                        LogAPI.Debug("查询总数失败!");
                    }
                    //分页查询
                    string    strBegin  = "select * from (select a.* ,rownum rn from ( ";
                    string    strEnd    = string.Format(")a where rownum < {0} ) where rn>{1} ", take, skip);
                    string    querySQL  = strBegin + sql + strEnd;
                    DataTable dataTable = helper.ExecuteDatatable("table", querySQL, true);
                    list = TBToList.ToList <T>(dataTable);
                }
                else
                {
                    count = 0;
                    LogAPI.Debug("数据库打开失败!");
                }
                return(list);
            }
            catch (Exception ex)
            {
                count = 0;
                LogAPI.Debug("查询受理列表异常:");
                LogAPI.Debug(ex);
                return(list);
            }
            finally
            {
                if (helper != null)
                {
                    helper.DisConnect();
                    helper = null;
                }
            }
        }