예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodecode"></param>
        /// <param name="isLike"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetList(long langId, string nodecode, bool isLike, int pageIndex, int pageSize, ref int recordCount)
        {
            WhereClipBuilder wcb = new WhereClipBuilder();

            wcb.And(cmsNews._.LangId == langId);
            if (!string.IsNullOrEmpty(nodecode))
            {
                if (!isLike)
                {
                    wcb.And(cmsNews._.NodeCode == nodecode);
                }
                else
                {
                    wcb.And(cmsNews._.NodeCode.BeginWith(nodecode));
                }
            }
            wcb.And(cmsNews._.IsAudit == 1); // 已审核的

            FromSection fs = GetFromSection(wcb.ToWhereClip(), null)
                             .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode)
                             .Select(cmsNews._.All, cmsNewsCatalog._.NodeName)
                             .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs.Page(pageSize, pageIndex).ToDataTable());
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public int Count(int type)
        {
            FromSection fs = entCMS.Services.DBSession.CurrentSession.From <cmsNews>()
                             .InnerJoin <cmsNewsCatalog>(cmsNews._.NodeCode == cmsNewsCatalog._.NodeCode)
                             .Select(cmsNewsCatalog._.NodeName, cmsNews._.All)
                             .Where(cmsNewsCatalog._.NodeType == type)
                             .OrderBy(cmsNews._.EditTime.Desc);

            return(fs.Count());
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="langId"></param>
        /// <param name="keyword">搜索关键字</param>
        /// <param name="type">搜索类别:0-按标题搜,1-按内容搜,2-按标题或内容搜</param>
        /// <param name="nodecode">如果为空,则全局搜;不为空,则在本类下搜</param>
        /// <param name="isLike">是否搜索子类</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable Search(int langId, string keyword, int type, string nodecode, bool isLike, int pageIndex, int pageSize, ref int recordCount)
        {
            WhereClipBuilder wcb = new WhereClipBuilder();

            if (!string.IsNullOrEmpty(nodecode) && nodecode != "0000")
            {
                if (!isLike)
                {
                    wcb.And(cmsNews._.NodeCode == nodecode);
                }
                else
                {
                    wcb.And(cmsNews._.NodeCode.BeginWith(nodecode));
                }
            }
            wcb.And(cmsNews._.IsAudit == 1); // 已审核的
            wcb.And(cmsNews._.IsIndex == 1); // 已推荐的

            if (!string.IsNullOrEmpty(keyword))
            {
                switch (type)
                {
                case -1:
                    break;

                case 0:
                    wcb.And(cmsNews._.Title.Contain(keyword));
                    break;

                case 1:
                    wcb.And(cmsNews._.Content.Contain(keyword));
                    break;

                case 2:
                    wcb.And(cmsNews._.Title.Contain(keyword) || cmsNews._.Content.Contain(keyword));
                    break;
                }
            }

            if (langId > 0)
            {
                wcb.And(cmsNewsCatalog._.LangId == langId);
            }
            FromSection fs = GetFromSection(null, null)
                             .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode)
                             .Select(cmsNews._.All, cmsNewsCatalog._.NodeName)
                             .Where(wcb.ToWhereClip())
                             .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs
                   .Page(pageSize, pageIndex)
                   .ToDataTable());
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetDataTable(int pageIndex, int pageSize, ref int recordCount)
        {
            FromSection fs = GetFromSection(null, null)
                             .LeftJoin <cmsLinkGroup>(cmsLinkGroup._.Id == cmsLink._.GroupId)
                             .Select(cmsLink._.All, cmsLinkGroup._.Name.As("TypeName"))
                             .OrderBy(cmsLink._.GroupId.Asc && cmsLink._.OrderNo.Asc && cmsLink._.Id.Desc);

            recordCount = fs.Count();

            return(fs
                   .Page(pageSize, pageIndex)
                   .ToDataTable());
        }
        private void BindRepeater()
        {
            int page = AspNetPager1.CurrentPageIndex;

            if (!this.IsPostBack)
            {
                if (Request["page"] + "" != "")
                {
                    page = int.Parse(Request["page"] + "");
                }
            }
            FromSection <Dos.Model.Manager_Groups> fromsection = DbSession.Default.From <Dos.Model.Manager_Groups>()
                                                                 .Where(s => s.Status.Equals(0))
                                                                 .OrderBy(s => s.AddTime).OrderByDescending(s => s.Id);

            //List<object> listDesc = new List<object>();
            //var  carlist = DbSession.Default.fr.Manager_Groups.Where(s => s.Status.Equals(0)).OrderBy(o => o.AddTime).ThenByDescending(o => o.Id);

            if (!string.IsNullOrEmpty(txtKeywords.Text.Trim()))
            {
                fromsection = fromsection.Where(s => s.Name.Contains(txtKeywords.Text));
            }
            //carlist.ToPagedList(page, AspNetPager1.PageSize);
            AspNetPager1.RecordCount = fromsection.Count();
            ltlCount.Text            = "<b>" + fromsection.Count() + "</b>";
            var dblist = fromsection.Page(AspNetPager1.PageSize, page).ToList();

            if (!this.IsPostBack)
            {
                if (Request["page"] + "" != "")
                {
                    int temp = int.Parse(Request["page"] + "");
                    AspNetPager1.CurrentPageIndex = temp;
                }
            }
            WebUtil.CtrlToList <Dos.Model.Manager_Groups>(rptLoop, dblist);
        }
