public ActionResult GetSubmitedZy(int pageIndex, int pageSize) { int totalCount = 0; List <dto_Zy> list = null; List <int> ids = B_Answer.GetSubmitedZyIds(UserId, pageIndex, pageSize, out totalCount); if (ids != null) { list = new List <dto_Zy>(); ids.ForEach(a => { list.Add(B_ZyRedis.GetZy(a)); }); } if (list != null) { foreach (var l in list) { //隐藏真实Id l.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Zy, l.Id); dto_User u = B_UserRedis.GetUser(l.UserId); l.UserName = u.UserName; l.TrueName = u.TrueName; l.Id = 0; } } ViewBag.ZyList = list; ViewBag.PageCount = Util.GetTotalPageCount(totalCount, pageSize); return(PartialView()); }
public ActionResult Index(long zyId) { int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); ViewBag.ZyId = zyId; List <dto_ClassSubmitCount> Classes = B_Analyze.GetSubmitClasses(id); if (Classes != null) { Classes.ForEach(a => { if (a.SchoolId == 0 && a.GradeId == 0 && a.ClassId == 0) { a.SchoolName = "试用学校"; a.GradeName = "试用年级"; a.ClassName = "试用班"; } else { a.SchoolName = B_BaseRedis.GetSchool(a.SchoolId).SchoolName; a.GradeName = Const.Grades[a.GradeId]; a.ClassName = a.ClassId + "班"; } }); } ViewBag.Classes = Classes; ViewBag.ClassCount = Classes == null ? 0 : Classes.Count; return(View(zy)); }
/// <summary> /// 获取已提交作业 /// </summary> /// <param name="lastId"></param> /// <param name="count"></param> /// <returns></returns> public ActionResult GetSubmitedZy(long lastId, int count) { int last = lastId == 0 ? 99999999 : IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, lastId); List <dto_Zy> list = null; List <int> ids = B_Answer.GetSubmitedZyIds(UserId, last, count); if (ids != null) { list = new List <dto_Zy>(); ids.ForEach(a => { list.Add(B_ZyRedis.GetZy(a)); }); } if (list != null) { foreach (var l in list) { //隐藏真实Id l.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Zy, l.Id); dto_User u = B_UserRedis.GetUser(l.UserId); l.UserName = u.UserName; l.TrueName = u.TrueName; l.Id = 0; } } ViewBag.ZyList = list; return(PartialView()); }
public JsonResult GetZyInfo(long zyId) { int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); zy.Id = 0; //隐藏真实Id dto_AjaxJsonResult <dto_Zy> r = AccessJudge(UserId, zy); return(Json(r)); }
public ActionResult GetQuestionAndAnswers(int courseId, long zyId, int studentId) { int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); T_Answer answer = null; if (zy.UserId == 0) { return(PartialView()); } else { answer = B_Answer.GetAnswer(id, (studentId == 0 ? UserId : studentId)); } List <dto_UserAnswer> ansl = null; if (answer != null) { ViewBag.PicPrefix = Util.GetAppSetting("UploadUrlPrefix") + "/"; ViewBag.AnswerImg = answer.AnswerImg; ansl = JsonConvert.DeserializeObject <List <dto_UserAnswer> >(answer.AnswerJson); } List <dto_Question> ql = B_ZyRedis.GetQdbZyQuestions(courseId, id); if (ql != null) { foreach (dto_Question q in ql) { if (!q.haschildren && Const.OBJECTIVE_QUES_TYPES.Contains(q.ptypeid)) { q.SAnswer = ansl == null ? "" : ansl.Find(b => b.QId == q.id).Answer; } //隐藏真实Id q.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, q.id); q.id = 0; if (q.Children != null && q.Children.Count > 0) { q.Children.ForEach(a => { if (Const.OBJECTIVE_QUES_TYPES.Contains(a.ptypeid)) { a.SAnswer = ansl == null ? "" : ansl.Find(b => b.QId == a.id).Answer; } a.NewId = IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, a.id); a.id = 0; }); } } } ViewBag.QuesList = ql; return(PartialView()); }
public JsonResult GetZyInfo(long zyId) { int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); zy.Id = 0; //隐藏真实Id dto_AjaxJsonResult <dto_Zy> r = new dto_AjaxJsonResult <dto_Zy>(); r.code = AjaxResultCodeEnum.Success; r.message = ""; r.data = zy; return(Json(r)); }
/// <summary> /// 关闭作业 /// </summary> /// <param name="zyId"></param> /// <returns></returns> public JsonResult CloseZy(long zyId) { dto_AjaxJsonResult <string> r = new dto_AjaxJsonResult <string>(); int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); if (zy.UserId == 0) { r.code = AjaxResultCodeEnum.Error; r.message = "试用作业仅用于数据展示,不允许进行操作!"; r.data = ""; return(Json(r)); } if (zy.Status == 2) { r.code = AjaxResultCodeEnum.Error; r.message = "作业已删除,不能关闭!"; r.data = ""; return(Json(r)); } else if (zy.Status == 1) { r.code = AjaxResultCodeEnum.Success; r.message = ""; r.data = ""; return(Json(r)); } else { bool isok = B_Zy.UpdateZyStatus(id, 1); if (isok) { B_ZyRedis.UpdateZyStatus(id, 1); r.code = AjaxResultCodeEnum.Success; r.message = ""; r.data = ""; return(Json(r)); } else { r.code = AjaxResultCodeEnum.Error; r.message = "关闭失败!"; r.data = ""; return(Json(r)); } } }
/// <summary> /// 提交统计 /// </summary> /// <param name="zyId"></param> /// <returns></returns> public ActionResult GetSubmitBar(long zyId, int schoolId, int gradeId, int classId) { int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Echart_Bar deb = B_Analyze.GetStudentPoint(id, schoolId, gradeId, classId); if (deb != null) { for (int i = 0; i < deb.x.Count; i++) { if (deb.x[i] == "0") { deb.x[i] = "试用学生"; } else { string tname = B_UserRedis.GetUser(int.Parse(deb.x[i])).TrueName; deb.x[i] = string.IsNullOrEmpty(tname) ? "未设姓名" : tname; } } ViewBag.xData = string.Join(",", deb.x); ViewBag.yData = string.Join(",", deb.y); } int ObjectiveCount = JsonConvert.DeserializeObject <List <dto_ZyQuestion> >(B_ZyRedis.GetQdbZyQuesJson(id)).Count(a => Const.OBJECTIVE_QUES_TYPES.Contains(a.PTypeId)); ViewBag.ObjectiveCount = ObjectiveCount; int SubmitCount = deb == null ? 0 : deb.x.Count; ViewBag.SubmitCount = SubmitCount; double ScoreRate = 0; ScoreRate = (SubmitCount == 0 || ObjectiveCount == 0 || deb == null) ? 0 : Math.Round((deb.y.Sum(a => int.Parse(a)) * 1.0 / (ObjectiveCount * SubmitCount)), 4) * 100; ViewBag.ScoreRate = ScoreRate; dto_Zy zy = B_ZyRedis.GetZy(id); ViewBag.InTime = deb == null ? 0 : deb.o.Count(a => a <= zy.DueDate); ViewBag.OverTime = deb == null ? 0 : deb.o.Count(a => a > zy.DueDate); return(PartialView()); }
/// <summary> /// 上传答案图片 /// 因为ajaxfileupload限制,这里不能返回json,所以特殊处理返回string /// </summary> /// <param name="zyId"></param> /// <returns></returns> public string UploadAnswerImage(long zyId) { dto_AjaxJsonResult <string> r = new dto_AjaxJsonResult <string>(); int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); //试用作业验证 if (zy.UserId == 0) { r.code = AjaxResultCodeEnum.Error; r.message = "试用作业仅用于数据展示,不允许进行操作!<br/>注册成为正式用户后即可体验所有功能!"; r.data = ""; return(JsonConvert.SerializeObject(r)); } #region 访问权限验证 dto_AjaxJsonResult <dto_Zy> r1 = AccessJudge(UserId, zy); if (r1.code == AjaxResultCodeEnum.Error) { r.code = AjaxResultCodeEnum.Error; r.message = r1.message; r.data = ""; return(JsonConvert.SerializeObject(r)); } #endregion //作业提交验证 T_Answer ans = B_Answer.GetAnswer(id, UserId); if (ans != null && ans.Submited) { r.code = AjaxResultCodeEnum.Error; r.message = "作业已提交,不能再上传答案图片!"; r.data = ""; return(JsonConvert.SerializeObject(r)); } //上传 HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; r = ZyImgUploader.Upload(files); bool isok = false; if (r.code == AjaxResultCodeEnum.Success) { //入库 if (ans == null) { T_Answer AnsAdd = new T_Answer() { ZyId = zy.Id, ZyType = zy.Type, StudentId = UserId, Submited = false, CreateDate = DateTime.Now, AnswerJson = "", AnswerImg = r.data, Ip = ClientUtil.Ip, IMEI = ClientUtil.IMEI, MobileBrand = ClientUtil.MobileBrand, SystemType = Request.Browser.Platform.ToString(), Browser = Request.Browser.Browser.ToString() }; isok = B_Answer.InsertZyAnswer(AnsAdd); } else { isok = B_Answer.AddZyImg(zy.Id, UserId, r.data); } } if (!isok) { r.code = AjaxResultCodeEnum.Error; r.message = "入库失败!"; r.data = ""; return(JsonConvert.SerializeObject(r)); } r.data = Util.GetAppSetting("UploadUrlPrefix") + "/" + r.data; return(JsonConvert.SerializeObject(r)); }
/// <summary> /// 提交答案 /// 仍然做各种状态判断 /// </summary> /// <param name="zyId"></param> /// <param name="questions"></param> /// <param name="answers"></param> /// <returns></returns> public JsonResult SubmitAnswer(long zyId, string questions, string answers) { dto_AjaxJsonResult <string> r = new dto_AjaxJsonResult <string>(); int id = IdNamingHelper.Decrypt(IdNamingHelper.IdTypeEnum.Zy, zyId); dto_Zy zy = B_ZyRedis.GetZy(id); //试用作业验证 if (zy.UserId == 0) { r.code = AjaxResultCodeEnum.Error; r.message = "试用作业仅用于数据展示,不允许进行操作!<br/>注册成为正式用户后即可体验所有功能!"; r.data = ""; return(Json(r)); } #region 访问权限验证 dto_AjaxJsonResult <dto_Zy> r1 = AccessJudge(UserId, zy); if (r1.code == AjaxResultCodeEnum.Error) { r.code = AjaxResultCodeEnum.Error; r.message = r1.message; r.data = ""; return(Json(r)); } #endregion //作业提交验证 T_Answer ans = B_Answer.GetAnswer(id, UserId); if (ans != null && ans.Submited) { r.code = AjaxResultCodeEnum.Error; r.message = "作业已提交,不能重复提交!"; r.data = ""; return(Json(r)); } //todo submit List <string> submitQlist = questions.Split(',').ToList(); List <string> submitAlist = string.IsNullOrEmpty(answers) ? new List <string>() : answers.Split(',').ToList(); if (submitQlist.Count != submitAlist.Count) { r.code = AjaxResultCodeEnum.Error; r.message = "试题信息有误,提交失败!"; r.data = ""; return(Json(r)); } string qjson = B_ZyRedis.GetQdbZyQuesJson(id); List <dto_ZyQuestion> ql = JsonConvert.DeserializeObject <List <dto_ZyQuestion> >(qjson); List <dto_UserAnswer> al = new List <dto_UserAnswer>(); ql.ForEach(a => { string CAnswer = ""; if (Const.OBJECTIVE_QUES_TYPES.Contains(a.PTypeId)) { if (a.QId == a.PQId) { CAnswer = B_QuesRedis.GetQuestion(zy.CourseId, a.QId).quesanswer; } else { CAnswer = B_QuesRedis.GetQuestion(zy.CourseId, a.PQId).Children.Find(b => b.id == a.QId).quesanswer; } } int i = submitQlist.IndexOf(IdNamingHelper.Encrypt(IdNamingHelper.IdTypeEnum.Ques, a.QId).ToString()); al.Add(new dto_UserAnswer() { QId = a.QId, PTypeId = a.PTypeId, Score = a.Score, Answer = (i == -1 ? "" : submitAlist[i]), CAnswer = CAnswer, Point = 0 }); }); bool isok = false; T_Answer answer = new T_Answer() { ZyId = id, ZyType = zy.Type, StudentId = UserId, Submited = true, CreateDate = DateTime.Now, AnswerJson = JsonConvert.SerializeObject(al), AnswerImg = "", Ip = ClientUtil.Ip, IMEI = ClientUtil.IMEI, MobileBrand = ClientUtil.MobileBrand, SystemType = Request.Browser.Platform.ToString(), Browser = Request.Browser.Browser.ToString() }; if (ans != null) { isok = B_Answer.UpdateAnswerJson(id, UserId, answer.AnswerJson); } else { isok = B_Answer.InsertZyAnswer(answer); } if (isok) { //写统计表 B_Analyze.GenerateAnalyze(answer); r.code = AjaxResultCodeEnum.Success; r.message = ""; r.data = ""; return(Json(r)); } else { r.code = AjaxResultCodeEnum.Error; r.message = "提交入库失败!"; r.data = ""; return(Json(r)); } }