コード例 #1
0
        public void UpdateExamCategory(ExamCategory examCategory)
        {
            Database db = DatabaseFactory.CreateDatabase();

            string    sqlCommand = "USP_Exam_Category_U";
            DbCommand dbCommand  = db.GetStoredProcCommand(sqlCommand);

            db.AddInParameter(dbCommand, "p_Exam_Category_id", DbType.Int32, examCategory.ExamCategoryId);
            db.AddInParameter(dbCommand, "p_parent_id", DbType.Int32, examCategory.ParentId);
            db.AddInParameter(dbCommand, "p_id_path", DbType.String, examCategory.IdPath);
            db.AddInParameter(dbCommand, "p_level_num", DbType.Int32, examCategory.LevelNum);
            db.AddInParameter(dbCommand, "p_order_index", DbType.Int32, examCategory.OrderIndex);
            db.AddInParameter(dbCommand, "p_Category_name", DbType.String, examCategory.CategoryName);
            db.AddInParameter(dbCommand, "p_description", DbType.String, examCategory.Description);
            db.AddInParameter(dbCommand, "p_memo", DbType.String, examCategory.Memo);

            DbConnection connection = db.CreateConnection();

            connection.Open();
            DbTransaction transaction = connection.BeginTransaction();

            try
            {
                db.ExecuteNonQuery(dbCommand, transaction);


                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
            }
            connection.Close();
        }
コード例 #2
0
        /// <summary>
        /// 根据ParentID
        /// 递归调用子分类
        /// 该方法不包含根
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        private static IList <ExamCategory> GetExamCategoryListByParentId(int parentId)
        {
            IList <ExamCategory> examCategoryList = new List <ExamCategory>();
            ExamCategory         examCategory     = null;

            string       strSql = "SELECT * FROM ExamCategory WHERE Parent_ID = @ParentID ORDER BY Column_Order ASC ";
            SqlParameter parm   = new SqlParameter("@ParentID", parentId);

            using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, parm)){
                while (dr.Read())
                {
                    int _categoryId = Convert.ToInt32(dr["Column_ID"]);
                    examCategory = GetExamCategoryByCategoryId(_categoryId);
                    examCategoryList.Add(examCategory);

                    IList <ExamCategory> list = GetExamCategoryListByParentId(examCategory.CategoryID);

                    foreach (ExamCategory item in list)
                    {
                        examCategoryList.Add(item);
                    }
                }
            }

            return(examCategoryList);
        }
コード例 #3
0
        private async Task <ExamForRenderDTO> ConvertExamForRender(ExamCategory examCat, RenderExamTypes type)
        {
            var query = await _ExamSkillCategoryRepository.GetQueryableAsync();

            var skillCats = query
                            .Where(x => x.ExamCategoryId == examCat.Id)
                            .ToList();
            var microSkillCats = new List <MicroSkillCategoryDTO>();

            foreach (var item in skillCats)
            {
                var converted = await ConvertRenderSkillCategory(item);

                microSkillCats.Add(converted);
            }
            // Sắp xếp chuẩn
            microSkillCats = microSkillCats.OrderBy(x => x.Order).ToList();
            return(new ExamForRenderDTO
            {
                Id = examCat.Id,
                Name = examCat.Name,
                Description = examCat.Description,
                RenderExamType = type,
                SkillCategories = microSkillCats
            });
        }
