Beispiel #1
0
        public ResponseJson SetScore(int id, int score)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Question model;

                model = olsEni.Questions.SingleOrDefault(m => m.Q_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                model.Q_Score             = score;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #2
0
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Question q;

                q = olsEni.Questions.SingleOrDefault(m => m.Q_Id == id);

                if (null == q)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                ResumeClassify(q.QC_Id, status);

                q.Q_Status            = (Byte)status;
                olsEni.Entry(q).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #3
0
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                PermissionCategory model;

                model = olsEni.PermissionCategories.SingleOrDefault(m => m.PC_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                model.PC_Status           = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #4
0
        public ResponseJson Create(Duty model)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            try
            {
                Int32 id;

                id = GetDuId();

                model.Du_Id   = id;
                model.Du_Sort = id;
                olsEni.Duties.Add(model);
                olsEni.SaveChanges();
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
            }

            return(resJson);
        }
Beispiel #5
0
        public ResponseJson Create(Duty model)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            try
            {

                Int32 id;

                id = GetDuId();

                model.Du_Id = id;
                model.Du_Sort = id;
                olsEni.Duties.Add(model);
                olsEni.SaveChanges();

            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
            }

            return resJson;
        }
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            throw new NotImplementedException();

            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationPaperTemplate model;

                model = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.EPT_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                model.EPT_Status          = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #7
0
        public ResponseJson ModifyPassword(Int32 uId, String oldPassword, String newPassword)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                User model;

                model = olsEni.Users.SingleOrDefault(m =>
                                                     m.U_Id == uId &&
                                                     m.U_Status == (Byte)Status.Available);

                if (null == model)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "用户不存在。";
                    return(resJson);
                }

                oldPassword = EncryptPassword(oldPassword);

                if (oldPassword != model.U_Password)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "旧密码不正确。";
                    return(resJson);
                }

                // 不允许将密码设置为“**********”
                if (newPassword == "**********")
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "新密码无效。";
                    return(resJson);
                }

                newPassword      = EncryptPassword(newPassword);
                model.U_Password = newPassword;
                if (olsEni.SaveChanges() == 0)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "密码修改失败。";
                    return(resJson);
                }

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #8
0
        internal ResponseJson CacheClear()
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                List <Question>         qs;
                List <QuestionClassify> qcs;

                qs = olsEni.Questions.Where(m => m.Q_Status == (Byte)Status.Cache).ToList();
                foreach (var q in qs)
                {
                    olsEni.Entry(q).State = EntityState.Deleted;
                }

                if (olsEni.SaveChanges() == 0)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "缓存清除失败。";
                    return(resJson);
                }

                // 获取状态为“缓存”的分类
                // 状态为“缓存”的分类中没有“正常”的试题,所以,如果其中仍存在试题,状态只可能是“回收”和“删除”两种类型
                qcs = olsEni.QuestionClassifies.Where(m => m.QC_Status == (Byte)Status.Cache).ToList();
                foreach (var qc in qcs)
                {
                    if (olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id).Count() == 0)
                    {
                        olsEni.Entry(qc).State = EntityState.Deleted;
                    }
                    // 如果所有试题状态为“删除”,则将分类状态也设为“删除”
                    else if (olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id).Count() == olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id && m.Q_Status == (Byte)Status.Delete).Count())
                    {
                        qc.QC_Status = (Byte)Status.Delete;
                    }
                    // 否则设为“回收”
                    else
                    {
                        qc.QC_Status = (Byte)Status.Recycle;
                    }
                }
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        public ResponseJson GetZTreeResJson(Byte status)
        {
            ResponseJson resJson;

            resJson      = new ResponseJson(ResponseStatus.Success, now);
            resJson.data = GetZTreeJson(status);

            return(resJson);
        }
        /*public ResponseJson GetQuestions(Int32 id, Int32 uId)
         * {
         *
         *  ResponseJson resJson;
         *
         *  resJson = new ResponseJson();
         *
         *  try
         *  {
         *
         *      Int32 epId;
         *      ExaminationPaper ep;
         *      List<ExaminationPaperQuestion> epqs;
         *      List<ExaminationPaperTemplateQuestion> eptqs;
         *
         *      ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EPT_Id == id && m.EP_UserId == uId);
         *
         *      if (null == ep)
         *      {
         *          resJson.status = ResponseStatus.Error;
         *          resJson.message = "未考试";
         *          return resJson;
         *      }
         *
         *      if (ep.EP_PaperStatus != (Byte)PaperStatus.Done)
         *      {
         *          resJson.status = ResponseStatus.Error;
         *          resJson.message = "考试未结束";
         *          return resJson;
         *      }
         *
         *      epId = ep.EP_Id;
         *
         *      eptqs =
         *          olsEni
         *          .ExaminationPaperTemplateQuestions
         *          .Where(m =>
         *              m.EPT_Id == id
         *              && m.EPTQ_Status == (Byte)Status.Available)
         *          .ToList();
         *      epqs = olsEni.ExaminationPaperQuestions.Where(m => m.EP_Id == epId).ToList();
         *
         *      resJson.status = ResponseStatus.Success;
         *      resJson.data = JsonConvert.SerializeObject(new Object[] { eptqs, epqs, epId });
         *      return resJson;
         *  }
         *  catch (Exception ex)
         *  {
         *      resJson.status = ResponseStatus.Error;
         *      resJson.message = ex.Message;
         *      resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
         *      return resJson;
         *  }
         * }*/

        public ResponseJson GetQuestions(Int32 id, Int32 epId, Int32 uId)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationPaper ep;
                List <ExaminationPaperQuestion>         epqs;
                List <ExaminationPaperTemplateQuestion> eptqs;
                ExaminationPaperTemplate ept;
                ExaminationTask          et;

                ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == epId && m.EP_UserId == uId);

                if (null == ep)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "未考试";
                    return(resJson);
                }

                if (ep.EP_PaperStatus != (Byte)PaperStatus.Done)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "考试未结束";
                    return(resJson);
                }

                eptqs =
                    olsEni
                    .ExaminationPaperTemplateQuestions
                    .Where(m =>
                           m.EPT_Id == id &&
                           m.EPTQ_Status == (Byte)Status.Available)
                    .ToList();
                epqs = olsEni.ExaminationPaperQuestions.Where(m => m.EP_Id == epId).ToList();

                ept = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == id);
                et  = olsEni.ExaminationTasks.Single(m => m.ET_Id == ept.ET_Id);

                resJson.status   = ResponseStatus.Success;
                resJson.data     = JsonConvert.SerializeObject(new Object[] { eptqs, epqs, epId });
                resJson.addition = et;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #11
0
        private ResponseJson SetManualTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus)
        {
            Int32        eptId;
            ResponseJson resJson;
            UExaminationPaperTemplate       uept;
            List <ExaminationPaperTemplate> epts;
            List <ExaminationPaper>         eps;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            epts =
                olsEni
                .ExaminationPaperTemplates
                .Where(m => m.ET_Id == et.ET_Id)
                .ToList();
            if (epts.Count != 1)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "试卷模板不匹配。";
                return(resJson);
            }

            epts[0].EPT_PaperTemplateStatus = (Byte)etStatus;

            // 开始任务及试卷模板
            if (ExaminationTaskStatus.Enabled == etStatus)
            {
                epts[0].EPT_StartTime = now;
                epts[0].EPT_StartDate = now.Date;
                epts[0].EPT_EndTime   = now.AddMinutes(epts[0].EPT_TimeSpan);
            }
            // 终止任务及试卷模板、试卷
            else if (ExaminationTaskStatus.Disabled == etStatus)
            {
                uept = new UExaminationPaperTemplate();

                epts[0].EPT_EndTime = DateTime.Now;

                // 终止试卷
                eptId = epts[0].EPT_Id;
                eps   = olsEni.ExaminationPapers
                        .Where(m => m.EPT_Id == eptId)
                        .ToList();
                foreach (var ep in eps)
                {
                    ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                    uept.GradePaper(ep);
                    uept.SaveChanges();
                }
            }

            return(resJson);
        }
        /// <summary>
        /// 终止考试
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ResponseJson Terminate(Int32 id)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationPaperTemplate model;
                ExaminationTask          et;
                List <ExaminationPaper>  eps;

                model = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == id);

                // 终止“手动”试卷模板时,应同时结束任务
                et = olsEni.ExaminationTasks.Single(m => m.ET_Id == model.ET_Id);
                if ((Byte)AutoType.Manual == et.ET_AutoType)
                {
                    et.ET_Enabled = (Byte)ExaminationTaskStatus.Disabled;
                }

                model.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;
                olsEni.Entry(model).State     = EntityState.Modified;

                eps = olsEni.ExaminationPapers
                      .Where(m =>
                             m.EPT_Id == id &&
                             m.EP_Status == (Byte)Status.Available)
                      .ToList();
                foreach (var ep in eps)
                {
                    ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                    GradePaper(ep);
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return(resJson);
                }

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        public ResponseJson Create(ExaminationTask model)
        {
            using (TransactionScope scope = new TransactionScope())
            {

                Int32 id;
                ResponseJson resJson;

                resJson = new ResponseJson(ResponseStatus.Success, now);

                id = GetETId();

                try
                {

                    model.ET_Id = id;
                    olsEni.ExaminationTasks.Add(model);
                    olsEni.SaveChanges();

                    try
                    {

                        // 添加参与人员
                        AddAttendees(model);

                        // 添加试卷模板与试题模板
                        AddPaperTemplateAndQuestionTemplate(model);

                    }
                    catch (Exception ex1)
                    {
                        throw ex1;
                    }

                    scope.Complete();

                    return resJson;
                }
                catch (Exception ex)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = ex.Message;
                    resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                    return resJson;
                }
            }
        }
