Ejemplo n.º 1
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="ht">Hashtable</param>
        /// <returns>
        /// ht["data"] List<T>
        /// ht["total"] 总条数
        /// </returns>
        public static Hashtable QueryBase <T>(string sql, QueryCondition gridParam, string connectionString = null)
        {
            try
            {
                int PageSize  = gridParam.PageSize;
                int PageIndex = gridParam.PageIndex;

                Hashtable     htArgs     = new Hashtable();
                List <string> listFilter = GetFilter(gridParam, out htArgs);

                string filter  = listFilter[0];
                string sortSQL = listFilter[1];
                //过滤条件
                if (String.IsNullOrEmpty(sql))
                {
                    throw new ArgumentNullException("调用函数QueryBase时参数sql为空");
                }


                Hashtable result = new Hashtable();
                string    newSql = string.Empty;



                if (gridParam.IsPagination)
                {
                    PageIndex = PageIndex < 0 ? 0 : PageIndex;
                    newSql    = "SELECT * FROM (SELECT T.*,ROW_NUMBER() OVER({0}) AS LIMIT_ROWNUMBER__ FROM({1})T WHERE {4} ) T where LIMIT_ROWNUMBER__ BETWEEN {2} AND {3}";
                    newSql    = String.Format(newSql, sortSQL, sql, PageIndex * PageSize, (PageIndex + 1) * PageSize, filter);
                    if (gridParam.IsPagination && gridParam.IsCalcTotal)
                    {
                        result["total"] = SQLHelper.ExecuteScalar <int>(String.Format("SELECT COUNT(1) FROM ({0}) A WHERE {1}", sql, filter), htArgs);
                    }
                }
                else
                {
                    newSql = string.Format("SELECT T.* FROM ({1}) T where {2} {0}", sortSQL, sql, filter);
                }
                List <T> list = SQLHelper.ToList <T>(newSql, htArgs);
                if (!gridParam.IsPagination || !gridParam.IsCalcTotal)
                {
                    result["total"] = list.Count;
                }
                result["data"] = list;
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 通过来源类型获取自定义标签
        /// </summary>
        /// <param name="SourceType">来源类型 <seealso cref="TagsSourceType"/></param>
        /// <param name="SourceId">来源Id</param>
        /// <returns>自定义标签</returns>
        public List <Tags> GetTags(string SourceType, string SourceId)
        {
            if (string.IsNullOrEmpty(SourceType))
            {
                return(new List <Tags>());
            }
            string strSQL = "SELECT * FROM p_Tags WHERE TagType=@SourceType  AND 1=1 ORDER BY TagHeat DESC";

            if (!string.IsNullOrEmpty(SourceId))
            {
                strSQL = strSQL.Replace("1=1", " SourceId = @SourceId ");
            }

            return(SQLHelper.ToList <Tags>(strSQL, new { SourceType = SourceType, SourceId = SourceId }));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获取所有启用的任务
 /// </summary>
 /// <returns>所有启用的任务</returns>
 public static List <TaskUtil> ReadConfig()
 {
     return(SQLHelper.ToList <TaskUtil>("SELECT * FROM p_Task"));
 }