Exemple #1
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);
        }
        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);
            }
        }
Exemple #3
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);
        }
        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;
        }
        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;
        }
        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;
        }
        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;
            }
        }
        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;
            }
        }
Exemple #9
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);
        }
Exemple #10
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);
            }
        }
        public ResponseJson Change()
        {
            ResponseJson resJson;

            resJson = new ResponseJson(ResponseStatus.Success);

            try
            {

                Boolean unsaved;
                ExaminationPaperTemplate ept;
                ExaminationTask et;
                UExaminationPaperTemplate uept;
                List<ExaminationPaper> eps;

                unsaved = false;
                uept = new UExaminationPaperTemplate();

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

                foreach (var ep in eps)
                {

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

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

                    // 考试时长无限制、试卷模板已终止,则关闭试卷、计算成绩
                    if (ep.EP_TimeSpan == 0)
                    {
                        ept = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == ep.EPT_Id);
                        if ((Byte)PaperTemplateStatus.Done == ept.EPT_PaperTemplateStatus)
                        {
                            ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                            if (1 != olsEni.SaveChanges())
                            {
                                unsaved = true;
                            }
                            uept.GradePaper(ep);
                            uept.SaveChanges();
                        }
                    }
                    else if (now > ep.EP_EndTime)
                    {
                        ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                        if (1 != olsEni.SaveChanges())
                        {
                            unsaved = true;
                        }
                        uept.GradePaper(ep);
                        uept.SaveChanges();
                    }
                }

                if (unsaved)
                {
                    resJson.status = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                }

                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
            {
                Boolean unsaved;
                ExaminationPaperTemplate  ept;
                ExaminationTask           et;
                UExaminationPaperTemplate uept;
                List <ExaminationPaper>   eps;

                unsaved = false;
                uept    = new UExaminationPaperTemplate();

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

                foreach (var ep in eps)
                {
                    et = olsEni.ExaminationTasks.Single(m => m.ET_Id == ep.ET_Id);

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

                    // 考试时长无限制、试卷模板已终止,则关闭试卷、计算成绩
                    if (ep.EP_TimeSpan == 0)
                    {
                        ept = olsEni.ExaminationPaperTemplates.Single(m => m.EPT_Id == ep.EPT_Id);
                        if ((Byte)PaperTemplateStatus.Done == ept.EPT_PaperTemplateStatus)
                        {
                            ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                            if (1 != olsEni.SaveChanges())
                            {
                                unsaved = true;
                            }
                            uept.GradePaper(ep);
                            uept.SaveChanges();
                        }
                    }
                    else if (now > ep.EP_EndTime)
                    {
                        ep.EP_PaperStatus = (Byte)PaperStatus.Done;
                        if (1 != olsEni.SaveChanges())
                        {
                            unsaved = true;
                        }
                        uept.GradePaper(ep);
                        uept.SaveChanges();
                    }
                }

                if (unsaved)
                {
                    resJson.status  = ResponseStatus.Error;
                    resJson.message = ResponseMessage.SaveChangesError;
                }

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