/// <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;
        }
 /// <summary>
 /// 获取数据集
 /// </summary>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 public List<Member_ClassRegister> GetList(string where, string orderBy)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from [dbo].[Member_ClassRegister]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     if (!string.IsNullOrEmpty(orderBy))
         sql.Append(" order by " + orderBy);
     List<Member_ClassRegister> list = new List<Member_ClassRegister>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Member_ClassRegister model = new Member_ClassRegister();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Member_ClassRegister model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("insert into [dbo].[Member_ClassRegister] ([ClassId],[PlanId],[AccountId],[Status],[ApplyRemark],[BatchCode],[ManagerId],[IsPass],[CurrentSchedule],[TotalSchedule],[ReadingScore],[DiscussScore],[HomeWorkScore],[TestingScore],[ExaminationScore],[CommentScore],[TotalScore],[Result],[ResultCreater],[Delflag],[CreateDate],[TrainingId],[OtherScore])");
     sql.Append(" values (@ClassId,@PlanId,@AccountId,@Status,@ApplyRemark,@BatchCode,@ManagerId,@IsPass,@CurrentSchedule,@TotalSchedule,@ReadingScore,@DiscussScore,@HomeWorkScore,@TestingScore,@ExaminationScore,@CommentScore,@TotalScore,@Result,@ResultCreater,@Delflag,@CreateDate,@TrainingId,@OtherScore)");
     sql.Append(" set @Id=@@IDENTITY");
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@PlanId", SqlDbType.Int, 4) { Value = model.PlanId },
         new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = model.AccountId },
         new SqlParameter("@Status", SqlDbType.Int, 4) { Value = model.Status },
         new SqlParameter("@ApplyRemark", SqlDbType.VarChar, 500) { Value = model.ApplyRemark },
         new SqlParameter("@BatchCode", SqlDbType.UniqueIdentifier, 16) { Value = model.BatchCode },
         new SqlParameter("@ManagerId", SqlDbType.Int, 4) { Value = model.ManagerId },
         new SqlParameter("@IsPass", SqlDbType.Bit, 1) { Value = model.IsPass },
         new SqlParameter("@CurrentSchedule", SqlDbType.Int, 4) { Value = model.CurrentSchedule },
         new SqlParameter("@TotalSchedule", SqlDbType.Int, 4) { Value = model.TotalSchedule },
         new SqlParameter("@ReadingScore", SqlDbType.Float, 8) { Value = model.ReadingScore },
         new SqlParameter("@DiscussScore", SqlDbType.Float, 8) { Value = model.DiscussScore },
         new SqlParameter("@HomeWorkScore", SqlDbType.Float, 8) { Value = model.HomeWorkScore },
         new SqlParameter("@TestingScore", SqlDbType.Float, 8) { Value = model.TestingScore },
         new SqlParameter("@ExaminationScore", SqlDbType.Float, 8) { Value = model.ExaminationScore },
         new SqlParameter("@CommentScore", SqlDbType.Float, 8) { Value = model.CommentScore },
         new SqlParameter("@TotalScore", SqlDbType.Float, 8) { Value = model.TotalScore },
         new SqlParameter("@Result", SqlDbType.Int, 4) { Value = model.Result },
         new SqlParameter("@ResultCreater", SqlDbType.Int, 4) { Value = model.ResultCreater },
         new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag },
         new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate },
         new SqlParameter("@TrainingId", SqlDbType.Int, 4) { Value = model.TrainingId },
         new SqlParameter("@OtherScore", SqlDbType.Float, 8) { Value = model.OtherScore }
     };
     int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams));
     model.Id = Convert.ToInt32(cmdParams[0].Value);
     return result;
 }
 private void ConvertToModel(IDataReader reader, Member_ClassRegister model)
 {
     if (reader["Id"] != DBNull.Value)
         model.Id = Convert.ToInt32(reader["Id"]);
     if (reader["ClassId"] != DBNull.Value)
         model.ClassId = Convert.ToInt32(reader["ClassId"]);
     if (reader["PlanId"] != DBNull.Value)
         model.PlanId = Convert.ToInt32(reader["PlanId"]);
     if (reader["AccountId"] != DBNull.Value)
         model.AccountId = Convert.ToInt32(reader["AccountId"]);
     if (reader["Status"] != DBNull.Value)
         model.Status = Convert.ToInt32(reader["Status"]);
     if (reader["ApplyRemark"] != DBNull.Value)
         model.ApplyRemark = reader["ApplyRemark"].ToString();
     if (reader["BatchCode"] != DBNull.Value)
         model.BatchCode = (Guid)(reader["BatchCode"]);
     if (reader["ManagerId"] != DBNull.Value)
         model.ManagerId = Convert.ToInt32(reader["ManagerId"]);
     if (reader["IsPass"] != DBNull.Value)
         model.IsPass = Convert.ToBoolean(reader["IsPass"]);
     if (reader["CurrentSchedule"] != DBNull.Value)
         model.CurrentSchedule = Convert.ToInt32(reader["CurrentSchedule"]);
     if (reader["TotalSchedule"] != DBNull.Value)
         model.TotalSchedule = Convert.ToInt32(reader["TotalSchedule"]);
     if (reader["ReadingScore"] != DBNull.Value)
         model.ReadingScore = Convert.ToDouble(reader["ReadingScore"]);
     if (reader["DiscussScore"] != DBNull.Value)
         model.DiscussScore = Convert.ToDouble(reader["DiscussScore"]);
     if (reader["HomeWorkScore"] != DBNull.Value)
         model.HomeWorkScore = Convert.ToDouble(reader["HomeWorkScore"]);
     if (reader["TestingScore"] != DBNull.Value)
         model.TestingScore = Convert.ToDouble(reader["TestingScore"]);
     if (reader["ExaminationScore"] != DBNull.Value)
         model.ExaminationScore = Convert.ToDouble(reader["ExaminationScore"]);
     if (reader["CommentScore"] != DBNull.Value)
         model.CommentScore = Convert.ToDouble(reader["CommentScore"]);
     if (reader["TotalScore"] != DBNull.Value)
         model.TotalScore = Convert.ToDouble(reader["TotalScore"]);
     if (reader["Result"] != DBNull.Value)
         model.Result = Convert.ToInt32(reader["Result"]);
     if (reader["ResultCreater"] != DBNull.Value)
         model.ResultCreater = Convert.ToInt32(reader["ResultCreater"]);
     if (reader["Delflag"] != DBNull.Value)
         model.Delflag = Convert.ToBoolean(reader["Delflag"]);
     if (reader["CreateDate"] != DBNull.Value)
         model.CreateDate = Convert.ToDateTime(reader["CreateDate"]);
     if (reader["TrainingId"] != DBNull.Value)
         model.TrainingId = Convert.ToInt32(reader["TrainingId"]);
     if (reader["OtherScore"] != DBNull.Value)
         model.OtherScore = Convert.ToDouble(reader["OtherScore"]);
 }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(Member_ClassRegister model)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("update [dbo].[Member_ClassRegister] set ");
     sql.Append("[ClassId]=@ClassId,[PlanId]=@PlanId,[AccountId]=@AccountId,[Status]=@Status,[ApplyRemark]=@ApplyRemark,[BatchCode]=@BatchCode,[ManagerId]=@ManagerId,[IsPass]=@IsPass,[CurrentSchedule]=@CurrentSchedule,[TotalSchedule]=@TotalSchedule,[ReadingScore]=@ReadingScore,[DiscussScore]=@DiscussScore,[HomeWorkScore]=@HomeWorkScore,[TestingScore]=@TestingScore,[ExaminationScore]=@ExaminationScore,[CommentScore]=@CommentScore,[TotalScore]=@TotalScore,[Result]=@Result,[ResultCreater]=@ResultCreater,[Delflag]=@Delflag,[CreateDate]=@CreateDate,[TrainingId]=@TrainingId,[OtherScore]=@OtherScore");
     sql.Append(" where [Id]=@Id");
     SqlParameter[] cmdParams = new SqlParameter[] {
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id },
         new SqlParameter("@ClassId", SqlDbType.Int, 4) { Value = model.ClassId },
         new SqlParameter("@PlanId", SqlDbType.Int, 4) { Value = model.PlanId },
         new SqlParameter("@AccountId", SqlDbType.Int, 4) { Value = model.AccountId },
         new SqlParameter("@Status", SqlDbType.Int, 4) { Value = model.Status },
         new SqlParameter("@ApplyRemark", SqlDbType.VarChar, 500) { Value = model.ApplyRemark },
         new SqlParameter("@BatchCode", SqlDbType.UniqueIdentifier, 16) { Value = model.BatchCode },
         new SqlParameter("@ManagerId", SqlDbType.Int, 4) { Value = model.ManagerId },
         new SqlParameter("@IsPass", SqlDbType.Bit, 1) { Value = model.IsPass },
         new SqlParameter("@CurrentSchedule", SqlDbType.Int, 4) { Value = model.CurrentSchedule },
         new SqlParameter("@TotalSchedule", SqlDbType.Int, 4) { Value = model.TotalSchedule },
         new SqlParameter("@ReadingScore", SqlDbType.Float, 8) { Value = model.ReadingScore },
         new SqlParameter("@DiscussScore", SqlDbType.Float, 8) { Value = model.DiscussScore },
         new SqlParameter("@HomeWorkScore", SqlDbType.Float, 8) { Value = model.HomeWorkScore },
         new SqlParameter("@TestingScore", SqlDbType.Float, 8) { Value = model.TestingScore },
         new SqlParameter("@ExaminationScore", SqlDbType.Float, 8) { Value = model.ExaminationScore },
         new SqlParameter("@CommentScore", SqlDbType.Float, 8) { Value = model.CommentScore },
         new SqlParameter("@TotalScore", SqlDbType.Float, 8) { Value = model.TotalScore },
         new SqlParameter("@Result", SqlDbType.Int, 4) { Value = model.Result },
         new SqlParameter("@ResultCreater", SqlDbType.Int, 4) { Value = model.ResultCreater },
         new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag },
         new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate },
         new SqlParameter("@TrainingId", SqlDbType.Int, 4) { Value = model.TrainingId },
         new SqlParameter("@OtherScore", SqlDbType.Float, 8) { Value = model.OtherScore }
     };
     return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams);
 }
        public Member_ClassRegister GetModel(string where)
        {
            string sql = "select * from [dbo].[Member_ClassRegister]";
            if (!string.IsNullOrEmpty(where))
                sql += " where " + where;

            using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql))
            {
                if (reader.Read())
                {
                    Member_ClassRegister model = new Member_ClassRegister();
                    ConvertToModel(reader, model);
                    return model;
                }
                else
                {
                    return null;
                }
            }
        }
 /// <summary>
 /// 取得一条记录
 /// </summary>
 /// <param name="id"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public Member_ClassRegister GetModel(int id, string where)
 {
     string sql = "select * from [dbo].[Member_ClassRegister] where [Id]=@Id";
     if (!string.IsNullOrEmpty(where))
         sql += " and " + where;
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = id }
     };
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams))
     {
         if (reader.Read())
         {
             Member_ClassRegister model = new Member_ClassRegister();
             ConvertToModel(reader, model);
             return model;
         }
         else
         {
             return null;
         }
     }
 }
        /// <summary>
        /// 课程是否已结束
        /// </summary>
        /// <param name="iClassId"></param>
        /// <param name="iTrainingId"></param>
        /// <param name="iAccountId"></param>
        /// <returns></returns>
        private bool GetCourseIsOver(int iClassId, int iTrainingId, int iAccountId)
        {
            var classBll = new Class_DetailBLL();
            var registerBll = new Member_ClassRegisterBLL();
            var Model_Member_ClassRegister = new Member_ClassRegister();
            int iPlanId = Code.SiteCache.Instance.PlanId;
            var iResult = 0;

            ///***************************************************************1. 判断当前班级的课程有没有结束  开始***************************************************************/
            //var Model_Class_Detail = classBll.GetModel(iClassId);
            //if (Model_Class_Detail.Status == 6 || Model_Class_Detail.OpenClassTo > DateTime.Now)//班级的课程已结束
            //{
            //    return true;
            //}
            ///***************************************************************判断当前班级的课程有没有结束  结束***************************************************************/

            /***************************************************************2. 判断当前用户的课程有没有结束  开始***************************************************************/
            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 = registerBll.GetList(strWhere, "CreateDate");
            if (List_Member_ClassRegister != null && List_Member_ClassRegister.Count == 1)
            {
                Model_Member_ClassRegister = List_Member_ClassRegister[0];
                iResult = Model_Member_ClassRegister.Result == null ? 0 : Convert.ToInt32(Model_Member_ClassRegister.Result.Value);
            }
            /***************************************************************判断当前用户的课程有没有结束  结束***************************************************************/

            return iResult == 1;
        }
        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);
        }
 /// <summary>
 /// 新增一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Add(Member_ClassRegister model)
 {
     return dal.Add(model);
 }
 /// <summary>
 /// 更新一条记录
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool Update(Member_ClassRegister model)
 {
     return dal.Update(model) > 0;
 }
        public JsonResult MyVerifyAll(int Status, string Ids)
        {
            try
            {
                string[] myIds = Ids.Trim(',').Split(',');
                foreach (string Id in myIds)
                {
                    Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
                    Member_ClassRegister member_ClassRegister = new Member_ClassRegister();
                    member_ClassRegister = member_ClassRegisterBLL.GetModel(Convert.ToInt32(Id), "");

                    if ((Status == 3 && member_ClassRegister.Status != 3) || (Status == 5 && member_ClassRegister.Status != 5))
                    {
                        Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
                        Class_Detail class_Detail = new Class_Detail();
                        class_Detail = class_DetailBLL.GetModel(member_ClassRegister.ClassId);
                        class_Detail.People -= 1;
                        class_DetailBLL.Update(class_Detail);
                    }
                    else if ((Status == 2 && member_ClassRegister.Status == 3) || (Status == 4 && member_ClassRegister.Status == 5) || (Status == 2 && member_ClassRegister.Status == 5))
                    {
                        Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
                        Class_Detail class_Detail = new Class_Detail();
                        class_Detail = class_DetailBLL.GetModel(member_ClassRegister.ClassId);
                        class_Detail.People += 1;
                        class_DetailBLL.Update(class_Detail);
                    }
                    member_ClassRegister.Status = Status;
                    member_ClassRegisterBLL.Update(member_ClassRegister);

                    Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
                    Member_ClassRegisterApplication member_ClassRegisterApplication = new Member_ClassRegisterApplication();
                    member_ClassRegisterApplication.ClassRegisterId = Convert.ToInt32(Id);
                    member_ClassRegisterApplication.Status = Status;
                    member_ClassRegisterApplication.Creater = Code.SiteCache.Instance.LoginInfo.UserId;
                    member_ClassRegisterApplication.Delflag = false;
                    member_ClassRegisterApplication.CreateDate = DateTime.Now;
                    member_ClassRegisterApplicationBLL.Add(member_ClassRegisterApplication);
                }
                return Json(new { Code = 0, Msg = "提交成功" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new { Code = -1, Msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult DetailInformation(int Id)
        {
            ViewBag.Title = "报名详细信息";
            Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
            Member_ClassRegister member_ClassRegister = new Member_ClassRegister();
            member_ClassRegister = member_ClassRegisterBLL.GetModel(Id, "");

            Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
            Class_Detail class_Detail = new Class_Detail();
            class_Detail = class_DetailBLL.GetModel(member_ClassRegister.ClassId);

            Member_AccountBLL member_AccountBLL = new Member_AccountBLL();
            ViewBag.AcountInfo = member_AccountBLL.GetModel(member_ClassRegister.AccountId, "");

            Member_BaseInfoBLL member_BaseInfoBLL = new Member_BaseInfoBLL();
            ViewBag.BaseInfo = member_BaseInfoBLL.GetModelByAccountId(member_ClassRegister.AccountId);

            Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
            ViewBag.CApplicationList = member_ClassRegisterApplicationBLL.GetList(" Delflag='false' and ClassRegisterId='" + member_ClassRegister.Id + "'", "CreateDate");
            return View(class_Detail);
        }
        public ActionResult CoursemarketVerifyPage(int Id)
        {
            int groupId = Code.SiteCache.Instance.GroupId;//4,学校管理7,普通教师
            ViewData["groupId"] = groupId;
            ViewData["mId"] = Id;
            ViewBag.Title = "报名审核";
            Member_ClassRegisterBLL member_ClassRegisterBLL = new Member_ClassRegisterBLL();
            Member_ClassRegister member_ClassRegister = new Member_ClassRegister();
            member_ClassRegister = member_ClassRegisterBLL.GetModel(Id, "");

            Class_DetailBLL class_DetailBLL = new Class_DetailBLL();
            Class_Detail class_Detail = new Class_Detail();
            class_Detail = class_DetailBLL.GetModel(member_ClassRegister.ClassId);

            Member_AccountBLL member_AccountBLL = new Member_AccountBLL();
            ViewBag.AcountInfo = member_AccountBLL.GetModel(member_ClassRegister.AccountId, "");

            Member_BaseInfoBLL member_BaseInfoBLL = new Member_BaseInfoBLL();
            ViewBag.BaseInfo = member_BaseInfoBLL.GetModelByAccountId(member_ClassRegister.AccountId);

            Member_ClassRegisterApplicationBLL member_ClassRegisterApplicationBLL = new Member_ClassRegisterApplicationBLL();
            ViewBag.CApplicationList = member_ClassRegisterApplicationBLL.GetList(" Delflag='false' and ClassRegisterId='" + member_ClassRegister.Id + "'", "CreateDate");
            return View(class_Detail);
        }
        /// <summary>
        /// 当前[我的进度]
        /// </summary>
        /// <param name="TrainingId"></param>
        public void MyProgress(int TrainingId)
        {
            int iAccountId = 0, iClassId = 0,iPlanId=0;

            iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;
            int.TryParse(Convert.ToString(Request["ClassId"]) == "" ? "0" : QueryString.Decrypt(Request["ClassId"]), out iClassId);//获取 ClassId
            iPlanId = Code.SiteCache.Instance.PlanId;

            Member_ClassRegister Model_Member_ClassRegister = new Member_ClassRegister();

            var bll = new Member_ClassRegisterBLL();
            string strWhere = string.Format(@"AccountId = {0} AND ClassId = {1} AND PlanId = {2} and TrainingId = {3} and Delflag = 0 AND Status = 4 ",
                iAccountId, iClassId, iPlanId, TrainingId);
            var List_Member_ClassRegister = bll.GetList(strWhere, "CreateDate");

            if (List_Member_ClassRegister != null && List_Member_ClassRegister.Count == 1)
            {
                Model_Member_ClassRegister = List_Member_ClassRegister[0];
            }

            ViewBag.Model_Member_ClassRegister = Model_Member_ClassRegister;
        }
 /// <summary>
 /// 获取分页数据集
 /// </summary>
 /// <param name="pageSize"></param>
 /// <param name="pageIndex"></param>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <param name="recordCount"></param>
 /// <returns></returns>
 public List<Member_ClassRegister> GetList(int pageSize, int pageIndex, string where, string orderBy, out int recordCount)
 {
     if (string.IsNullOrEmpty(orderBy))
         throw new ArgumentNullException();
     StringBuilder sb = new StringBuilder();
     sb.Append("select count(1) from [dbo].[Member_ClassRegister]");
     if (!string.IsNullOrEmpty(where))
         sb.Append(" where " + where);
     recordCount = Convert.ToInt32(MSEntLibSqlHelper.ExecuteScalarBySql(sb.ToString()));
     int start = (pageIndex - 1) * pageSize + 1;
     int end = pageIndex * pageSize;
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from (select *,ROW_NUMBER() over (order by " + orderBy + ") as [RowNum] from [dbo].[Member_ClassRegister]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     sql.Append(") as T where [RowNum] between " + start + " and " + end);
     List<Member_ClassRegister> list = new List<Member_ClassRegister>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             Member_ClassRegister model = new Member_ClassRegister();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }
        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); }
            }
        }