/// <summary>
        /// 检测是否能报名
        /// </summary>
        /// <param name="ClassId"></param>
        /// <returns></returns>
        public static bool CheckCanEnroll(int ClassId)
        {
            Class_Detail class_Detail = new Class_Detail();
            Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
            Member_ClassRegister member_ClassRegister = new Member_ClassRegister();
            member_ClassRegister.ClassId = ClassId;
            member_ClassRegister.PlanId = Code.SiteCache.Instance.PlanId;
            Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
            member_ClassRegister.TrainingId = class_DetailBLL.GetModel(ClassId).TraningId;
            member_ClassRegister.AccountId = Code.SiteCache.Instance.LoginInfo.UserId;
            member_ClassRegister.Status = 1;
            member_ClassRegister.ManagerId = Code.SiteCache.Instance.LoginInfo.UserId;
            member_ClassRegister.Delflag = false;
            member_ClassRegister.CreateDate = DateTime.Now;
            Course_UnitDetailBLL course_UnitDetailBLL = new Course_UnitDetailBLL();
            member_ClassRegister.TotalSchedule = course_UnitDetailBLL.GetList(" TrainingId='" + class_DetailBLL.GetModel(ClassId).TraningId + "' and ParentId=0 and Display=1 and Delflag='false'", "").Count;

            List<Member_ClassRegister> listno = member_ClassRegisterBLL.GetList(" ClassId='" + ClassId + "' and AccountId='" + Code.SiteCache.Instance.LoginInfo.UserId + "' and delflag='false' and Status in (1,2,4)", "");
            if (listno.Count > 0)
            {
                return false;
            }

            //List<Member_ClassRegister> listpass = member_ClassRegisterBLL.GetList(" TrainingId='" + member_ClassRegister.TrainingId + "' and AccountId='" + Code.SiteCache.Instance.LoginInfo.UserId + "' and delflag='false' and (Result=1 or (Result is NULL and Status=4))", "");
            //if (listpass.Count > 0)
            //{
            //    return false;
            //}

            return true;
        }
        public ActionResult AddCourseUnit(Course_UnitDetail model)
        {
            Course_UnitDetailBLL bll = new Course_UnitDetailBLL();

            if (bll.Add(model))
            {
                return Json(new { Result = true, Msg = "新增成功!" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = false, Msg = "新增失败!" }, JsonRequestBehavior.AllowGet);
            }
        }
 public List<Course_ChapterSectionInfo> GetChapterSectionInfo(int TrainingId, int ParentId)
 {
     Course_UnitDetailBLL bll = new Course_UnitDetailBLL();
     return bll.GetChapterSectionInfo(TrainingId, ParentId);
 }
        /*
         * 进度汇总逻辑:
         *
         * 1.用户每次学习课程时需要往 Member_ClassUnitContentSchedule 中插入数据,作为当前的章节小进度.
         * 2.当当前章节所有的课程学习结束,需要判断当前在章节是否学习结束;
         * 3.在修改章节进度和总进度时,需要重新验证所有的章节进度是否已完成(可能存在章节追加的情况).
         * 4.若当前章节全部学习结束,需要在总进度表中 Member_ClassRegister 更改CurrentSchedule(当前章节进度),TotalSchedule(总课程进度).
         *
         * 所用表:
            select * from Member_ClassRegister
            select * from Course_UnitContent  --1文本,2影音教材,3讨论,4作业 5测试,6结业考试
            select * from Member_ClassUnitContentSchedule
            select * from Course_Detail
            select * from Course_UnitDetail
         *
         * [课程]下 分 [章]下 分 [节]下 分 [活动]
         * 同时也可以在[章]下面没有节,只有[活动],所以需要获取章下面所有的活动
         */
        /// <summary>
        /// 更新总体进度
        /// </summary>
        /// <param name="iUnitId">当前[活动]所在[节]的ID</param>
        /// <param name="iClassId"></param>
        /// <param name="iTrainingId"></param>
        /// <param name="iAccountId"></param>
        /// <param name="iUnitContent"></param>
        private void UpdateOverallProgress(int iUnitId, int iClassId, int iTrainingId, int iAccountId, int iUnitContent)
        {
            var unitBll = new Course_UnitContentBLL();
            var detailBll = new Class_DetailBLL();
            var UnitDetailBll = new Course_UnitDetailBLL();
            var ClassRegisterBll = new Member_ClassRegisterBLL();
            var Member_ClassUnitContentSchedulebll = new Member_ClassUnitContentScheduleBLL();
            int iOverChapterCount = 0, iChapterTotalCount = 0;//完成的[章]的数量,当前课程需要学习的[章]总数,该[章]已完成的[节]的数量(该章的进度)

            //用户的在线学习模块都要插入一条数据到Member_ClassUnitContentSchedule,作为当前小章节的学习进度
            if (this.InsertMember_ClassUnitContentSchedule(iClassId, iTrainingId, iAccountId, iUnitContent))
            {
                var List_Course_UnitDetail = UnitDetailBll.GetList(" ParentId = 0 AND Display = 1 AND Delflag = 0 AND TrainingId = " + iTrainingId, string.Empty);
                iChapterTotalCount = List_Course_UnitDetail.Count;//当前课程学员需要完成学习的总章数

                foreach (var ChapterItem in List_Course_UnitDetail)
                {
                    bool bolResult = this.GetChapterProgress(ChapterItem.Id, iClassId, ChapterItem.TrainingId.Value, iAccountId);
                    if (bolResult)//当前[章]的进度
                    {
                        iOverChapterCount++;
                    }
                }
                //[Status] 1等待学校审核 2学校审核通过 3学校审核不通过 4开班机构审核通过 5开班机构审核不通过
                int iPlanId = Code.SiteCache.Instance.PlanId;
                string strWhere = string.Format(@" AccountId = {0} AND ClassId = {1} AND PlanId = {2} and TrainingId = {3} and Delflag = 0 AND Status = 4",
                    iAccountId, iClassId, iPlanId, iTrainingId);

                var List_Member_ClassRegister = ClassRegisterBll.GetList(strWhere, "CreateDate");
                if (List_Member_ClassRegister != null && List_Member_ClassRegister.Count == 1)
                {
                    var Model_Member_ClassRegister = List_Member_ClassRegister[0];

                    Model_Member_ClassRegister.CurrentSchedule = iOverChapterCount;//[章,节]完成数
                    Model_Member_ClassRegister.TotalSchedule = iChapterTotalCount;//课程总章,节数
                    Model_Member_ClassRegister.CreateDate = DateTime.Now;

                    bool bolResult = ClassRegisterBll.Update(Model_Member_ClassRegister);
                }
            }
        }
        /// <summary>
        /// 设置分数
        /// </summary>
        /// <param name="iUnitType">//1阅读,2讨论
        /// <param name="IsAdd">True:新增 False:删除</param>
        /// <param name="obj">数据对象</param>
        private void ScoreSet(int iUnitType, int? iUnitContent = 0, int iClassId = 0, int iTrainingId = 0, bool IsAdd = false, Object obj = null)
        {
            var scheduleBll = new Member_ClassUnitContentScheduleBLL();
            var replyBll = new Course_UnitReplyDetailBLL();

            int iPlanId = 0, iAccountId = 0, iUnitId = 0;
            double dblScore = 0;
            var stbSqlWhere = new StringBuilder();

            if (iUnitType == 1)
            {
                iPlanId = Code.SiteCache.Instance.PlanId;
                iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;

                stbSqlWhere.AppendFormat(" ClassId = {0} AND TrainingId = {1} AND AccountId = {2} AND UnitContent = {3} AND Status = 1 AND Delflag = 0",
                    iClassId, iTrainingId, iAccountId, iUnitContent);

                var List_Schedule = scheduleBll.GetList(stbSqlWhere.ToString(), string.Empty);
                if (List_Schedule != null && List_Schedule.Count > 0 && List_Schedule[0].score == null)//当存在记录,并且Score=null时记录分数
                {
                    Web.Code.ScoreSetHelper.ScoreSet(iUnitContent, iUnitType, iClassId, iPlanId, iAccountId, dblScore);
                }
            }
            else if (iUnitType == 2)//讨论  参与次数要 >=1
            {
                var model = obj as Course_UnitReplyDetail;
                iUnitContent = model.UnitContent;
                iClassId = model.ClassId;
                iPlanId = Code.SiteCache.Instance.PlanId;
                iAccountId = model.AccountId;
                stbSqlWhere.AppendFormat(" ClassId = {0} AND AccountId = {1} AND UnitContent = {2} AND Display = 1 AND Delflag = 0",
                        iClassId, iAccountId, iUnitContent);

                var List_ReplyDetail = replyBll.GetList(stbSqlWhere.ToString(), string.Empty);
                if (List_ReplyDetail != null)
                {
                    if (IsAdd)
                    {
                        if (List_ReplyDetail.Count <= 0)
                        {
                            Web.Code.ScoreSetHelper.ScoreSet(iUnitContent, iUnitType, iClassId, iPlanId, iAccountId, dblScore, true);
                        }
                    }
                    else
                    {
                        Web.Code.ScoreSetHelper.ScoreSet(iUnitContent, iUnitType, iClassId, iPlanId, iAccountId, dblScore, false);
                    }
                }

                //获取当前活动的UnitId
                var unitContentBll = new Course_UnitContentBLL();
                var Model_UnitContent = unitContentBll.GetModel(iUnitContent.Value, string.Empty);
                iUnitId = Model_UnitContent.UnitId == null ? 0 : Model_UnitContent.UnitId.Value;
                //获取TrainingId
                var unitDetailBll = new Course_UnitDetailBLL();
                var Model_UnitDetail = unitDetailBll.GetModel(iUnitId, string.Empty);
                iTrainingId = Model_UnitDetail.TrainingId == null ? 0 : Model_UnitDetail.TrainingId.Value;
                //更新总进度
                this.UpdateOverallProgress(iUnitId, iClassId, iTrainingId, iAccountId, iUnitContent.Value);//分数添加之后更新总进度
            }
        }
        /// <summary>
        /// 找到当前[活动小节]的最外层[章]
        /// </summary>
        /// <param name="iId"></param>
        /// <param name="iTrainingId"></param>
        /// <returns></returns>
        private Course_UnitDetail GetCourse_UnitDetail(int iId, int? iTrainingId)
        {
            var unitBll = new Course_UnitDetailBLL();
            var model = new Course_UnitDetail();

            model = unitBll.GetModel(iId, "TrainingId = " + iTrainingId.Value);

            if (model != null)
            {
                if (model.ParentId != 0)
                {
                    return GetCourse_UnitDetail(model.ParentId.Value, iTrainingId);
                }
                else
                {
                    return model;
                }
            }
            else
            {
                return null;
            }
        }
        public ActionResult DisplayCourseUnit(int id)
        {
            Course_UnitDetailBLL bll = new Course_UnitDetailBLL();

            Course_UnitDetail model = bll.GetModel(id,"Delflag = 0");

            //设置是否显示
            if (model.Display)
            {
                model.Display = false;
            }
            else
            {
                model.Display = true;
            }

            if (bll.Update(model))
            {
                return Json(new { Result = true,  Display= model.Display}, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = false, Display = model.Display}, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult DeleteCourseUnit(int id)
        {
            Course_UnitDetailBLL bll = new Course_UnitDetailBLL();

            if (bll.Delete(id))
            {
                return Json(new { Result = true, Msg = "删除成功!" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Result = false, Msg = "删除失败!" }, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult CourseUnitEdit(int TrainingId,int CourseId)
        {
            //ViewBag.Title = "课程单元编辑";
            Course_DetailBLL bll_CourseDetail = new Course_DetailBLL();
            Course_UnitDetailBLL bll = new Course_UnitDetailBLL();

            //指定课程的课程ID
            ViewBag.TrainingId = TrainingId;
            //获取指定课程ID对应的课程单元信息
            ViewBag.TrainingInfo = bll_CourseDetail.GetTrainingInfoById(TrainingId);
            //获取课程单元Model
            ViewBag.UnitDetailModel = bll.GetModel(CourseId,"Delflag = 0");

            return View();
        }
 public ActionResult TotalTimeLength(int TimeLengthId)
 {
     Course_UnitDetailBLL bll = new Course_UnitDetailBLL();
     int TotalTimeLength = bll.GetTotalTimeLength(TimeLengthId);
     return Json(new { Data = TotalTimeLength }, JsonRequestBehavior.AllowGet);
 }
 public ActionResult GetChapterSectionMaxOrder(int ParentId,int TrainingId)
 {
     Course_UnitDetailBLL bll = new Course_UnitDetailBLL();
     int Order = bll.GetChapterSectionMaxOrder(ParentId, TrainingId);
     return Json(new { MaxOrder = Order }, JsonRequestBehavior.AllowGet);
 }
 public List<Course_ChapterSectionInfo> GetChapterSectionInfo(int TrainingId, int ParentId)
 {
     List<Course_ChapterSectionInfo> list = new Course_UnitDetailBLL().GetChapterSectionInfo(TrainingId, ParentId); ;
     return list;
 }
        public JsonResult ClassRegisterAll(int ClassId, string Members, string MembersNames)
        {
            Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
            string[] members = Members.Trim().Substring(1, Members.Length - 2).Split(',');
            string[] membersNames = MembersNames.Trim().Substring(1, MembersNames.Length - 2).Split(',');
            string names = "";
            string namespass = "";
            string namescannotmessage = "";
            string message = "";

            for (int i = 0; i < members.Length; i++)
            {
                Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
                Member_ClassRegister member_ClassRegister = new Member_ClassRegister();

                List<Member_ClassRegister> listno = member_ClassRegisterBLL.GetList(" ClassId='" + ClassId + "' and AccountId='" + members[i] + "' and delflag='false' and Status in (1,2,4)", "");
                if (listno.Count > 0)
                {
                    names += membersNames[i] + ",";
                }

                List<Member_ClassRegister> listpass = member_ClassRegisterBLL.GetList(" TrainingId='" + member_ClassRegister.TrainingId + "' and AccountId='" + members[i] + "' and delflag='false' and (Result=1 or (Result is NULL and Status in(1,2,4)))", "");
                if (listpass.Count > 0)
                {
                    namespass += membersNames[i] + ",";
                }
                string checkmessage = IsCanRegisterAll(ClassId, false, Convert.ToInt32(members[i]));
                if (checkmessage != "")
                {
                    namescannotmessage += membersNames[i] + checkmessage;
                }
            }

            if (names != "")
            {
                message += names.Trim(',') + "已报名该课程;";
            }
            if (namespass != "")
            {
                message += namespass.Trim(',') + "已学过该课程;";
            }
            if (namescannotmessage != "")
            {
                message += namescannotmessage;
            }
            if (message != "")
            {
                return Json(new { Code = -1, Msg = message }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                Class_Detail class_Detail = new Class_Detail();
                class_Detail = class_DetailBLL.GetModel(ClassId);
                class_Detail.People += members.Length;
                class_DetailBLL.Update(class_Detail);
                for (int i = 0; i < members.Length; i++)
                {
                    Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
                    Member_ClassRegister member_ClassRegister = new Member_ClassRegister();

                    member_ClassRegister.ClassId = ClassId;
                    member_ClassRegister.PlanId = Code.SiteCache.Instance.PlanId;
                    member_ClassRegister.TrainingId = class_DetailBLL.GetModel(ClassId).TraningId;
                    member_ClassRegister.AccountId = Convert.ToInt32(members[i]);
                    member_ClassRegister.Status = 2;
                    member_ClassRegister.BatchCode = Guid.NewGuid();
                    member_ClassRegister.ManagerId = Code.SiteCache.Instance.LoginInfo.UserId;
                    member_ClassRegister.Delflag = false;
                    member_ClassRegister.CreateDate = DateTime.Now;
                    Course_UnitDetailBLL course_UnitDetailBLL = new Course_UnitDetailBLL();
                    member_ClassRegister.TotalSchedule = course_UnitDetailBLL.GetList(" TrainingId='" + class_DetailBLL.GetModel(ClassId).TraningId + "' and ParentId=0 and Display=1 and Delflag='false'", "").Count;

                    List<Member_ClassRegister> listup = member_ClassRegisterBLL.GetList(" ClassId='" + ClassId + "' and AccountId='" + members[i] + "' and delflag='false' and Status in (3,5)", "");
                    if (listup.Count > 0)
                    {
                        member_ClassRegister.Id = listup[0].Id;
                        member_ClassRegister.Status = 2;
                        member_ClassRegisterBLL.Update(member_ClassRegister);
                        if (member_ClassRegister.Id > 0)
                        {
                            Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
                            Member_ClassRegisterApplication member_ClassRegisterApplication = new Member_ClassRegisterApplication();
                            member_ClassRegisterApplication.ClassRegisterId = member_ClassRegister.Id;
                            member_ClassRegisterApplication.Status = 2;
                            member_ClassRegisterApplication.Creater = Code.SiteCache.Instance.LoginInfo.UserId;
                            member_ClassRegisterApplication.CreateDate = DateTime.Now;
                            member_ClassRegisterApplication.Delflag = false;
                            member_ClassRegisterApplicationBLL.Add(member_ClassRegisterApplication);
                        }
                        else { return Json(new { Code = -1, Msg = "提交失败" }, JsonRequestBehavior.AllowGet); }
                    }
                    else
                    {
                        int RegisterId = member_ClassRegisterBLL.Add(member_ClassRegister);
                        if (RegisterId > 0)
                        {
                            Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
                            Member_ClassRegisterApplication member_ClassRegisterApplication = new Member_ClassRegisterApplication();
                            member_ClassRegisterApplication.ClassRegisterId = RegisterId;
                            member_ClassRegisterApplication.Status = 2;
                            member_ClassRegisterApplication.Creater = Code.SiteCache.Instance.LoginInfo.UserId;
                            member_ClassRegisterApplication.CreateDate = DateTime.Now;
                            member_ClassRegisterApplication.Delflag = false;
                            member_ClassRegisterApplicationBLL.Add(member_ClassRegisterApplication);
                        }
                        else { return Json(new { Code = -1, Msg = "提交失败" }, JsonRequestBehavior.AllowGet); }
                    }
                }
            }
            return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult ClassRegister(int ClassId)
        {
            Class_Detail class_Detail = new Class_Detail();
            Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
            Member_ClassRegister member_ClassRegister = new Member_ClassRegister();
            member_ClassRegister.ClassId = ClassId;
            member_ClassRegister.PlanId = Code.SiteCache.Instance.PlanId;
            Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
            member_ClassRegister.TrainingId = class_DetailBLL.GetModel(ClassId).TraningId;
            member_ClassRegister.AccountId = Code.SiteCache.Instance.LoginInfo.UserId;
            member_ClassRegister.Status = 1;
            member_ClassRegister.ManagerId = Code.SiteCache.Instance.LoginInfo.UserId;
            member_ClassRegister.Delflag = false;
            member_ClassRegister.CreateDate = DateTime.Now;
            Course_UnitDetailBLL course_UnitDetailBLL = new Course_UnitDetailBLL();
            member_ClassRegister.TotalSchedule = course_UnitDetailBLL.GetList(" TrainingId='" + class_DetailBLL.GetModel(ClassId).TraningId + "' and ParentId=0 and Display=1 and Delflag='false'", "").Count;

            //if (!IsCanRegister(ClassId, true, Code.SiteCache.Instance.LoginInfo.UserId))
            string checkmessage = IsCanRegisterAll(ClassId, true, Code.SiteCache.Instance.LoginInfo.UserId);
            if (checkmessage != "")
            {
                return Json(new { Code = -1, Msg = checkmessage }, JsonRequestBehavior.AllowGet);
            }

            List<Member_ClassRegister> listno = member_ClassRegisterBLL.GetList(" ClassId='" + ClassId + "' and AccountId='" + Code.SiteCache.Instance.LoginInfo.UserId + "' and delflag='false' and Status in (1,2,4)", "");
            if (listno.Count > 0)
            {
                return Json(new { Code = -1, Msg = "您已经提交了报名申请" }, JsonRequestBehavior.AllowGet);
            }

            List<Member_ClassRegister> listpass = member_ClassRegisterBLL.GetList(" TrainingId='" + member_ClassRegister.TrainingId + "' and AccountId='" + Code.SiteCache.Instance.LoginInfo.UserId + "' and delflag='false' and (Result=1 or (Result is NULL and Status in(1,2,4)))", "");
            if (listpass.Count > 0)
            {
                return Json(new { Code = -1, Msg = "您已经学过该课程或已报名该课程下的其他班级" }, JsonRequestBehavior.AllowGet);
            }

            List<Member_ClassRegister> listup = member_ClassRegisterBLL.GetList(" ClassId='" + ClassId + "' and AccountId='" + Code.SiteCache.Instance.LoginInfo.UserId + "' and delflag='false' and Status in (3,5)", "");
            if (listup.Count > 0)
            {
                member_ClassRegister.Id = listup[0].Id;
                member_ClassRegister.Status = 1;
                member_ClassRegisterBLL.Update(member_ClassRegister);

                if (member_ClassRegister.Id > 0)
                {
                    class_Detail = class_DetailBLL.GetModel(member_ClassRegister.ClassId);
                    class_Detail.People += 1;
                    class_DetailBLL.Update(class_Detail);

                    Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
                    Member_ClassRegisterApplication member_ClassRegisterApplication = new Member_ClassRegisterApplication();
                    member_ClassRegisterApplication.ClassRegisterId = member_ClassRegister.Id;
                    member_ClassRegisterApplication.Status = 1;
                    member_ClassRegisterApplication.Creater = Code.SiteCache.Instance.LoginInfo.UserId;
                    member_ClassRegisterApplication.CreateDate = DateTime.Now;
                    member_ClassRegisterApplication.Delflag = false;
                    member_ClassRegisterApplicationBLL.Add(member_ClassRegisterApplication);
                    return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet);
                }
                else { return Json(new { Code = -1, Msg = "提交失败" }, JsonRequestBehavior.AllowGet); }
            }
            else
            {
                int RegisterId = member_ClassRegisterBLL.Add(member_ClassRegister);
                class_Detail = class_DetailBLL.GetModel(member_ClassRegister.ClassId);
                class_Detail.People += 1;
                class_DetailBLL.Update(class_Detail);
                if (RegisterId > 0)
                {
                    Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
                    Member_ClassRegisterApplication member_ClassRegisterApplication = new Member_ClassRegisterApplication();
                    member_ClassRegisterApplication.ClassRegisterId = RegisterId;
                    member_ClassRegisterApplication.Status = 1;
                    member_ClassRegisterApplication.Creater = Code.SiteCache.Instance.LoginInfo.UserId;
                    member_ClassRegisterApplication.CreateDate = DateTime.Now;
                    member_ClassRegisterApplication.Delflag = false;
                    member_ClassRegisterApplicationBLL.Add(member_ClassRegisterApplication);
                    return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet);
                }
                else { return Json(new { Code = -1, Msg = "提交失败" }, JsonRequestBehavior.AllowGet); }
            }
        }