123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- 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<IStudentScoreServices> studentScoreServices { get; set; }
- public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
- public Lazy<IStudentsServices> StudentfileServices { get; set; }
- public IRoleServices RoleServices { get; set; }
-
- /// <summary>
- /// 学生成绩页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- var schoolYear = SchoolYearServices.Value.GetSchoolYearIsCurrent(true);
- ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年
- return View();
- }
- /// <summary>
- /// 查询列表
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [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<Dictionary<string, string>> listDictionary = new List<Dictionary<string, string>>();
- var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- ViewBag.ScoreDynamicTypes = scoreDynamicTypes;
- StudentScoreView studentScoreView = new StudentScoreView();
- if (submitedScoreID.HasValue)
- {
- List<ER_SubmitedScoreDetail> 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<string, string> { { "Formula_" + submitedScoreDetail.ScoreTypeID, submitedScoreDetail.Score == null ? "0" : submitedScoreDetail.Score.ToString() } });
- }
- listDictionary.Add(new Dictionary<string, string> { { "TotalScore", studentScoreView.TotalScore == null ? "0" : studentScoreView.TotalScore.ToString() } });
- //listDictionary.Add(new Dictionary<string, string> { { "ScoreCredit", studentScoreView.ScoreCredit == null ? "0" : studentScoreView.ScoreCredit.ToString() } });
- //listDictionary.Add(new Dictionary<string, string> { { "GradePoint", studentScoreView.GradePoint == null ? "0" : studentScoreView.GradePoint.ToString() } });
- }
- else
- {
- foreach (var scoreDynamicType in scoreDynamicTypes)
- {
- listDictionary.Add(new Dictionary<string, string> { { "Formula_" + scoreDynamicType.Value, "0" } });
- }
- listDictionary.Add(new Dictionary<string, string> { { "TotalScore", "0" } });
- //listDictionary.Add(new Dictionary<string, string> { { "ScoreCredit", "0" } });
- //listDictionary.Add(new Dictionary<string, string> { { "GradePoint", "0" } });
- }
- ViewBag.ListDictionary = listDictionary;
- return View(studentScoreView);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="studentScoreView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Add(StudentScoreView studentScoreView)
- {
- try
- {
- List<ExpandoObject> listExpandoObject = new List<ExpandoObject>();
- 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<Dictionary<string, string>> listDictionary = new List<Dictionary<string, string>>();
- var scoreDynamicTypes = DictionaryHelper.GetDictionaryValue(DictionaryItem.CF_ScoreType);
- ViewBag.ScoreDynamicTypes = scoreDynamicTypes;
- StudentScoreView studentScoreView = new StudentScoreView();
- if (submitedScoreID.HasValue)
- {
- List<ER_SubmitedScoreDetail> 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<string, string> { { "Formula_" + submitedScoreDetail.ScoreTypeID, submitedScoreDetail.Score == null ? "0" : submitedScoreDetail.Score.ToString() } });
- }
- listDictionary.Add(new Dictionary<string, string> { { "TotalScore", studentScoreView.TotalScore == null ? "0" : studentScoreView.TotalScore.ToString() } });
- //listDictionary.Add(new Dictionary<string, string> { { "ScoreCredit", studentScoreView.ScoreCredit == null ? "0" : studentScoreView.ScoreCredit.ToString() } });
- //listDictionary.Add(new Dictionary<string, string> { { "GradePoint", studentScoreView.GradePoint == null ? "0" : studentScoreView.GradePoint.ToString() } });
- }
- else
- {
- foreach (var scoreDynamicType in scoreDynamicTypes)
- {
- listDictionary.Add(new Dictionary<string, string> { { "Formula_" + scoreDynamicType.Value, "0" } });
- }
- listDictionary.Add(new Dictionary<string, string> { { "TotalScore", "0" } });
- //listDictionary.Add(new Dictionary<string, string> { { "ScoreCredit", "0" } });
- //listDictionary.Add(new Dictionary<string, string> { { "GradePoint", "0" } });
- }
- ViewBag.ListDictionary = listDictionary;
- return View(studentScoreView);
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="studentScoreView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(StudentScoreView studentScoreView)
- {
- try
- {
- List<ExpandoObject> listExpandoObject = new List<ExpandoObject>();
- 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 });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="submitedScoreIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string submitedScoreIDs)
- {
- try
- {
- List<Guid> list = new List<Guid>();
- 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);
- }
- }
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var submitedScoreID = Request.Form["SubmitedScoreID"];
- List<Guid?> submitedScoreIDList = new List<Guid?>();
- if (submitedScoreID != "")
- {
- submitedScoreIDList = submitedScoreID.SplitIDString();
- }
- else
- {
- submitedScoreIDList = null;
- }
- var collegeID = Request.Form["CollegeComboGrid"].ParseStrTo<Guid>();
- var departmentID = Request.Form["DepartmentComboGrid"].ParseStrTo<Guid>();
- var yearID = Request.Form["DictionaryGrade"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo<int>();
- var grademajorID = Request.Form["GrademajorComboGrid"].ParseStrTo<Guid>();
- var classmajorID = Request.Form["ClassmajorDropdown"].ParseStrTo<Guid>();
- var coursematerialID = Request.Form["CoursematerialComboGrid"].ParseStrTo<Guid>();
- var courseTypeID = Request.Form["DictionaryCourseType"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryCourseType"].ParseStrTo<int>();
- var examsCategoryID = Request.Form["DictionaryExamsCategory"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryExamsCategory"].ParseStrTo<int>();
- var schoolyearID = Request.Form["SchoolyearDropdown"].ParseStrTo<Guid>();
- var learningformID = Request.Form["LearningformDictionaryDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["LearningformDictionaryDropDown"].ParseStrTo<int>();
- var education = Request.Form["DictionaryEducation"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo<int>();
- var LearnSystem = Request.Form["DictionaryLearnSystem"].ToString();
- Func<IWorkbook, HSSFCellStyle> noPassStyleFunc = (x =>
- {
- var style = (HSSFCellStyle)x.CreateCellStyle();
- var font = (HSSFFont)x.CreateFont();
- font.Color = HSSFColor.RED.index;
- style.SetFont(font);
- return style;
- });
- List<NpoiExcelCellStyle> styleList = new List<NpoiExcelCellStyle>();
- 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
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="bindType"></param>
- /// <param name="collegeID"></param>
- /// <param name="year"></param>
- /// <param name="standardID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult BindDropdownListBySchoolyearNum(DropdownListBindType? bindType, int? year)
- {
- var StarttermList = this.studentScoreServices.Value.GetStarttermList(year);
- List<DropdownListItem> 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);
- }
- }
- }
|