コード例 #1
0
        public List <Guestbooks> GetDataList(string Search, ForPaging Paging)
        {
            IQueryable <Guestbooks> data;

            if (string.IsNullOrEmpty(Search))
            {
                data = GetDataList(Paging);
            }
            else
            {
                data = GetDataList(Paging, Search);
            }

            return(data.OrderByDescending(p => p.Id).Skip((Paging.NowPage - 1) * Paging.ItemNo).Take(Paging.ItemNo).ToList());
        }
コード例 #2
0
        public List <ForumArticle> GetDataList(ForPaging Paging, string Search)
        {
            IQueryable <ForumArticle> data;

            if (string.IsNullOrEmpty(Search))
            {
                data = GetAllDataList(Paging);
            }
            else
            {
                data = GetAllDataList(Paging, Search);
            }

            data = data.OrderByDescending(p => p.AId).Skip((Paging.NowPage - 1) * Paging.ItemNo).Take(Paging.ItemNo);

            return(data.ToList());
        }
コード例 #3
0
        public List <int> GetIdList(ForPaging Paging)
        {
            //計算所需的總頁面
            SetMaxPaging(Paging);
            //取得資料庫中的Item資料表
            List <int> IdList = new List <int>();
            //Sql語法
            //desc為反向排序 越晚新增的越前面
            string sql = $@" select Id from (select row_number() over(order by Id desc) as sort,* from Item ) m
Where m.sort Between {(Paging.NowPage - 1) * Paging.ItemNum + 1} and {Paging.NowPage * Paging.ItemNum} ";

            //確保程式不會因執行錯誤而整個中斷
            try
            {
                //開啟資料庫連線
                conn.Open();
                //執行Sql指令
                SqlCommand cmd = new SqlCommand(sql, conn);
                //取得Sql資料
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read()) //獲得下一筆資料直到沒有資料
                {
                    IdList.Add(Convert.ToInt32(dr["Id"]));
                }
            }
            catch (Exception e)
            {
                //丟出錯誤
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                //關閉資料庫連線
                conn.Close();
            }
            //先排序再根據分頁來回傳所需的部分資料陣列
            return(IdList);
        }
コード例 #4
0
        public void SetMaxPaging(ForPaging Paging)
        {
            //計算列數
            int Row = 0;
            //Sql語法
            string sql = $@" select * from Item ";

            //確保程式不會因執行錯誤而整個中斷
            try
            {
                //開啟資料庫連線
                conn.Open();
                //執行Sql指令
                SqlCommand cmd = new SqlCommand(sql, conn);
                //取得Sql資料
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read()) //獲得下一筆資料直到沒有資料
                {
                    Row++;
                }
            }
            catch (Exception e)
            {
                //丟出錯誤
                throw new Exception(e.Message.ToString());
            }
            finally
            {
                //關閉資料庫連線
                conn.Close();
            }
            //計算所需的總頁數
            Paging.MaxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Row) / Paging.ItemNum));
            //重新設定正確的頁數,避免有不正確值傳入
            Paging.SetRightPage();
        }
コード例 #5
0
        public List <FileContent> GetFileList(ForPaging Paging)
        {
            IQueryable <FileContent> fileList = GetAllFileList(Paging);

            return(fileList.OrderByDescending(p => p.Id).Skip((Paging.NowPage - 1) * Paging.ItemNo).Take(Paging.ItemNo).ToList());
        }
コード例 #6
0
        public List <ForumAlbum> GetDataList(ForPaging Paging)
        {
            IQueryable <ForumAlbum> Data = GetAllDataList(Paging);

            return(Data.OrderByDescending(p => p.AlbId).Skip((Paging.NowPage - 1) * Paging.ItemNo).Take(Paging.ItemNo).ToList());
        }
コード例 #7
0
ファイル: FMessageService.cs プロジェクト: qo4rmp1/MemoBoard
        public List <ForumMessage> GetDataList(ForPaging Paging, int AId)
        {
            IQueryable <ForumMessage> Data = GetAllDataList(Paging, AId);

            return(Data.OrderByDescending(p => p.AId).Skip((Paging.NowPage - 1) * Paging.ItemNo).Take(Paging.ItemNo).ToList());
        }