/// <summary> /// 获取指定ID的章节信息(课程详细) /// </summary> /// <param name="id"></param> /// <returns></returns> public List<Course_ChapterSectionInfo> GetChapterSectionInfo(int TrainingId,int id) { string sql = @"select id,title,content,display, ((select COUNT(0) from [Course_UnitDetail] where ParentId = tt.Id and Delflag = 0) +(select COUNT(0) from Course_UnitContent where UnitId = tt.Id and Delflag = 0)) as AcCnt, ((select COUNT(0) from [Course_UnitDetail] where ParentId = tt.Id and Delflag = 0 and Display = 1) +(select COUNT(0) from Course_UnitContent where UnitId = tt.Id and Delflag = 0 and Display = 1)) as DisCnt from [dbo].[Course_UnitDetail] as tt where TrainingId =@TrainingId and ParentId=@Id and Delflag=0 order by sort"; SqlParameter[] cmdParams = new SqlParameter[]{ new SqlParameter("@TrainingId", SqlDbType.Int, 4) { Value = TrainingId }, new SqlParameter("@Id", SqlDbType.Int, 4) { Value = id } }; List<Course_ChapterSectionInfo> list = new List<Course_ChapterSectionInfo>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams)) { while(reader.Read()) { Course_ChapterSectionInfo model = new Course_ChapterSectionInfo(); model.Id = Convert.ToInt32(reader["id"]); model.Title = reader["title"].ToString(); model.Content = reader["content"].ToString(); model.Display = Convert.ToBoolean(reader["display"]); model.AcCnt = Convert.ToInt32(reader["AcCnt"]); model.DisCnt = Convert.ToInt32(reader["DisCnt"]); list.Add(model); } } return list; }
//Type=1表示只获取章,Type=2表示获取所有章节 public List<Course_ChapterSectionInfo> GetAllChapterSectionInfo(int TrainingId, int Type) { List<Course_ChapterSectionInfo> lstAllChapterSectionInfo = new List<Course_ChapterSectionInfo>(); //增加【请选择章节】节点 Course_ChapterSectionInfo head = new Course_ChapterSectionInfo(); head.Id = -1; if (Type == 1) { head.Title = "--请选择章--"; lstAllChapterSectionInfo.Add(head); } else { head.Title = "--请选择章节--"; lstAllChapterSectionInfo.Add(head); } //获取所有章的章节信息 List<Course_ChapterSectionInfo> list = GetChapterSectionInfo(TrainingId,0); foreach (var model in list) { model.Title = " " + model.Title; lstAllChapterSectionInfo.Add(model); if (Type == 2) { //若章有节,则将节添加到列表 if (GetChapterSectionInfo(TrainingId, model.Id) != null) { foreach (var model1 in GetChapterSectionInfo(TrainingId, model.Id)) { model1.Title = " |--" + model1.Title; lstAllChapterSectionInfo.Add(model1); } } } } return lstAllChapterSectionInfo; }