예제 #6
0
        /// <summary>
        /// 读取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="isOrderBy"></param>
        /// <returns></returns>
        public static async Task <Page <T> > ToPageAsync <T>(this FromSection <T> query,
                                                             int pageIndex,
                                                             int pageSize,
                                                             bool isOrderBy = false) where T : Dos.ORM.Entity
        {
            var page       = new Page <T>();
            var totalItems = query.Count();
            var totalPages = totalItems != 0 ? (totalItems % pageSize) == 0 ? (totalItems / pageSize) : (totalItems / pageSize) + 1 : 0;

            page.CurrentPage  = pageIndex;
            page.ItemsPerPage = pageSize;
            page.TotalItems   = totalItems;
            page.TotalPages   = totalPages;
            page.Items        = totalItems == 0 ? null : query.Page(pageSize, pageIndex).ToList();
            return(page);
        }
예제 #7
0
        /// <summary>
        /// 根据模块类别获取列表
        /// </summary>
        /// <param name="type"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetListByType(long langId, string type, int pageIndex, int pageSize, ref int recordCount)
        {
            string[] types = type.Split('|');

            WhereClipBuilder wcb = new WhereClipBuilder();

            wcb.And(cmsNewsCatalog._.LangId == langId);
            if (types.Length > 0)
            {
                wcb.And(cmsNewsCatalog._.NodeType.SelectIn(types));
            }
            FromSection fs = GetFromSection(wcb.ToWhereClip(), null)
                             .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode)
                             .Select(cmsNews._.All, cmsNewsCatalog._.NodeName)
                             .OrderBy(cmsNews._.IsTop.Desc && cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs.Page(pageSize, pageIndex).ToDataTable());
        }
