//开放关闭编辑
        public ActionResult AjaxEditStatus(int id, int value)
        {
            PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL();
            Traning_Detail model = bll.GetTrainingDetail(id, "Delflag=0");
            bool result;
            string msg;

            if (model == null)
            {
                result = false;
                msg = "记录不存在!";
            }
            else
            {
                if (value == 1)//开放编辑
                {
                    if (model.CanEdit)
                    {
                        result = false;
                        msg = "课程已开放编辑!";
                    }
                    else
                    {
                        model.CanEdit = true;
                        bll.UpdateTrainingDetail(model);
                        result = true;
                        msg = "开放编辑成功!";
                    }
                }
                else if (value == 0)//关闭编辑
                {
                    if (!model.CanEdit)
                    {
                        result = false;
                        msg = "课程已关闭编辑!";
                    }
                    else
                    {
                        model.CanEdit = false;
                        bll.UpdateTrainingDetail(model);
                        result = true;
                        msg = "关闭编辑成功!";
                    }
                }
                else
                {
                    result = false;
                    msg = "操作失败!";
                }
            }

            return Json(new { Result = result, Msg = msg }, JsonRequestBehavior.AllowGet);
        }
        //课程审核
        public ActionResult AjaxTrainingCheck(int id, string value, string remark)
        {
            PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL();
            Traning_Detail model = bll.GetTrainingDetail(id, "Delflag=0 and Status in (2,4) and PartitionId=" + Code.SiteCache.Instance.LoginInfo.PartitionId);
            if (model == null)
            {
                return Json(new { Result = true, Msg = "记录不存在!" }, JsonRequestBehavior.AllowGet);
            }

            if (value == "1")//审核通过
            {
                model.Status = 3;
                model.ApplyRemark = "";
            }
            else//审核不通过
            {
                model.Status = 4;
                model.ApplyRemark = remark;
            }

            Traning_ApplyApplication apply = new Traning_ApplyApplication();
            apply.TraningId = model.Id;
            apply.Status = Convert.ToInt32(value);
            apply.Remark = model.ApplyRemark;
            apply.Creater = Code.SiteCache.Instance.LoginInfo.UserId;
            apply.OrganId = Code.SiteCache.Instance.ManageOrganId;
            apply.Delflag = false;
            apply.CreateDate = DateTime.Now;

            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    bll.UpdateTrainingDetail(model);//更新课程
                    bll.AddTrainingApply(apply);//新增一条课程审核记录
                    trans.Complete();
                    return Json(new { Result = true, Msg ="操作成功!" }, JsonRequestBehavior.AllowGet);
                }
                catch
                {
                    return Json(new { Result = false, Msg = "操作失败!" }, JsonRequestBehavior.AllowGet);
                }
            }
        }
        public ActionResult Edit(int id)
        {
            PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL();
            NationalAbility_CourseBLL nationalAbility_CourseBLL = new NationalAbility_CourseBLL();
            Traning_Detail model = bll.GetTrainingDetail(id, "Delflag=0 and Status<>1");
            if (model == null)
            {
                return Content("<script>setTimeout(function () { window.location.href = '/Prepare/TrainingCheck/List' }, 3000);</script>操作失败,3秒后自动返回到列表!");
            }

            ViewBag.TrainingObjectData = bll.GetTraningObject();
            ViewBag.SubjectData = bll.GetSubject();
            ViewBag.StudyLevelData = bll.GetStudyLevel();
            ViewBag.TrainingFormData = bll.GetTrainingForm();
            ViewBag.TeacherTitleData = bll.GetTeacherTitle();
            ViewBag.TrainingFeildData = bll.GetTrainingField("Delflag=0 and IsSpec=0", "");
            ViewBag.TrainingCategoryData = bll.GetTrainingCategory("Delflag=0 and Field=" + model.TraingField, "");
            ViewBag.TrainingTopicData = bll.GetTrainingTopic("Delflag=0 and CategoryId=" + model.TraingCategory, "");
            ViewBag.NationalCoursData = nationalAbility_CourseBLL.GetList2("Delflag=0 and TCategoryId=" + model.TraingCategory, "");
            ViewBag.AttachData = bll.GetAttachTable("Delflag=0 and TraningId=" + id, "");
            ViewBag.OutCourseTypeData = bll.GetOutCourseType("Delflag=0", "");
            Organ_Detail otypeModel = new Organ_DetailBLL().GetModel(Convert.ToInt32(model.OrganId));
            ViewBag.OTypeId = otypeModel == null ? 0 : Convert.ToInt32(otypeModel.OType);
            return View(model);
        }
        public ActionResult Check(int id, string checkResult, string unpassRemark)
        {
            PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL();
            Traning_Detail model = bll.GetTrainingDetail(id, "Delflag=0 and Status in (2,4)");
            if (model == null)
            {
                return Content("<script>setTimeout(function () { window.location.href = '/Prepare/TrainingCheck/List' }, 3000);</script>操作失败,3秒后自动返回到列表!");
            }

            if (checkResult == "1")//审核通过
            {
                model.Status = 3;
                model.ApplyRemark = null;
            }
            else//审核不通过
            {
                if (unpassRemark.Trim() == "")
                {
                    TempData["Msg"] = "不通过原因不能为空白!";
                    return Redirect("Check?Id=" + Dianda.Common.QueryString.UrlEncrypt(id));
                }
                model.Status = 4;
                model.ApplyRemark = unpassRemark.Trim();
            }

            int managerId = Code.SiteCache.Instance.ManagerId;
            int partitionId = Code.SiteCache.Instance.LoginInfo.PartitionId;

            Traning_ApplyApplication apply = new Traning_ApplyApplication();
            apply.TraningId = model.Id;
            apply.Status = Convert.ToInt32(checkResult);
            apply.Remark = model.ApplyRemark;
            apply.Creater = managerId;
            apply.OrganId = Code.SiteCache.Instance.ManageOrganId;
            apply.Delflag = false;
            apply.CreateDate = DateTime.Now;

            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    bll.UpdateTrainingDetail(model);//更新课程
                    bll.AddTrainingApply(apply);//新增一条课程审核记录
                    string msg = "";
                    if (model.Status == 3)
                    {
                        msg = string.Format("课程:{0} 审核通过!", model.Title);
                    }
                    else
                    {
                        msg = string.Format("课程:{0} 审核不通过,原因:{1}", model.Title, model.ApplyRemark);
                    }
                    Code.MsgHelper.sendMsg(model.Creater, managerId, partitionId, "审核信息", msg);//新增消息通知
                    trans.Complete();
                    return RedirectToAction("List");
                }
                catch
                {
                    TempData["Msg"] = "操作失败!";
                    return Redirect("Check?Id=" + Dianda.Common.QueryString.UrlEncrypt(id));
                }
            }
        }