Beispiel #14
0
        public ResponseJson Sort(Int32 originId, Byte sortFlag)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Int32           departmentId;
                User            originUser;
                User_Department ud;

                originUser   = olsEni.Users.Single(m => m.U_Id == originId);
                ud           = olsEni.User_Department.Single(m => m.U_Id == originUser.U_Id);
                departmentId = ud.D_Id;

                if (sortFlag == 1) // 置顶
                {
                    resJson = SetSortTop(departmentId, originId);
                    return(resJson);
                }
                else if (sortFlag == 2) // 上移
                {
                    resJson = SetSortUp(departmentId, originId);
                    return(resJson);
                }
                else if (sortFlag == 3) // 下移
                {
                    resJson = SetSortDown(departmentId, originId);
                    return(resJson);
                }
                else //if (sortFlag != 1 && sortFlag != 2 && sortFlag != 3)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "未设置排序类型。";
                    return(resJson);
                }
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #15
0
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Duty        model;
                List <User> us;

                model = olsEni.Duties.SingleOrDefault(m => m.Du_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                // 处理职务中的用户状态
                if (status != Status.Available)
                {
                    us = olsEni.Users.Where(m => m.Du_Id == model.Du_Id).ToList();
                    foreach (var u in us)
                    {
                        u.U_Status = (Byte)status;
                    }
                }

                model.Du_Status           = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        internal ResponseJson HandIn(Int32 id, Int32 uId)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationPaper          ep;
                UExaminationPaperTemplate uept;

                ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == id && m.EP_UserId == uId);

                if (ep == null)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "试卷不存在";
                    return(resJson);
                }

                ep.EP_PaperStatus = (Byte)PaperStatus.Done;

                if (0 == olsEni.SaveChanges())
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return(resJson);
                }

                uept         = new UExaminationPaperTemplate();
                resJson.data = uept.GradePaper(ep);
                uept.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        internal ResponseJson GetUndoNumber(Int32 id, Int32 uId)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Int32               undoNumber;
                String              sql;
                ExaminationPaper    ep;
                List <SqlParameter> sps;

                ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == id && m.EP_UserId == uId);

                if (ep == null)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "试卷不存在";
                    return(resJson);
                }

                sql =
                    "SELECT   COUNT(EPQ_Id) " +
                    "FROM     ExaminationPaperQuestions " +
                    "WHERE    EP_Id = @epId " +
                    "         AND (CAST(EPQ_Answer AS NVARCHAR(5)) = '' " +
                    "              OR CAST(EPQ_Answer AS NVARCHAR(5)) = '[]')";
                sps = new List <SqlParameter>();
                sps.Add(new SqlParameter("@epId", id));
                undoNumber = Convert.ToInt32(olsDbo.ExecuteSqlScalar(sql, sps));

                resJson.data   = undoNumber;
                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #18
0
        internal ResponseJson RefreshTime(User u)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {
                UserOnline uo;

                uo = olsEni.UserOnlines.SingleOrDefault(m => m.U_Id == u.U_Id);

                if (uo == null)
                {
                    uo = new UserOnline
                    {
                        U_Id            = u.U_Id,
                        UO_Name         = u.U_Name,
                        UO_IdCardNumber = u.U_IdCardNumber,
                        UO_RefreshTime  = now
                    };
                    olsEni.Entry(uo).State = EntityState.Added;
                }
                else
                {
                    uo.UO_RefreshTime = now;
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.message = ResponseMessage.SaveChangesError;
                    return(resJson);
                }

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #19
0
        public ResponseJson Create(ExaminationTask model)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                Int32        id;
                ResponseJson resJson;

                resJson = new ResponseJson(ResponseStatus.Success, now);

                id = GetETId();

                try
                {
                    model.ET_Id = id;
                    olsEni.ExaminationTasks.Add(model);
                    olsEni.SaveChanges();

                    try
                    {
                        // 添加参与人员
                        AddAttendees(model);

                        // 添加试卷模板与试题模板
                        AddPaperTemplateAndQuestionTemplate(model);
                    }
                    catch (Exception ex1)
                    {
                        throw ex1;
                    }

                    scope.Complete();

                    return(resJson);
                }
                catch (Exception ex)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = ex.Message;
                    resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                    return(resJson);
                }
            }
        }
Beispiel #20
0
        private ResponseJson SetAutoTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus)
        {
            ResponseJson resJson;
            UExaminationPaperTemplate       uept;
            List <ExaminationPaperTemplate> epts;
            List <ExaminationPaper>         eps;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            // 终止自动任务时,同时终止进行中的试卷模板、试卷。
            if (ExaminationTaskStatus.Disabled == etStatus)
            {
                epts =
                    olsEni
                    .ExaminationPaperTemplates
                    .Where(m =>
                           m.ET_Id == et.ET_Id)
                    .ToList();

                foreach (var ept in epts)
                {
                    uept = new UExaminationPaperTemplate();

                    ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;

                    // 终止试卷
                    eps = olsEni.ExaminationPapers
                          .Where(m => m.EPT_Id == ept.EPT_Id)
                          .ToList();
                    foreach (var ep in eps)
                    {
                        ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                        uept.GradePaper(ep);
                        uept.SaveChanges();
                    }
                }
            }

            return(resJson);
        }
Beispiel #21
0
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationTask model;

                model = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == id);
                // 已开始/已结束的手动任务不允许编辑;已开始的自动任务不允许编辑
                if ((model.ET_AutoType == 0 && model.ET_Enabled != 0) || (model.ET_AutoType > 0 && model.ET_Enabled == 1))
                {
                    resJson.message = "不允许编辑。";
                    return(resJson);
                }

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                model.ET_Status           = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                QuestionClassify model;

                model = olsEni.QuestionClassifies.SingleOrDefault(m => m.QC_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                model.QC_Status           = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;

                // 批量处理分类所属试题
                // 只处理“回收”或“删除”操作
                setQuestionStatus(id, status);

                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #23
0
        internal ResponseJson ListOnline()
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {
                List <UserOnline> uos;

                uos = olsEni.UserOnlines.ToList();

                resJson.status = ResponseStatus.Success;
                resJson.data   = uos;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #24
0
        public ResponseJson SetStatus(String ids, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Int32    id;
                Question q;
                String[] ids1;

                ids1 = ids.Split(',');

                foreach (var id1 in ids1)
                {
                    id = Convert.ToInt32(id1);
                    q  = olsEni.Questions.SingleOrDefault(m => m.Q_Id == id);
                    if (null != q)
                    {
                        q.Q_Status = (Byte)status;
                        ResumeClassify(q.QC_Id, status);
                    }
                }
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Department model;

                model = olsEni.Departments.SingleOrDefault(m => m.D_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return(resJson);
                }

                // 处理部门中的用户状态
                setUserStatus(id, status);

                model.D_Status            = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationTask model;

                model = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == id);
                // 已开始/已结束的手动任务不允许编辑;已开始的自动任务不允许编辑
                if ((model.ET_AutoType == 0 && model.ET_Enabled != 0) || (model.ET_AutoType > 0 && model.ET_Enabled == 1))
                {
                    resJson.message = "不允许编辑。";
                    return resJson;
                }

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return resJson;
                }

                model.ET_Status = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        private ResponseJson SetAutoTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus)
        {
            ResponseJson resJson;
            UExaminationPaperTemplate uept;
            List<ExaminationPaperTemplate> epts;
            List<ExaminationPaper> eps;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            // 终止自动任务时,同时终止进行中的试卷模板、试卷。
            if (ExaminationTaskStatus.Disabled == etStatus)
            {
                epts =
                    olsEni
                    .ExaminationPaperTemplates
                    .Where(m =>
                        m.ET_Id == et.ET_Id)
                    .ToList();

                foreach (var ept in epts)
                {

                    uept = new UExaminationPaperTemplate();

                    ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;

                    // 终止试卷
                    eps = olsEni.ExaminationPapers
                        .Where(m => m.EPT_Id == ept.EPT_Id)
                        .ToList();
                    foreach (var ep in eps)
                    {
                        ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                        uept.GradePaper(ep);
                        uept.SaveChanges();
                    }
                }
            }

            return resJson;
        }
