Esempio n. 1
0
        public ActionResult EditQuestion(int qid, string mode = "edit", int sortId = 0)
        {
            var q = _cdeQuestionManager.GetQuestion(qid);

            if (q == null || q.TenantId != CurrentUser.TenantId)
            {
                q = new Cde_IndexQuestion();
                if (sortId != 0)
                {
                    var sort = _sortManager.GetSort(sortId);
                    if (sort.IsSecondIndex)
                    {
                        ViewBag.secondsorts = _sortManager.GetSecondSorts(sort.ParentId);
                        q.SortId            = sort.ParentId;
                        q.SecondSortId      = sort.SortId;
                    }
                    else
                    {
                        ViewBag.secondsorts = _sortManager.GetSecondSorts(sort.SortId);
                        q.SortId            = sortId;
                    }
                }
            }
            else
            {
                //加载二级指标
                ViewBag.secondsorts = _sortManager.GetSecondSorts(q.SortId);
            }
            ViewBag.mode   = string.IsNullOrEmpty(mode) ? "edit" : mode;
            ViewBag.fsorts = _sortManager.GetFirstSorts(CurrentUser.TenantId);
            return(View(q));
        }
Esempio n. 2
0
        public JsonResult ImportQuestion(int saveflag = -1)
        {
            try
            {
                int needloadSort = 0;
                if (Request.Files.Count == 0 || Request.Files[0] == null || Request.Files[0].ContentLength == 0)
                {
                    return(Json(new
                    {
                        result = 0,
                        msg = RetechWing.LanguageResources.Notes.NoteLanguage.PleaseChoose + "Excel" + RetechWing.LanguageResources.TalnetUI.CdeQuestion.File
                    }, "text/html", JsonRequestBehavior.DenyGet));
                }
                var file = Request.Files[0];

                if (!file.FileName.EndsWith(".xls", StringComparison.CurrentCultureIgnoreCase))
                {
                    //不是Excel文件
                    return(Json(new
                    {
                        result = 0,
                        msg = RetechWing.LanguageResources.Notes.NoteLanguage.PleaseChoose + "Excel" + RetechWing.LanguageResources.TalnetUI.CdeQuestion.File
                    }, "text/html", JsonRequestBehavior.DenyGet));
                }
                string path = Server.MapPath("~/UploadFiles/tmp/");
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                var filename = path + Guid.NewGuid() + ".xls";
                file.SaveAs(filename);

                IWorkbook workbook = Factory.GetWorkbook(filename, System.Globalization.CultureInfo.CurrentCulture);
                DataSet   ds       = workbook.GetDataSet(GetDataFlags.FormattedText);
                if ((ds.Tables.Count < 1) || (!ds.Tables[0].TableName.StartsWith("Sheet1")))
                {
                    return(Json(new
                    {
                        result = 0,
                        msg = "Excel" + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr1
                    }, "text/html", JsonRequestBehavior.DenyGet));
                }

                DataTable dt = ds.Tables[0];

                //把所有的指标全部找出来
                var allIndexs = _sortManager.GetSorts(CurrentTenant.TenantId);
                //记录问题提干所在的行
                var questions = new Dictionary <int, Cde_IndexQuestion>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var question = new Cde_IndexQuestion();
                    question.TenantId = CurrentTenant.TenantId;
                    if (dt.Rows[i][0] != null && dt.Rows[i][0] != DBNull.Value && dt.Rows[i][0].ToString() != "")
                    {
                        questions.Add(i, question);
                    }
                }
                var list = questions.Keys.ToList();

                for (int i = 0; i < questions.Count; i++)
                {
                    int rowIndex = list[i];
                    //questions[rowIndex].Order = int.Parse(dt.Rows[rowIndex][0].ToString());
                    questions[rowIndex].QuestionType = 0;
                    //处理指标
                    var sortName1 = dt.Rows[rowIndex].Field <string>(RetechWing.LanguageResources.TalnetUI.CdeQuestion.ClassStr);
                    if (string.IsNullOrEmpty(sortName1))
                    {
                        return(Json(new { result = 0, msg = RetechWing.LanguageResources.TalnetUI.CdeQuestion.The + (rowIndex + 1) + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr4 + RetechWing.LanguageResources.TalnetUI.CdeQuestion.ClassStr }, "text/html", JsonRequestBehavior.DenyGet));
                    }
                    var sort1 = allIndexs.FirstOrDefault(p => p.SortName == sortName1 && p.ParentId == 0);
                    if (sort1 == null)
                    {
                        needloadSort = 1;
                        sort1        = new Cde_IndexSort()
                        {
                            SortName  = sortName1,
                            ParentId  = 0,
                            LevelPath = sortName1,
                            TenantId  = CurrentTenant.TenantId,
                            IsDelete  = 0
                        };
                        allIndexs.Add(sort1);
                        _sortManager.AddSort(sort1);
                    }
                    var sortName2 = dt.Rows[rowIndex].Field <string>(RetechWing.LanguageResources.TalnetUI.CdeQuestion.ClassStr1);
                    if (string.IsNullOrEmpty(sortName2))
                    {
                        return(Json(new { result = 0, msg = RetechWing.LanguageResources.TalnetUI.CdeQuestion.The + (rowIndex + 1) + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr2 + RetechWing.LanguageResources.TalnetUI.CdeQuestion.ClassStr1 }, "text/html", JsonRequestBehavior.DenyGet));
                    }
                    var sort2 = allIndexs.FirstOrDefault(p => p.SortName == sortName2 && p.ParentId > 0);
                    if (sort2 == null)
                    {
                        needloadSort = 1;
                        sort2        = new Cde_IndexSort()
                        {
                            SortName  = sortName2,
                            ParentId  = sort1.SortId,
                            LevelPath = sortName1 + "/" + sortName2,
                            TenantId  = CurrentTenant.TenantId,
                            IsDelete  = 0
                        };
                        allIndexs.Add(sort2);
                        _sortManager.AddSort(sort2);
                    }
                    questions[rowIndex].SortId       = sort1.SortId;
                    questions[rowIndex].SecondSortId = sort2.SortId;
                    questions[rowIndex].QuestionName = dt.Rows[rowIndex]["题目"].ToString();
                    if (string.IsNullOrEmpty(questions[rowIndex].QuestionName))
                    {
                        return(Json(new { result = 0, msg = RetechWing.LanguageResources.TalnetUI.CdeQuestion.The + (rowIndex + 2) + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr3 }, "text/html", JsonRequestBehavior.DenyGet));
                    }

                    questions[rowIndex].IsDelete   = 0;
                    questions[rowIndex].CreateTime = DateTime.Now;
                    questions[rowIndex].UserId     = CurrentUser.UserId;
                    int maxIndex = i == list.Count - 1 ? dt.Rows.Count : list[i + 1];
                    //if (maxIndex == rowIndex)
                    //{
                    //   return Json(new { result = 0, msg = "第"+(rowIndex+1)+"行的题目没有选项"},"text/html", JsonRequestBehavior.DenyGet);
                    //}
                    for (int j = rowIndex; j < maxIndex; j++)
                    {
                        if (questions[rowIndex].QuestionType == 2)
                        {
                            continue;
                        }
                        var answer = new Cde_IndexQuestionAnswer()
                        {
                            OrderChar = dt.Rows[j]["答案序号"].ToString(),
                            Answer    = dt.Rows[j]["答案内容"].ToString(),
                            Score     = dt.Rows[j]["分值"].ToString().GetInt32(0)
                        };
                        questions[rowIndex].Answers.Add(answer);
                    }
                    if (questions[rowIndex].Answers.Count == 0)
                    {
                        //添加默认选项
                        questions[rowIndex].Answers.Add(new Cde_IndexQuestionAnswer()
                        {
                            Answer = RetechWing.LanguageResources.TalnetUI.CdeQuestion.VeryAgree, OrderChar = "A", Score = 5
                        });
                        questions[rowIndex].Answers.Add(new Cde_IndexQuestionAnswer()
                        {
                            Answer = RetechWing.LanguageResources.TalnetUI.CdeQuestion.MoreAgree, OrderChar = "B", Score = 4
                        });
                        questions[rowIndex].Answers.Add(new Cde_IndexQuestionAnswer()
                        {
                            Answer = RetechWing.LanguageResources.TalnetUI.CdeQuestion.General, OrderChar = "C", Score = 3
                        });
                        questions[rowIndex].Answers.Add(new Cde_IndexQuestionAnswer()
                        {
                            Answer = RetechWing.LanguageResources.TalnetUI.CdeQuestion.VeryNoAgree, OrderChar = "D", Score = 2
                        });
                        questions[rowIndex].Answers.Add(new Cde_IndexQuestionAnswer()
                        {
                            Answer = RetechWing.LanguageResources.TalnetUI.CdeQuestion.MoreNoAgree, OrderChar = "E", Score = 1
                        });
                    }
                    //验证选项的多少
                    if (questions[rowIndex].Answers.Count > 26)
                    {
                        return(Json(new { result = 0, msg = RetechWing.LanguageResources.TalnetUI.CdeQuestion.The + (rowIndex + 1) + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr4 + RetechWing.LanguageResources.Survey.SurveyLanguage.OptionsTooMany }, "text/html", JsonRequestBehavior.DenyGet));
                    }
                    if (questions[rowIndex].Answers.Count < 2)
                    {
                        return(Json(new { result = 0, msg = RetechWing.LanguageResources.TalnetUI.CdeQuestion.The + (rowIndex + 1) + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr4 + RetechWing.LanguageResources.Survey.SurveyLanguage.OptionsTooLittle }, "text/html", JsonRequestBehavior.DenyGet));
                    }
                }
                _cdeQuestionManager.AddQuestions(questions.Values.ToArray());
                try
                {
                    System.IO.File.Delete(filename);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(RetechWing.LanguageResources.TalnetUI.CdeQuestion.Nullfile + filename + RetechWing.LanguageResources.Exam.Exampaper.DeleteFail, ex);
                }
                if (saveflag == 0)
                {
                    return(Json(new { result = 1, msg = RetechWing.LanguageResources.Exam.Exampaper.ImportSuccess, list = questions.Values.ToArray() }, "text/html;charset=utf-8", JsonRequestBehavior.DenyGet));
                }
                return(Json(new
                {
                    result = 1,
                    needloadSort,
                    msg = RetechWing.LanguageResources.Exam.Exampaper.ImportSuccess
                }, "text/html", JsonRequestBehavior.DenyGet));
            }
            catch (Exception)
            {
                return(Json(new
                {
                    result = 0,
                    msg = "Excel" + RetechWing.LanguageResources.TalnetUI.CdeQuestion.LongStr1
                }, "text/html", JsonRequestBehavior.DenyGet));
            }
        }
