コード例 #1
0
ファイル: MultipleItemDAL.cs プロジェクト: yienit/KST
        /// <summary>
        /// 添加实体信息,返回添加成功后的主键ID
        /// </summary>
        public int Insert(MultipleItem multiple)
        {
            int id = 0;

            const string sql = @"INSERT INTO MultipleItem(AgencyID, ChapterID, IsVipItem,
                               Title, Image, A, B, C, D, Answer, Annotation, Difficulty, AddPerson)
                               VALUES (@AgencyID, @ChapterID, @IsVipItem,
                               @Title, @Image, @A, @B, @C, @D, @Answer, @Annotation, @Difficulty, @AddPerson);
                               SELECT LAST_INSERT_ID();";
            using (DbConnection connection = ConnectionManager.OpenConnection)
            {
                id = connection.Query<int>(sql, multiple).SingleOrDefault<int>();
            }
            return id;
        }
コード例 #2
0
ファイル: MultipleItemDTO.cs プロジェクト: yienit/KST
        public MultipleItemDTO(MultipleItem multiple)
        {
            this.ID = multiple.ID;
            this.AgencyID = multiple.AgencyID;
            this.ChapterID = multiple.ChapterID;
            this.IsVipItem = multiple.IsVipItem;

            this.Title = multiple.Title;
            this.Image = multiple.Image;
            this.A = multiple.A;
            this.B = multiple.B;
            this.C = multiple.C;
            this.D = multiple.D;
            this.Answer = multiple.Answer;
            this.Annotation = multiple.Annotation;
            this.Difficulty = multiple.Difficulty;
            this.AddPerson = multiple.AddPerson;
            this.AddTime = multiple.AddTime;
        }
コード例 #3
0
ファイル: ItemDataService.cs プロジェクト: yienit/KST
        /// <summary>
        /// 更新多选题
        /// </summary>
        public ServiceInvokeDTO UpdateMultiple(MultipleItem multiple)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                MultipleItem dbMulitiple = multipleDAL.GetByID(multiple.ID);
                if (dbMulitiple != null)
                {
                    multipleDAL.Update(multiple);
                    result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
                }
                else
                {
                    result = new ServiceInvokeDTO(InvokeCode.SYS_OBJECT_NOT_EXIST_ERROR);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }
コード例 #4
0
ファイル: ItemDataService.cs プロジェクト: yienit/KST
        /// <summary>
        /// 添加多选题
        /// </summary>
        public ServiceInvokeDTO AddMultiple(MultipleItem multiple)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                multipleDAL.Insert(multiple);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }
コード例 #5
0
ファイル: ItemController.cs プロジェクト: yienit/KST
        public ActionResult UpdateMultiple()
        {
            log.Debug(Constant.DEBUG_START);

            string idString = ApiQueryUtil.QueryArgByPost("id");
            string isVipItemString = ApiQueryUtil.QueryArgByPost("is_vip_item");
            string chapterIDString = ApiQueryUtil.QueryArgByPost("chapter_id");

            string title = ApiQueryUtil.QueryArgByPost("title");
            HttpPostedFileBase imageFile = Request.Files["image"];
            string a = ApiQueryUtil.QueryArgByPost("a");
            string b = ApiQueryUtil.QueryArgByPost("b");
            string c = ApiQueryUtil.QueryArgByPost("c");
            string d = ApiQueryUtil.QueryArgByPost("d");
            string answer = ApiQueryUtil.QueryArgByPost("answer");
            string annotation = ApiQueryUtil.QueryArgByPost("annotation");
            string difficultyString = ApiQueryUtil.QueryArgByPost("difficulty");

            ServiceInvokeDTO result = null;
            try
            {
                MultipleItem multiple = new MultipleItem();
                multiple.ID = Convert.ToInt32(idString);
                multiple.IsVipItem = Convert.ToInt32(isVipItemString);
                multiple.ChapterID = Convert.ToInt32(chapterIDString);

                multiple.Title = title;
                multiple.A = a;
                multiple.B = b;
                multiple.C = c;
                multiple.D = d;
                multiple.Answer = answer;
                multiple.Annotation = annotation;
                multiple.Difficulty = Convert.ToInt32(difficultyString);

                if (imageFile != null)
                {
                    byte[] imageBytes = null;
                    using (Stream inputStream = imageFile.InputStream)
                    {
                        MemoryStream memoryStream = inputStream as MemoryStream;
                        if (memoryStream == null)
                        {
                            memoryStream = new MemoryStream();
                            inputStream.CopyTo(memoryStream);
                        }
                        imageBytes = memoryStream.ToArray();
                    }
                    multiple.Image = imageBytes;
                }

                AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO;
                ServiceInvokeDTO checkResult = permissionService.CheckPermission(DoActionType.UpdateMultiple, currentAdmin.Agency.ID, multiple.ID);
                if (checkResult.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    result = itemDataService.UpdateMultiple(multiple);

                    // Write admin do record.
                    if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                    {
                        AdminDoRecord doRecord = new AdminDoRecord();
                        doRecord.AdminID = currentAdmin.ID;
                        doRecord.AdminName = currentAdmin.ChineseName;
                        doRecord.DoTime = DateTime.Now;
                        doRecord.DoName = DoActionType.UpdateMultiple.GetDescription();
                        doRecord.DoContent = string.Format("被更新的主键ID:{0}", idString);
                        doRecord.Remark = string.Empty;
                        recordDataService.AddAdminDoRecord(doRecord);
                    }
                }
                else
                {
                    result = checkResult;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR);
            }

            string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER);
            log.Debug(Constant.DEBUG_END);

            return Content(json, Constant.JSON_MIME_TYPE);
        }