Beispiel #28
0
        private ResponseJson SetSortTop(Int32 departmentId, Int32 originId)
        {
            Int32 repeatCount;
            ResponseJson resJson;
            String sql;
            Double originSort, destSort;
            User originUser, destUser;
            List<SqlParameter> sps;

            resJson = new ResponseJson();

            originUser = olsEni.Users.Single(m => m.U_Id == originId);
            originSort = originUser.U_Sort;

            sql =
                "SELECT    Min(u.U_Sort) " +
                "FROM      Users u " +
                "          LEFT JOIN User_Department ud ON u.U_Id = ud.U_Id " +
                "          LEFT JOIN Departments d ON d.D_Id = ud.D_Id " +
                "WHERE     d.D_Id = @dId " +
                "          AND d.D_Status = 1 " +
                "          AND u.U_Status = 1 ";
            sps = new List<SqlParameter>();
            sps.Add(new SqlParameter("@dId", departmentId));
            destSort = Convert.ToDouble(olsDbo.ExecuteSqlScalar(sql, sps));
            destSort = Math.Round(destSort, 5);

            destUser = olsEni.Users.Single(m => m.U_Sort == destSort);

            if (destSort == originSort)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = "该用户已位于部门顶部。";
                return resJson;
            }

            originSort = destSort - 1;
            originUser.U_Sort = originSort;

            repeatCount = HandleRepeat(originSort);
            if (-1 == repeatCount)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = "处理排序重复时抛出错误。";
                return resJson;
            }
            else if (-2 == repeatCount)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = "处理排序重复时保存出错。";
                return resJson;
            }
            else if (0 == repeatCount && olsEni.SaveChanges() == 0)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = ResponseMessage.SaveChangesError;
                return resJson;
            }

            resJson.status = ResponseStatus.Success;
            return resJson;
        }
Beispiel #29
0
        private ResponseJson SetCustomTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus)
        {
            Int32        eptId, continueDays;
            DateTime     startTime, endTime;
            ResponseJson resJson;
            UExaminationPaperTemplate       uept;
            List <ExaminationPaperTemplate> epts;
            List <ExaminationPaper>         eps;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            epts =
                olsEni
                .ExaminationPaperTemplates
                .Where(m => m.ET_Id == et.ET_Id)
                .ToList();
            // 验证类型为“考试”的任务
            if (epts.Count != 1 && et.ET_Type == (Byte)ExaminationTaskType.Examination)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "试卷模板不匹配。";
                return(resJson);
            }
            else if (et.ET_Type == (Byte)ExaminationTaskType.Exercise)
            {
                resJson.status = ResponseStatus.Success;
                return(resJson);
            }

            epts[0].EPT_PaperTemplateStatus = (Byte)etStatus;

            // 开始任务及试卷模板
            if (ExaminationTaskStatus.Enabled == etStatus)
            {
                startTime             = et.ET_StartTime;
                epts[0].EPT_StartTime = startTime;
                epts[0].EPT_StartDate = startTime.Date;

                continueDays        = et.ET_ContinuedDays > 0 ? et.ET_ContinuedDays - 1 : 0;
                startTime           = startTime.AddDays(continueDays);
                endTime             = et.ET_EndTime;
                endTime             = new DateTime(startTime.Year, startTime.Month, startTime.Day, endTime.Hour, endTime.Minute, endTime.Second);
                epts[0].EPT_EndTime = endTime;
            }
            // 终止任务及试卷模板、试卷
            else if (ExaminationTaskStatus.Disabled == etStatus)
            {
                uept = new UExaminationPaperTemplate();

                epts[0].EPT_EndTime = DateTime.Now;

                // 终止试卷
                eptId = epts[0].EPT_Id;
                eps   = olsEni.ExaminationPapers
                        .Where(m => m.EPT_Id == eptId)
                        .ToList();
                foreach (var ep in eps)
                {
                    ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                    uept.GradePaper(ep);
                    uept.SaveChanges();
                }
            }

            return(resJson);
        }