コード例 #4
0
        /// <summary>
        /// 查询组织机构
        /// </summary>
        /// <param name="ExamCategoryId"></param>
        /// <param name="parentId"></param>
        /// <param name="idPath"></param>
        /// <param name="levelNum"></param>
        /// <param name="orderIndex"></param>
        /// <param name="CategoryName"></param>
        /// <param name="description"></param>
        /// <param name="memo"></param>
        /// <param name="startRowIndex">起始记录行</param>
        /// <param name="maximumRows">每页记录条数</param>
        /// <param name="orderBy">排序字符串,如"FieldName ASC"</param>
        /// <returns></returns>
        public IList <ExamCategory> GetExamCategory(int ExamCategoryId, int parentId, string idPath, int levelNum, int orderIndex,
                                                    string CategoryName, string description, string memo, int startRowIndex, int maximumRows, string orderBy)
        {
            IList <ExamCategory> examCategories = new List <ExamCategory>();

            Database db = DatabaseFactory.CreateDatabase();

            string    sqlCommand = "USP_Exam_Category_S";
            DbCommand dbCommand  = db.GetStoredProcCommand(sqlCommand);

            db.AddInParameter(dbCommand, "p_start_row_index", DbType.Int32, startRowIndex);
            db.AddInParameter(dbCommand, "p_page_size", DbType.Int32, maximumRows);
            db.AddInParameter(dbCommand, "p_order_by", DbType.AnsiString, GetMappingOrderBy(orderBy));
            db.AddOutParameter(dbCommand, "p_count", DbType.Int32, 4);

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    ExamCategory examCategory = CreateModelObject(dataReader);

                    examCategories.Add(examCategory);
                }
            }

            _recordCount = Convert.ToInt32(db.GetParameterValue(dbCommand, "p_count"));

            return(examCategories);
        }
コード例 #5
0
        /// <summary>
        /// 删除知识类别
        /// </summary>
        /// <param name="examCategory">要删除的知识类别</param>
        public void DeleteExamCategory(ExamCategory examCategory)
        {
            string strName = GetExamCategory(examCategory.ExamCategoryId).CategoryName;

            objLogBll.WriteLog("新增考试类别“" + strName + "”基本信息");
            dal.DeleteExamCategory(examCategory.ExamCategoryId);
        }
コード例 #6
0
        /// <summary>
        /// 新增知识类别
        /// </summary>
        /// <param name="examCategory">新增的知识类别信息</param>
        /// <returns></returns>
        public int AddExamCategory(ExamCategory examCategory)
        {
            int id = dal.AddExamCategory(examCategory);

            objLogBll.WriteLog("新增考试类别“" + examCategory.CategoryName + "”基本信息");
            return(id);
        }
コード例 #7
0
        /// <summary>
        /// 获得分类实体
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public static ExamCategory GetExamCategoryByCategoryId(int categoryId)
        {
            string       strSql       = "SELECT * FROM ExamCategory WHERE Column_ID = @CategoryID";
            SqlParameter parm         = new SqlParameter("@CategoryId", categoryId);
            ExamCategory examCategory = null;

            using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, parm)){
                if (dr.Read())
                {
                    examCategory = new ExamCategory();
                    examCategory.CategoryDepth = Convert.ToInt32(dr["Column_Depth"]);
                    examCategory.CategoryID    = categoryId;
                    examCategory.CategoryName  = dr["Column_Name"].ToString();
                    examCategory.CategoryOrder = Convert.ToInt32(dr["Column_Order"]);
                    examCategory.CategoryPath  = dr["Column_Path"].ToString();
                    examCategory.ParentID      = Convert.ToInt32(dr["Parent_ID"]);
                }
            }
            return(examCategory);
        }
コード例 #8
0
        public ExamCategory GetExamCategory(int ExamCategoryId)
        {
            ExamCategory examCategory = null;

            Database db = DatabaseFactory.CreateDatabase();

            string    sqlCommand = "USP_Exam_Category_G";
            DbCommand dbCommand  = db.GetStoredProcCommand(sqlCommand);

            db.AddInParameter(dbCommand, "p_Exam_Category_id", DbType.Int32, ExamCategoryId);

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    examCategory = CreateModelObject(dataReader);
                }
            }

            return(examCategory);
        }
