123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using EMIS.CommonLogic.TeachingMaterial;
- using EMIS.ViewModel;
- using EMIS.Web.Controls;
- using Bowin.Web.Controls.Mvc;
- using Bowin.Common.Utility;
- using EMIS.ViewModel.TeachingMaterial;
- using EMIS.CommonLogic.Cultureplan;
- using Bowin.Common.Data;
- using Bowin.Common.Exceptions;
- using System.IO;
- using EMIS.Utility;
- using System.Text;
- using EMIS.Entities;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.Cultureplan;
- namespace EMIS.Web.Controllers.TeachingMaterial
- {
- [Authorization]
- public class TeachingMaterialPoolController : Controller
- {
- public ITeachingMaterialPoolServices TeachingMaterialPoolServices { get; set; }
- public ICoursematerialServices CoursematerialServices { get; set; }
- public ICoursematerialServices coursematerialServices { get; set; }
- /// <summary>
- /// 教材信息页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult List()
- {
- return View();
- }
- public ActionResult StudentList()
- {
- return View();
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- Guid? publishID = null;
- Guid? coursematerialID = null;
- bool? isLate = null;
- publishID = pararms.getExtraGuid("PublishDropdown");
- coursematerialID = pararms.getExtraGuid("CourseDropdown");
- if (pararms.getExtraInt("LateDropdown") != null && pararms.getExtraInt("LateDropdown") != DropdownList.SELECT_ALL)
- {
- isLate = pararms.getExtraInt("LateDropdown") == 1 ? true : false; ;
- }
- int? teachingMaterialType = pararms.getExtraInt("TeachingMaterialTypeDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("TeachingMaterialTypeDropdown");
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(TeachingMaterialPoolServices.GetTeachingMaterialPoolViewGrid(configuretView, publishID, coursematerialID, isLate, teachingMaterialType, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult StudentList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- return base.Json(TeachingMaterialPoolServices.GetStudentTeachingMaterialViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
- }
- [HttpPost]
- public ActionResult Excel(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- //避开全选值
- Guid? publishID = null;
- Guid? coursematerialID = null;
- bool? isLate = null;
- publishID = Request.Form["PublishDropdown"].ParseStrTo<Guid>();
- coursematerialID = Request.Form["CourseDropdown"].ParseStrTo<Guid>();
- if (Request.Form["LateDropdown"].ParseStrTo<int>() != null && Request.Form["LateDropdown"].ParseStrTo<int>() != DropdownList.SELECT_ALL)
- {
- isLate = Request.Form["LateDropdown"].ParseStrTo<int>() == 1 ? true : false; ;
- }
- int? teachingMaterialType = Request.Form["TeachingMaterialTypeDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["TeachingMaterialTypeDropdown"].ParseStrTo<int>();
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- NpoiExcelHelper neh = new NpoiExcelHelper();
- var dt = TeachingMaterialPoolServices.GetTeachingMaterialPoolViewExcel(configuretView, publishID, coursematerialID, isLate, teachingMaterialType).Select(x => new
- {
- x.TeachingMaterialCode,
- x.CoursematerialCode,
- x.CoursematerialName,
- x.TeachingMaterialName,
- x.ISBN,
- x.TeachingMaterialTypeName,
- x.PublishTime,
- x.PublishName,
- x.Author,
- x.Price,
- x.IsLateName,
- x.Desc
- }).ToTable();
- string[] liststring = { "教材编号", "课程代码", "课程名称", "教材名称", "ISBN", "教材类型", "版本时间",
- "出版单位","作者","单价","是否过期","备注"};
- neh.Export(dt, liststring, "教材总库信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/TeachingMaterialPool/List").AddMenuParameter()
- });
- }
- [HttpPost]
- public ActionResult StudentExcel(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- NpoiExcelHelper neh = new NpoiExcelHelper();
- var dt = TeachingMaterialPoolServices.GetStudentTeachingMaterialViewList(configuretView).Select(x => new
- {
- x.SchoolYearCode,
- x.CourseName,
- x.TeachingMaterialName,
- x.PublishTime,
- x.ISBN,
- x.PublishName,
- x.Price
- }).ToTable();
- string[] liststring = { "学年学期", "课程名称", "教材名称", "版本", "ISBN", "出版单位", "价格" };
- neh.Export(dt, liststring, "课程教材信息");
- return RedirectToAction("MsgShow", "Common", new
- {
- msg = "导出成功!",
- url = Url.Content("~/ TeachingMaterialPool/StudentList").AddMenuParameter()
- });
- }
- /// <summary>
- /// 编辑页面
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edit(Guid? teachingMaterialPoolID)
- {
- TeachingMaterialPoolView TeachingMaterialPoolView;
- if (teachingMaterialPoolID != null && teachingMaterialPoolID != Guid.Empty)
- {
- TeachingMaterialPoolView = TeachingMaterialPoolServices.GetSingleTeachingMaterialPool(teachingMaterialPoolID.Value);
- }
- else
- {
- string code = TeachingMaterialPoolServices.GetLastTeachingMaterialCode();
- TeachingMaterialPoolView = new TeachingMaterialPoolView()
- {
- TeachingMaterialPoolID = Guid.Empty,
- TeachingMaterialCode = code,
- IsLate = false
- };
- }
- return View(TeachingMaterialPoolView);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(TeachingMaterialPoolView TeachingMaterialPoolView)
- {
- try
- {
- var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
- var coursematerialList = DataGrid.GetTableData<CoursematerialView>("dgCoursematerialList");
- if (coursematerialList.Count == 0)
- {
- throw new Exception("没有选择课程");
- }
- TeachingMaterialPoolServices.EditTeachingMaterialPool(TeachingMaterialPoolView, user.UserID, coursematerialList);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功!"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败,原因:" + ex.Message + "!"
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="roleID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string teachingMaterialPoolIDs)
- {
- try
- {
- var TeachingMaterialPoolIDList = teachingMaterialPoolIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
- TeachingMaterialPoolServices.DeleteTeachingMaterialPool(TeachingMaterialPoolIDList);
- 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>
- /// 查询教材对应的课程信息
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetTeachingMaterialPoolCoursematerialList(Guid? teachingMaterialPoolID)
- {
- var coursematerialViewList = TeachingMaterialPoolServices.GetTeachingMaterialCoursematerialList(teachingMaterialPoolID);
- return base.Json(new GridResultSet<CoursematerialView> { rows = coursematerialViewList, total = coursematerialViewList.Count });
- }
- /// <summary>
- /// 查询没有过期的教材信息(下拉框条件为出版单位和课程)
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetTeachingMaterialPoolIsEffectiveList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //避开全选值
- Guid? publishID = null;
- Guid? coursematerialID = null;
- string ISBN = null;
- string teachingMaterialName = null;
- publishID = pararms.getExtraGuid("PublishDropdown");
- coursematerialID = pararms.getExtraGuid("hidCoursematerialID");
- ISBN = pararms.getExtraString("txtISBN");
- teachingMaterialName = pararms.getExtraString("TeachingMaterialName");
- var isCheck = pararms.getExtraString("isCheck") == null ? "true" : pararms.getExtraString("isCheck");
- if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
- return base.Json(TeachingMaterialPoolServices.GetTeachingMaterialPoolForOrder(configuretView, publishID, ISBN, coursematerialID, teachingMaterialName, isCheck, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 查询启用的课程资料信息
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult CoursematerialList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var courseScienceID = pararms.getExtraInt("DictionaryCourseScience") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseScience");
- var courseLevelID = pararms.getExtraInt("DictionaryCourseLevel") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseLevel");
- var isEnable = 1;
- return base.Json(coursematerialServices.GetCoursematerialViewGrid(configuretView, courseLevelID, courseScienceID, null, isEnable, (int)pararms.page, (int)pararms.rows));
- }
- #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
- {
- if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
- {
- throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
- }
- var excel = new NpoiExcelHelper();
- #region 表单头
- Dictionary<string, string> cellheader = new Dictionary<string, string>
- {
- { "TeachingMaterialCode", "教材编号" },
- { "CoursematerialName", "课程名称" },
- { "TeachingMaterialName", "教材名称" },
- { "PublishTime", "版本时间" },
- { "PublishName", "出版单位" }, { "Author", "作者" },
- { "ISBN", "ISBN" },
- { "Price", "单价" }, { "TeachingMaterialTypeName", "教材类型" },
- { "WnningLevelName", "获奖级别" }, { "Desc", "备注" }, { "ErrorMessage", "错误信息" }
- };
- #endregion
- StringBuilder errorMsg = new StringBuilder(); // 错误信息
- string sourceWebPath = FileUploadHelper.UploadFile(file);
- var sourcePhysicalPath = Server.MapPath(sourceWebPath);
- List<TeachingMaterialPoolImportView> errList = new List<TeachingMaterialPoolImportView>();
- List<TeachingMaterialPoolImportView> dataList = new List<TeachingMaterialPoolImportView>();
- int errCount = 0;
- int OkCount = 0;
- TeachingMaterialPoolServices.TeachingMaterialPoolImport(cellheader, out errCount, out errList, out OkCount, 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()
- });
- }
- #endregion
- }
- }
- }
|