Beispiel #30
0
        public ResponseJson Sort(Int32 originId, Byte sortFlag)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                Int32 departmentId;
                User originUser;
                User_Department ud;

                originUser = olsEni.Users.Single(m => m.U_Id == originId);
                ud = olsEni.User_Department.Single(m => m.U_Id == originUser.U_Id);
                departmentId = ud.D_Id;

                if (sortFlag == 1) // 置顶
                {
                    resJson = SetSortTop(departmentId, originId);
                    return resJson;
                }
                else if (sortFlag == 2) // 上移
                {
                    resJson = SetSortUp(departmentId, originId);
                    return resJson;
                }
                else if (sortFlag == 3) // 下移
                {
                    resJson = SetSortDown(departmentId, originId);
                    return resJson;
                }
                else //if (sortFlag != 1 && sortFlag != 2 && sortFlag != 3)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "未设置排序类型。";
                    return resJson;
                }
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
Beispiel #31
0
        internal ResponseJson RefreshTime(User u)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {

                UserOnline uo;

                uo = olsEni.UserOnlines.SingleOrDefault(m => m.U_Id == u.U_Id);

                if (uo == null)
                {
                    uo = new UserOnline
                    {
                        U_Id = u.U_Id,
                        UO_Name = u.U_Name,
                        UO_IdCardNumber = u.U_IdCardNumber,
                        UO_RefreshTime = now
                    };
                    olsEni.Entry(uo).State = EntityState.Added;
                }
                else
                {
                    uo.UO_RefreshTime = now;
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson GetQuestions(Int32 epId, Int32 uId, Boolean hasModelAnswer = false)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                ExaminationPaper ep;
                ExaminationTask et;
                Int32 eptId;
                List<ExaminationPaperQuestion> epqs;
                List<ExaminationPaperTemplateQuestion> eptqs;

                ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == epId && m.EP_UserId == uId);

                if (null == ep)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "试卷不存在";
                    return resJson;
                }

                if (ep.EP_PaperStatus == (Byte)PaperStatus.Done)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "考试已结束。";
                    return resJson;
                }

                eptId = ep.EPT_Id;

                eptqs =
                    olsEni
                    .ExaminationPaperTemplateQuestions
                    .Where(m =>
                        m.EPT_Id == eptId
                        && m.EPTQ_Status == (Byte)Status.Available)
                    .ToList();
                epqs = olsEni.ExaminationPaperQuestions.Where(m => m.EP_Id == epId).ToList();

                // 判断是否为练习任务,是则允许保留标准答案。[201608301015]
                et = olsEni.ExaminationTasks.Single(m => m.ET_Id == ep.ET_Id);

                if (!hasModelAnswer && et.ET_Type == (Byte)ExaminationTaskType.Exercise)
                {
                    hasModelAnswer = true;
                }

                // 清除标准答案
                if (!hasModelAnswer)
                {
                    foreach (var eptq in eptqs)
                    {
                        eptq.EPTQ_ModelAnswer = null;
                    }
                }

                resJson.status = ResponseStatus.Success;
                resJson.data = JsonConvert.SerializeObject(new Object[] { eptqs, epqs });
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
Beispiel #33
0
        public ResponseJson ModifyPassword(Int32 uId, String oldPassword, String newPassword)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                User model;

                model = olsEni.Users.SingleOrDefault(m =>
                    m.U_Id == uId
                    && m.U_Status == (Byte)Status.Available);

                if (null == model)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "用户不存在。";
                    return resJson;
                }

                oldPassword = EncryptPassword(oldPassword);

                if (oldPassword != model.U_Password)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "旧密码不正确。";
                    return resJson;
                }

                // 不允许将密码设置为“**********”
                if (newPassword == "**********")
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "新密码无效。";
                    return resJson;
                }

                newPassword = EncryptPassword(newPassword);
                model.U_Password = newPassword;
                if (olsEni.SaveChanges() == 0)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "密码修改失败。";
                    return resJson;
                }

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        /// <summary>
        /// 进入考试
        /// </summary>
        /// <param name="id"></param>
        /// <param name="uId"></param>
        /// <returns></returns>
        public ResponseJson EnterExamination(Int32 id, Int32 uId)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                ExaminationTask et;
                ExaminationPaperTemplate ept;
                ExaminationPaper ep;
                ResponseJson addResJson;

                ept = Get(id);
                et = olsEni.ExaminationTasks.Single(m => m.ET_Id == ept.ET_Id);

                // 任务类型非“考试”
                /*if (et.ET_Type != (Byte)ExaminationTaskType.Examination)
                {
                    resJson.message = "此任务类型非“考试”。";
                    return resJson;
                }*/

                switch (ept.EPT_PaperTemplateStatus)
                {
                    case 0: // 任务未开始

                        resJson.message = "任务未开始。";
                        break;
                    case 1: // 任务进行中

                        ep =
                            olsEni
                            .ExaminationPapers
                            .SingleOrDefault(m =>
                                m.EPT_Id == ept.EPT_Id
                                && m.EP_UserId == uId);

                        // 试卷不存在
                        if (null == ep && et.ET_Type == (Byte)ExaminationTaskType.Examination)
                        {
                            addResJson = addExaminationPaper(ept, uId);
                            if (addResJson.status == ResponseStatus.Error)
                            {
                                resJson.message = "试卷不存在。";
                                return addResJson;
                            }

                            resJson.status = ResponseStatus.Success;
                            resJson.addition = addResJson.data;
                            break;
                        }
                        /*else if (null == ep && et.ET_Type == (Byte)ExaminationTaskType.Exercise)
                        {
                            addResJson = addExercisePaper(et, userId);
                            if (addResJson.status == ResponseStatus.Error)
                            {
                                return addResJson;
                            }

                            resJson.status = ResponseStatus.Success;
                            resJson.addition = addResJson.data;
                            break;
                        }*/
                        // 试卷已存在
                        // 任务未结束
                        else if (ep.EP_PaperStatus != (Byte)PaperStatus.Done)
                        {
                            resJson.status = ResponseStatus.Success;
                            resJson.addition = ep.EP_Id;
                            break;
                        }

                        // 任务已结束
                        resJson.message = "任务已结束。";

                        break;
                    //case 2:// 任务已结束
                    default:

                        ep =
                            olsEni
                            .ExaminationPapers
                            .SingleOrDefault(m =>
                            m.EPT_Id == ept.EPT_Id
                            && m.EP_UserId == uId);

                        if (null != ep)
                        {
                            resJson.status = ResponseStatus.Success;
                            resJson.addition = ep.EP_Id;
                            break;
                        }

                        resJson.message = "任务已结束。";
                        break;
                }

                return resJson;
            }
            catch (Exception ex)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        internal ResponseJson HandIn(Int32 id, Int32 uId)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                ExaminationPaper ep;
                UExaminationPaperTemplate uept;

                ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == id && m.EP_UserId == uId);

                if (ep == null)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "试卷不存在";
                    return resJson;
                }

                ep.EP_PaperStatus = (Byte)PaperStatus.Done;

                if (0 == olsEni.SaveChanges())
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                uept = new UExaminationPaperTemplate();
                resJson.data = uept.GradePaper(ep);
                uept.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            throw new NotImplementedException();

            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationPaperTemplate model;

                model = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.EPT_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return resJson;
                }

                model.EPT_Status = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        /// <summary>
        /// 终止考试
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ResponseJson Terminate(Int32 id)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                ExaminationPaperTemplate model;
                ExaminationTask et;
                List<ExaminationPaper> eps;

                model = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == id);

                // 终止“手动”试卷模板时,应同时结束任务
                et = olsEni.ExaminationTasks.Single(m => m.ET_Id == model.ET_Id);
                if ((Byte)AutoType.Manual == et.ET_AutoType)
                {
                    et.ET_Enabled = (Byte)ExaminationTaskStatus.Disabled;
                }

                model.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;
                olsEni.Entry(model).State = EntityState.Modified;

                eps = olsEni.ExaminationPapers
                    .Where(m =>
                        m.EPT_Id == id
                        && m.EP_Status == (Byte)Status.Available)
                    .ToList();
                foreach (var ep in eps)
                {
                    ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                    GradePaper(ep);
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson Change()
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Success);

            try
            {

                Int32 success, operate;
                Boolean changed;
                ExaminationTask et;
                Dictionary<String, String> data;
                List<ExaminationPaperTemplate> epts;

                success = 0;
                operate = 0;
                changed = false;
                data = new Dictionary<string, string>();

                epts =
                    olsEni
                    .ExaminationPaperTemplates
                    .Where(m =>
                        m.ET_Type == (Byte)ExaminationTaskType.Examination // 不处理练习任务
                        && (m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Undone
                        || m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Doing)
                        && m.EPT_Status == (Byte)Status.Available)
                    .ToList();
                data.Add(
                    "RecordInfo", "共有 " + epts.Count + "条记录。" +
                    "其中“未做” " + epts.Where(m => m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Undone).Count() + "条;" +
                    "“进行中” " + epts.Where(m => m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Doing).Count() + "条。");

                foreach (var ept in epts)
                {

                    et = olsEni.ExaminationTasks.Single(m => m.ET_Id == ept.ET_Id);

                    /*// 不处理练习任务
                    if (et.ET_Type == (Byte)ExaminationTaskType.Exercise)
                        continue;*/

                    if ((Byte)ExaminationTaskStatus.Enabled != et.ET_Enabled
                        && (et.ET_Mode == (Byte)ExaminationTaskMode.Manual
                            || et.ET_Mode == (Byte)ExaminationTaskMode.Custom)
                        && ept.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Undone)
                    {
                        // 当任务状态为“关闭”,出题类型为“手动”、“预定”,模板状态为“未开始”。
                        // 符合条件时,不处理。
                        continue;

                    } // TODO: 此处条件似乎没有作用,因为关闭“自动任务”时将自动同时关闭试卷模板。
                    else if ((Byte)ExaminationTaskStatus.Enabled != et.ET_Enabled
                        && et.ET_Mode == (Byte)ExaminationTaskMode.Auto)
                    {
                        // 当任务状态为“关闭”,出题类型为“自动”。
                        // 符合条件时,关闭考试(将模板设为“关闭”)。
                        ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;

                        changed = true;
                        success += 1;
                        operate += 1;
                    }
                    else if (ept.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Undone
                       && now > ept.EPT_StartTime)
                    {
                        // 当模板状态为“未开始”,已到“考试开始时间”。
                        // 符合条件时,开始考试(将模板设为“进行中”)。
                        ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Doing;
                        changed = true;
                        success += 1;
                    }
                    else if (ept.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Doing
                        && ept.EPT_TimeSpan != 0
                        && now > ept.EPT_EndTime)
                    {
                        // 当模板状态为“进行中”,考试时长非零,已到“考试结束时间”。
                        // 符合条件时,关闭考试(将模板设为“关闭”)。
                        ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;

                        // TODO: 预定考试的试卷模板已关闭,是否应同时关闭任务?
                        // 当出题方式为“手动”、“预定”时,同时将任务设为“关闭”。
                        /*if (et.ET_AutoType != (Byte)ExaminationTaskMode.Auto)
                        {
                            et.ET_Enabled = (Byte)ExaminationTaskStatus.Disabled;
                        }*/
                        // 当出题方式为“手动”时,同时将任务设为“关闭”。
                        if (et.ET_AutoType == (Byte)ExaminationTaskMode.Manual)
                        {
                            et.ET_Enabled = (Byte)ExaminationTaskStatus.Disabled;
                        }

                        changed = true;
                        success += 1;
                    }
                }

                if (changed)
                {
                    if (0 == olsEni.SaveChanges())
                    {
                        resJson.status = ResponseStatus.Error;
                        resJson.message = ResponseMessage.SaveChangesError;
                    }
                }

                data.Add("OperateInfo", "终止已关闭考试任务的试卷模板 " + operate + "条。");
                data.Add("SuccessInfo", "成功处理 " + success + "条记录。");
                resJson.data = data;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        private ResponseJson SetManualTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus)
        {
            Int32 eptId;
            ResponseJson resJson;
            UExaminationPaperTemplate uept;
            List<ExaminationPaperTemplate> epts;
            List<ExaminationPaper> eps;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            epts =
                olsEni
                .ExaminationPaperTemplates
                .Where(m => m.ET_Id == et.ET_Id)
                .ToList();
            if (epts.Count != 1)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = "试卷模板不匹配。";
                return resJson;
            }

            epts[0].EPT_PaperTemplateStatus = (Byte)etStatus;

            // 开始任务及试卷模板
            if (ExaminationTaskStatus.Enabled == etStatus)
            {
                epts[0].EPT_StartTime = now;
                epts[0].EPT_StartDate = now.Date;
                epts[0].EPT_EndTime = now.AddMinutes(epts[0].EPT_TimeSpan);
            }
            // 终止任务及试卷模板、试卷
            else if (ExaminationTaskStatus.Disabled == etStatus)
            {

                uept = new UExaminationPaperTemplate();

                epts[0].EPT_EndTime = DateTime.Now;

                // 终止试卷
                eptId = epts[0].EPT_Id;
                eps = olsEni.ExaminationPapers
                    .Where(m => m.EPT_Id == eptId)
                    .ToList();
                foreach (var ep in eps)
                {
                    ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                    uept.GradePaper(ep);
                    uept.SaveChanges();
                }
            }

            return resJson;
        }
        public ResponseJson Grade(String gradeJson)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                Int32 score, exactnessNumber, totalNumber;
                ExaminationTask et;
                ExaminationPaper ep;
                ExaminationPaperTemplate ept;
                ExaminationPaperQuestion epq1;
                List<ExaminationPaper> eps;
                List<ExaminationPaperTemplateQuestion> eptqs;
                List<ExaminationPaperQuestion> epqs;

                eps = new List<ExaminationPaper>();

                epqs = JsonConvert.DeserializeObject<List<ExaminationPaperQuestion>>(gradeJson);

                foreach (var epq in epqs)
                {

                    // 检查是否在考试时间内
                    ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == epq.EP_Id);
                    if (null == ep || ep.EP_PaperStatus != (Byte)PaperStatus.Done)
                    {
                        continue;
                    }

                    epq1 =
                        olsEni
                        .ExaminationPaperQuestions
                        .SingleOrDefault(m =>
                            m.EP_Id == epq.EP_Id
                            && m.EPTQ_Id == epq.EPTQ_Id);

                    if (null != epq1)
                    {

                        epq1.EPQ_Exactness = epq.EPQ_Exactness;
                        olsEni.Entry(epq1).State = EntityState.Modified;

                        if (eps.Where(m => m.EP_Id == ep.EP_Id).Count() == 0)
                        {
                            eps.Add(ep);
                        }
                    }
                }

                epqs = null;

                // 计算成绩
                foreach (var ep1 in eps)
                {

                    ept = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.EPT_Id == ep1.EPT_Id);

                    if (null == ept || ept.EPT_PaperTemplateStatus != (Byte)PaperTemplateStatus.Done)
                    {
                        continue;
                    }

                    et = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == ept.ET_Id);

                    if (null == et)
                    {
                        continue;
                    }

                    score = 0;

                    if (et.ET_StatisticType == (Byte)StatisticType.Score)
                    {
                        // 计算分数
                        epqs =
                            olsEni.ExaminationPaperQuestions
                            .Where(m => m.EP_Id == ep1.EP_Id).ToList();
                        eptqs =
                            olsEni.ExaminationPaperTemplateQuestions
                            .Where(m =>
                                m.EPT_Id == ep1.EPT_Id
                                && m.EPTQ_Status == (Byte)Status.Available)
                            .ToList();

                        foreach (var epq in epqs)
                        {
                            if (epq.EPQ_Exactness == (Byte)AnswerStatus.Exactness)
                            {
                                score += eptqs.Single(m => m.EPTQ_Id == epq.EPTQ_Id).EPTQ_Score;
                            }
                        }

                    }
                    else if (et.ET_StatisticType == (Byte)StatisticType.Number)
                    {
                        // 计算正确率
                        epqs =
                            olsEni.ExaminationPaperQuestions
                            .Where(m => m.EP_Id == ep1.EP_Id).ToList();
                        exactnessNumber = 0;
                        totalNumber =
                            olsEni.ExaminationPaperTemplateQuestions
                            .Where(m =>
                                m.EPT_Id == ep1.EPT_Id
                                && m.EPTQ_Status == (Byte)Status.Available)
                            .Count();

                        foreach (var epq in epqs)
                        {
                            if (epq.EPQ_Exactness == (Byte)AnswerStatus.Exactness)
                            {
                                exactnessNumber += 1;
                            }
                        }

                        score = (Int32)Math.Round((double)exactnessNumber / (double)totalNumber * 100, MidpointRounding.AwayFromZero);
                    }

                    ep1.EP_Score = score;
                    olsEni.Entry(ep1).State = EntityState.Modified;
                }

                if (0 == olsEni.SaveChanges())
                {

                    resJson.status = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                resJson.data = JsonConvert.SerializeObject(eps);
                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                LearningDataCategory model;

                model = olsEni.LearningDataCategories.SingleOrDefault(m => m.LDC_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return resJson;
                }

                // 处理目录中的资料状态
                setDataStatus(id, status);

                model.LDC_Status = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson GetUsers(Int32 id)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            try
            {

                Int32 etId;
                String users;
                Int32[] userAry;
                ExaminationPaperTemplate ept;
                ExaminationTask et;
                User u;
                ExaminationPaper ep;
                List<User> userModels;

                userModels = new List<User>();

                ept = Get(id);
                etId = ept.ET_Id;
                et = olsEni.ExaminationTasks.Single(m => m.ET_Id == etId);
                users = et.ET_Attendee;
                userAry = JsonConvert.DeserializeObject<Int32[]>(users);

                foreach (var uId in userAry)
                {
                    u = olsEni.Users.SingleOrDefault(m =>
                        m.U_Id == uId
                        && m.U_Status == (Byte)Status.Available);
                    if (null != u)
                    {
                        u.U_Password = "******";
                        userModels.Add(u);
                    }

                    ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EPT_Id == id && m.EP_UserId == u.U_Id);
                    if (null == ep)
                    {
                        continue;
                    }

                    u.EP_Id = ep.EP_Id;
                    u.EP_Score = GetScoreString(et.ET_StatisticType, ep.EP_Score);

                }

                if (userModels.Count == 0)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "没有参与人员。";
                    return resJson;
                }

                resJson.data = JsonConvert.SerializeObject(userModels);
                resJson.addition = et;
                return resJson;
            }
            catch (Exception ex)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