コード例 #9
0
        public int AddExamCategory(ExamCategory examCategory)
        {
            int      id = 0;
            Database db = DatabaseFactory.CreateDatabase();

            string    sqlCommand = "USP_Exam_Category_I";
            DbCommand dbCommand  = db.GetStoredProcCommand(sqlCommand);

            db.AddOutParameter(dbCommand, "p_Exam_Category_id", DbType.Int32, 4);
            db.AddInParameter(dbCommand, "p_parent_id", DbType.Int32, examCategory.ParentId);
            db.AddOutParameter(dbCommand, "p_id_path", DbType.String, 20);
            db.AddOutParameter(dbCommand, "p_level_num", DbType.Int32, 4);
            db.AddOutParameter(dbCommand, "p_order_index", DbType.Int32, 4);
            db.AddInParameter(dbCommand, "p_Category_name", DbType.String, examCategory.CategoryName);
            db.AddInParameter(dbCommand, "p_description", DbType.String, examCategory.Description);
            db.AddInParameter(dbCommand, "p_memo", DbType.String, examCategory.Memo);

            DbConnection connection = db.CreateConnection();

            connection.Open();
            DbTransaction transaction = connection.BeginTransaction();

            try
            {
                db.ExecuteNonQuery(dbCommand, transaction);
                id = Convert.ToInt32(db.GetParameterValue(dbCommand, "p_Exam_Category_id"));

                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
            }
            connection.Close();

            return(id);
        }
コード例 #10
0
        public IList <ExamCategory> GetExamCategories()
        {
            IList <ExamCategory> examCategories = new List <ExamCategory>();

            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("USP_GET_ALL");

            db.AddInParameter(dbCommand, "p_table_name", DbType.String, "EXAM_CATEGORY");
            db.AddInParameter(dbCommand, "p_order_by", DbType.String, "LEVEL_NUM, ORDER_INDEX ASC");

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    ExamCategory examCategory = CreateModelObject(dataReader);

                    examCategories.Add(examCategory);
                }
            }

            _recordCount = examCategories.Count;

            return(examCategories);
        }
コード例 #11
0
        public ActionResult CourseList(FormCollection form, int?id)
        {
            int trueCounter  = 0;
            int falseCounter = 0;


            Exam exam = new Exam {
                StudentId = Convert.ToInt32(Session["StudentId"]), Date = DateTime.Now
            };

            List <ExamCategory> examCategories = new List <ExamCategory>();

            foreach (var item in _questionIdList)
            {
                if (form[item.Key.ToString()] == null)
                {
                    continue;
                }
                string result   = form[item.Key.ToString()];
                string dbAnswer = GetRightAnswer(item.Key);

                bool isNewCategory = true;
                foreach (ExamCategory examCategory in examCategories.Where(x => x.CategoryId == item.Value))
                {
                    isNewCategory = false;
                    if (result == dbAnswer)
                    {
                        examCategory.TrueCounter += 1;
                        trueCounter += 1;
                    }
                    else
                    {
                        examCategory.FalseCounter += 1;
                        falseCounter += 1;
                    }
                }

                if (!isNewCategory)
                {
                    continue;
                }

                ExamCategory newExamCategory = new ExamCategory {
                    CategoryId = item.Value, TrueCounter = 0, FalseCounter = 0
                };

                examCategories.Add(newExamCategory);
                if (result == dbAnswer)
                {
                    newExamCategory.TrueCounter += 1;
                    trueCounter += 1;
                }
                else
                {
                    newExamCategory.FalseCounter += 1;
                    falseCounter += 1;
                }
            }
            exam.TrueCounter  = trueCounter;
            exam.FalseCounter = falseCounter;
            exam.Point        = trueCounter * 2;

            context.Exams.Add(exam);
            //context.Users.Add(user);

            context.SaveChanges();



            return(RedirectToAction($"StatisticList/{id}", "Statistic"));
        }