Esempio n. 3
0
        public JsonResult SaveSurveyAnswer(string data, int userSurveyId, int sendId, int issubmit, int exampaperId)
        {
            try
            {
                dynamic replyAnswer = JsonConvert.DeserializeObject(data);
                List <Cde_IndexQuestion> questions = _questionManager.GetExampaperQuestions(exampaperId);
                var list = new List <Cde_SurveyReplyAnswer>();
                foreach (dynamic reply in replyAnswer)
                {
                    int id = reply.id;
                    if (reply.content == null)
                    {
                        continue;
                    }
                    string            content = reply.content;
                    Cde_IndexQuestion q       = questions.FirstOrDefault(p => p.QuestionId == id);
                    if (q == null)
                    {
                        q = new Cde_IndexQuestion();
                    }
                    int score = 0;
                    if (reply.type == 0)
                    {
                        Cde_IndexQuestionAnswer a = q.Answers.FirstOrDefault(p => p.AnswerId == int.Parse(content));
                        if (a == null)
                        {
                            a = new Cde_IndexQuestionAnswer();
                        }
                        score = a.Score;
                    }

                    list.Add(new Cde_SurveyReplyAnswer
                    {
                        SendUserId       = sendId,
                        QuestionId       = reply.id,
                        ExampaperID      = exampaperId,
                        UserSurveyID     = userSurveyId,
                        Status           = issubmit == 0 ? 0 : 1,
                        UserID           = CurrentUser.UserId,
                        ObjectiveAnswer  = reply.content,
                        SubjectiveAnswer = reply.content,
                        AnswerTime       = DateTime.Now,
                        Score            = score
                    });
                }
                if (list.Count > 0)
                {
                    _userSurveyManager.AddSurveyAnswers(userSurveyId, sendId, list);
                }

                Cde_SurveySendUsers sendInfo = _userSendSurveyManager.GetSendUserById(sendId);
                sendInfo.Status     = issubmit + 2;
                sendInfo.SubmitTime = DateTime.Now;
                _userSendSurveyManager.UpdateSurveySendUser(sendInfo);

                return(Json(1, JsonRequestBehavior.DenyGet));
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("填写360评估提交答案时出现问题", ex);
                return(Json(0, JsonRequestBehavior.DenyGet));
            }
        }