123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMIS.CommonLogic.MinorManage;
- using EMIS.ViewModel;
- using EMIS.Web.Controls;
- using Bowin.Web.Controls.Mvc;
- using EMIS.ViewModel.MinorManage.MinorCourseManage;
- using Bowin.Common.Exceptions;
- using Bowin.Common.Utility;
- using EMIS.Utility;
- using Bowin.Common.Data;
- namespace EMIS.Web.Controllers.MinorManage
- {
- [Authorization]
- public class MinorSpecialtyCourseController : Controller
- {
- public IMinorSpecialtyCourseServices minorSpecialtyCourseServices { get; set; }
- //
- // GET: /MinorCourse/
- public ActionResult List()
- {
- return View();
- }
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
- var coursematerialID = pararms.getExtraGuid("CoursematerialIDDropdownGridBo");
- var startYearID = 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 departmentID = pararms.getExtraGuid("DepartmentDropdown");
- return this.Json(minorSpecialtyCourseServices.GetMinorSpecialtyCourseViewGrid(configuretView, standardID, coursematerialID, startYearID, schoolcodeID, departmentID, isEnable, (int)pararms.page, (int)pararms.rows));
- }
-
- /// <summary>
- /// 复制新增
- /// </summary>
- /// <param name="sourceMinorCourseID"></param>
- /// <returns></returns>
- public ActionResult CopyAdd(Guid sourceMinorCourseID)
- {
- MinorSpecialtyCourseView minorSpecialtyCourseView = new MinorSpecialtyCourseView();
- minorSpecialtyCourseView = minorSpecialtyCourseServices.GetMinorSpecialtyCourseView(sourceMinorCourseID);
- minorSpecialtyCourseView.MinorCourseID = null;
- return View("Edit", minorSpecialtyCourseView);
- }
- [HttpPost]
- public ActionResult CopyAdd(MinorSpecialtyCourseView minorSpecialtyCourseView)
- {
- return this.Edit(minorSpecialtyCourseView);
- }
-
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="MinorCourseID"></param>
- /// <returns></returns>
- public ActionResult Edit(Guid? MinorCourseID)
- {
- MinorSpecialtyCourseView minorSpecialtyCourseView = new MinorSpecialtyCourseView();
- if (MinorCourseID.HasValue)
- {
- minorSpecialtyCourseView = minorSpecialtyCourseServices.GetMinorSpecialtyCourseView(MinorCourseID);
- }
- else
- {
- minorSpecialtyCourseView.ResultTypeID = (int)CF_ResultType.Percentage;
- minorSpecialtyCourseView.Credit = 0;
- minorSpecialtyCourseView.TheoryCourse = 0;
- minorSpecialtyCourseView.Practicehours = 0;
- minorSpecialtyCourseView.Trialhours = 0;
- minorSpecialtyCourseView.Totalhours = 0;
- minorSpecialtyCourseView.TheoryWeeklyNum = 0;
- minorSpecialtyCourseView.PracticeWeeklyNum = 0;
- minorSpecialtyCourseView.TrialWeeklyNum = 0;
- minorSpecialtyCourseView.SchoolweeksNum = 0;
- minorSpecialtyCourseView.WeeklyHours = 0;
- minorSpecialtyCourseView.WeeklyNum = 0;
- minorSpecialtyCourseView.IsEnable = true;
- }
- return View(minorSpecialtyCourseView);
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="minorSpecialtyCourseView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(MinorSpecialtyCourseView minorSpecialtyCourseView)
- {
- try
- {
- minorSpecialtyCourseServices.MinorSpecialtyCourseAdd(minorSpecialtyCourseView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 获取已经存在在授课方式
- /// </summary>
- /// <param name="MinorCourseID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult TeachingModeType(Guid? MinorCourseID)
- {
- List<string> list = new List<string>();
- if (MinorCourseID.HasValue && MinorCourseID != Guid.Empty)
- list = minorSpecialtyCourseServices.GetTeachingModeType(MinorCourseID);
- else
- list.Add(((int)EMIS.ViewModel.CF_TeachingMode.Theory).ToString());
- return base.Json(list);
- }
- /// <summary>
- /// 获取已经存在在授课地点
- /// </summary>
- /// <param name="MinorCourseID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult TeachingPlace(Guid? MinorCourseID)
- {
- List<string> list = new List<string>();
- if (MinorCourseID.HasValue && MinorCourseID != Guid.Empty)
- list = minorSpecialtyCourseServices.GetTeachingPlace(MinorCourseID);
- return base.Json(list);
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="MinorCourseIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string MinorCourseIDs)
- {
- try
- {
- List<Guid?> list = new List<Guid?>();
- for (int i = 0; i < MinorCourseIDs.Split(',').Length; i++)
- {
- string id = MinorCourseIDs.Split(',')[i];
- if (!string.IsNullOrEmpty(id))
- {
- Guid MinorCourseID = new Guid(id);
- list.Add(MinorCourseID);
- }
- }
- minorSpecialtyCourseServices.MinorCourseDelete(list);
- return base.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 base.Json("删除失败,原因:" + mge);
- }
- }
- /// <summary>
- /// 导出Excel
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- var MinorCourseID = Request.Form["MinorCourseID"];
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["StandardDictionaryDropDown"].ParseStrTo<int>();
- var coursematerialID = Request.Form["CoursematerialIDDropdownGridBo"].ParseStrTo<Guid>();
- var startYearID = Request.Form["DictionarySchoolYearNum"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolYearNum"].ParseStrTo<int>();
- var schoolcodeID = Request.Form["DictionarySchoolcode"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionarySchoolcode"].ParseStrTo<int>();
- var isEnable = Request.Form["DictionaryIsEnable"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryIsEnable"].ParseStrTo<int>();
- var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
- List<Guid?> MinorCourseIDList = new List<Guid?>();
- if (MinorCourseID != "")
- {
- MinorCourseIDList = MinorCourseID.SplitIDString();
- }
- else
- {
- MinorCourseIDList = null;
- }
- var dt = minorSpecialtyCourseServices.GetMinorCourseViewList(configuretView, standardID, coursematerialID, startYearID, schoolcodeID, departmentID, isEnable, MinorCourseIDList).Select(x => new
- {
- x.SpecialtyCode,
- x.StandardName,
- x.CourseCode,
- x.CourseName,
- x.CourseTypeName,
- x.Credit,
- x.TheoryCourse,
- x.Practicehours,
- x.Trialhours,
- x.Totalhours,
- x.SchoolyearNumName,
- x.SchoolcodeName,
- x.DepartmentName,
- x.IsEnableName
- }).ToTable();
- string[] liststring = { "专业代码", "专业名称", "课程代码", "课程名称", "课程类型","学分",
- "理论学时","实践学时","实验学时","总学时","开课学年","开课学期","开课教研室","是否启用"};
- neh.Export(dt, liststring, "辅修课程信息");
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "导出成功。"
- });
- }
- #region 辅修课程信息导入
- [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
- if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
- {
- throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
- }
- #region 构建单元头
- Dictionary<string, string> cellheader = new Dictionary<string, string>
- {
- { "SpecialtyCodeStr", "专业代码" },
- { "StandardNameStr", "专业名称" },
- {"CourseCode","课程代码"}, { "CourseName", "课程名称" },
- { "DepartmentName", "教研室" }, { "SchoolyearNumNameStr", "授课年级" },
- { "SchoolcodeStr", "学期" }, { "CourseTypeStr", "课程类型" },
- { "CourseCategoryNameStr", "课程属性" }, { "CourseQualityNameStr", "课程性质" },
- { "CourseStructureNameStr", "课程结构" }, { "CreditStr", "学分" },
- { "TheoryCourseStr", "理论学时" }, { "PracticehoursStr", "实践学时" },
- { "TrialhoursStr", "实验学时" }, { "PracticeTypeNameStr", "实践方式" },
- { "ExaminationModeNameStr", "考试方式" },{ "ResultTypeNameStr", "成绩类型" },
- { "IsSpecialtycoreName", "是否专业核心" },{ "IsCooperationName", "是否校企开发" },
- { "IsRequiredName", "是否课证融通" },/*是否必修课*/{ "IsMainCourseName", "是否学位主干" },
- { "IsElectiveName", "是否选修" },{ "IsNetworkCourseName", "是否网络" },
- { "CourseFineNameStr", "精品课程" },{ "TeachinglanguageNameStr", "授课语言" },
- { "TeachingModeStr", "授课方式" },{ "TeachingPlaceStr", "授课地点" },
- { "Remarks", "备注" }, { "ErrorMessage", "错误信息" }
- };
- #endregion
- string sourceWebPath = FileUploadHelper.UploadFile(file);
- var sourcePhysicalPath = Server.MapPath(sourceWebPath);
- List<MinorSpecialtyCourseView> errList = new List<MinorSpecialtyCourseView>();
- int errCount = 0;
- int OkCount = 0;
- minorSpecialtyCourseServices.MinorSpecialtyCourseImport(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
- }
- }
|