您的位置:首页 > 其它

列表条件分页查询

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: