Beispiel #1
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 #2
0
        private Int32 HandleRepeat(Double sort)
        {
            try
            {
                Int32 count;
                User  sortRepeatUser;

                count = 0;

                sortRepeatUser = olsEni.Users.SingleOrDefault(m => m.U_Sort == sort);
                while (sortRepeatUser != null)
                {
                    sort = Math.Round(sort + 0.00001, 5, MidpointRounding.AwayFromZero);
                    sortRepeatUser.U_Sort = sort;
                    if (0 == olsEni.SaveChanges())
                    {
                        return(-2);
                    }

                    count += 1;

                    sortRepeatUser = olsEni.Users.SingleOrDefault(m => m.U_Id != sortRepeatUser.U_Id && m.U_Sort == sort);
                }

                return(count);
            }
            catch (Exception ex)
            {
                StaticHelper.GetExceptionMessageAndRecord(ex);
                return(-1);
            }
        }
Beispiel #3
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 #4
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 #5
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);
            }
        }
        public VMExaminationTaskPersonalStatistic GetPersonalStatistic(Int32 uId)
        {
            try
            {
                String       sql;
                SqlParameter sp;
                DataTable    dataTable;
                List <VMExaminationTaskPersonalStatistic> etpss;

                sql       = "SELECT * FROM ExaminationTaskPersonalStatistic WHERE ETPS_UserId = @uId";
                sp        = new SqlParameter("@uId", uId);
                dataTable = olsDbo.GetDataTable(sql, sp);

                etpss = (List <VMExaminationTaskPersonalStatistic>) ModelConvert <VMExaminationTaskPersonalStatistic> .ConvertToModel(dataTable);

                if (etpss.Count == 0)
                {
                    return(null);
                }

                return(etpss[0]);
            }
            catch (Exception ex)
            {
                StaticHelper.GetExceptionMessageAndRecord(ex);
                return(null);
            }
        }
        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 #8
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 #9
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 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);
            }
        }
        /// <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);
            }
        }
Beispiel #12
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 #13
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 #14
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 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);
            }
        }
        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);
            }
        }
Beispiel #17
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 #18
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 #20
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 #21
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 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);
            }
        }
Beispiel #24
0
        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);
            }
        }