예제 #8
0
        /// <summary>
        /// 提取某专题下的分页文章
        /// </summary>
        /// <param name="ztId"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetZtNewsList(int ztId, int pageSize, int pageIndex, ref int recordCount)
        {
            WhereClipBuilder wcb = new WhereClipBuilder();

            if (ztId > 0)
            {
                wcb.And(cmsNewsTopicRel._.TopicId == ztId);
            }
            wcb.And(cmsNews._.IsAudit == 1); // 已审核的
            wcb.And(cmsNews._.IsIndex == 1); // 已推荐的

            FromSection fs = GetFromSection(null, null)
                             .InnerJoin <cmsNewsCatalog>(cmsNewsCatalog._.NodeCode == cmsNews._.NodeCode)
                             .InnerJoin <cmsNewsTopicRel>(cmsNews._.Id == cmsNewsTopicRel._.NewsId)
                             .Select(cmsNews._.All, cmsNewsCatalog._.NodeName)
                             .Where(wcb.ToWhereClip())
                             .OrderBy(cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs.Page(pageSize, pageIndex).ToDataTable());
        }
        /// <summary>
        /// 使用linq查询(分页)
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="OutEntity"></typeparam>
        /// <param name="linq"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="lambdaOrderBy"></param>
        /// <returns></returns>
        public PageResponse <OutEntity> getListByPaging <TEntity, OutEntity>(FromSection <TEntity> linq, int pageSize, int pageIndex, Expression <Func <TEntity, object> > lambdaOrderBy = null) where TEntity : Entity
        {
            if (pageIndex <= 0)
            {
                pageIndex = 1;
            }
            if (pageSize <= 0)
            {
                pageSize = 10;
            }
            PageResponse <OutEntity> result = new PageResponse <OutEntity>();

            result.totalItems = linq.Count();
            List <OutEntity> sqlList = new List <OutEntity>();

            if (lambdaOrderBy != null)
            {
                sqlList = linq.OrderBy(lambdaOrderBy).Page(pageSize, pageIndex).ToList <OutEntity>();
            }
            else
            {
                sqlList = linq.Page(pageSize, pageIndex).ToList <OutEntity>();
            }

            if (sqlList == null || sqlList.Count == 0)
            {
                return(null);
            }
            result.items        = sqlList;
            result.currentPage  = pageIndex;
            result.itemsPerPage = pageSize;
            result.totalPages   = result.totalItems / pageSize;
            if ((result.totalItems % pageSize) != 0)
            {
                result.totalPages++;
            }
            return(result);
        }
        /// <summary>
        /// 使用linq查询(分页)
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <typeparam name="OutEnity"></typeparam>
        /// <param name="linq"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="lambdaOrderBy"></param>
        /// <returns></returns>
        public ActionResult getListByPaging <TEntity, OutEnity>(FromSection <TEntity> linq, Pagination pagination, OrderByClip lambdaOrderBy = null) where TEntity : Entity
        {
            int             pageIndex = pagination.page;
            int             pageSize  = pagination.rows <= 0 ? 20 : pagination.rows;
            List <OutEnity> sqlList   = new List <OutEnity>();

            if (lambdaOrderBy != null)
            {
                sqlList = linq.OrderBy(lambdaOrderBy).Page(pageSize, pageIndex).ToList <OutEnity>();
            }
            else
            {
                sqlList = linq.Page(pageSize, pageIndex).ToList <OutEnity>();
            }
            int totalCount = linq.Count();

            return(Content(new
            {
                rows = sqlList,
                total = (totalCount / pageSize) + 1,
                page = pagination.page,
                records = totalCount
            }.ToJson()));
        }
