コード例 #1
0
ファイル: DbService.cs プロジェクト: 760354196/FirstProject
        /// <summary>
        /// 根据Sql查询实体分页列表
        /// </summary>
        public static PageList <T> GetPageList <T>(string sql, object paramValues = null, int pageIndex = 1, int pageSize = 10, bool needTotalCount = true) where T : class
        {
            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }
            if (pageSize <= 0)
            {
                pageSize = 10;
            }

            var pageList = new PageList <T>()
            {
                PageIndex = pageIndex, PageSize = pageSize
            };

            //获取总数
            if (needTotalCount)
            {
                var sqlTotal = $"select count(0) from ({sql}) t_total";
                var count    = DbFactory.Instance.MyConnection.QueryFirstOrDefault <int>(sqlTotal, paramValues);

                pageList.TotalCount = count;
            }
            //获取分页列表
            sql = $"{sql} limit {(pageIndex - 1) * pageSize},{pageSize}";
            var list = DbFactory.Instance.MyConnection.Query <T>(sql, paramValues);

            pageList.AddRange(list);
            return(pageList);
        }
コード例 #2
0
ファイル: Spider.cs プロジェクト: GihanSoft/PageRankAsp
        public void Stop()
        {
            Pause = true;
            while (!Pause)
            {
                Thread.Sleep(1);
            }
            var temp = PageList.Where(a => PageList.IndexOf(a) < AnalyzingPage).ToList();

            PageList.Clear();
            PageList.AddRange(temp);
            matrix = matrix.SubMatrix(0, AnalyzingPage, 0, AnalyzingPage);

            OnComplete();
            Dispose();
        }
コード例 #3
0
ファイル: DbSetExtensions.cs プロジェクト: yangyue1943/song
        public static PageList <T> ToPagingList <T>(this IQueryable <T> query, int pageIndex = 1, int pageSize = 10)
        {
            var          total  = query.Count();
            PageList <T> paging = new PageList <T>()
            {
                PageIndex = pageIndex,
                PageSize  = pageSize
            };
            var list = query.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();

            if (list != null)
            {
                paging.AddRange(list);
            }
            paging.TotalRecord = total;
            return(paging);
        }
コード例 #4
0
        public virtual PageList <TL> GetPageList(string selector, string ordering, string colList, int pageIndex, int pageSize, params DBParam[] values)
        {
            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }
            if (pageSize <= 0)
            {
                pageSize = PageSize;
            }
            PageList <TL> pageList = new PageList <TL>(pageIndex, pageSize, 0);
            string        str      = creator.CreatePageSql(selector, pageIndex, pageSize, ordering, colList, values);
            string        str2     = creator.CreateCountSql(selector, string.Empty);

            try
            {
                List <TL> list = new List <TL>();
                using (IDataReader dataReader = SqlHelper.ExecuteDataReader(DbName, str + "  " + str2, CommandType.Text, values))
                {
                    while (dataReader.Read())
                    {
                        list.Add(GetModel(dataReader));
                    }
                    if (!dataReader.IsClosed)
                    {
                        dataReader.Close();
                    }
                }
                pageList.TotalCount = GetModelListCount(selector, values);
                pageList.AddRange(list);
                return(pageList);
            }
            catch (Exception ex)
            {
                Log log = new Log();
                log.Write(new LogMessage
                {
                    Content = "GLib.Data.Core.Repository.GetPageList(String selector, String ordering, String colList, int pageIndex, int pageSize, params DBParam[] values):\r\n " + ex.Message,
                    Type    = MessageType.Error
                });
                return(pageList);
            }
        }