using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.CommonLogic.ScoreManage; using EMIS.ViewModel; using EMIS.Web.Controls; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.CalendarManage; using EMIS.ViewModel.ScoreManage; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using EMIS.ViewModel.Students; using Bowin.Common.Data; using EMIS.CommonLogic.Students; using EMIS.Utility; namespace EMIS.Web.Controllers.ScoreManage { [Authorization] public class FinalExaminationController : Controller { public Lazy StudentfileServices { get; set; } public Lazy finalExaminationServices { 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.FinalExamination, 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.FinalExam; finalExaminationView.ExaminationModeID =(int)CF_ExaminationMode.WrittenExam; finalExaminationView.ResultTypeID = (int)CF_ResultType.Percentage; finalExaminationView.TotalHours = 0; } if(aType=="add"){ finalExaminationView.FinalExaminationID = null; } finalExaminationView.isAutoAdd = true; return View(finalExaminationView); } /// /// 新增/编辑 /// /// /// [HttpPost] public ActionResult Edit(FinalExaminationView finalExaminationView) { try { finalExaminationView.ExaminationType = (int)EMIS.ViewModel.CF_ExaminationType.FinalExamination; 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 GenerateEdit(Guid? schoolYearID) { var schoolYear = SchoolYearServices.Value.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString(); return View(); } /// /// 生成考试科目 /// /// /// [HttpPost] public ActionResult GenerateEdit() { 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 isGenerateNotSubmit = Request.Form["IsGenerateNotSubmit"].ParseStrTo(); finalExaminationServices.Value.GenerateFinalExamination(schoolYearID, collegeID, gradeID, standardID, isGenerateNotSubmit == true); 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 FinalExaminationStudentList() { var finalExaminationID = Request["finalExaminationID"].ParseStrTo(); return Json(finalExaminationServices.Value.GetFinalExaminationStudent(finalExaminationID)); } ///// ///// 添加学生 ///// ///// ///// ///// //[HttpPost] //public ActionResult FinalExaminationStudentAdd(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); // } //} /// /// 允许录入 /// /// /// [HttpPost] public ActionResult Final_ResitExaminationIsEntry(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.GetFinal_ResitExaminationIsEntry(list); return Json("允许录入成功。"); } catch (Exception ex) { return Json("允许录入失败,原因:" + ex.Message); } } /// /// 撤销录入 /// /// /// [HttpPost] public ActionResult Final_ResitExaminationBack(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.GetFinal_ResitExaminationBack(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.FinalExamination, 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() }); } /// /// 查找默认开课学期 /// /// /// [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("存在"); } } [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.FinalExamination, 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 CanBatchEdit(string finalExaminationIDs) //{ // 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); // } // } // var Student = finalExaminationServices.Value.CanBatchEdit(list); // if (Student == "可以修改") // { // return base.Json("可以修改"); // } // else // { // return base.Json("不能修改"); // } //} } }