Beispiel #43
0
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                User model;

                model = olsEni.Users.SingleOrDefault(m => m.U_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return resJson;
                }

                ResumeDepartment(id, status);

                model.U_Status = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
Beispiel #44
0
        private ResponseJson SetSortDown(Int32 departmentId, Int32 originId)
        {
            Int32               repeatCount;
            ResponseJson        resJson;
            String              sql;
            Double              originSort, destSort;
            DataTable           dt;
            User                originUser, destUser;
            List <SqlParameter> sps;
            List <User>         us;

            resJson = new ResponseJson();

            originUser = olsEni.Users.Single(m => m.U_Id == originId);
            originSort = originUser.U_Sort;

            sql =
                "SELECT    TOP 1 * " +
                "FROM      Users u " +
                "          LEFT JOIN User_Department ud ON u.U_Id = ud.U_Id " +
                "          LEFT JOIN Departments d ON d.D_Id = ud.D_Id " +
                "WHERE     d.D_Id = @dId " +
                "          AND u.U_Sort > @uSort " +
                "          AND d.D_Status = 1 " +
                "          AND u.U_Status = 1 " +
                "ORDER BY  u.U_Sort ASC";
            sps = new List <SqlParameter>();
            sps.Add(new SqlParameter("@dId", departmentId));
            sps.Add(new SqlParameter("@uSort", originSort));
            dt = olsDbo.GetDataTable(sql, sps);
            us = (List <User>) ModelConvert <User> .ConvertToModel(dt);

            if (us.Count == 0)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "该用户已位于部门底部。";
                return(resJson);
            }
            else
            {
                destUser          = us[0];
                destSort          = destUser.U_Sort;
                originSort        = Math.Round(destSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                originUser.U_Sort = originSort;
            }

            repeatCount = HandleRepeat(originSort);
            if (-1 == repeatCount)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "处理排序重复时抛出错误。";
                return(resJson);
            }
            else if (-2 == repeatCount)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "处理排序重复时保存出错。";
                return(resJson);
            }
            else if (0 == repeatCount && olsEni.SaveChanges() == 0)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ResponseMessage.SaveChangesError;
                return(resJson);
            }

            resJson.status = ResponseStatus.Success;
            return(resJson);
        }
