using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using EMIS.ViewModel; using Bowin.Web.Controls.Mvc; using EMIS.Web.Controls; using EMIS.CommonLogic.CultureplanManage.PlanManagement; using EMIS.ViewModel.SelectCourse; using Bowin.Common.Exceptions; using EMIS.Entities; using Bowin.Common.Utility; using Bowin.Common.Data; using EMIS.CommonLogic.UniversityManage.SpecialtyClassManage; using EMIS.CommonLogic.CalendarManage; using EMIS.ViewModel.UniversityManage.SpecialtyClassManage; using EMIS.ViewModel.CultureplanManage.PlanManagement; using System.IO; using System.Text; using EMIS.Utility; using EMIS.ViewModel.EnrollManage.NewStudentManage; using EMIS.CommonLogic.SelectCourse; namespace EMIS.Web.Controllers.CultureplanManage.PlanManagement { [Authorization] public class OptionalCoursePlanController : Controller { public IOptionalCoursePlanServices optionalCourseSettingServices { get; set; } /// /// 限选计划页面 /// /// public ActionResult List() { return View(); } /// /// 查询列表 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var coursematerialID = pararms.getExtraGuid("CoursematerialIDDropdownGridBo"); var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown"); var schoolYearNumID = pararms.getExtraInt("DictionarySchoolYearNum") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolYearNum"); var schoolCodeID = pararms.getExtraInt("DictionarySchoolCode") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionarySchoolCode"); var isEnable = pararms.getExtraInt("DictionaryIsEnable") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsEnable"); var isOpen = pararms.getExtraInt("DictionaryIsOpen") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIsOpen"); var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation"); var learningFormID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform"); var LearnSystem = pararms.getExtraString("DictionaryLearnSystem"); return this.Json(optionalCourseSettingServices.GetOptionalCourseSettingViewGrid(configuretView, standardID, coursematerialID, schoolYearNumID, schoolCodeID, isEnable, isOpen, educationID, learningFormID,LearnSystem, (int)pararms.page, (int)pararms.rows)); } /// /// 编辑 /// /// public ActionResult Edit(Guid? optionalCoursePlanID) { OptionalCoursePlanView optionalCourseSettingView = new OptionalCoursePlanView(); if (optionalCoursePlanID.HasValue && optionalCoursePlanID != Guid.Empty) optionalCourseSettingView = optionalCourseSettingServices.GetOptionalCourseSettingView(optionalCoursePlanID); return View(optionalCourseSettingView); } /// /// 保存修改 /// /// /// [HttpPost] public ActionResult Edit(OptionalCoursePlanView optionalCourseSettingView) { try { optionalCourseSettingServices.OptionalCourseUpdate(optionalCourseSettingView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } [HttpPost] public ActionResult TeachingModeType(Guid? OptionalCourseID) { List list = new List(); if (OptionalCourseID.HasValue && OptionalCourseID != Guid.Empty) list = optionalCourseSettingServices.GetTeachingModeType(OptionalCourseID); else list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory).ToString()); return base.Json(list); } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string optionalCoursePlanIDs) { try { List list = new List(); for (int i = 0; i < optionalCoursePlanIDs.Split(',').Length; i++) { if (!string.IsNullOrEmpty(optionalCoursePlanIDs.Split(',')[i])) { Guid optionalCoursePlanID = new Guid(optionalCoursePlanIDs.Split(',')[i]); list.Add(optionalCoursePlanID); } } optionalCourseSettingServices.OptionalCourseDelete(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 Add(Guid? optionalCoursePlanID) { OptionalCoursePlanView optionalCourseSettingView = new OptionalCoursePlanView(); if (optionalCoursePlanID.HasValue && optionalCoursePlanID != Guid.Empty) { optionalCourseSettingView = optionalCourseSettingServices.GetOptionalCourseSettingView(optionalCoursePlanID); } //默认值 optionalCourseSettingView.CourseStructureID = 1; optionalCourseSettingView.CourseCategoryID = 2; optionalCourseSettingView.CourseTypeID = 4; optionalCourseSettingView.CourseQualityID = 5; optionalCourseSettingView.ExaminationModeID = (int)EMIS.ViewModel.CF_ExaminationMode.WrittenExam; optionalCourseSettingView.TeachinglanguageID = 1; optionalCourseSettingView.IsEnable = true; return View(optionalCourseSettingView); } /// /// 添加 /// /// /// [HttpPost] public ActionResult Add(OptionalCoursePlanView optionalCourseSettingView) { try { optionalCourseSettingServices.OptionalCourseAdd(optionalCourseSettingView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功!" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败:" + ex.Message }); } } /// ///导出Excel /// /// [HttpPost] public ActionResult Excel() { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["StandardDictionaryDropDown"].ParseStrTo(); var coursematerialID = Request.Form["CoursematerialIDDropdownGridBo"].ParseStrTo(); var schoolYearNumID = Request.Form["DictionarySchoolYearNum"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolYearNum"].ParseStrTo(); var schoolCodeID = Request.Form["DictionarySchoolCode"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolCode"].ParseStrTo(); var isEnable = Request.Form["DictionaryIsEnable"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEnable"].ParseStrTo(); var isOpen = Request.Form["DictionaryIsOpen"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsOpen"].ParseStrTo(); var educationID = Request.Form["DictionaryEducation"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo(); var learningFormID = Request.Form["DictionaryLearningform"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo(); var LearnSystem = ""; //Request.Form["DictionaryLearnSystem"].ToString(); var dt = optionalCourseSettingServices.GetOptionalCourseSettingViewList(configuretView, standardID, coursematerialID, schoolYearNumID, schoolCodeID, isEnable, isOpen,educationID,learningFormID, LearnSystem).Select(x => new { x.StandardCode, x.StandardName, x.CourseCode, x.CourseName, x.CourseTypeName, x.CourseCategoryName, x.CourseQualityName, x.SchoolcodeName, x.SchoolyearNumName, //x.Credit, //x.Totalhours, //x.TheoryCourse, //x.Practicehours, x.DepartmentName, x.IsEnableDesc, //x.IsOpenedDesc }).ToTable(); string[] liststring = { "专业代码", "专业名称", "课程代码","课程名称","课程类型","课程属性", "课程性质", "学期", //"学分","总学时","理论学时","实践学时", "开课年级","教研室","是否启用" //,"是否开放" }; neh.Export(dt, liststring, "限选计划信息"); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功!" }); } //#region 13.0 新生信息导入 //[HttpGet] //public ActionResult Import(string errorFile, string operationTips) //{ // ViewBag.ErrorFile = errorFile; // if (string.IsNullOrEmpty(operationTips)) // { // operationTips = "错误数据下载"; // } // ViewBag.operationTips = operationTips; // return View(); //} //[HttpPost] //public ActionResult Import(HttpPostedFileBase file) //{ // try // { // //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls // //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx // var accept = new[] { ".xls", ".xlsx" }; // var p = Path.GetExtension(file.FileName); // if (!accept.Contains(p)) // { // throw new Exception("只允许上传xls和xlsx格式的Excel文件!"); // } // Dictionary cellheader = new Dictionary // { // { "ExamineeNum", "考生号" }, { "Name", "姓名" }, // { "SexStr", "性别" }, { "NationStr", "民族" }, // { "PoliticsStr", "政治面貌" }, { "BirthDateStr", "出生日期" }, // { "CertificatesTypeStr", "证件类型" }, { "IDNumber", "证件号码" }, // { "EntranceDateStr", "入学日期" }, { "YearID", "年级" }, // { "StandardName", "专业名称" }, { "LearnSystemStr", "学制" }, // { "EducationStr", EMIS.Utility.RSL.Get("EducationID") }, { "LearningformStr", "学习形式" }, // { "ScoreStr", "总分" }, { "Telephone", "联系电话" }, // { "Address", "通讯地址" },{ "Remark", "备注" } // }; // 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; // otionalCourseSettingServices.OptionalCoursePlanImport(cellheader, out OkCount, out errList, out errCount, sourcePhysicalPath); // System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件 // if (errList.Count() > 0) // { // //将异常文件路径显示 // string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "新生信息导入失败文件", sourcePhysicalPath)); // 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() // }); // } //#endregion //} } }