Beispiel #25
0
        public Dictionary <String, String> ImportDocx(String filePath)
        {
            Dictionary <String, String> dic;

            dic = new Dictionary <String, String>();
            dic.Add("Status", "0");
            dic.Add("Data", "");
            dic.Add("Message", "");

            try
            {
                List <DocxParagraph> docxPara;
                const String         qTypes = "单选题;多选题;判断题;公文改错题;计算题;案例分析题;问答题;";
                DateTime             now;
                Regex commentRegex, typeRegex, contentRegex1, contentRegex2, optionalAnswerRegex, modelAnswerRegex,
                      difficultyCoefficientRegex, scoreRegex, digitRegex;
                String                  text, qType, qClassify, qContent, qOptionalAnswer, qModelAnswer;
                Int32                   i1, i2, len, qId, qcId, currentQCId, score, duplicate;
                Byte                    difficultyCoefficient;
                Boolean                 isContent, existsFlag;
                List <Question>         qs, tmpQs;
                List <QuestionClassify> qcs;
                QuestionClassify        qc;
                StringBuilder           errorIds;

                errorIds = new StringBuilder();

                docxPara = OpenXmlDocHelper.GetDocxParagraphs(filePath);

                now = DateTime.Now;

                commentRegex               = new Regex(@"^\/\/");
                typeRegex                  = new Regex(@"^题型[::]{1}");
                contentRegex1              = new Regex(@"^\s*\d+[\..、]");            // 示例:1.
                contentRegex2              = new Regex(@"^\s*\(.+\)|^\s*(.+)");      // 示例:(一) (一)
                optionalAnswerRegex        = new Regex(@"^\s*[a-zA-Z]{1}[\..、]{1}"); // 示例:A. B. C.
                modelAnswerRegex           = new Regex(@"^\s*((答案|参考答案){1}[::]{1})|【答】");
                difficultyCoefficientRegex = new Regex(@"^难度系数[::]{1}\d{1}");
                scoreRegex                 = new Regex(@"^分数[::]{1}\d+$");
                digitRegex                 = new Regex(@"\d+");

                qType           = "";
                qClassify       = "";
                qContent        = "";
                qOptionalAnswer = "";
                qModelAnswer    = "";
                isContent       = true;

                qs  = new List <Question>();
                qcs = new List <QuestionClassify>();

                // 获取数据编号
                qcId        = GetQCId();
                currentQCId = qcId;

                difficultyCoefficient = 0;
                score = 0;

                foreach (var para in docxPara)
                {
                    text = para.Text;

                    // 忽略“备注行”
                    if (commentRegex.IsMatch(text))
                    {
                        continue;
                    }

                    #region 添加试题数据

                    switch (qType)
                    {
                    case "单选题":
                    case "多选题":
                    case "判断题":
                    case "计算题":
                    case "案例分析题":
                    case "问答题":

                        if ((contentRegex1.IsMatch(text) || typeRegex.IsMatch(text)) &&
                            qModelAnswer != "")
                        {
                            // 格式化单选题/多选题的答案
                            if (qType == "单选题" || qType == "多选题")
                            {
                                qOptionalAnswer = FormatOptionalAnswer(qOptionalAnswer);
                                qModelAnswer    = FormatModelAnswer(qModelAnswer);
                            }

                            qs.Add(new Question()
                            {
                                Q_Id   = 0,
                                Q_Type = qType,
                                QC_Id  = currentQCId,
                                Q_DifficultyCoefficient = difficultyCoefficient,
                                Q_Score          = SetDefaultScore(qType, score),
                                Q_Content        = qContent,
                                Q_OptionalAnswer = qOptionalAnswer,
                                Q_ModelAnswer    = qModelAnswer,
                                Q_AddTime        = now,
                                Q_Status         = 4
                            });

                            difficultyCoefficient = 0;
                            score           = 0;
                            qContent        = "";
                            qOptionalAnswer = "";
                            qModelAnswer    = "";
                            isContent       = true;
                        }

                        break;

                    case "公文改错题":

                        if ((contentRegex2.IsMatch(text) || typeRegex.IsMatch(text)) &&
                            qModelAnswer != "")
                        {
                            qs.Add(new Question()
                            {
                                Q_Id   = 0,
                                Q_Type = qType,
                                QC_Id  = currentQCId,
                                Q_DifficultyCoefficient = difficultyCoefficient,
                                Q_Score          = SetDefaultScore(qType, score),
                                Q_Content        = qContent,
                                Q_OptionalAnswer = qOptionalAnswer,
                                Q_ModelAnswer    = qModelAnswer,
                                Q_AddTime        = now,
                                Q_Status         = 4
                            });

                            difficultyCoefficient = 0;
                            score           = 0;
                            qContent        = "";
                            qOptionalAnswer = "";
                            qModelAnswer    = "";
                            isContent       = true;
                        }

                        break;

                    default:
                        break;
                    }
                    #endregion

                    #region 判断是否为分类行

                    // 此行为分类行
                    if (text.IndexOf("分类:") == 0)
                    {
                        // 添加分类数据,记录分类编号
                        qClassify = text.Substring(3);

                        // 判断分类是否存在
                        qc =
                            olsEni.QuestionClassifies
                            .SingleOrDefault(m =>
                                             m.QC_Name == qClassify);

                        // 如果不存在,则新增
                        if (null == qc)
                        {
                            currentQCId = qcId;

                            qcs.Add(new QuestionClassify()
                            {
                                QC_Id      = qcId,
                                QC_Name    = qClassify,
                                QC_Level   = "000" + qcId.ToString(),
                                QC_AddTime = now,
                                QC_Status  = (Byte)Status.Cache
                            });
                            qcId += 1;
                        }
                        // 如果存在,但状态非“正常”,则新增同名分类加编号后缀
                        else if (qc.QC_Status != (Byte)Status.Available)
                        {
                            currentQCId = qcId;

                            qcs.Add(new QuestionClassify()
                            {
                                QC_Id      = qcId,
                                QC_Name    = qClassify + qcId,
                                QC_Level   = "000" + qcId.ToString(),
                                QC_AddTime = now,
                                QC_Status  = (Byte)Status.Cache
                            });
                            qcId += 1;
                        }
                        // 如果存在,设置当前分类编号
                        else
                        {
                            currentQCId = qc.QC_Id;
                        }

                        continue;
                    }

                    #endregion

                    #region 判断是否为题型行

                    // 此行为题型行
                    if (typeRegex.IsMatch(text))
                    {
                        qType = text.Substring(3);
                        qType = qType.Replace("单项选择题", "单选题");
                        qType = qType.Replace("多项选择题", "多选题");

                        if (qTypes.IndexOf(qType) == -1)
                        {
                            //TODO:返回,提示“当前题型不支持导入”
                            dic["Message"] = "题型“" + qType + "”不支持导入。";
                            return(dic);
                        }

                        continue;
                    }

                    #endregion

                    #region 判断是否为难度系数行

                    if (difficultyCoefficientRegex.IsMatch(text))
                    {
                        difficultyCoefficient = Convert.ToByte(digitRegex.Match(text).Value);
                        continue;
                    }

                    #endregion

                    #region 判断是否为分数行

                    if (scoreRegex.IsMatch(text))
                    {
                        score = Convert.ToInt32(digitRegex.Match(text).Value);
                        continue;
                    }

                    #endregion

                    #region 判断是否为试题内容行

                    //TODO:记录试题内容
                    switch (qType)
                    {
                    case "单选题":
                    case "多选题":
                    case "判断题":

                        if (contentRegex1.IsMatch(text))
                        {
                            // 提取标准答案
                            text     = contentRegex1.Replace(text, "");
                            qContent = text;
                            qContent = qContent.Replace("(", "(");
                            qContent = qContent.Replace(")", ")");

                            i1 = qContent.LastIndexOf("(");
                            i2 = qContent.LastIndexOf(")");

                            if (i1 == -1 || i2 == -1)
                            {
                                //TODO:返回提示格式错误
                                dic["Message"] = "题型格式有误。";
                                return(dic);
                            }

                            len          = i2 - i1 - 1;
                            qModelAnswer = qContent.Substring(i1 + 1, len);
                            if (qModelAnswer != "")
                            {
                                qContent     = qContent.Replace(qModelAnswer, "  ");
                                qModelAnswer = qModelAnswer.Trim();

                                // 处理判断题答案
                                if ("判断题" == qType && qModelAnswer.ToLower() == "x")
                                {
                                    qModelAnswer = "×";
                                }

                                // 当判断题答案有误时的处理
                                if ("判断题" == qType && "×" != qModelAnswer && "√" != qModelAnswer)
                                {
                                    qModelAnswer = "O";
                                }
                            }
                            else     // 避免模板中没有设置答案时不添加试题
                            {
                                qModelAnswer = " ";
                            }

                            continue;
                        }

                        break;

                    case "公文改错题":
                    case "计算题":
                    case "案例分析题":
                    case "问答题":

                        // 公文改错题;计算题;案例分析题;问答题;
                        // 判断是否为标准答案行
                        if (modelAnswerRegex.IsMatch(text))
                        {
                            isContent = false;

                            text = modelAnswerRegex.Replace(text, "");
                        }

                        if (isContent)
                        {
                            if ("公文改错题" == qType)
                            {
                                text = contentRegex2.Replace(text, "");
                            }
                            else
                            {
                                text = contentRegex1.Replace(text, "");
                            }
                            qContent += text + "\\r\\n";
                        }

                        break;

                    default:

                        break;
                    }

                    #endregion

                    #region 判断是否为试题答案行

                    switch (qType)
                    {
                    case "单选题":
                    case "多选题":

                        // 单选题;多选题;
                        // 判断是否为备选答案行
                        if (optionalAnswerRegex.IsMatch(text))
                        {
                            qOptionalAnswer += text + " ";
                        }

                        break;

                    case "公文改错题":
                    case "计算题":
                    case "案例分析题":
                    case "问答题":

                        if (!isContent)
                        {
                            //TODO:记录试题答案
                            qModelAnswer += text + "\\r\\n";
                        }

                        break;

                    default:
                        break;
                    }

                    #endregion
                }

                if (qModelAnswer != "")
                {
                    // 格式化单选题/多选题的答案
                    if (qType == "单选题" || qType == "多选题")
                    {
                        qOptionalAnswer = FormatOptionalAnswer(qOptionalAnswer);
                        qModelAnswer    = FormatModelAnswer(qModelAnswer);
                    }

                    qs.Add(new Question()
                    {
                        Q_Id   = 0,
                        Q_Type = qType,
                        QC_Id  = currentQCId,
                        Q_DifficultyCoefficient = difficultyCoefficient,
                        Q_Score          = SetDefaultScore(qType, score),
                        Q_Content        = qContent,
                        Q_OptionalAnswer = qOptionalAnswer,
                        Q_ModelAnswer    = qModelAnswer,
                        Q_AddTime        = now,
                        Q_Status         = 4
                    });

                    difficultyCoefficient = 0;
                    score           = 0;
                    qContent        = "";
                    qOptionalAnswer = "";
                    qModelAnswer    = "";
                    isContent       = true;
                }

                foreach (var qc1 in qcs)
                {
                    olsEni.QuestionClassifies.Add(qc1);
                }

                olsEni.SaveChanges();

                // 获取试题初始编号
                qId       = GetQId();
                duplicate = 0;
                foreach (var m1 in qs)
                {
                    tmpQs =
                        olsEni.Questions
                        .Where(m =>
                               m.Q_Content.Contains(m1.Q_Content) &&
                               (m.Q_Status == (Byte)Status.Available ||
                                m.Q_Status == (Byte)Status.Cache))
                        .ToList();

                    existsFlag = false;
                    foreach (var m2 in tmpQs)
                    {
                        if (m2.Q_Content == m1.Q_Content)
                        {
                            existsFlag = true;
                            break;
                        }
                    }

                    if (!existsFlag)
                    {
                        m1.Q_Id = qId;
                        olsEni.Questions.Add(m1);
                        qId += 1;

                        // 标识数据错误
                        if (("单选题" == m1.Q_Type ||
                             "多选题" == m1.Q_Type) &&
                            ("{}" == m1.Q_ModelAnswer ||
                             "[]" == m1.Q_ModelAnswer))
                        {
                            errorIds.Append(qId + ", ");
                        }

                        if ("判断题" == m1.Q_Type && "O" == m1.Q_ModelAnswer)
                        {
                            errorIds.Append(qId + ", ");
                        }
                    }
                    else
                    {
                        duplicate += 1;
                    }
                }

                if (duplicate > 0)
                {
                    dic["Message"] = "发现重复试题 " + duplicate + " 条\r\n";
                }

                if (olsEni.SaveChanges() == 0)
                {
                    dic["Message"] += ResponseMessage.SaveChangesError;
                    return(dic);
                }

                if (errorIds.Length > 0)
                {
                    dic["Message"] += "试题模板数据存在错误(" + errorIds.Remove(errorIds.Length - 2, 2).ToString() + ")";
                }

                dic["Status"] = "1";
                return(dic);
            }
            catch (Exception ex)
            {
                dic["Message"] = StaticHelper.GetExceptionMessageAndRecord(ex);
                return(dic);
            }
        }
        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 #27
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);
            }
        }
        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 #29
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 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);
            }
        }