Beispiel #45
0
        internal ResponseJson ListOnline()
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {

                List<UserOnline> uos;

                uos = olsEni.UserOnlines.ToList();

                resJson.status = ResponseStatus.Success;
                resJson.data = uos;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
Beispiel #46
0
        private ResponseJson SetSortTop(Int32 departmentId, Int32 originId)
        {
            Int32               repeatCount;
            ResponseJson        resJson;
            String              sql;
            Double              originSort, destSort;
            User                originUser, destUser;
            List <SqlParameter> sps;

            resJson = new ResponseJson();

            originUser = olsEni.Users.Single(m => m.U_Id == originId);
            originSort = originUser.U_Sort;

            sql =
                "SELECT    Min(u.U_Sort) " +
                "FROM      Users u " +
                "          LEFT JOIN User_Department ud ON u.U_Id = ud.U_Id " +
                "          LEFT JOIN Departments d ON d.D_Id = ud.D_Id " +
                "WHERE     d.D_Id = @dId " +
                "          AND d.D_Status = 1 " +
                "          AND u.U_Status = 1 ";
            sps = new List <SqlParameter>();
            sps.Add(new SqlParameter("@dId", departmentId));
            destSort = Convert.ToDouble(olsDbo.ExecuteSqlScalar(sql, sps));
            destSort = Math.Round(destSort, 5);

            destUser = olsEni.Users.Single(m => m.U_Sort == destSort);

            if (destSort == originSort)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "该用户已位于部门顶部。";
                return(resJson);
            }

            originSort        = destSort - 1;
            originUser.U_Sort = originSort;

            repeatCount = HandleRepeat(originSort);
            if (-1 == repeatCount)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "处理排序重复时抛出错误。";
                return(resJson);
            }
            else if (-2 == repeatCount)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = "处理排序重复时保存出错。";
                return(resJson);
            }
            else if (0 == repeatCount && olsEni.SaveChanges() == 0)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ResponseMessage.SaveChangesError;
                return(resJson);
            }

            resJson.status = ResponseStatus.Success;
            return(resJson);
        }
Beispiel #47
0
        private ResponseJson SetSortDown(Int32 departmentId, Int32 originId)
        {
            Int32 repeatCount;
            ResponseJson resJson;
            String sql;
            Double originSort, destSort;
            DataTable dt;
            User originUser, destUser;
            List<SqlParameter> sps;
            List<User> us;

            resJson = new ResponseJson();

            originUser = olsEni.Users.Single(m => m.U_Id == originId);
            originSort = originUser.U_Sort;

            sql =
                "SELECT    TOP 1 * " +
                "FROM      Users u " +
                "          LEFT JOIN User_Department ud ON u.U_Id = ud.U_Id " +
                "          LEFT JOIN Departments d ON d.D_Id = ud.D_Id " +
                "WHERE     d.D_Id = @dId " +
                "          AND u.U_Sort > @uSort " +
                "          AND d.D_Status = 1 " +
                "          AND u.U_Status = 1 " +
                "ORDER BY  u.U_Sort ASC";
            sps = new List<SqlParameter>();
            sps.Add(new SqlParameter("@dId", departmentId));
            sps.Add(new SqlParameter("@uSort", originSort));
            dt = olsDbo.GetDataTable(sql, sps);
            us = (List<User>)ModelConvert<User>.ConvertToModel(dt);

            if (us.Count == 0)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = "该用户已位于部门底部。";
                return resJson;
            }
            else
            {

                destUser = us[0];
                destSort = destUser.U_Sort;
                originSort = Math.Round(destSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                originUser.U_Sort = originSort;
            }

            repeatCount = HandleRepeat(originSort);
            if (-1 == repeatCount)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = "处理排序重复时抛出错误。";
                return resJson;
            }
            else if (-2 == repeatCount)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = "处理排序重复时保存出错。";
                return resJson;
            }
            else if (0 == repeatCount && olsEni.SaveChanges() == 0)
            {

                resJson.status = ResponseStatus.Error;
                resJson.message = ResponseMessage.SaveChangesError;
                return resJson;
            }

            resJson.status = ResponseStatus.Success;
            return resJson;
        }
Beispiel #48
0
        public ResponseJson CacheImport()
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                List <Question>         qs;
                Boolean                 errorFlag;
                List <QuestionClassify> qcs;
                String modelAnswer;

                errorFlag = false;

                qs = olsEni.Questions.Where(m => m.Q_Status == (Byte)Status.Cache).ToList();
                foreach (var q in qs)
                {
                    modelAnswer = q.Q_ModelAnswer.Trim();

                    if (("单选题" == q.Q_Type ||
                         "多选题" == q.Q_Type) &&
                        ("{}" == q.Q_OptionalAnswer ||
                         "[]" == modelAnswer))
                    {
                        errorFlag = true;
                        continue;
                    }

                    if ("判断题" == q.Q_Type && "O" == modelAnswer)
                    {
                        errorFlag = true;
                        continue;
                    }

                    q.Q_Status            = (Byte)Status.Available;
                    olsEni.Entry(q).State = EntityState.Modified;
                }

                if (olsEni.SaveChanges() == 0)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = "缓存导入失败。";
                    return(resJson);
                }

                resJson.status = ResponseStatus.Success;
                if (errorFlag)
                {
                    resJson.message = "未导入部分存在错误的试题模板数据。";
                }

                // 设置分类状态
                qcs = olsEni.QuestionClassifies.Where(m => m.QC_Status == (Byte)Status.Cache).ToList();
                foreach (var qc in qcs)
                {
                    if (olsEni.Questions.Where(m => m.QC_Id == qc.QC_Id).Count() > 0)
                    {
                        qc.QC_Status           = (Byte)Status.Available;
                        olsEni.Entry(qc).State = EntityState.Modified;
                    }
                }
                if (olsEni.SaveChanges() == 0)
                {
                    //resJson.status = ResponseStatus.Error;
                    //resJson.message = "设置分类状态失败。";
                    //return resJson;
                }

                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
Beispiel #49
0
        internal ResponseJson GetDoingUserNumber(Int32 id)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {
                ExaminationTask et;
                List <ExaminationPaperTemplate> epts;
                List <ExaminationPaper>         eps, tmpEps;

                et = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == id);

                if (et == null)
                {
                    resJson.message = "任务不存在。";
                    return(resJson);
                }

                if (et.ET_Enabled != (Byte)ExaminationTaskStatus.Enabled)
                {
                    resJson.message = "任务未启动。";
                    return(resJson);
                }

                epts = olsEni.ExaminationPaperTemplates
                       .Where(m =>
                              m.ET_Id == id &&
                              m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Doing &&
                              m.EPT_Status == (Byte)Status.Available)
                       .ToList();

                eps = new List <ExaminationPaper>();
                foreach (var ept in epts)
                {
                    tmpEps = olsEni.ExaminationPapers
                             .Where(m =>
                                    m.EPT_Id == ept.EPT_Id &&
                                    m.EP_PaperStatus == (Byte)PaperStatus.Doing &&
                                    m.EP_Status == (Byte)Status.Available)
                             .ToList();

                    if (tmpEps.Count() > 0)
                    {
                        eps.AddRange(tmpEps);
                    }
                }

                resJson.status = ResponseStatus.Success;
                resJson.data   = eps.Count();

                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                StaticHelper.RecordSystemLog(ex);
                return(resJson);
            }
        }
