using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.ViewModel; using EMIS.Web.Controls; using EMIS.CommonLogic.ScoreManage; using Bowin.Web.Controls.Mvc; using EMIS.ViewModel.ScoreManage; using EMIS.ViewModel.Students; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using EMIS.CommonLogic.CalendarManage; using Bowin.Common.Data; using EMIS.CommonLogic.Students; using EMIS.Utility; namespace EMIS.Web.Controllers.ScoreManage { [Authorization] public class ResitExaminationController : Controller { public Lazy finalExaminationServices { get; set; } public Lazy StudentfileServices { get; set; } public Lazy SchoolYearServices { 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 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 approvalStatus = pararms.getExtraInt("DictionaryScoreState") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryScoreState"); var gradeYearID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade"); return Json(finalExaminationServices.Value.GetFinalExaminationViewGrid(configuretView, collegeID, departmentID, schoolyearID, coursematerialID, courseTypeID, examsCategoryID, (int)EMIS.ViewModel.CF_ExaminationType.ResitExamination, approvalStatus, gradeYearID, (int)pararms.page, (int)pararms.rows)); } /// /// 编辑 /// /// /// public ActionResult Edit(Guid? finalExamination, string aType) { FinalExaminationView finalExaminationView = new FinalExaminationView(); var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var schoolYear = SchoolYearServices.Value.GetSchoolYearIsCurrent(true); if (finalExamination.HasValue) { finalExaminationView = finalExaminationServices.Value.GetFinalExaminationView(finalExamination); } else { finalExaminationView.CollegeID = curUser.CollegeID; finalExaminationView.SchoolyearID = schoolYear.SchoolyearID; finalExaminationView.GradeYearID = schoolYear.Years; finalExaminationView.ExamsCategoryID = (int)CF_ExamsCategory.Resit; finalExaminationView.ExaminationModeID = (int)CF_ExaminationMode.WrittenExam; finalExaminationView.ResultTypeID = (int)CF_ResultType.Percentage; finalExaminationView.TotalHours = 0; } if (aType == "add") { finalExaminationView.FinalExaminationID = null; } return View(finalExaminationView); } /// /// 新增/编辑 /// /// /// [HttpPost] public ActionResult Edit(FinalExaminationView finalExaminationView) { try { finalExaminationView.ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.ResitExamination; var studentList = DataGrid.GetTableData("dgStudentList"); var ClassmajorID = finalExaminationView.ClassID; List ClassmajorIDList = new List(); if (ClassmajorID != null) { ClassmajorIDList = ClassmajorID.SplitIDString(); } finalExaminationServices.Value.FinalExaminationAdd(finalExaminationView, ClassmajorIDList); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 增加学生 /// /// /// public ActionResult StudentEdit(Guid? finalExamination) { FinalExaminationView finalExaminationView = new FinalExaminationView(); var schoolYear = SchoolYearServices.Value.GetSchoolYearIsCurrent(true); if (finalExamination.HasValue) { finalExaminationView = finalExaminationServices.Value.GetFinalExaminationView(finalExamination); } else { finalExaminationView.SchoolyearID = schoolYear.SchoolyearID; finalExaminationView.GradeYearID = schoolYear.Years; finalExaminationView.ExamsCategoryID = (int)CF_ExamsCategory.FinalExam; finalExaminationView.ExaminationModeID = (int)CF_ExaminationMode.WrittenExam; } return View(finalExaminationView); } /// /// 增加学生 /// /// /// [HttpPost] public ActionResult StudentEdit(FinalExaminationView finalExaminationView) { try { finalExaminationView.ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination; var studentList = DataGrid.GetTableData("dgStudentList"); finalExaminationServices.Value.FinalExaminationStudentAdd(finalExaminationView.FinalExaminationID, studentList); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 添加学生 /// /// /// public ActionResult StudentAdd(Guid? finalExamination, Guid? UserID) { FinalExaminationView finalExaminationView = new FinalExaminationView(); finalExaminationView = finalExaminationServices.Value.GetFinalExaminationView(finalExamination); finalExaminationView.isAutoAdd = true; if (UserID != Guid.Empty && UserID != null) { var student = StudentfileServices.Value.GetStudentfileView((Guid)UserID); var StarttermID = finalExaminationServices.Value.GetFinalExaminationStudentForStudentAdd(finalExamination, UserID); var f = finalExaminationServices.Value.GetStarttermID(finalExamination, UserID); finalExaminationView.UserID = UserID; finalExaminationView.UserName = student.UserName; finalExaminationView.StarttermID = StarttermID.StarttermID; //如果是修改变成false finalExaminationView.isAutoAdd = false; } return View(finalExaminationView); } /// /// 添加学生 /// /// /// [HttpPost] public ActionResult StudentAdd(FinalExaminationView finalExaminationView) { try { finalExaminationServices.Value.StudentAdd(finalExaminationView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string finalExaminationIDs) { try { List list = new List(); for (int i = 0; i < finalExaminationIDs.Split(',').Length; i++) { if (!string.IsNullOrEmpty(finalExaminationIDs.Split(',')[i])) { Guid FinalExaminationID = new Guid(finalExaminationIDs.Split(',')[i]); list.Add(FinalExaminationID); } } finalExaminationServices.Value.FinalExaminationDelete(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); } } /// /// 删除学生 /// /// /// [HttpPost] public ActionResult StudentDelete(Guid finalExaminationID, string UserIDs) { try { List list = new List(); for (int i = 0; i < UserIDs.Split(',').Length; i++) { if (!string.IsNullOrEmpty(UserIDs.Split(',')[i])) { Guid FinalExaminationID = new Guid(UserIDs.Split(',')[i]); list.Add(FinalExaminationID); } } finalExaminationServices.Value.FinalExaminationStudentDelete(finalExaminationID, 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); } } /// /// /// /// /// public ActionResult GenerateFinalExaminationEdit(Guid? schoolYearID) { var schoolYear = SchoolYearServices.Value.GetSchoolYearViewBeforeCurrent(); ViewBag.SchoolYearID = schoolYear == null ? DropdownList.PLEASE_SELECT.ToString() : schoolYear.SchoolYearID.ToString(); return View(); } /// /// 期末补考生成,按兵良要求,加上院系所、年级、专业下拉条件 增加班级条件 /// /// [HttpPost] public ActionResult GenerateFinalExaminationEdit() { try { var schoolYearID = Request.Form["SchoolyearDropdown"].ParseStrTo(); var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); var gradeID = Request.Form["SchoolyearDictionaryDropDown"].ParseStrTo(); var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo(); var classmajorID = Request.Form["ClassmajorDropdown"].ParseStrTo(); finalExaminationServices.Value.GenerateResitExamination(schoolYearID, collegeID, gradeID, standardID, classmajorID); return Json(new ReturnMessage() { IsSuccess = true, Message = "生成成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "生成失败:" + ex.Message }); } } /// /// /// /// /// public ActionResult GenerateResitExaminationEdit(Guid? schoolYearID) { var schoolYear = SchoolYearServices.Value.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? DropdownList.PLEASE_SELECT.ToString() : schoolYear.SchoolyearID.ToString(); return View(); } /// /// 毕业补考生成 /// /// [HttpPost] public ActionResult GenerateResitExaminationEdit() { try { //var year = Request.Form["ddlYear"].ParseStrTo(); var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); var year = Request.Form["SchoolyearDictionaryDropDown"].ParseStrTo(); var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo(); var classmajorID = Request.Form["ClassmajorDropdown"].ParseStrTo(); var learnSystem = Request.Form["DictionaryLearnSystem"].ParseStrTo(); finalExaminationServices.Value.GenerateGraduationExam(year, collegeID, standardID, classmajorID, learnSystem); return Json(new ReturnMessage() { IsSuccess = true, Message = "生成成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "生成失败:" + ex.Message }); } } /// /// 学生成绩录入名单 /// /// public ActionResult StudentList(Guid? finalExaminationID) { ViewBag.FinalExaminationID = finalExaminationID; return View(); } /// /// 补考设定学生成绩录入名单 /// /// /// [HttpPost] public ActionResult ResitExaminationStudentList() { var finalExaminationID = Request["finalExaminationID"].ParseStrTo(); return Json(finalExaminationServices.Value.GetFinalExaminationStudent(finalExaminationID)); } ///// ///// 添加学生 ///// ///// ///// ///// //[HttpPost] //public ActionResult ResitExaminationStudentAdd(Guid? finalExaminationID, string userIDs) //{ // try // { // List list = new List(); // for (int i = 0; i < userIDs.Split(',').Length; i++) // { // if (!string.IsNullOrEmpty(userIDs.Split(',')[i])) // { // Guid userID = new Guid(userIDs.Split(',')[i]); // list.Add(userID); // } // } // finalExaminationServices.Value.FinalExaminationStudentAdd(finalExaminationID, list); // return Json("成功"); // } // catch (Exception ex) // { // return Json("增加学生失败,原因:" + ex.Message); // } //} /// /// 导出Excel /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var FinalExaminationID = Request.Form["FinalExaminationID"]; var collegeID = Request.Form["CollegeComboGrid"].ParseStrTo(); var departmentID = Request.Form["DepartmentComboGrid"].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 approvalStatus = Request.Form["DictionaryScoreState"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryScoreState"].ParseStrTo(); var gradeYearID = Request.Form["DictionaryGrade"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo(); List FinalExaminationIDList = new List(); if (FinalExaminationID != "") { FinalExaminationIDList = FinalExaminationID.SplitIDString(); } else { FinalExaminationIDList = null; } var dt = finalExaminationServices.Value.GetFinalExaminationViewList_Excel(configuretView, collegeID, departmentID, schoolyearID, coursematerialID, courseTypeID, examsCategoryID, (int)EMIS.ViewModel.CF_ExaminationType.ResitExamination, approvalStatus, gradeYearID, FinalExaminationIDList).Select(x => new { x.SchoolyearCode, x.GradeYearID, x.ClassName, x.CourseCode, x.CourseName, x.CourseTypeName, x.Credit, x.ExamsCategoryName, x.CreatorUserNo, x.CreatorUserName, x.EntryDeadlineTime, x.StudentCount, x.SAPunlogStudentCount, x.ApprovalStatusName }).ToTable(); string[] liststring = { "学年学期", "年级", "录入班级名称", "课程代码", "课程名称","课程类型","学分", "考试性质","录入人编号", "录入人姓名", "录入截止日期","学生数","未录入人数","状态" }; neh.Export(dt, liststring, "补考设定信息"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Action("List").AddMenuParameter() }); } /// /// 导出Excel /// /// [HttpPost] public ActionResult StudentDetails_Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var FinalExaminationID = Request.Form["FinalExaminationID"]; var collegeID = Request.Form["CollegeComboGrid"].ParseStrTo(); var departmentID = Request.Form["DepartmentComboGrid"].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 approvalStatus = Request.Form["DictionaryScoreState"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryScoreState"].ParseStrTo(); var gradeYearID = Request.Form["DictionaryGrade"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo(); List FinalExaminationIDList = new List(); if (FinalExaminationID != "") { FinalExaminationIDList = FinalExaminationID.SplitIDString(); } else { FinalExaminationIDList = null; } var dt = finalExaminationServices.Value.GetFinalExaminationStudentDetailsList(configuretView, collegeID, departmentID, schoolyearID, coursematerialID, courseTypeID, examsCategoryID, (int)EMIS.ViewModel.CF_ExaminationType.ResitExamination, approvalStatus, gradeYearID, FinalExaminationIDList).Select(x => new { x.SchoolyearCode, x.ClassName, x.CourseCode, x.CourseName, x.CourseTypeName, x.Credit, x.ExamsCategoryName, x.LoginID, x.UserName, x.CollegeName, x.Year, x.StandardName, x.ClassmajorName, }).ToTable(); string[] liststring = { "学年学期","录入班级", "课程代码", "课程名称", "课程类型","学分","考试性质", "学号","姓名",RSL.Get("College"), "年级","专业名称","班级名称" }; neh.Export(dt, liststring, "成绩录入学生名单" + DateTime.Now.ToString("yyyyMMdd")); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Action("List").AddMenuParameter() }); } /// /// 查找默认开课学期 /// /// /// [HttpPost] public ActionResult GetStarttermID(Guid? finalExaminationID, Guid? UserID) { var value = finalExaminationServices.Value.GetStarttermID(finalExaminationID, UserID); return Json(value); } /// /// 查找默认开课学期 /// /// /// [HttpPost] public ActionResult Verification(Guid? finalExaminationID, Guid? UserID) { var Student = finalExaminationServices.Value.GetFinalExaminationStudentForStudentAdd(finalExaminationID, UserID); if (Student == null) { return base.Json("不存在"); } else { return base.Json("存在"); } } } }