码迷,mamicode.com
首页 > 其他好文 > 详细

列表条件分页查询

时间:2015-12-08 18:31:06      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:

//sql=sqlSelect+sqlFrom+sqlWhere+sqlOrder

 

            string sql = string.Empty;

            string sqlSelect = "SELECT cc.ClassId,cc.ClassName,cp.CourseName,pp.Title,pp.ReleaseTime,pp.IsPublic,pp.id as preparationId,cu.id as UnitId,cp.id as PackId,pp.ExamId,pp.IsPractice,pp.ExamId  ";//查询列

 

            //数据来源

            string sqlFrom = @"from yk_preparation pp -- 课程备课

                        join yk_courseunit cu on pp.CoureUnitId=cu.id -- 课程单元

                        join yk_coursepack cp on cu.CoursePackId=cp.id -- 课程包

                         left join yk_courseclass cc on cc.CoursePackId=cp.Id ";

 

            StringBuilder sqlWhere = new StringBuilder();//查询条件

            string sqlOrder = string.Empty;//排序

            string sqlCount = string.Empty;//查询总记录数

 

            sqlWhere.Append("where pp.`Status` = 0 and cu.`Status` = 0 ");

                       

            sqlWhere.Append("and cp.TeacherId = @0 ");//当前老师

            sqlWhere.Append("and cp.Term = @8 ");//当前学期

 

            //课程名称

            if(coursePackId>0)

                sqlWhere.Append("and cp.id =@1 ");

 

            //课程单元

            if (unitId>0)

                sqlWhere.Append("and cu.id  =@2 ");

 

            //是否分享 (-1:全部,0:不共享,1:共享)

            //if(isPublic >=0)

            //    sqlWhere.Append("and pp.IsPublic = @3 ");

 

            //发布日期

            sqlWhere.Append("and pp.ReleaseTime between @4 and @5 ");

 

            sqlOrder="ORDER BY pp.ReleaseTime DESC ";

 

            sql = sqlSelect + sqlFrom + sqlWhere.ToString() + sqlOrder + "limit @6,@7 ";

            sqlCount = @"select count(pp.id) "+sqlFrom+sqlWhere.ToString();

            int pageStart = (pageIndex - 1) * pageSize;

           

            List<PreparationModel> list = _content.FindPage<PreparationModel>(sql, sqlCount, pageIndex, pageSize, out totalCount, teacherId, coursePackId, unitId, isPublic, publishDateStart, publishDateEnd, pageStart, pageSize,termId);

           

            return list;

列表条件分页查询

标签:

原文地址:http://www.cnblogs.com/t-allen/p/5029679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!