コード例 #12
0
        public ActionResult <Edit> Update([FromBody] Edit param)
        {
            if (param == null)
            {
                param          = new Edit();
                param._message = _localizer["No parameters."];
                return(BadRequest(param));
            }
            if (!TryValidateModel(param))
            {
                param._message = _localizer["The input is incorrect."];

                return(BadRequest(param));
            }

            try
            {
                //更新前データを取得する
                var storeModel = (from a in _context.Exams
                                  where a.ExamId.Equals(param.ExamId)
                                  select a).FirstOrDefault();


                if (storeModel == null)
                {
                    param._message = _localizer["It has already been deleted."];
                    return(BadRequest(param));
                }
                if (storeModel.Version != param.Version)
                {
                    param._message = _localizer["Other people have been updated."];
                    return(BadRequest(param));
                }
                ReflectionUtility.Model2Model(param, storeModel);

                storeModel.Updated  = DateTime.Now;
                storeModel.Version += 1;
                //更新
                _context.Exams.Update(storeModel);
                //_context.SaveChanges();

                //更新前データを取得する
                var ec = from a in _context.ExamCategories
                         where a.ExamId.Equals(param.ExamId)
                         select a;
                //削除
                _context.ExamCategories.RemoveRange(ec);

                if (param.CategoryIds != null)
                {
                    foreach (var r in param.CategoryIds)
                    {
                        var m = new ExamCategory
                        {
                            ExamCategoryId = (Guid.NewGuid()).ToString(),
                            ExamId         = storeModel.ExamId,
                            CategoryId     = r.ToString(),
                            Owner          = HttpContext.User.Identity.Name,
                            Registed       = DateTime.Now,
                            Updated        = DateTime.Now,
                            Version        = 1
                        };

                        //登録
                        _context.ExamCategories.Add(m);
                    }
                }
                _context.SaveChanges();
                ReflectionUtility.Model2Model(storeModel, param);

                return(Ok(param));
            }
            catch (Exception ex)
            {
                param._message = _localizer["System error Please inform system personnel.({0})", ex.Message];
                return(BadRequest(param));
            }
        }
コード例 #13
0
        public ActionResult <Create> Insert([FromBody] Create param)
        {
            if (param == null)
            {
                param          = new Create();
                param._message = _localizer["No parameters."];
                return(BadRequest(param));
            }
            if (!TryValidateModel(param))
            {
                param._message = _localizer["The input is incorrect."];

                return(BadRequest(param));
            }

            try
            {
                var storeModel = new Exam();
                ReflectionUtility.Model2Model(param, storeModel);
                storeModel.ExamId = (Guid.NewGuid()).ToString();
                //storeModel.ExamCategoryIds = string.Join(",", model.ExamCategoryIds);

                storeModel.Owner    = HttpContext.User.Identity.Name;
                storeModel.Registed = DateTime.Now;
                storeModel.Updated  = DateTime.Now;
                storeModel.Version  = 1;

                //登録
                _context.Exams.Add(storeModel);
                //_context.SaveChanges();

                if (param.CategoryIds != null)
                {
                    foreach (var r in param.CategoryIds)
                    {
                        var m = new ExamCategory
                        {
                            ExamCategoryId = (Guid.NewGuid()).ToString(),
                            ExamId         = storeModel.ExamId,
                            CategoryId     = r.ToString(),
                            Owner          = HttpContext.User.Identity.Name,
                            Registed       = DateTime.Now,
                            Updated        = DateTime.Now,
                            Version        = 1
                        };

                        //登録
                        _context.ExamCategories.Add(m);
                    }
                }
                _context.SaveChanges();

                ReflectionUtility.Model2Model(storeModel, param);
                return(Ok(param));
            }
            catch (Exception ex)
            {
                param._message = _localizer["System error Please inform system personnel.({0})", ex.Message];
                return(BadRequest(param));
            }
        }