Beispiel #50
0
        public ResponseJson Login(String userName, String password)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                User u;

                userName = userName.ToLower();
                password = EncryptPassword(password);

                /*u = olsEni.Users.SingleOrDefault(m =>
                 *      ((m.U_Name.ToLower() == userName
                 *          && m.U_Password == password)
                 || (m.U_LoginName.ToLower() == userName
                 ||         && m.U_Password == password))
                 ||     && m.U_Status == (Byte)Status.Available);*/

                u = olsEni.Users.SingleOrDefault(m =>
                                                 m.U_IdCardNumber.ToLower() == userName &&
                                                 m.U_Password == password &&
                                                 m.U_Status == (Byte)Status.Available);

                if (null == u)
                {
                    resJson.message = "身份证号或密码有误。";
                    return(resJson);
                }



                // 收集角色列表
                var rs = GetUserRoleList(u.U_Id);
                var ds = GetDepartmentList(u.U_Id);

                if (rs.Count() == 0)
                {
                    rs = GetDepartmentRoleList(ds);
                }
                u.U_RoleList = rs;

                // 收集部门列表
                u.U_DepartmentList = ds;

                // 收集权限列表
                var ps = GetPermissionList(u.U_RoleList);
                u.U_PermissionList = ps;

                resJson.status   = ResponseStatus.Success;
                resJson.addition = u;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        public ResponseJson SetExaminationTaskStatus(Int32 etId, ExaminationTaskStatus etStatus)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                Int32 saveReturn;
                ExaminationTask model;
                UExaminationPaperTemplate uept;

                using (TransactionScope scope = new TransactionScope())
                {

                    model = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == etId);

                    if (null == model)
                    {
                        resJson.message = "数据不存在!";
                        return resJson;
                    }

                    uept = new UExaminationPaperTemplate();

                    // 手动任务处理
                    if ((Byte)AutoType.Manual == model.ET_AutoType)
                    {
                        resJson = SetManualTypeStatus(model, etStatus);

                    }
                    // 预定任务处理
                    else if ((Byte)AutoType.Custom == model.ET_AutoType)
                    {
                        resJson = SetCustomTypeStatus(model, etStatus);
                    }
                    // 自动任务处理
                    else
                    {
                        resJson = SetAutoTypeStatus(model, etStatus);
                    }

                    if (resJson.status == ResponseStatus.Error)
                    {
                        return resJson;
                    }

                    model.ET_Enabled = (Byte)etStatus;
                    model.ET_ErrorMessage = null;
                    if (ExaminationTaskStatus.Disabled == etStatus)
                    {
                        ClearQuestionDone(model.ET_Id);
                    }

                    saveReturn = olsEni.SaveChanges();
                    scope.Complete();

                    if (0 == saveReturn)
                    {
                        resJson.status = ResponseStatus.Error;
                        resJson.message = ResponseMessage.SaveChangesError;
                        return resJson;
                    }

                    resJson.status = ResponseStatus.Success;
                    return resJson;

                }
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson GetZTreeResJson(Byte status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Success, now);
            resJson.data = GetZTreeJson(status);

            return resJson;
        }
        internal ResponseJson GetDoingUserNumber(Int32 id)
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            try
            {

                ExaminationTask et;
                List<ExaminationPaperTemplate> epts;
                List<ExaminationPaper> eps, tmpEps;

                et = olsEni.ExaminationTasks.SingleOrDefault(m => m.ET_Id == id);

                if (et == null)
                {
                    resJson.message = "任务不存在。";
                    return resJson;
                }

                if (et.ET_Enabled != (Byte)ExaminationTaskStatus.Enabled)
                {
                    resJson.message = "任务未启动。";
                    return resJson;
                }

                epts = olsEni.ExaminationPaperTemplates
                    .Where(m =>
                        m.ET_Id == id
                        && m.EPT_PaperTemplateStatus == (Byte)PaperTemplateStatus.Doing
                        && m.EPT_Status == (Byte)Status.Available)
                    .ToList();

                eps = new List<ExaminationPaper>();
                foreach (var ept in epts)
                {

                    tmpEps = olsEni.ExaminationPapers
                        .Where(m =>
                            m.EPT_Id == ept.EPT_Id
                            && m.EP_PaperStatus == (Byte)PaperStatus.Doing
                            && m.EP_Status == (Byte)Status.Available)
                        .ToList();

                    if (tmpEps.Count() > 0)
                    {
                        eps.AddRange(tmpEps);
                    }
                }

                resJson.status = ResponseStatus.Success;
                resJson.data = eps.Count();

                return resJson;
            }
            catch (Exception ex)
            {
                resJson.message = ex.Message;
                StaticHelper.RecordSystemLog(ex);
                return resJson;
            }
        }
        public ResponseJson Sort(Int32 originId, Byte sortFlag)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                String name;
                Double originSort, destSort;
                Department originModel, destModel, adjustModel;
                Department[] modelAry;
                List<Department> us;

                name = "部门";
                modelAry = new Department[2];

                originModel = olsEni.Departments.Single(m => m.D_Id == originId);
                originSort = originModel.D_Sort;

                // 置顶
                if (1 == sortFlag)
                {

                    destSort = olsEni.Departments.Min(m => m.D_Sort);
                    destModel = olsEni.Departments.Single(m => m.D_Sort == destSort);

                    if (destSort == originSort)
                    {
                        resJson.status = ResponseStatus.Error;
                        resJson.message = "该" + name + "已置顶。";
                        return resJson;
                    }

                    originSort = destSort - 1;
                    originModel.D_Sort = originSort;
                }
                else if (2 == sortFlag)
                {

                    us = olsEni.Departments
                        .Where(m => m.D_Sort < originSort)
                        .OrderByDescending(m => m.D_Sort).Take(2).ToList();

                    if (us.Count == 0)
                    {
                        resJson.status = ResponseStatus.Error;
                        resJson.message = "该" + name + "已处于顶部。";
                        return resJson;
                    }
                    else if (us.Count == 1)
                    {
                        destModel = us[0];
                        originSort = destModel.D_Sort;
                        destSort = originModel.D_Sort;
                        originModel.D_Sort = originSort;
                        destModel.D_Sort = destSort;
                    }
                    else
                    {
                        destModel = us[1];
                        destSort = destModel.D_Sort;
                        originSort = Math.Round(destSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                        originModel.D_Sort = originSort;
                    }

                }
                else// if (3 == sortFlag)
                {

                    us = olsEni.Departments
                        .Where(m => m.D_Sort > originSort)
                        .OrderBy(m => m.D_Sort).Take(1).ToList();

                    if (us.Count == 0)
                    {
                        resJson.status = ResponseStatus.Error;
                        resJson.message = "该" + name + "已处于底部。";
                        return resJson;
                    }

                    destModel = us[0];
                    destSort = destModel.D_Sort;

                    originSort = Math.Round(destSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                    originModel.D_Sort = originSort;
                }

                adjustModel = olsEni.Departments.SingleOrDefault(m => m.D_Sort == originSort);
                if (adjustModel != null)
                {
                    adjustModel.D_Sort = Math.Round(originSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                modelAry[0] = originModel;
                modelAry[1] = destModel;

                resJson.addition = modelAry;
                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        private ResponseJson SetCustomTypeStatus(ExaminationTask et, ExaminationTaskStatus etStatus)
        {
            Int32 eptId, continueDays;
            DateTime startTime, endTime;
            ResponseJson resJson;
            UExaminationPaperTemplate uept;
            List<ExaminationPaperTemplate> epts;
            List<ExaminationPaper> eps;

            resJson = new ResponseJson(ResponseStatus.Success, now);

            epts =
                olsEni
                .ExaminationPaperTemplates
                .Where(m => m.ET_Id == et.ET_Id)
                .ToList();
            // 验证类型为“考试”的任务
            if (epts.Count != 1 && et.ET_Type == (Byte)ExaminationTaskType.Examination)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = "试卷模板不匹配。";
                return resJson;
            }
            else if (et.ET_Type == (Byte)ExaminationTaskType.Exercise)
            {
                resJson.status = ResponseStatus.Success;
                return resJson;
            }

            epts[0].EPT_PaperTemplateStatus = (Byte)etStatus;

            // 开始任务及试卷模板
            if (ExaminationTaskStatus.Enabled == etStatus)
            {

                startTime = et.ET_StartTime;
                epts[0].EPT_StartTime = startTime;
                epts[0].EPT_StartDate = startTime.Date;

                continueDays = et.ET_ContinuedDays > 0 ? et.ET_ContinuedDays - 1 : 0;
                startTime = startTime.AddDays(continueDays);
                endTime = et.ET_EndTime;
                endTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, endTime.Hour, endTime.Minute, endTime.Second);
                epts[0].EPT_EndTime = endTime;
            }
            // 终止任务及试卷模板、试卷
            else if (ExaminationTaskStatus.Disabled == etStatus)
            {

                uept = new UExaminationPaperTemplate();

                epts[0].EPT_EndTime = DateTime.Now;

                // 终止试卷
                eptId = epts[0].EPT_Id;
                eps = olsEni.ExaminationPapers
                    .Where(m => m.EPT_Id == eptId)
                    .ToList();
                foreach (var ep in eps)
                {
                    ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                    uept.GradePaper(ep);
                    uept.SaveChanges();
                }
            }

            return resJson;
        }
Beispiel #56
0
        public ResponseJson Login(String userName, String password)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                User u;

                userName = userName.ToLower();
                password = EncryptPassword(password);

                /*u = olsEni.Users.SingleOrDefault(m =>
                        ((m.U_Name.ToLower() == userName
                            && m.U_Password == password)
                        || (m.U_LoginName.ToLower() == userName
                            && m.U_Password == password))
                        && m.U_Status == (Byte)Status.Available);*/

                u = olsEni.Users.SingleOrDefault(m =>
                        m.U_IdCardNumber.ToLower() == userName
                        && m.U_Password == password
                        && m.U_Status == (Byte)Status.Available);

                if (null == u)
                {
                    resJson.message = "身份证号或密码有误。";
                    return resJson;
                }

                // 收集角色列表
                var rs = GetUserRoleList(u.U_Id);
                var ds = GetDepartmentList(u.U_Id);

                if (rs.Count() == 0)
                {
                    rs = GetDepartmentRoleList(ds);
                }
                u.U_RoleList = rs;

                // 收集部门列表
                u.U_DepartmentList = ds;

                // 收集权限列表
                var ps = GetPermissionList(u.U_RoleList);
                u.U_PermissionList = ps;

                resJson.status = ResponseStatus.Success;
                resJson.addition = u;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson SubmitAnswers(String answersJson)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                Int32 epqId;
                ExaminationPaperQuestion epq1;
                ExaminationPaper ep;
                List<ExaminationPaperQuestion> epqs;

                epqs = JsonConvert.DeserializeObject<List<ExaminationPaperQuestion>>(answersJson);

                epqId = GetEPQId();

                foreach (var epq in epqs)
                {

                    // 检查是否在考试时间内
                    ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == epq.EP_Id);
                    if (null != ep && ep.EP_PaperStatus == (Byte)PaperStatus.Done)
                    {
                        resJson.status = ResponseStatus.Error;
                        resJson.message = "考试已结束";
                        return resJson;
                    }
                    else if (null != ep && ep.EP_PaperStatus == (Byte)PaperStatus.Undone)
                    {
                        continue;
                    }

                    epq1 =
                        olsEni
                        .ExaminationPaperQuestions
                        .SingleOrDefault(m =>
                            m.EP_Id == epq.EP_Id
                            && m.EPTQ_Id == epq.EPTQ_Id);

                    if (null != epq1)
                    {

                        epq1.EPQ_Answer = epq.EPQ_Answer;
                        olsEni.Entry(epq1).State = EntityState.Modified;
                    }
                    else
                    {

                        epq.EPQ_Id = epqId;
                        epq.EPQ_AddTime = now;
                        epq.EPQ_Exactness = (Byte)AnswerStatus.Unset;
                        epq.EPQ_Critique = null;
                        olsEni.Entry(epq).State = EntityState.Added;

                        epqId += 1;
                    }
                }

                if (0 == olsEni.SaveChanges())
                {

                    resJson.status = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return resJson;
                }

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
Beispiel #58
0
        public ResponseJson SetStatus(Int32 id, Status status)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                Duty model;
                List<User> us;

                model = olsEni.Duties.SingleOrDefault(m => m.Du_Id == id);

                if (null == model)
                {
                    resJson.message = "数据不存在!";
                    return resJson;
                }

                // 处理职务中的用户状态
                if (status != Status.Available)
                {
                    us = olsEni.Users.Where(m => m.Du_Id == model.Du_Id).ToList();
                    foreach (var u in us)
                    {
                        u.U_Status = (Byte)status;
                    }
                }

                model.Du_Status = (Byte)status;
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }
        public ResponseJson Sort(Int32 originId, Byte sortFlag)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {
                String            name;
                Double            originSort, destSort;
                Department        originModel, destModel, adjustModel;
                Department[]      modelAry;
                List <Department> us;

                name     = "部门";
                modelAry = new Department[2];

                originModel = olsEni.Departments.Single(m => m.D_Id == originId);
                originSort  = originModel.D_Sort;

                // 置顶
                if (1 == sortFlag)
                {
                    destSort  = olsEni.Departments.Min(m => m.D_Sort);
                    destModel = olsEni.Departments.Single(m => m.D_Sort == destSort);

                    if (destSort == originSort)
                    {
                        resJson.status  = ResponseStatus.Error;
                        resJson.message = "该" + name + "已置顶。";
                        return(resJson);
                    }

                    originSort         = destSort - 1;
                    originModel.D_Sort = originSort;
                }
                else if (2 == sortFlag)
                {
                    us = olsEni.Departments
                         .Where(m => m.D_Sort < originSort)
                         .OrderByDescending(m => m.D_Sort).Take(2).ToList();

                    if (us.Count == 0)
                    {
                        resJson.status  = ResponseStatus.Error;
                        resJson.message = "该" + name + "已处于顶部。";
                        return(resJson);
                    }
                    else if (us.Count == 1)
                    {
                        destModel          = us[0];
                        originSort         = destModel.D_Sort;
                        destSort           = originModel.D_Sort;
                        originModel.D_Sort = originSort;
                        destModel.D_Sort   = destSort;
                    }
                    else
                    {
                        destModel          = us[1];
                        destSort           = destModel.D_Sort;
                        originSort         = Math.Round(destSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                        originModel.D_Sort = originSort;
                    }
                }
                else// if (3 == sortFlag)
                {
                    us = olsEni.Departments
                         .Where(m => m.D_Sort > originSort)
                         .OrderBy(m => m.D_Sort).Take(1).ToList();

                    if (us.Count == 0)
                    {
                        resJson.status  = ResponseStatus.Error;
                        resJson.message = "该" + name + "已处于底部。";
                        return(resJson);
                    }

                    destModel = us[0];
                    destSort  = destModel.D_Sort;

                    originSort         = Math.Round(destSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                    originModel.D_Sort = originSort;
                }

                adjustModel = olsEni.Departments.SingleOrDefault(m => m.D_Sort == originSort);
                if (adjustModel != null)
                {
                    adjustModel.D_Sort = Math.Round(originSort + 0.00001, 5, MidpointRounding.AwayFromZero);
                }

                if (0 == olsEni.SaveChanges())
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                    return(resJson);
                }

                modelAry[0] = originModel;
                modelAry[1] = destModel;

                resJson.addition = modelAry;
                resJson.status   = ResponseStatus.Success;
                return(resJson);
            }
            catch (Exception ex)
            {
                resJson.status  = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail  = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(resJson);
            }
        }
        internal ResponseJson GetUndoNumber(Int32 id, Int32 uId)
        {
            ResponseJson resJson;

            resJson = new ResponseJson();

            try
            {

                Int32 undoNumber;
                String sql;
                ExaminationPaper ep;
                List<SqlParameter> sps;

                ep = olsEni.ExaminationPapers.SingleOrDefault(m => m.EP_Id == id && m.EP_UserId == uId);

                if (ep == null)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = "试卷不存在";
                    return resJson;
                }

                sql =
                    "SELECT   COUNT(EPQ_Id) "+
                    "FROM     ExaminationPaperQuestions " +
                    "WHERE    EP_Id = @epId " +
                    "         AND (CAST(EPQ_Answer AS NVARCHAR(5)) = '' " +
                    "              OR CAST(EPQ_Answer AS NVARCHAR(5)) = '[]')";
                sps = new List<SqlParameter>();
                sps.Add(new SqlParameter("@epId", id));
                undoNumber = Convert.ToInt32(olsDbo.ExecuteSqlScalar(sql, sps));

                resJson.data = undoNumber;
                resJson.status = ResponseStatus.Success;
                return resJson;
            }
            catch (Exception ex)
            {
                resJson.status = ResponseStatus.Error;
                resJson.message = ex.Message;
                resJson.detail = StaticHelper.GetExceptionMessageAndRecord(ex);
                return resJson;
            }
        }