列表条件分页查询
2015-12-08 17:12
573 查看
//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;
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;
相关文章推荐
- APP第一次使用会显示的页面,之后再次打开应用不会再显示
- sublime配置react开发环境
- 组合与继承之间选择
- 一个JavaWeb项目开发总结
- 图------有向网的建立、深度优先遍历,广度优先遍历
- 二叉树遍历算法之三:后序遍历
- 禁用键盘事件
- 1-3-03:计算(a+b)/c的值
- 如何更好地限制一个UITextField的输入长度
- 【总结】UML九种图
- tableview 中cell的复用机制
- python之路: 基础篇
- 1-4-18:点和正方形的关系
- Win8开机出现致命错误C00000022怎么办 解决方法介绍
- 面试复习必备之:Java面向对象
- Android使用ViewPager、PhotoView实现类似QQ空间图片浏览功能
- 人民币大小写金额转换
- Java编程思想学习心得(四)赋值操作符的陷阱
- 1-3-02:计算(a+b)*c的值
- JUinte测试