コード例 #14
0
        public ActionResult TakeTheExam(FormCollection form)
        {
            int trueCounter  = 0;
            int falseCounter = 0;

            Exam exam = new Exam {
                StudentId = Convert.ToInt32(Session["StudentId"]), Date = DateTime.Now
            };

            List <ExamCategory> examCategories = new List <ExamCategory>();

            foreach (var item in _questionsIdList)
            {
                if (form[item.Key.ToString()] == null)
                {
                    continue;
                }

                string result   = form[item.Key.ToString()];
                string dbAnswer = GetRightAnswer(item.Key);

                bool isNewCategory = true;
                foreach (ExamCategory examCategory in examCategories.Where(examCategory => examCategory.CategoryId == item.Value))
                {
                    isNewCategory = false;
                    if (result == dbAnswer)
                    {
                        examCategory.TrueCounter += 1;
                        trueCounter += 1;
                    }
                    else
                    {
                        examCategory.FalseCounter += 1;
                        falseCounter += 1;
                    }
                }

                if (!isNewCategory)
                {
                    continue;
                }

                ExamCategory newExamCategory = new ExamCategory {
                    CategoryId = item.Value, TrueCounter = 0, FalseCounter = 0
                };

                examCategories.Add(newExamCategory);

                if (result == dbAnswer)
                {
                    newExamCategory.TrueCounter += 1;
                    trueCounter += 1;
                }
                else
                {
                    newExamCategory.FalseCounter += 1;
                    falseCounter += 1;
                }
            }

            exam.TrueCounter  = trueCounter;
            exam.FalseCounter = falseCounter;
            exam.Point        = trueCounter * 2;

            _context.Exams.Add(exam);
            _context.SaveChanges();

            foreach (var examCategory in examCategories)
            {
                int examId = exam.Id;
                examCategory.ExamId = examId;
                _context.ExamCategories.Add(examCategory);
            }

            List <PerformanceCategory> performanceCategories = new List <PerformanceCategory>();

            foreach (var examCategory in examCategories)
            {
                bool isExist = IsCategoryInList(performanceCategories, examCategory);

                if (isExist)
                {
                    continue;
                }

                PerformanceCategory newPerformanceCategory = new PerformanceCategory
                {
                    CategoryId   = examCategory.CategoryId,
                    TrueCounter  = examCategory.TrueCounter,
                    FalseCounter = examCategory.FalseCounter,
                    StudentID    = GetStundetId()
                };

                performanceCategories.Add(newPerformanceCategory);
            }

            foreach (PerformanceCategory performanceCategory in performanceCategories)
            {
                PerformanceCategory performCategory =
                    GetPerformanceWithCategoryId(GetStundetId(), performanceCategory.CategoryId);

                if (performCategory != null)
                {
                    performCategory.TrueCounter  += performanceCategory.TrueCounter;
                    performCategory.FalseCounter += performanceCategory.FalseCounter;
                }
                else
                {
                    AddPerformanceCategory(performanceCategory);
                }
            }

            _context.SaveChanges();

            List <Category> categories = GetTeacherCategories(GetTeacherIDForStudent());

            List <PerformanceCategory> existPerformanceCategories = GetPerformanceCategoriesForStudent(GetStundetId());

            foreach (var category in categories)
            {
                bool isExist = false;
                foreach (var performanceCategory in existPerformanceCategories)
                {
                    if (category.Id == performanceCategory.CategoryId)
                    {
                        isExist = true;
                        break;
                    }
                }

                if (isExist)
                {
                    continue;
                }

                var newPerformanceCategory = new PerformanceCategory
                {
                    CategoryId   = category.Id,
                    TrueCounter  = 0,
                    FalseCounter = 0,
                    StudentID    = GetStundetId()
                };

                AddPerformanceCategory(newPerformanceCategory);
            }

            _context.SaveChanges();
            ToastrService.AddToUserQueue("", "Sınavınız tamamlandı!", ToastrType.Info);
            return(RedirectToAction("Index", "Student"));
        }
コード例 #15
0
        private bool IsCategoryInList(List <PerformanceCategory> performanceCategories, ExamCategory examCategory)  // Parametre olarak gelen examCategory, performanceCategories listesinde var mı yok mu kontrol eder. Eger varsa bu examCategory nin dogru ve yanlislari, performanceCategorieste var olanin ustune yazdirilir.
        {
            bool isSameCategory = false;

            foreach (var performanceCategory in performanceCategories.Where(performanceCategory => examCategory.CategoryId == performanceCategory.CategoryId))
            {
                performanceCategory.TrueCounter  += examCategory.TrueCounter;
                performanceCategory.FalseCounter += examCategory.FalseCounter;
                isSameCategory = true;
            }

            return(isSameCategory);
        }
コード例 #16
0
 /// <summary>
 /// 更新知识类别
 /// </summary>
 /// <param name="examCategory">更新后的知识类别信息</param>
 public void UpdateExamCategory(ExamCategory examCategory)
 {
     dal.UpdateExamCategory(examCategory);
     objLogBll.WriteLog("修改考试类别“" + examCategory.CategoryName + "”基本信息");
 }