PaperSettingController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMISOnline.CommonLogic.ExamServices;
  7. using EMISOnline.ViewModel.ExamView;
  8. using Bowin.Web.Controls.Mvc;
  9. using System.Web.Script.Serialization;
  10. using EMISOnline.ViewModel;
  11. using System.Data;
  12. using System.Collections;
  13. namespace EMISOnline.Web.Controllers.Manage
  14. {
  15. [Authorization]
  16. public class PaperSettingController : Controller
  17. {
  18. public IExamPaperServices IExamPaperServices { get; set; }
  19. public IQuestionServices IQuestionServices { get; set; }
  20. //
  21. // GET: /PaperSetting/
  22. public ActionResult PaperList()
  23. {
  24. return View();
  25. }
  26. /// <summary>
  27. /// 列表查询
  28. /// </summary>
  29. /// <param name="pararms"></param>
  30. /// <returns></returns>
  31. [HttpPost]
  32. public ActionResult List(string PaperName, int page, int rows)
  33. {
  34. var result = IExamPaperServices.ListPaper(page, rows, PaperName);
  35. return Json(result);
  36. }
  37. public ActionResult PageSetupOne(decimal? paperid)
  38. {
  39. PaperAddView view = new PaperAddView();
  40. if (paperid.HasValue)
  41. {
  42. var paper = IExamPaperServices.GetPaperByPaperID(paperid.Value);
  43. view.QuesLevelBeg = paper.difficulty_degree_minvalue.ToString();
  44. view.QuesLevelEnd = paper.difficulty_degree_maxvalue.ToString();
  45. view.UseFBeg = paper.used_count_min.ToString();
  46. view.UseFEnd = paper.used_count_max.ToString();
  47. //paper.distributing_option = Convert.ToInt32(this.rblDis.SelectedValue);
  48. view.ErrRate = paper.error_percent.ToString();
  49. view.IsEnable = paper.is_vaild == true ? "1" : "0";
  50. view.PageName = paper.PaperName;
  51. SetQuesChooseSort(paper.Prority.ToString(), view);
  52. view.LibarysString = TransStringToJson(paper.note);
  53. view.PageType = paper.is_dynamic ? "1" : "0";
  54. view.QuestionTypeString = paper.question_setting;
  55. }
  56. return View(view);
  57. }
  58. private string TransStringToJson(string LibarysString)
  59. {
  60. try
  61. {
  62. var libs = LibarysString.Split(',');
  63. var datas = new ArrayList();
  64. foreach (string lib in libs)
  65. {
  66. var items = lib.Split('|');
  67. datas.Add(new { Libaryid = items[0], Name = items[1], Number = items[2] });
  68. }
  69. var json = new JavaScriptSerializer();
  70. return json.Serialize(datas);
  71. }
  72. catch (Exception ex)
  73. {
  74. return LibarysString;
  75. }
  76. }
  77. /// <summary>
  78. /// 设置优先级的checkbox值
  79. /// </summary>
  80. /// <param name="sort_value"></param>
  81. private void SetQuesChooseSort(string sort_value, PaperAddView view)
  82. {
  83. switch (sort_value)
  84. {
  85. case "0":
  86. view.QuesFCount = false;
  87. view.QuesUpdateTime = false;
  88. break;
  89. case "1":
  90. view.QuesFCount = true;
  91. view.QuesUpdateTime = false;
  92. break;
  93. case "2":
  94. view.QuesFCount = false;
  95. view.QuesUpdateTime = true;
  96. break;
  97. case "3":
  98. view.QuesFCount = true;
  99. view.QuesUpdateTime = true;
  100. break;
  101. default:
  102. break;
  103. }
  104. }
  105. public ActionResult PageTransfer(decimal paperid, string ac, string is_dynamic)
  106. {
  107. if (is_dynamic == "静态")
  108. {
  109. return RedirectToAction("PageSetupTwo", new { paperid = paperid, ac = ac });
  110. }
  111. return RedirectToAction("PageSetupOne", new { paperid = paperid, ac = ac });
  112. }
  113. public ActionResult PageSetupTwo(string ac, decimal paperid)
  114. {
  115. ViewBag.PervStepVisible = ac != "edit";
  116. ViewBag.paperid = paperid;
  117. ViewBag.Action = ac;
  118. if (ac == "edit")
  119. {
  120. var paper = IExamPaperServices.GetPaperByPaperID(paperid);
  121. ViewBag.hid_Dynamic = paper.is_dynamic ? "1" : "0";
  122. ViewBag.hid_Setting = paper.note;
  123. }
  124. else
  125. {
  126. PageSetupParam psp = Session["PageSetupParam"] as PageSetupParam;
  127. ViewBag.hid_Dynamic = psp.PageType;
  128. ViewBag.hid_Setting = psp.QuesSetting;
  129. }
  130. return View();
  131. }
  132. public ActionResult QuestionLibaryTree()
  133. {
  134. return View();
  135. }
  136. public ActionResult ListQuesLibTree()
  137. {
  138. List<TreeItem> list = IQuestionServices.ListQuesLibTreeStu();
  139. return base.Json(list, JsonRequestBehavior.AllowGet);
  140. }
  141. public JsonResult ArrangePaper(PaperAddView PaperAdd)
  142. {
  143. var json = new JavaScriptSerializer();
  144. var libarys = json.Deserialize<List<QuestionLibaryArrangeView>>(PaperAdd.LibarysString);
  145. 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"));
  146. return Json(data, JsonRequestBehavior.AllowGet);
  147. }
  148. [HttpPost]
  149. public ActionResult PageSetupOne(PaperAddView PaperAdd)
  150. {
  151. try
  152. {
  153. string url = "~/PaperSetting/PageSetupTwo?ac=add&paperid=" + PaperAdd.PaperID;
  154. if (PaperAdd.PageType == "0")
  155. {
  156. var psp = IExamPaperServices.SetPageSetupCondition(PaperAdd);
  157. Session["PageSetupParam"] = psp;
  158. Session["quesDt"] = null;
  159. }
  160. else
  161. {
  162. var user = ((EMISOnline.Utility.FormValidate.CustomPrincipal)HttpContext.User);
  163. IExamPaperServices.ExamPaperSave(PaperAdd, user.LoginID);
  164. url = "~/PaperSetting/PaperList";
  165. }
  166. return Json(new ReturnMessage()
  167. {
  168. IsSuccess = true,
  169. Message = "保存成功!",
  170. RedictUrl = Url.Content(url)
  171. });
  172. }
  173. catch (Exception ex)
  174. {
  175. return Json(new ReturnMessage()
  176. {
  177. IsSuccess = false,
  178. Message = "保存失败:" + ex.Message
  179. });
  180. }
  181. }
  182. [HttpPost]
  183. public ActionResult PageSetupTwo(string ac, decimal paperid, string hid_Setting, string hid_pageSetting)
  184. {
  185. try
  186. {
  187. PageSetupParam psp = Session["PageSetupParam"] as PageSetupParam;
  188. if (ac == "edit")
  189. {
  190. IExamPaperServices.PaperEdit(paperid, hid_pageSetting);
  191. }
  192. else if (ac == "add")
  193. {
  194. var user = ((EMISOnline.Utility.FormValidate.CustomPrincipal)HttpContext.User);
  195. IExamPaperServices.AddPaperDetail(psp, hid_pageSetting, user.LoginID);
  196. }
  197. Session["PageSetupParam"] = null;
  198. Session["quesDt"] = null;
  199. Session["SelectKey"] = null;
  200. return Json(new ReturnMessage()
  201. {
  202. IsSuccess = true,
  203. Message = "保存成功!",
  204. RedictUrl = "/PaperSetting/PaperList"
  205. });
  206. }
  207. catch (Exception ex)
  208. {
  209. return Json(new ReturnMessage()
  210. {
  211. IsSuccess = false,
  212. Message = "保存失败:" + ex.Message
  213. });
  214. }
  215. }
  216. public JsonResult GetPaperList(decimal paperid, string ac)
  217. {
  218. DataTable quesDt = new DataTable();
  219. if (ac == "edit")
  220. {
  221. quesDt = IExamPaperServices.GetQuestionByPaperID(paperid);
  222. }
  223. else if (ac == "add")
  224. {
  225. PageSetupParam psp = Session["PageSetupParam"] as PageSetupParam;
  226. quesDt = IExamPaperServices.GetQuestionByParam(psp);
  227. }
  228. //暂存到ViewState
  229. Session["quesDt"] = quesDt;
  230. var Serializer = new JavaScriptSerializer();
  231. var json = DataTable2Json(quesDt);
  232. var source = Serializer.Deserialize<DataGridView>(json);
  233. return Json(source, JsonRequestBehavior.AllowGet);
  234. }
  235. public JsonResult DeleteQuestion(string QuestionIDstr)
  236. {
  237. DataTable quesDt = Session["quesDt"] as DataTable;
  238. DataTable newDt = quesDt.Clone();
  239. var QuestionIDs = QuestionIDstr.Split(',');
  240. foreach (DataRow dr in quesDt.Rows)
  241. {
  242. if (!QuestionIDs.Contains(dr["test_question_Id"].ToString()))
  243. {
  244. newDt.Rows.Add(dr.ItemArray);
  245. }
  246. }
  247. Session["quesDt"] = newDt;
  248. var Serializer = new JavaScriptSerializer();
  249. var json = DataTable2Json(newDt);
  250. var source = Serializer.Deserialize<DataGridView>(json);
  251. return Json(source, JsonRequestBehavior.AllowGet);
  252. }
  253. public ActionResult ShowPaper(decimal paperid)
  254. {
  255. ViewBag.questions = IExamPaperServices.GetPaperQuestions(paperid);
  256. return View();
  257. }
  258. public string DataTable2Json(System.Data.DataTable dt)
  259. {
  260. System.Text.StringBuilder jsonBuilder = new System.Text.StringBuilder();
  261. jsonBuilder.Append("{");
  262. jsonBuilder.AppendFormat("\"total\":{0}, ", dt.Rows.Count);
  263. jsonBuilder.Append("\"rows\":[ ");
  264. for (int i = 0; i < dt.Rows.Count; i++)
  265. {
  266. jsonBuilder.Append("{");
  267. for (int j = 0; j < dt.Columns.Count; j++)
  268. {
  269. jsonBuilder.Append("\"");
  270. jsonBuilder.Append(dt.Columns[j].ColumnName);
  271. jsonBuilder.Append("\":\"");
  272. jsonBuilder.Append(dt.Rows[i][j].ToString().Replace("\"", "\\\""));
  273. jsonBuilder.Append("\",");
  274. }
  275. jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
  276. jsonBuilder.Append("},");
  277. }
  278. jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
  279. jsonBuilder.Append("]");
  280. jsonBuilder.Append("}");
  281. return jsonBuilder.ToString().Replace("\r", "").Replace("\n", "");
  282. }
  283. }
  284. public class DataGridView
  285. {
  286. public int total { get; set; }
  287. public List<QuestionRowView> rows { get; set; }
  288. }
  289. public class QuestionRowView
  290. {
  291. public decimal test_question_Id { get; set; }
  292. public string content { get; set; }
  293. public decimal base_question_type_id { get; set; }
  294. public string question_type { get; set; }
  295. public string created_date { get; set; }
  296. public decimal score { get; set; }
  297. public decimal difficulty_degree { get; set; }
  298. public int used_count { get; set; }
  299. public string created_by { get; set; }
  300. }
  301. }