コード例 #6
0
ファイル: TemplateUtil.cs プロジェクト: yienit/KST
        /// <summary>
        /// 读取多选题题库模板数据
        /// </summary>
        /// <param name="adminDTO">管理员对象</param>
        /// <param name="courseID">课程主键ID</param>
        /// <param name="fileName">Excel文件路径名称</param>
        /// <param name="isFirstRowTitle">第一行是否为标题</param>
        public static List<MultipleItem> ReadMultipleTemplate(AgencyAdminDTO adminDTO, int courseID, string fileName, bool isFirstRowTitle)
        {
            List<MultipleItem> multiples = new List<MultipleItem>();

            // 获取所有章节
            ServiceInvokeDTO<List<Chapter>> chaptersResult = ServiceFactory.Instance.ItemDataService.GetAgencyChapters(courseID);
            if (chaptersResult.Code == InvokeCode.SYS_INVOKE_SUCCESS && chaptersResult.Data != null && chaptersResult.Data.Count > 0)
            {
                List<Chapter> chapters = chaptersResult.Data;

                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    // 默认读取第一张表
                    IWorkbook workBook = WorkbookFactory.Create(fs);
                    ISheet sheet = workBook.GetSheetAt(0);

                    int startRowIndex = 0;
                    if (isFirstRowTitle && sheet.LastRowNum >= 1)
                    {
                        startRowIndex = 1;
                    }

                    for (int index = startRowIndex; index <= sheet.LastRowNum; index++)
                    {
                        IRow row = sheet.GetRow(index);
                        if (row != null)
                        {
                            // 题库类型
                            ICell isVipItemCell = row.GetCell(0); if (isVipItemCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string isVipItem = isVipItemCell.ToString().Trim();
                            if (!isVipItem.Equals(IS_VIP_ITEM_NO) && !isVipItem.Equals(IS_VIP_ITEM_YES))
                            {
                                throw new ArgumentException(IS_VIP_ITEM_ERROR);
                            }

                            // 所属章节
                            ICell chapterCell = row.GetCell(1); if (chapterCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string chapterName = chapterCell.ToString().Trim();
                            int chapterID = 0;
                            foreach (var chapter in chapters)
                            {
                                if (chapterName.Equals(chapter.Name))
                                {
                                    chapterID = chapter.ID;
                                    break;
                                }
                            }
                            if (chapterID == 0)
                            {
                                throw new ArgumentException(CHAPTER_ID_ERROR);
                            }

                            ICell titleCell = row.GetCell(2); if (titleCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            ICell aCell = row.GetCell(3); if (aCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            ICell bCell = row.GetCell(4); if (bCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            ICell cCell = row.GetCell(5); if (cCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            ICell dCell = row.GetCell(6); if (dCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }

                            // 答案
                            ICell amswerCell = row.GetCell(7); if (amswerCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string answer = amswerCell.ToString().Trim().ToUpper();
                            if (answer.Length == 1)
                            {
                                if (!answer.Equals(ANSWER_A) && !answer.Equals(ANSWER_B) && !answer.Equals(ANSWER_C) && !answer.Equals(ANSWER_D))
                                {
                                    throw new ArgumentException(ANSWER_ARG_ERROR);
                                }
                            }
                            else
                            {
                                if (!answer.Contains(MULTIPLE_ANSWER_SPILT))
                                {
                                    throw new ArgumentException(ANSWER_ARG_ERROR);
                                }
                            }

                            // 试题难易度
                            ICell difficltyCell = row.GetCell(9); if (difficltyCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string difficltyString = difficltyCell.ToString().Trim();

                            int difficulty = 0;
                            if (int.TryParse(difficltyString, out difficulty))
                            {
                                if (difficulty < DIFFICULTY_MIN || difficulty > DIFFICULTY_MAX)
                                {
                                    throw new ArgumentException(DIFFICULTY_ARG_ERROR);
                                }
                            }
                            else
                            {
                                throw new ArgumentException(DIFFICULTY_ARG_ERROR);
                            }

                            MultipleItem multiple = new MultipleItem();
                            multiple.AgencyID = adminDTO.Agency.ID;
                            multiple.ChapterID = chapterID;
                            multiple.IsVipItem = isVipItem.Equals(IS_VIP_ITEM_YES) ? 1 : 0;
                            multiple.Title = titleCell.ToString();
                            multiple.A = aCell.ToString();
                            multiple.B = bCell.ToString();
                            multiple.C = cCell.ToString();
                            multiple.D = dCell.ToString();
                            multiple.Answer = answer;
                            multiple.Annotation = row.GetCell(8) == null ? string.Empty : row.GetCell(8).ToString();
                            multiple.Difficulty = difficulty;
                            multiple.AddPerson = adminDTO.ChineseName;

                            multiples.Add(multiple);
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentException(CHAPTER_ID_ERROR);
            }

            return multiples;
        }
コード例 #7
0
ファイル: MultipleItemDAL.cs プロジェクト: yienit/KST
 /// <summary>
 /// 更新实体信息
 /// </summary>
 public void Update(MultipleItem multiple)
 {
     const string sql = @"UPDATE MultipleItem SET ChapterID = @ChapterID, IsVipItem= @IsVipItem,
                        Title = @Title, Image = @Image, A = @A, B= @B, C = @C, D = @D, Answer = @Answer, Annotation = @Annotation, Difficulty = @Difficulty
                        WHERE IsDeleted = 0 AND ID = @ID";
     using (DbConnection connection = ConnectionManager.OpenConnection)
     {
         connection.Execute(sql, multiple);
     }
 }