using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.CommonLogic.ExaminationApply; using EMIS.ViewModel; using EMIS.Web.Controls; using Bowin.Common.Data; using Bowin.Common.Utility; using EMIS.Utility; using Bowin.Common; using EMIS.CommonLogic.CalendarManage; using EMIS.CommonLogic.Students; using Bowin.Web.Controls.Mvc; using System.Text; using EMIS.ViewModel.ExaminationApply; namespace EMIS.Web.Controllers.ExaminationApply { [Authorization] public class ExaminationApplayStudentListController : Controller { public IExaminationSubjectServices ExaminationSubjectServices { get; set; } public ISchoolYearServices SchoolYearServices { get; set; } public IExamineApplyServices ExamineApplyService { get; set; } public ActionResult List() { var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年 return View(); } public ActionResult Export() { return View(); } [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var schoolyearID = pararms.getExtraGuid("SchoolYearDropdown"); var subjectID = pararms.getExtraGuid("ddlExaminationSubject"); var collegeID = pararms.getExtraGuid("cgCollege"); var classmajorID = pararms.getExtraGuid("cgClassmajor"); var examinationTypeID = pararms.getExtraGuid("cgExamination"); var year = pararms.getExtraInt("ddlYear") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlYear"); var standardID = pararms.getExtraInt("ddlStandard") == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ddlStandard"); var isPay = pararms.getExtraInt("IsPay") == DropdownList.SELECT_ALL ? (bool?)null : (pararms.getExtraInt("IsPay") == (int)CF_GeneralPurpose.IsYes); if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; return base.Json(ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID, year, standardID, classmajorID, examinationTypeID, schoolyearID, isPay, (int)pararms.page, (int)pararms.rows)); } [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo(); var collegeID = Request.Form["cgCollege"].ParseStrTo(); var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); var classmajorID = Request.Form["cgClassmajor"].ParseStrTo(); var examinationTypeID = Request.Form["cgExamination"].ParseStrTo(); var year = Request.Form["ddlYear"].ParseStrTo() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlYear"].ParseStrTo(); var standardID = Request.Form["ddlStandard"].ParseStrTo() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlStandard"].ParseStrTo(); var isPay = Request.Form["IsPay"]; bool? IsPay = null; if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsNo) { IsPay = false; } if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsYes) { IsPay = true; } if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; var dt = ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID, year, standardID, null, examinationTypeID, schoolyearID,IsPay).Select(x => new { x.SchoolyearCode, x.StudentNo, x.Name, x.SexName, x.ClassmajorName, x.SubjectName, x.CertificatesTypeName, x.IDNumber, x.Cost, x.IsPay }).ToTable(); string[] liststring = { "考试学年学期", "学号", "姓名", "性别", "班级名称", "科目名称", "证件类型", "证件号码", "报名费","是否交费" }; neh.Export(dt, liststring, "报考学生名单"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/ExaminationApplayStudentList/List").AddMenuParameter() }); } public ActionResult ClassStudentStatisticsList() { var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true); ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年 return View(); } [HttpPost] public ActionResult ClassStudentStatisticsList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); var collegeID = pararms.getExtraGuid("CollegeDropdown"); var classmajorID = pararms.getExtraGuid("ClassmajorDropdown"); var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown"); //var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true); //ViewBag.SchoolYearID = schoolYear == null ? "-1" : schoolYear.SchoolyearID.ToString();//默认当前学年 var schoolYear = pararms.getExtraInt("SchoolyearDictionaryDropDown"); var schoolyearID = pararms.getExtraGuid("SchoolYearDropdown"); var subjectID = pararms.getExtraGuid("ddlExaminationSubject"); return base.Json(ExaminationSubjectServices.GetExaminationSubjectClassStudentStatisticsListView(subjectID, schoolYear, schoolyearID, (int)pararms.page, (int)pararms.rows, campusID, collegeID, classmajorID, standardID)); } [HttpPost] public ActionResult ClassStudentStatisticsExcel() { NpoiExcelHelper neh = new NpoiExcelHelper(); //ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); //if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo(); var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); var dt = ExaminationSubjectServices.GetExaminationSubjectClassStudentStatisticsList(subjectID, schoolyearID).Select(x => new { x.Year, x.GrademajorName, x.ClassmajorName, x.SchoolyearCode, x.SubjectName, x.StudentCount, x.Cost, }).ToTable(); string[] liststring = { "年级", "年级专业", "班级", "学期", "科目", "报名人数", "收费" }; neh.Export(dt, liststring, "报考班级学生统计"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/ExaminationApplayStudentList/ClassStudentStatisticsList").AddMenuParameter() }); } public ActionResult ClassStudentStatisticsReport() { return View(); } [HttpPost] public ActionResult ExportStudentData() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo(); var examinationTypeID = Request.Form["cgExamination"].ParseStrTo(); var collegeID = Request.Form["cgCollege"].ParseStrTo(); var year = Request.Form["ddlYear"].ParseStrTo() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlYear"].ParseStrTo(); var standardID = Request.Form["ddlStandard"].ParseStrTo() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlStandard"].ParseStrTo(); var isPay = Request.Form["IsPay"]; bool? IsPay = null; if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsNo) { IsPay = false; } if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsYes) { IsPay = true; } if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; var dt = ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID, year, standardID, null, examinationTypeID, schoolyearID,IsPay).Select(x => new { x.SchoolyearCode, x.StudentNo, x.Name, x.SexName, x.ClassmajorName, x.SubjectName, x.CertificatesTypeName, x.IDNumber, x.CardNo, //x.EducationName, //LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null, x.CollegeName, x.Year, //x.SchoolyearNumName, x.StandardName, // x.ClassmajorNo }).ToTable(); //RSL.Get("EducationID"), "学制", string[] liststring = { "考试学年学期","学号", "姓名", "性别", "班级名称", "科目名称", "证件类型", "证件号码","银行卡号", "院系", "年级", "专业" }; neh.Export(dt, liststring, "报考学生数据导出"); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/ExaminationApplayStudentList/Export").AddMenuParameter() }); } [HttpPost] public ActionResult ExportStudentPic() { string tempVirtualFilePath = Const.LOCAL_SETTING_UPLOAD_FILEPATH + "/" + Guid.NewGuid().ToString(); string tempPhysicalFilePath = HttpContext.Server.MapPath(tempVirtualFilePath); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var schoolyearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); var subjectID = Request.Form["ddlExaminationSubject"].ParseStrTo(); var collegeID = Request.Form["cgCollege"].ParseStrTo(); var classmajorID = Request.Form["cgClassmajor"].ParseStrTo(); var examinationTypeID = Request.Form["cgExamination"].ParseStrTo(); var year = Request.Form["ddlYear"].ParseStrTo() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlYear"].ParseStrTo(); var standardID = Request.Form["ddlStandard"].ParseStrTo() == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL ? null : Request.Form["ddlStandard"].ParseStrTo(); var isPay = Request.Form["IsPay"]; bool? IsPay = null; if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsNo) { IsPay = false; } if (Convert.ToInt32(isPay) == (int)CF_GeneralPurpose.IsYes) { IsPay = true; } if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = ""; var studentList = ExaminationSubjectServices.GetExaminationSubjectStudentListView(configuretView, subjectID, collegeID, year, standardID, null, examinationTypeID, schoolyearID,IsPay).ToList(); if (!System.IO.Directory.Exists(tempPhysicalFilePath)) { System.IO.Directory.CreateDirectory(tempPhysicalFilePath); } var fileInfo = studentList.Where(x => x.PhotoUrl != null) .Select(x => new EMIS.Utility.FileUploadHelper.RemoteFileInfo { RemotePath = x.PhotoUrl, FileName = x.IDNumber + ".jpg" }).ToList(); FileUploadHelper.DownLoadFiles("studentPhoto" + Guid.NewGuid().ToString(), "报考学生照片", fileInfo); return RedirectToAction("MsgShow", "Common", new { msg = "导出成功!", url = Url.Content("~/ExaminationApplayStudentList/Export").AddMenuParameter() }); } public ActionResult ApplyCancel(string ExaminationRegistrationIDs) { try { var xaminationRegistrationIDList = ExaminationRegistrationIDs.Split(',').Where(x => x.IndexOf("-") >= 0).Select(x => new Guid(x)).ToList(); var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal; ExamineApplyService.ApplyCancel(xaminationRegistrationIDList); return base.Json("撤销成功"); } catch (Exception ex) { string mge = ex.Message; return base.Json("撤销失败,原因:" + mge); } } /// /// 学生名单导入 /// /// /// /// [HttpGet] public ActionResult Import(string errorFile, string operationTips) { ViewBag.ErrorFile = errorFile; if (string.IsNullOrEmpty(operationTips)) { operationTips = "错误数据下载"; } ViewBag.operationTips = operationTips; return View(); } public ActionResult Import(HttpPostedFileBase file) { try { if (!NpoiExcelHelper.GetIsCompatible(file.FileName)) { throw new Exception("只允许上传xls和xlsx格式的Excel文件!"); } var excel = new NpoiExcelHelper(); #region 表单头 Dictionary cellheader = new Dictionary { { "SchoolyearCode", "考试学年学期" }, { "StudentNo", "学号" }, { "Name", "姓名" }, { "SexForImpor", "性别" }, { "ClassmajorName", "班级名称" }, { "SubjectName", "科目名称" }, { "CertificatesTypeNameForImport", "证件类型" }, { "IDNumber", "证件号码" }, { "CostForImpor", "报名费" }, { "IsPay", "是否交费" }, { "ErrorMessage", "错误信息" } }; #endregion StringBuilder errorMsg = new StringBuilder(); // 错误信息 string sourceWebPath = FileUploadHelper.UploadFile(file); var sourcePhysicalPath = Server.MapPath(sourceWebPath); List errList = new List(); List dataList = new List(); int errCount = 0; int OkCount = 0; ExaminationSubjectServices.ExaminationSubjectStudentImport(cellheader, out OkCount, out errList, out errCount, sourcePhysicalPath); System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件 if (errCount > 0) { var errorPhysicalPath = sourcePhysicalPath; var errorWebPaths = sourceWebPath; string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "学生缴费名单失败文件", errorWebPaths)); ViewBag.ErrorFile = errorWebPath; string Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", OkCount < 1 ? 0 : OkCount, errCount < 1 ? 0 : errCount); ViewBag.operationTips = Errinfo; // //return RedirectToAction("Import", new { errorFile = errorWebPath, operationTips = Errinfo }); return RedirectToAction("MsgShow", "Common", new { WindowID = "none", msg = "导入失败!", url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"] }); } else { return RedirectToAction("MsgShow", "Common", new { WindowID = Request["WindowID"], msg = "导入成功!", url = Url.Action("List").AddMenuParameter() }); } } catch (Exception ex) { return RedirectToAction("MsgShow", "Common", new { WindowID = Request["WindowID"], msg = "导入失败,原因:" + ex.Message + "!", url = Url.Action("List").AddMenuParameter() }); } } } }