using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.ViewModel; using EMIS.CommonLogic.ScoreManage; using EMIS.Web.Controls; using Bowin.Web.Controls.Mvc; using EMIS.ViewModel.ScoreManage; using System.Dynamic; using EMIS.Utility; using Bowin.Common.Exceptions; using EMIS.Entities; using Bowin.Common.Utility; using Bowin.Common.Data; using EMIS.CommonLogic.CalendarManage; using NPOI.SS.UserModel; using NPOI.HSSF.UserModel; using NPOI.HSSF.Util; using EMIS.CommonLogic.Students; using EMIS.CommonLogic.SystemServices; namespace EMIS.Web.Controllers.ScoreManage { [Authorization] public class StudentScoreController : Controller { public Lazy studentScoreServices { get; set; } public Lazy SchoolYearServices { get; set; } public Lazy StudentfileServices { get; set; } public IRoleServices RoleServices { get; set; } /// /// 学生成绩页面 /// /// public ActionResult List() { var schoolYear = SchoolYearServices.Value.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年 return View(); } /// /// 查询列表 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var collegeID = pararms.getExtraGuid("CollegeComboGrid"); var yearID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade"); var standardID = pararms.getExtraInt("StandardID") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardID"); var classmajorID = pararms.getExtraGuid("ClassmajorDropdown"); var departmentID = pararms.getExtraGuid("DepartmentComboGrid"); var coursematerialID = pararms.getExtraGuid("CoursematerialComboGrid"); var courseTypeID = pararms.getExtraInt("DictionaryCourseType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseType"); var examsCategoryID = pararms.getExtraInt("DictionaryExamsCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryExamsCategory"); var schoolyearID = pararms.getExtraGuid("SchoolyearDropdown"); var starttermBegin = pararms.getExtraInt("DictionaryStarttermBegin") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStarttermBegin"); var starttermEnd = pararms.getExtraInt("DictionaryStarttermEnd") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStarttermEnd"); var handleModeID = pararms.getExtraInt("HandleModeDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("HandleModeDictionaryDropDown"); var learningformID = pararms.getExtraInt("LearningformDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("LearningformDictionaryDropDown"); var education = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation"); var LearnSystem = pararms.getExtraString("DictionaryLearnSystem"); return Json(studentScoreServices.Value.GetStudentScoreViewGrid(configuretView, collegeID, departmentID, schoolyearID, coursematerialID, courseTypeID, examsCategoryID, standardID, classmajorID, starttermBegin, starttermEnd, yearID, learningformID, handleModeID, education, LearnSystem, (int)pararms.page, (int)pararms.rows)); } public ActionResult StudentScoreReport(QueryParamsModel pararms) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var dataRange = RoleServices.GetDataRange(); ViewBag.DataRange = dataRange; ViewBag.UserID = curUser.UserID.ToString(); return View(); } public ActionResult HBKDStudentScoreReport(QueryParamsModel pararms) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var dataRange = RoleServices.GetDataRange(); var LoginCampusID = RoleServices.GetLoginCampusID(dataRange, curUser.UserID); var LoginCollegeID = RoleServices.GetLoginCollegeID(dataRange, curUser.UserID); var LoginClassmajorID = RoleServices.GetLoginClassmajorID(dataRange, curUser.UserID); ViewBag.LoginCampusID = LoginCampusID; ViewBag.LoginCollegeID = LoginCollegeID; ViewBag.LoginClassmajorID = LoginClassmajorID; return View(); } public ActionResult GzzyStudentScoreReport(QueryParamsModel pararms) { var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var dataRange = RoleServices.GetDataRange(); var LoginCampusID = RoleServices.GetLoginCampusID(dataRange, curUser.UserID); var LoginCollegeID = RoleServices.GetLoginCollegeID(dataRange, curUser.UserID); var LoginClassmajorID = RoleServices.GetLoginClassmajorID(dataRange, curUser.UserID); ViewBag.LoginCampusID = LoginCampusID; ViewBag.LoginCollegeID = LoginCollegeID; ViewBag.LoginClassmajorID = LoginClassmajorID; return View(); } public ActionResult Add(Guid? submitedScoreID) { List> listDictionary = new List>(); var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType); ViewBag.ScoreDynamicTypes = scoreDynamicTypes; StudentScoreView studentScoreView = new StudentScoreView(); if (submitedScoreID.HasValue) { List listSubmitedScoreDetail = studentScoreServices.Value.GetSubmitedScore(submitedScoreID).ER_SubmitedScoreDetail.ToList(); studentScoreView = studentScoreServices.Value.GetStudentScoreView(submitedScoreID); foreach (var scoreDynamicType in scoreDynamicTypes) { ER_SubmitedScoreDetail submitedScoreDetail = listSubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault(); listDictionary.Add(new Dictionary { { "Formula_" + submitedScoreDetail.ScoreTypeID, submitedScoreDetail.Score == null ? "0" : submitedScoreDetail.Score.ToString() } }); } listDictionary.Add(new Dictionary { { "TotalScore", studentScoreView.TotalScore == null ? "0" : studentScoreView.TotalScore.ToString() } }); //listDictionary.Add(new Dictionary { { "ScoreCredit", studentScoreView.ScoreCredit == null ? "0" : studentScoreView.ScoreCredit.ToString() } }); //listDictionary.Add(new Dictionary { { "GradePoint", studentScoreView.GradePoint == null ? "0" : studentScoreView.GradePoint.ToString() } }); } else { foreach (var scoreDynamicType in scoreDynamicTypes) { listDictionary.Add(new Dictionary { { "Formula_" + scoreDynamicType.Value, "0" } }); } listDictionary.Add(new Dictionary { { "TotalScore", "0" } }); //listDictionary.Add(new Dictionary { { "ScoreCredit", "0" } }); //listDictionary.Add(new Dictionary { { "GradePoint", "0" } }); } ViewBag.ListDictionary = listDictionary; return View(studentScoreView); } /// /// 新增 /// /// /// [HttpPost] public ActionResult Add(StudentScoreView studentScoreView) { try { List listExpandoObject = new List(); var scoreTypeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType); foreach (var scoreType in scoreTypeList) { dynamic dyic = new ExpandoObject(); dyic.ScoreTypeID = scoreType.Value; dyic.Score = Convert.ToDecimal(Request.Form["Formula_" + scoreType.Value]); listExpandoObject.Add(dyic); } studentScoreView.TotalScore = Convert.ToDecimal(Request.Form["TotalScore"]); studentScoreView.ScoreCredit = Convert.ToDecimal(Request.Form["ScoreCredit"]); studentScoreView.GradePoint = Convert.ToDecimal(Request.Form["GradePoint"]); //studentScoreView.StudentScoreRemark = Request.Form["Remark"]; if (Request.Params["SaveType"] == "Add")//识别是否是复制性新增操作~~ { studentScoreView.SubmitedScoreID = null; } studentScoreServices.Value.StudentScoreAdd(studentScoreView, listExpandoObject); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message + "!" }); } } public ActionResult Edit(Guid? submitedScoreID) { List> listDictionary = new List>(); var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType); ViewBag.ScoreDynamicTypes = scoreDynamicTypes; StudentScoreView studentScoreView = new StudentScoreView(); if (submitedScoreID.HasValue) { List listSubmitedScoreDetail = studentScoreServices.Value.GetSubmitedScore(submitedScoreID).ER_SubmitedScoreDetail.ToList(); studentScoreView = studentScoreServices.Value.GetStudentScoreView(submitedScoreID); foreach (var scoreDynamicType in scoreDynamicTypes) { ER_SubmitedScoreDetail submitedScoreDetail = listSubmitedScoreDetail.Where(x => x.ScoreTypeID == scoreDynamicType.Value).FirstOrDefault(); listDictionary.Add(new Dictionary { { "Formula_" + submitedScoreDetail.ScoreTypeID, submitedScoreDetail.Score == null ? "0" : submitedScoreDetail.Score.ToString() } }); } listDictionary.Add(new Dictionary { { "TotalScore", studentScoreView.TotalScore == null ? "0" : studentScoreView.TotalScore.ToString() } }); //listDictionary.Add(new Dictionary { { "ScoreCredit", studentScoreView.ScoreCredit == null ? "0" : studentScoreView.ScoreCredit.ToString() } }); //listDictionary.Add(new Dictionary { { "GradePoint", studentScoreView.GradePoint == null ? "0" : studentScoreView.GradePoint.ToString() } }); } else { foreach (var scoreDynamicType in scoreDynamicTypes) { listDictionary.Add(new Dictionary { { "Formula_" + scoreDynamicType.Value, "0" } }); } listDictionary.Add(new Dictionary { { "TotalScore", "0" } }); //listDictionary.Add(new Dictionary { { "ScoreCredit", "0" } }); //listDictionary.Add(new Dictionary { { "GradePoint", "0" } }); } ViewBag.ListDictionary = listDictionary; return View(studentScoreView); } /// /// 编辑 /// /// /// [HttpPost] public ActionResult Edit(StudentScoreView studentScoreView) { try { List listExpandoObject = new List(); var scoreTypeList = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType); foreach (var scoreType in scoreTypeList) { dynamic dyic = new ExpandoObject(); dyic.ScoreTypeID = scoreType.Value; dyic.Score = Convert.ToDecimal(Request.Form["Formula_" + scoreType.Value]); listExpandoObject.Add(dyic); } studentScoreView.TotalScore = Convert.ToDecimal(Request.Form["TotalScore"]); studentScoreView.ScoreCredit = Convert.ToDecimal(Request.Form["ScoreCredit"]); studentScoreView.GradePoint = Convert.ToDecimal(Request.Form["GradePoint"]); //studentScoreView.StudentScoreRemark = Request.Form["Remark"]; if (Request.Params["SaveType"] == "Add")//识别是否是复制性新增操作~~ { studentScoreView.SubmitedScoreID = null; } studentScoreServices.Value.StudentScoreAdd(studentScoreView, listExpandoObject); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message + "!" }); } } [HttpPost] public ActionResult ValidateDuplicate(Guid? submitedScoreID, Guid? userID, Guid? coursematerialID, int? examsCategoryID, int? startTermID) { try { studentScoreServices.Value.ValidateDuplicate(submitedScoreID, userID, coursematerialID, examsCategoryID, startTermID); return Json(new ReturnMessage { IsSuccess = true }); } catch (Exception ex) { return Json(new ReturnMessage { IsSuccess = false, Message = ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string submitedScoreIDs) { try { List list = new List(); for (int i = 0; i < submitedScoreIDs.Split(',').Length; i++) { if (!string.IsNullOrEmpty(submitedScoreIDs.Split(',')[i])) { Guid SubmitedScoreID = new Guid(submitedScoreIDs.Split(',')[i]); list.Add(SubmitedScoreID); } } studentScoreServices.Value.StudentScoreDelete(list); return this.Json("删除成功"); } catch (Exception ex) { string mge = ex.Message; System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex); if (num != null) { if (num.Number == 547) mge = "请先删除所有关联的数据!"; } return this.Json("删除失败,原因:" + mge); } } /// /// 导出Excel /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var submitedScoreID = Request.Form["SubmitedScoreID"]; List submitedScoreIDList = new List(); if (submitedScoreID != "") { submitedScoreIDList = submitedScoreID.SplitIDString(); } else { submitedScoreIDList = null; } var collegeID = Request.Form["CollegeComboGrid"].ParseStrTo(); var departmentID = Request.Form["DepartmentComboGrid"].ParseStrTo(); var yearID = Request.Form["DictionaryGrade"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo(); var grademajorID = Request.Form["GrademajorComboGrid"].ParseStrTo(); var classmajorID = Request.Form["ClassmajorDropdown"].ParseStrTo(); var coursematerialID = Request.Form["CoursematerialComboGrid"].ParseStrTo(); var courseTypeID = Request.Form["DictionaryCourseType"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryCourseType"].ParseStrTo(); var examsCategoryID = Request.Form["DictionaryExamsCategory"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryExamsCategory"].ParseStrTo(); var schoolyearID = Request.Form["SchoolyearDropdown"].ParseStrTo(); var learningformID = Request.Form["LearningformDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["LearningformDictionaryDropDown"].ParseStrTo(); var education = Request.Form["DictionaryEducation"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo(); var LearnSystem = Request.Form["DictionaryLearnSystem"].ToString(); Func noPassStyleFunc = (x => { var style = (HSSFCellStyle)x.CreateCellStyle(); var font = (HSSFFont)x.CreateFont(); font.Color = HSSFColor.RED.index; style.SetFont(font); return style; }); List styleList = new List(); var dt = studentScoreServices.Value.GetStudentScoreViewList(configuretView, collegeID, departmentID, schoolyearID, coursematerialID, courseTypeID, examsCategoryID, grademajorID, classmajorID, yearID, learningformID, education, LearnSystem, submitedScoreIDList).Select(x => new { x.LoginID, x.UserName, x.ClassName, x.SchoolyearCode, x.CourseName, x.CourseCode, x.CourseTypeName, x.ExamsCategoryName, x.ExaminationModeName, x.ExamsStateName, x.StarttermName, x.Pingshi, x.Jishu, x.Lilun, TotalScore = x.TotalScoreStr, x.ScoreCredit, x.GradePoint, x.Remarks }).ToTable(); for (int i = 0; i < dt.Rows.Count; i++) { decimal tmpPingshi; if (decimal.TryParse(Convert.ToString(dt.Rows[i]["Pingshi"]), out tmpPingshi)) { if (tmpPingshi < 60) { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 11, StyleFunc = noPassStyleFunc }); } } else { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 11, StyleFunc = noPassStyleFunc }); } decimal tmpJishu; if (decimal.TryParse(Convert.ToString(dt.Rows[i]["Jishu"]), out tmpJishu)) { if (tmpJishu < 60) { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 12, StyleFunc = noPassStyleFunc }); } } else { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 12, StyleFunc = noPassStyleFunc }); } decimal tmpLilun; if (decimal.TryParse(Convert.ToString(dt.Rows[i]["Lilun"]), out tmpLilun)) { if (tmpLilun < 60) { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 13, StyleFunc = noPassStyleFunc }); } } else { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 13, StyleFunc = noPassStyleFunc }); } decimal tmpTotalScore; if (decimal.TryParse(Convert.ToString(dt.Rows[i]["TotalScore"]), out tmpTotalScore)) { if (tmpTotalScore < 60) { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 14, StyleFunc = noPassStyleFunc }); } } else { styleList.Add(new NpoiExcelCellStyle { RowIndex = i, ColumnIndex = 14, StyleFunc = noPassStyleFunc }); } } string[] liststring = { "学号", "姓名", "班级名称", "学年学期", "课程名称","课程代码","课程类型", "考试性质","考试方式", "考试状态", "开课学期",@EMIS.Utility.RSL.Get("Peacetime"),@EMIS.Utility.RSL.Get("Technique"),@EMIS.Utility.RSL.Get("Theoretical"), "总成绩", "学分", "绩点","备注" }; neh.PresetCellStyle(styleList); neh.Export(dt, liststring, "学生成绩信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Action("List").AddMenuParameter() }); } [HttpPost] public ActionResult RefreshFinallyScoreForBatchUpdate(string submitedScoreIDString) { var submitedScoreIDList = submitedScoreIDString.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => new Guid(x)).ToList(); try { this.studentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList); return Json(new ReturnMessage() { IsSuccess = true, Message = "更新成功。" }); } catch (Exception ex) { this.studentScoreServices.Value.RefreshFinallyScoreBySubmitedScoreID(submitedScoreIDList); return Json(new ReturnMessage() { IsSuccess = true, Message = "更新失败:" + ex.Message }); } } /// /// /// /// /// /// /// /// [HttpPost] public ActionResult BindDropdownListBySchoolyearNum(DropdownListBindType? bindType, int? year) { var StarttermList = this.studentScoreServices.Value.GetStarttermList(year); List list = StarttermList.Select(x=> new DropdownListItem{ Text=x.StarttermName,Value=x.StarttermID }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } } }