123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMISOnline.CommonLogic.ExamServices;
- using EMISOnline.ViewModel.ExamView;
- using Bowin.Web.Controls.Mvc;
- using System.Web.Script.Serialization;
- using EMISOnline.ViewModel;
- using System.Data;
- using System.Collections;
- namespace EMISOnline.Web.Controllers.Manage
- {
- [Authorization]
- public class PaperSettingController : Controller
- {
- public IExamPaperServices IExamPaperServices { get; set; }
- public IQuestionServices IQuestionServices { get; set; }
- //
- // GET: /PaperSetting/
- public ActionResult PaperList()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(string PaperName, int page, int rows)
- {
- var result = IExamPaperServices.ListPaper(page, rows, PaperName);
- return Json(result);
- }
- public ActionResult PageSetupOne(decimal? paperid)
- {
- PaperAddView view = new PaperAddView();
- if (paperid.HasValue)
- {
- var paper = IExamPaperServices.GetPaperByPaperID(paperid.Value);
- view.QuesLevelBeg = paper.difficulty_degree_minvalue.ToString();
- view.QuesLevelEnd = paper.difficulty_degree_maxvalue.ToString();
- view.UseFBeg = paper.used_count_min.ToString();
- view.UseFEnd = paper.used_count_max.ToString();
- //paper.distributing_option = Convert.ToInt32(this.rblDis.SelectedValue);
- view.ErrRate = paper.error_percent.ToString();
- view.IsEnable = paper.is_vaild == true ? "1" : "0";
- view.PageName = paper.PaperName;
- SetQuesChooseSort(paper.Prority.ToString(), view);
- view.LibarysString = TransStringToJson(paper.note);
- view.PageType = paper.is_dynamic ? "1" : "0";
- view.QuestionTypeString = paper.question_setting;
- }
- return View(view);
- }
- private string TransStringToJson(string LibarysString)
- {
- try
- {
- var libs = LibarysString.Split(',');
- var datas = new ArrayList();
- foreach (string lib in libs)
- {
- var items = lib.Split('|');
- datas.Add(new { Libaryid = items[0], Name = items[1], Number = items[2] });
- }
- var json = new JavaScriptSerializer();
- return json.Serialize(datas);
- }
- catch (Exception ex)
- {
- return LibarysString;
- }
- }
- /// <summary>
- /// 设置优先级的checkbox值
- /// </summary>
- /// <param name="sort_value"></param>
- private void SetQuesChooseSort(string sort_value, PaperAddView view)
- {
- switch (sort_value)
- {
- case "0":
- view.QuesFCount = false;
- view.QuesUpdateTime = false;
- break;
- case "1":
- view.QuesFCount = true;
- view.QuesUpdateTime = false;
- break;
- case "2":
- view.QuesFCount = false;
- view.QuesUpdateTime = true;
- break;
- case "3":
- view.QuesFCount = true;
- view.QuesUpdateTime = true;
- break;
- default:
- break;
- }
- }
- public ActionResult PageTransfer(decimal paperid, string ac, string is_dynamic)
- {
- if (is_dynamic == "静态")
- {
- return RedirectToAction("PageSetupTwo", new { paperid = paperid, ac = ac });
- }
- return RedirectToAction("PageSetupOne", new { paperid = paperid, ac = ac });
- }
- public ActionResult PageSetupTwo(string ac, decimal paperid)
- {
- ViewBag.PervStepVisible = ac != "edit";
- ViewBag.paperid = paperid;
- ViewBag.Action = ac;
- if (ac == "edit")
- {
- var paper = IExamPaperServices.GetPaperByPaperID(paperid);
- ViewBag.hid_Dynamic = paper.is_dynamic ? "1" : "0";
- ViewBag.hid_Setting = paper.note;
- }
- else
- {
- PageSetupParam psp = Session["PageSetupParam"] as PageSetupParam;
- ViewBag.hid_Dynamic = psp.PageType;
- ViewBag.hid_Setting = psp.QuesSetting;
- }
- return View();
- }
- public ActionResult QuestionLibaryTree()
- {
- return View();
- }
- public ActionResult ListQuesLibTree()
- {
- List<TreeItem> list = IQuestionServices.ListQuesLibTreeStu();
- return base.Json(list, JsonRequestBehavior.AllowGet);
- }
- public JsonResult ArrangePaper(PaperAddView PaperAdd)
- {
- var json = new JavaScriptSerializer();
- var libarys = json.Deserialize<List<QuestionLibaryArrangeView>>(PaperAdd.LibarysString);
- var data = IExamPaperServices.CountQuesSumByCondition(libarys.Select(q => q.Libaryid).ToList(), decimal.Parse(PaperAdd.QuesLevelBeg ?? "0"), decimal.Parse(PaperAdd.QuesLevelEnd ?? "0"), decimal.Parse(PaperAdd.ErrRate ?? "0"), int.Parse(PaperAdd.UseFBeg ?? "0"), int.Parse(PaperAdd.UseFEnd ?? "0"));
- return Json(data, JsonRequestBehavior.AllowGet);
- }
- [HttpPost]
- public ActionResult PageSetupOne(PaperAddView PaperAdd)
- {
- try
- {
- string url = "~/PaperSetting/PageSetupTwo?ac=add&paperid=" + PaperAdd.PaperID;
- if (PaperAdd.PageType == "0")
- {
- var psp = IExamPaperServices.SetPageSetupCondition(PaperAdd);
- Session["PageSetupParam"] = psp;
- Session["quesDt"] = null;
- }
- else
- {
- var user = ((EMISOnline.Utility.FormValidate.CustomPrincipal)HttpContext.User);
- IExamPaperServices.ExamPaperSave(PaperAdd, user.LoginID);
- url = "~/PaperSetting/PaperList";
- }
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!",
- RedictUrl = Url.Content(url)
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- [HttpPost]
- public ActionResult PageSetupTwo(string ac, decimal paperid, string hid_Setting, string hid_pageSetting)
- {
- try
- {
- PageSetupParam psp = Session["PageSetupParam"] as PageSetupParam;
- if (ac == "edit")
- {
- IExamPaperServices.PaperEdit(paperid, hid_pageSetting);
- }
- else if (ac == "add")
- {
- var user = ((EMISOnline.Utility.FormValidate.CustomPrincipal)HttpContext.User);
- IExamPaperServices.AddPaperDetail(psp, hid_pageSetting, user.LoginID);
- }
- Session["PageSetupParam"] = null;
- Session["quesDt"] = null;
- Session["SelectKey"] = null;
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!",
- RedictUrl = "/PaperSetting/PaperList"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- public JsonResult GetPaperList(decimal paperid, string ac)
- {
- DataTable quesDt = new DataTable();
- if (ac == "edit")
- {
- quesDt = IExamPaperServices.GetQuestionByPaperID(paperid);
- }
- else if (ac == "add")
- {
- PageSetupParam psp = Session["PageSetupParam"] as PageSetupParam;
- quesDt = IExamPaperServices.GetQuestionByParam(psp);
- }
- //暂存到ViewState
- Session["quesDt"] = quesDt;
- var Serializer = new JavaScriptSerializer();
- var json = DataTable2Json(quesDt);
- var source = Serializer.Deserialize<DataGridView>(json);
- return Json(source, JsonRequestBehavior.AllowGet);
- }
- public JsonResult DeleteQuestion(string QuestionIDstr)
- {
- DataTable quesDt = Session["quesDt"] as DataTable;
- DataTable newDt = quesDt.Clone();
- var QuestionIDs = QuestionIDstr.Split(',');
- foreach (DataRow dr in quesDt.Rows)
- {
- if (!QuestionIDs.Contains(dr["test_question_Id"].ToString()))
- {
- newDt.Rows.Add(dr.ItemArray);
- }
- }
- Session["quesDt"] = newDt;
- var Serializer = new JavaScriptSerializer();
- var json = DataTable2Json(newDt);
- var source = Serializer.Deserialize<DataGridView>(json);
- return Json(source, JsonRequestBehavior.AllowGet);
- }
- public ActionResult ShowPaper(decimal paperid)
- {
- ViewBag.questions = IExamPaperServices.GetPaperQuestions(paperid);
- return View();
- }
- public string DataTable2Json(System.Data.DataTable dt)
- {
- System.Text.StringBuilder jsonBuilder = new System.Text.StringBuilder();
- jsonBuilder.Append("{");
- jsonBuilder.AppendFormat("\"total\":{0}, ", dt.Rows.Count);
- jsonBuilder.Append("\"rows\":[ ");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- jsonBuilder.Append("{");
- for (int j = 0; j < dt.Columns.Count; j++)
- {
- jsonBuilder.Append("\"");
- jsonBuilder.Append(dt.Columns[j].ColumnName);
- jsonBuilder.Append("\":\"");
- jsonBuilder.Append(dt.Rows[i][j].ToString().Replace("\"", "\\\""));
- jsonBuilder.Append("\",");
- }
- jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
- jsonBuilder.Append("},");
- }
- jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
- jsonBuilder.Append("]");
- jsonBuilder.Append("}");
- return jsonBuilder.ToString().Replace("\r", "").Replace("\n", "");
- }
- }
- public class DataGridView
- {
- public int total { get; set; }
- public List<QuestionRowView> rows { get; set; }
- }
- public class QuestionRowView
- {
- public decimal test_question_Id { get; set; }
- public string content { get; set; }
- public decimal base_question_type_id { get; set; }
- public string question_type { get; set; }
- public string created_date { get; set; }
- public decimal score { get; set; }
- public decimal difficulty_degree { get; set; }
- public int used_count { get; set; }
- public string created_by { get; set; }
- }
- }
|