예제 #11
0
        /// <summary>
        /// 创建分页查询
        /// </summary>
        /// <param name="fromSection"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        public virtual FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex)
        {
            Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual <int>(1));
            Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual <int>(1));
            Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!");
            Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty);



            int pageSize = endIndex - startIndex + 1;

            if (startIndex == 1)
            {
                fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString());
            }
            else
            {
                if (OrderByClip.IsNullOrEmpty(fromSection.OrderByClip))
                {
                    foreach (Field f in fromSection.Fields)
                    {
                        if (!f.PropertyName.Equals("*") && f.PropertyName.IndexOf('(') == -1)
                        {
                            fromSection.OrderBy(f.Asc);
                            break;
                        }
                    }
                }



                Check.Require(!OrderByClip.IsNullOrEmpty(fromSection.OrderByClip), "query.OrderByClip could not be null or empty!");

                int count = fromSection.Count(fromSection);

                List <Parameter> list = fromSection.Parameters;

                if (endIndex > count)
                {
                    int lastnumber = count - startIndex + 1;
                    if (startIndex > count)
                    {
                        lastnumber = count % pageSize;
                    }

                    fromSection.PrefixString = string.Concat(" TOP ", lastnumber.ToString());

                    fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                    //

                    fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS temp_table ");

                    fromSection.PrefixString = string.Empty;

                    fromSection.DistinctString = string.Empty;

                    fromSection.GroupBy(GroupByClip.None);

                    fromSection.Select(Field.All);

                    fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                    fromSection.Where(WhereClip.All);
                }
                else
                {
                    if (startIndex < count / 2)
                    {
                        fromSection.PrefixString = string.Concat(" TOP ", endIndex.ToString());

                        fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempIntable ");

                        fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString());

                        fromSection.DistinctString = string.Empty;

                        fromSection.GroupBy(GroupByClip.None);

                        fromSection.Select(Field.All);

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                        fromSection.Where(WhereClip.All);

                        //

                        fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempOuttable ");

                        fromSection.PrefixString = string.Empty;

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);
                    }
                    else
                    {
                        fromSection.PrefixString = string.Concat(" TOP ", (count - startIndex + 1).ToString());

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                        fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempIntable ");

                        fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString());

                        fromSection.DistinctString = string.Empty;

                        fromSection.GroupBy(GroupByClip.None);

                        fromSection.Select(Field.All);

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                        fromSection.Where(WhereClip.All);
                    }
                }

                fromSection.Parameters = list;
            }

            return(fromSection);
        }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodecode"></param>
        /// <param name="title"></param>
        /// <param name="productNo"></param>
        /// <param name="productModel"></param>
        /// <param name="tags"></param>
        /// <param name="iIndex"></param>
        /// <param name="iTop"></param>
        /// <param name="iAudit"></param>
        /// <param name="dtAdd1"></param>
        /// <param name="dtAdd2"></param>
        /// <param name="dtEdit1"></param>
        /// <param name="dtEdit2"></param>
        /// <param name="userId"></param>
        /// <param name="isAdmin"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetProductsByFilter(
            string nodecode,
            string title,
            string productNo,
            string productModel,
            string tags,
            int iIndex,
            int iTop,
            int iAudit,
            string dtAdd1,
            string dtAdd2,
            string dtEdit1,
            string dtEdit2,
            long userId,
            bool isAdmin,
            int pageIndex,
            int pageSize,
            ref int recordCount
            )
        {
            WhereClipBuilder wcb = new WhereClipBuilder();

            if (!string.IsNullOrEmpty(nodecode))
            {
                wcb.And(cmsNews._.NodeCode == nodecode); // 当前栏目
            }
            if (!isAdmin)
            {
                wcb.And(cmsNews._.IsAudit < 3);
            }
            if (!string.IsNullOrEmpty(title.Trim()))
            {
                wcb.And(cmsNews._.Title.Contain(title.Trim()));
            }
            if (!string.IsNullOrEmpty(productNo.Trim()))
            {
                wcb.And(cmsNews._.ProductNo.Contain(productNo.Trim()));
            }
            if (!string.IsNullOrEmpty(productModel.Trim()))
            {
                wcb.And(cmsNews._.ProductModel.Contain(productModel.Trim()));
            }
            if (!string.IsNullOrEmpty(tags.Trim()))
            {
                wcb.And(cmsNews._.Tags.Contain(tags.Trim()));
            }
            if (iIndex >= 0)
            {
                wcb.And(cmsNews._.IsIndex == iIndex);
            }
            if (iTop >= 0)
            {
                wcb.And(cmsNews._.IsTop == iTop);
            }
            if (iAudit >= 0)
            {
                wcb.And(cmsNews._.IsAudit == iAudit);
            }
            if (!isAdmin && userId > 0)
            {
                wcb.And(cmsNews._.AddUser == userId);
            }
            DateTime dt;

            if (DateTime.TryParse(dtAdd1.Trim(), out dt))
            {
                wcb.And(cmsNews._.AddTime >= dt);
            }
            if (DateTime.TryParse(dtAdd2.Trim(), out dt))
            {
                wcb.And(cmsNews._.AddTime <= dt);
            }
            if (DateTime.TryParse(dtEdit1.Trim(), out dt))
            {
                wcb.And(cmsNews._.EditTime >= dt);
            }
            if (DateTime.TryParse(dtEdit2.Trim(), out dt))
            {
                wcb.And(cmsNews._.EditTime <= dt);
            }

            FromSection fs = GetFromSection(wcb.ToWhereClip(), cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs
                   .Page(pageSize, pageIndex)
                   .ToDataTable());
        }
