/// <summary>
        /// 根据ID获取问题信息
        /// </summary>
        public string GetOptionById()
        {
            var    quesQuestionsBLL = new QuesOptionBLL(this.CurrentUserInfo);
            string content          = string.Empty;

            string key = string.Empty;

            if (FormatParamValue(Request("OptionID")) != null && FormatParamValue(Request("OptionID")) != string.Empty)
            {
                key = FormatParamValue(Request("OptionID")).ToString().Trim();
            }

            var condition = new List <IWhereCondition>();

            if (!key.Equals(string.Empty))
            {
                condition.Add(new EqualsCondition()
                {
                    FieldName = "OptionID", Value = key
                });
            }

            var data = quesQuestionsBLL.Query(condition.ToArray(), null).ToList().FirstOrDefault();

            var jsonData = new JsonData();

            jsonData.totalCount = (data == null) ? "0" : "1";
            jsonData.data       = data;

            content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}",
                                    data.ToJSON(),
                                    (data == null) ? "0" : "1");

            return(content);
        }
Esempio n. 2
0
        public string GetTestPaper(string pRequest)
        {
            var rd     = new APIResponse <GetTestPaperRD>();
            var rdData = new GetTestPaperRD();

            var rp = pRequest.DeserializeJSONTo <APIRequest <GetTestPaperRP> >();

            if (rp.Parameters == null)
            {
                throw new ArgumentException();
            }

            if (rp.Parameters != null)
            {
                rp.Parameters.Validate();
            }

            var loggingSessionInfo = Default.GetBSLoggingSession(rp.CustomerID, rp.UserID);

            try
            {
                //获取考题
                QuesQuestionsBLL        queBll   = new QuesQuestionsBLL(loggingSessionInfo);
                DataTable               dTbl     = queBll.GetQuesQuestions(rp.Parameters.SurveyTestId);
                List <QuesQuestionItem> quesList = new List <QuesQuestionItem>();
                if (dTbl != null)
                {
                    quesList = DataTableToObject.ConvertToList <QuesQuestionItem>(dTbl);
                }

                //循环获取考题选项
                QuesOptionBLL         quesOpBll      = new QuesOptionBLL(loggingSessionInfo);
                List <QuesOptionItem> quesOptionList = new List <QuesOptionItem>();
                DataTable             dTblOption     = null;
                foreach (var qItem in quesList)
                {
                    quesOptionList = new List <QuesOptionItem>();
                    dTblOption     = quesOpBll.GetQuesOptions(qItem.QuestionID);
                    if (dTblOption != null && dTblOption.Rows.Count > 0)
                    {
                        quesOptionList = DataTableToObject.ConvertToList <QuesOptionItem>(dTblOption);
                    }
                    qItem.QuesOptionList = quesOptionList;
                }
                rdData.QuesQuestionList = quesList;
                rd.ResultCode           = 0;
            }
            catch (Exception ex)
            {
                rd.ResultCode = 103;
                rd.Message    = ex.Message;
            }
            rd.Data = rdData;
            return(rd.ToJSON());
        }
        /// <summary>
        /// 保存试题信息
        /// </summary>
        public string SaveOption()
        {
            var quesOptionsBLL = new QuesOptionBLL(this.CurrentUserInfo);

            string content      = string.Empty;
            string error        = "";
            var    responseData = new ResponseData();

            string key      = string.Empty;
            string OptionID = string.Empty;
            var    option   = Request("Option");

            if (FormatParamValue(option) != null && FormatParamValue(option) != string.Empty)
            {
                key = FormatParamValue(option).ToString().Trim();
            }
            if (FormatParamValue(Request("OptionID")) != null && FormatParamValue(Request("OptionID")) != string.Empty)
            {
                OptionID = FormatParamValue(Request("OptionID")).ToString().Trim();
            }

            var optionEntity = key.DeserializeJSONTo <QuesOptionEntity>();


            if (OptionID.Trim().Length == 0)
            {
                optionEntity.OptionsID = Utils.NewGuid();
                //questionnairesEntity.Status = 0;
                //questionnairesEntity.ApplyCount = 0;
                //questionnairesEntity.CheckInCount = 0;
                //questionnairesEntity.PostCount = 0;
                quesOptionsBLL.Create(optionEntity);
            }
            else
            {
                optionEntity.OptionsID = OptionID;
                quesOptionsBLL.Update(optionEntity, false);
            }

            responseData.success = true;
            responseData.msg     = error;

            content = responseData.ToJSON();
            return(content);
        }
        /// <summary>
        /// 查询问题选项列表
        /// </summary>
        public string GetQuesOptionListData()
        {
            var quesOptionBLL = new QuesOptionBLL(this.CurrentUserInfo);

            string content = string.Empty;

            string QuestionID = FormatParamValue(Request("QuestionID"));
            int    pageIndex  = Utils.GetIntVal(FormatParamValue(Request("page"))) - 1;

            var queryEntity = new QuesOptionEntity();

            queryEntity.QuestionID = QuestionID;

            var data           = quesOptionBLL.GetWebQuesOptions(queryEntity, pageIndex, PageSize);
            int dataTotalCount = data.Count;

            content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}",
                                    data.ToJSON(),
                                    dataTotalCount);

            return(content);
        }
        public string GetSingleAnswer(string pQuestionId, string pAnswer)
        {
            string              ret     = "-1";
            QuesQuestionsBLL    quesBll = new QuesQuestionsBLL(_loggingSessionInfo);
            QuesQuestionsEntity entity  = quesBll.GetByID(pQuestionId);

            if (entity != null)
            {
                QuesOptionBLL quesOpBll  = new QuesOptionBLL(_loggingSessionInfo);
                DataTable     dTblOption = quesOpBll.GetQuesOptions(pQuestionId);
                //1单选,2多选,3主观选择题,4填空题,5标准打分题
                int       questionType = (int)entity.QuestionType;
                DataRow[] drs          = null;
                if (questionType == 1)//1单选
                {
                    if (dTblOption != null && dTblOption.Rows.Count > 0)
                    {
                        drs = dTblOption.Select("IsAnswer=1");
                        if (drs != null && drs.Length > 0)
                        {
                            if (drs[0]["OptionIndex"].ToString().ToLower().Equals(pAnswer.ToLower()))
                            {
                                ret = "1";
                            }
                            else
                            {
                                ret = "0";
                            }
                        }
                    }
                }
                else
                if (questionType == 2)    //2多选
                {
                    string[] answerArr = pAnswer.ToLower().Split(',');
                    if (dTblOption != null && dTblOption.Rows.Count > 0)
                    {
                        drs = dTblOption.Select("IsAnswer=1");
                        int index = 0;
                        foreach (DataRow row in drs)
                        {
                            for (int i = 0; i < answerArr.Length; i++)
                            {
                                if (row["OptionIndex"].ToString().ToLower().Equals(answerArr[i]))
                                {
                                    index++;
                                }
                            }
                        }
                        if (index != answerArr.Length)
                        {
                            ret = "1";
                        }
                        else
                        {
                            ret = "0";
                        }
                    }
                }
                else
                {
                    ret = "-1";
                }
                ret += "|" + entity.QuestionValue;
            }
            else
            {
                ret += "|题不存在";
            }
            return(ret);
        }