예제 #13
0
        /// <summary>
        /// 根据条件取得专题下所有文章
        /// </summary>
        /// <param name="nodecode"></param>
        /// <param name="title"></param>
        /// <param name="source"></param>
        /// <param name="author"></param>
        /// <param name="tags"></param>
        /// <param name="iIndex"></param>
        /// <param name="iTop"></param>
        /// <param name="iAudit"></param>
        /// <param name="dtAdd1"></param>
        /// <param name="dtAdd2"></param>
        /// <param name="dtEdit1"></param>
        /// <param name="dtEdit2"></param>
        /// <param name="userId"></param>
        /// <param name="isAdmin"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetListInTopicByFilter(
            int ztId,
            string title,
            string source,
            string author,
            string tags,
            int iIndex,
            int iTop,
            int iAudit,
            string dtAdd1,
            string dtAdd2,
            string dtEdit1,
            string dtEdit2,
            int userId,
            bool isAdmin,
            int pageIndex,
            int pageSize,
            ref int recordCount
            )
        {
            WhereClipBuilder wcb = new WhereClipBuilder();

            if (ztId > 0)
            {
                wcb.And(cmsNewsTopicRel._.TopicId == ztId);
            }
            if (!isAdmin)
            {
                wcb.And(cmsNews._.IsAudit < 3);
            }
            if (!string.IsNullOrEmpty(title.Trim()))
            {
                wcb.And(cmsNews._.Title.Contain(title.Trim()));
            }
            if (!string.IsNullOrEmpty(source.Trim()))
            {
                wcb.And(cmsNews._.Source.Contain(source.Trim()));
            }
            if (!string.IsNullOrEmpty(author.Trim()))
            {
                wcb.And(cmsNews._.Author.Contain(author.Trim()));
            }
            if (!string.IsNullOrEmpty(tags.Trim()))
            {
                wcb.And(cmsNews._.Tags.Contain(tags.Trim()));
            }
            if (iIndex >= 0)
            {
                wcb.And(cmsNews._.IsIndex == iIndex);
            }
            if (iTop >= 0)
            {
                wcb.And(cmsNews._.IsTop == iTop);
            }
            if (iAudit >= 0)
            {
                wcb.And(cmsNews._.IsAudit == iAudit);
            }
            if (!isAdmin && userId > 0)
            {
                wcb.And(cmsNews._.AddUser == userId);
            }
            DateTime dt;

            if (DateTime.TryParse(dtAdd1.Trim(), out dt))
            {
                wcb.And(cmsNews._.AddTime >= dt);
            }
            if (DateTime.TryParse(dtAdd2.Trim(), out dt))
            {
                wcb.And(cmsNews._.AddTime <= dt);
            }
            if (DateTime.TryParse(dtEdit1.Trim(), out dt))
            {
                wcb.And(cmsNews._.EditTime >= dt);
            }
            if (DateTime.TryParse(dtEdit2.Trim(), out dt))
            {
                wcb.And(cmsNews._.EditTime <= dt);
            }

            FromSection fs = entCMS.Services.DBSession.CurrentSession.From <cmsNews>()
                             .InnerJoin <cmsNewsCatalog>(cmsNews._.NodeCode == cmsNewsCatalog._.NodeCode)
                             .InnerJoin <cmsNewsTopicRel>(cmsNews._.Id == cmsNewsTopicRel._.NewsId)
                             .Select(cmsNewsTopicRel._.TopicId, cmsNewsCatalog._.NodeName, cmsNews._.All)
                             .Where(wcb.ToWhereClip())
                             .OrderBy(cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs
                   .Page(pageSize, pageIndex)
                   .ToDataTable());
        }
예제 #14
0
        /// <summary>
        /// 根据条件取得下级所有文章
        /// </summary>
        /// <param name="nodecode"></param>
        /// <param name="title"></param>
        /// <param name="source"></param>
        /// <param name="author"></param>
        /// <param name="tags"></param>
        /// <param name="iIndex"></param>
        /// <param name="iTop"></param>
        /// <param name="iAudit"></param>
        /// <param name="dtAdd1"></param>
        /// <param name="dtAdd2"></param>
        /// <param name="dtEdit1"></param>
        /// <param name="dtEdit2"></param>
        /// <param name="userId"></param>
        /// <param name="isAdmin"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetListByFilter2(
            string nodecode,
            string title,
            string source,
            string author,
            string tags,
            int iIndex,
            int iTop,
            int iAudit,
            string dtAdd1,
            string dtAdd2,
            string dtEdit1,
            string dtEdit2,
            int userId,
            bool isAdmin,
            int pageIndex,
            int pageSize,
            ref int recordCount
            )
        {
            WhereClipBuilder wcb = new WhereClipBuilder();

            if (!string.IsNullOrEmpty(nodecode))
            {
                wcb.And(cmsNews._.NodeCode == nodecode); // 当前栏目
            }
            if (!string.IsNullOrEmpty(title.Trim()))
            {
                wcb.And(cmsNews._.Title.Contain(title.Trim()));
            }
            if (!string.IsNullOrEmpty(source.Trim()))
            {
                wcb.And(cmsNews._.Source.Contain(source.Trim()));
            }
            if (!string.IsNullOrEmpty(author.Trim()))
            {
                wcb.And(cmsNews._.Author.Contain(author.Trim()));
            }
            if (!string.IsNullOrEmpty(tags.Trim()))
            {
                wcb.And(cmsNews._.Tags.Contain(tags.Trim()));
            }
            if (iIndex >= 0)
            {
                wcb.And(cmsNews._.IsIndex == iIndex);
            }
            if (iTop >= 0)
            {
                wcb.And(cmsNews._.IsTop == iTop);
            }
            if (iAudit >= 0)
            {
                wcb.And(cmsNews._.IsAudit == iAudit);
            }
            if (!isAdmin && userId > 0)
            {
                //wcb.And(cmsNews._.AddUser == userId);
                wcb.And(cmsNews._.AddUser.SubQueryIn(
                            DBSession.CurrentSession.From <cmsUserMap>()
                            .Select(cmsUserMap._.UserId)
                            .Where(cmsUserMap._.UpUserId == userId)
                            )
                        );
            }
            DateTime dt;

            if (DateTime.TryParse(dtAdd1.Trim(), out dt))
            {
                wcb.And(cmsNews._.AddTime >= dt);
            }
            if (DateTime.TryParse(dtAdd2.Trim(), out dt))
            {
                wcb.And(cmsNews._.AddTime <= dt);
            }
            if (DateTime.TryParse(dtEdit1.Trim(), out dt))
            {
                wcb.And(cmsNews._.EditTime >= dt);
            }
            if (DateTime.TryParse(dtEdit2.Trim(), out dt))
            {
                wcb.And(cmsNews._.EditTime <= dt);
            }

            FromSection fs = GetFromSection(wcb.ToWhereClip(), cmsNews._.EditTime.Desc);

            recordCount = fs.Count();

            return(fs
                   .Select(cmsNews._.All)
                   .Page(pageSize, pageIndex)
                   .ToDataTable());
        }
예제 #15
0
        /// <summary>
        /// 创建分页查询
        /// </summary>
        /// <param name="fromSection"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        public virtual FromSection CreatePageFromSection(FromSection fromSection, int startIndex, int endIndex)
        {
            Check.Require(startIndex, "startIndex", Check.GreaterThanOrEqual<int>(1));
            Check.Require(endIndex, "endIndex", Check.GreaterThanOrEqual<int>(1));
            Check.Require(startIndex <= endIndex, "startIndex must be less than endIndex!");
            Check.Require(fromSection, "fromSection", Check.NotNullOrEmpty);



            int pageSize = endIndex - startIndex + 1;
            if (startIndex == 1)
            {
                fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString());
            }
            else
            {

                if (OrderByClip.IsNullOrEmpty(fromSection.OrderByClip))
                {
                    foreach (Field f in fromSection.Fields)
                    {
                        if (!f.PropertyName.Equals("*") && f.PropertyName.IndexOf('(') == -1)
                        {
                            fromSection.OrderBy(f.Asc);
                            break;
                        }
                    }
                }



                Check.Require(!OrderByClip.IsNullOrEmpty(fromSection.OrderByClip), "query.OrderByClip could not be null or empty!");

                int count = fromSection.Count(fromSection);

                List<Parameter> list = fromSection.Parameters;

                if (endIndex > count)
                {
                    int lastnumber = count - startIndex + 1;
                    if (startIndex > count)
                        lastnumber = count % pageSize;

                    fromSection.PrefixString = string.Concat(" TOP ", lastnumber.ToString());

                    fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                    //

                    fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS temp_table ");

                    fromSection.PrefixString = string.Empty;

                    fromSection.DistinctString = string.Empty;

                    fromSection.GroupBy(GroupByClip.None);

                    fromSection.Select(Field.All);

                    fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                    fromSection.Where(WhereClip.All);

                }
                else
                {

                    if (startIndex < count / 2)
                    {

                        fromSection.PrefixString = string.Concat(" TOP ", endIndex.ToString());

                        fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempIntable ");

                        fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString());

                        fromSection.DistinctString = string.Empty;

                        fromSection.GroupBy(GroupByClip.None);

                        fromSection.Select(Field.All);

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                        fromSection.Where(WhereClip.All);

                        //

                        fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempOuttable ");

                        fromSection.PrefixString = string.Empty;

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);
                    }
                    else
                    {
                        fromSection.PrefixString = string.Concat(" TOP ", (count - startIndex + 1).ToString());

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                        fromSection.TableName = string.Concat(" (", fromSection.SqlString, ") AS tempIntable ");

                        fromSection.PrefixString = string.Concat(" TOP ", pageSize.ToString());

                        fromSection.DistinctString = string.Empty;

                        fromSection.GroupBy(GroupByClip.None);

                        fromSection.Select(Field.All);

                        fromSection.OrderBy(fromSection.OrderByClip.ReverseOrderByClip);

                        fromSection.Where(WhereClip.All);
                    }

                }

                fromSection.Parameters = list;

            }

            return fromSection;

        }
예제 #16
0
 public static int Count <T>(FromSection <T> query) where T : Entity => query.Count();