TeachingMaterialPoolController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.TeachingMaterial;
  7. using EMIS.ViewModel;
  8. using EMIS.Web.Controls;
  9. using Bowin.Web.Controls.Mvc;
  10. using Bowin.Common.Utility;
  11. using EMIS.ViewModel.TeachingMaterial;
  12. using EMIS.CommonLogic.Cultureplan;
  13. using Bowin.Common.Data;
  14. using Bowin.Common.Exceptions;
  15. using System.IO;
  16. using EMIS.Utility;
  17. using System.Text;
  18. using EMIS.Entities;
  19. using Bowin.Common.Linq.Entity;
  20. using EMIS.ViewModel.Cultureplan;
  21. namespace EMIS.Web.Controllers.TeachingMaterial
  22. {
  23. [Authorization]
  24. public class TeachingMaterialPoolController : Controller
  25. {
  26. public ITeachingMaterialPoolServices TeachingMaterialPoolServices { get; set; }
  27. public ICoursematerialServices CoursematerialServices { get; set; }
  28. public ICoursematerialServices coursematerialServices { get; set; }
  29. /// <summary>
  30. /// 教材信息页面
  31. /// </summary>
  32. /// <returns></returns>
  33. [HttpGet]
  34. public ActionResult List()
  35. {
  36. return View();
  37. }
  38. public ActionResult StudentList()
  39. {
  40. return View();
  41. }
  42. /// <summary>
  43. /// 列表查询
  44. /// </summary>
  45. /// <param name="pararms"></param>
  46. /// <returns></returns>
  47. [HttpPost]
  48. public ActionResult List(QueryParamsModel pararms)
  49. {
  50. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  51. //避开全选值
  52. Guid? publishID = null;
  53. Guid? coursematerialID = null;
  54. bool? isLate = null;
  55. publishID = pararms.getExtraGuid("PublishDropdown");
  56. coursematerialID = pararms.getExtraGuid("CourseDropdown");
  57. if (pararms.getExtraInt("LateDropdown") != null && pararms.getExtraInt("LateDropdown") != DropdownList.SELECT_ALL)
  58. {
  59. isLate = pararms.getExtraInt("LateDropdown") == 1 ? true : false; ;
  60. }
  61. int? teachingMaterialType = pararms.getExtraInt("TeachingMaterialTypeDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("TeachingMaterialTypeDropdown");
  62. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  63. return base.Json(TeachingMaterialPoolServices.GetTeachingMaterialPoolViewGrid(configuretView, publishID, coursematerialID, isLate, teachingMaterialType, (int)pararms.page, (int)pararms.rows));
  64. }
  65. /// <summary>
  66. /// 列表查询
  67. /// </summary>
  68. /// <param name="pararms"></param>
  69. /// <returns></returns>
  70. [HttpPost]
  71. public ActionResult StudentList(QueryParamsModel pararms)
  72. {
  73. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  74. return base.Json(TeachingMaterialPoolServices.GetStudentTeachingMaterialViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
  75. }
  76. [HttpPost]
  77. public ActionResult Excel(QueryParamsModel pararms)
  78. {
  79. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  80. //避开全选值
  81. Guid? publishID = null;
  82. Guid? coursematerialID = null;
  83. bool? isLate = null;
  84. publishID = Request.Form["PublishDropdown"].ParseStrTo<Guid>();
  85. coursematerialID = Request.Form["CourseDropdown"].ParseStrTo<Guid>();
  86. if (Request.Form["LateDropdown"].ParseStrTo<int>() != null && Request.Form["LateDropdown"].ParseStrTo<int>() != DropdownList.SELECT_ALL)
  87. {
  88. isLate = Request.Form["LateDropdown"].ParseStrTo<int>() == 1 ? true : false; ;
  89. }
  90. int? teachingMaterialType = Request.Form["TeachingMaterialTypeDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["TeachingMaterialTypeDropdown"].ParseStrTo<int>();
  91. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  92. NpoiExcelHelper neh = new NpoiExcelHelper();
  93. var dt = TeachingMaterialPoolServices.GetTeachingMaterialPoolViewExcel(configuretView, publishID, coursematerialID, isLate, teachingMaterialType).Select(x => new
  94. {
  95. x.TeachingMaterialCode,
  96. x.CoursematerialCode,
  97. x.CoursematerialName,
  98. x.TeachingMaterialName,
  99. x.ISBN,
  100. x.TeachingMaterialTypeName,
  101. x.PublishTime,
  102. x.PublishName,
  103. x.Author,
  104. x.Price,
  105. x.IsLateName,
  106. x.Desc
  107. }).ToTable();
  108. string[] liststring = { "教材编号", "课程代码", "课程名称", "教材名称", "ISBN", "教材类型", "版本时间",
  109. "出版单位","作者","单价","是否过期","备注"};
  110. neh.Export(dt, liststring, "教材总库信息");
  111. return RedirectToAction("MsgShow", "Common", new
  112. {
  113. msg = "导出成功!",
  114. url = Url.Content("~/TeachingMaterialPool/List").AddMenuParameter()
  115. });
  116. }
  117. [HttpPost]
  118. public ActionResult StudentExcel(QueryParamsModel pararms)
  119. {
  120. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  121. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  122. NpoiExcelHelper neh = new NpoiExcelHelper();
  123. var dt = TeachingMaterialPoolServices.GetStudentTeachingMaterialViewList(configuretView).Select(x => new
  124. {
  125. x.SchoolYearCode,
  126. x.CourseName,
  127. x.TeachingMaterialName,
  128. x.PublishTime,
  129. x.ISBN,
  130. x.PublishName,
  131. x.Price
  132. }).ToTable();
  133. string[] liststring = { "学年学期", "课程名称", "教材名称", "版本", "ISBN", "出版单位", "价格" };
  134. neh.Export(dt, liststring, "课程教材信息");
  135. return RedirectToAction("MsgShow", "Common", new
  136. {
  137. msg = "导出成功!",
  138. url = Url.Content("~/ TeachingMaterialPool/StudentList").AddMenuParameter()
  139. });
  140. }
  141. /// <summary>
  142. /// 编辑页面
  143. /// </summary>
  144. /// <returns></returns>
  145. [HttpGet]
  146. public ActionResult Edit(Guid? teachingMaterialPoolID)
  147. {
  148. TeachingMaterialPoolView TeachingMaterialPoolView;
  149. if (teachingMaterialPoolID != null && teachingMaterialPoolID != Guid.Empty)
  150. {
  151. TeachingMaterialPoolView = TeachingMaterialPoolServices.GetSingleTeachingMaterialPool(teachingMaterialPoolID.Value);
  152. }
  153. else
  154. {
  155. string code = TeachingMaterialPoolServices.GetLastTeachingMaterialCode();
  156. TeachingMaterialPoolView = new TeachingMaterialPoolView()
  157. {
  158. TeachingMaterialPoolID = Guid.Empty,
  159. TeachingMaterialCode = code,
  160. IsLate = false
  161. };
  162. }
  163. return View(TeachingMaterialPoolView);
  164. }
  165. /// <summary>
  166. /// 新增
  167. /// </summary>
  168. /// <returns></returns>
  169. [HttpPost]
  170. public ActionResult Edit(TeachingMaterialPoolView TeachingMaterialPoolView)
  171. {
  172. try
  173. {
  174. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  175. var coursematerialList = DataGrid.GetTableData<CoursematerialView>("dgCoursematerialList");
  176. if (coursematerialList.Count == 0)
  177. {
  178. throw new Exception("没有选择课程");
  179. }
  180. TeachingMaterialPoolServices.EditTeachingMaterialPool(TeachingMaterialPoolView, user.UserID, coursematerialList);
  181. return Json(new ReturnMessage()
  182. {
  183. IsSuccess = true,
  184. Message = "保存成功!"
  185. });
  186. }
  187. catch (Exception ex)
  188. {
  189. return Json(new ReturnMessage()
  190. {
  191. IsSuccess = false,
  192. Message = "保存失败,原因:" + ex.Message + "!"
  193. });
  194. }
  195. }
  196. /// <summary>
  197. /// 删除
  198. /// </summary>
  199. /// <param name="roleID"></param>
  200. /// <returns></returns>
  201. [HttpPost]
  202. public ActionResult Delete(string teachingMaterialPoolIDs)
  203. {
  204. try
  205. {
  206. var TeachingMaterialPoolIDList = teachingMaterialPoolIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
  207. TeachingMaterialPoolServices.DeleteTeachingMaterialPool(TeachingMaterialPoolIDList);
  208. return base.Json("删除成功");
  209. }
  210. catch (Exception ex)
  211. {
  212. string mge = ex.Message;
  213. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  214. if (num != null)
  215. {
  216. if (num.Number == 547)
  217. mge = "请先删除所有关联的数据,如:教材入库单,出库单等";
  218. }
  219. return base.Json("删除失败,原因:" + mge + "!");
  220. }
  221. }
  222. /// <summary>
  223. /// 查询教材对应的课程信息
  224. /// </summary>
  225. /// <param name="pararms"></param>
  226. /// <returns></returns>
  227. [HttpPost]
  228. public ActionResult GetTeachingMaterialPoolCoursematerialList(Guid? teachingMaterialPoolID)
  229. {
  230. var coursematerialViewList = TeachingMaterialPoolServices.GetTeachingMaterialCoursematerialList(teachingMaterialPoolID);
  231. return base.Json(new GridResultSet<CoursematerialView> { rows = coursematerialViewList, total = coursematerialViewList.Count });
  232. }
  233. /// <summary>
  234. /// 查询没有过期的教材信息(下拉框条件为出版单位和课程)
  235. /// </summary>
  236. /// <param name="pararms"></param>
  237. /// <returns></returns>
  238. [HttpPost]
  239. public ActionResult GetTeachingMaterialPoolIsEffectiveList(QueryParamsModel pararms)
  240. {
  241. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  242. //避开全选值
  243. Guid? publishID = null;
  244. Guid? coursematerialID = null;
  245. string ISBN = null;
  246. string teachingMaterialName = null;
  247. publishID = pararms.getExtraGuid("PublishDropdown");
  248. coursematerialID = pararms.getExtraGuid("hidCoursematerialID");
  249. ISBN = pararms.getExtraString("txtISBN");
  250. teachingMaterialName = pararms.getExtraString("TeachingMaterialName");
  251. var isCheck = pararms.getExtraString("isCheck") == null ? "true" : pararms.getExtraString("isCheck");
  252. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  253. return base.Json(TeachingMaterialPoolServices.GetTeachingMaterialPoolForOrder(configuretView, publishID, ISBN, coursematerialID, teachingMaterialName, isCheck, (int)pararms.page, (int)pararms.rows));
  254. }
  255. /// <summary>
  256. /// 查询启用的课程资料信息
  257. /// </summary>
  258. /// <param name="pararms"></param>
  259. /// <returns></returns>
  260. [HttpPost]
  261. public ActionResult CoursematerialList(QueryParamsModel pararms)
  262. {
  263. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  264. var courseScienceID = pararms.getExtraInt("DictionaryCourseScience") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseScience");
  265. var courseLevelID = pararms.getExtraInt("DictionaryCourseLevel") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryCourseLevel");
  266. var isEnable = 1;
  267. return base.Json(coursematerialServices.GetCoursematerialViewGrid(configuretView, courseLevelID, courseScienceID, null, isEnable, (int)pararms.page, (int)pararms.rows));
  268. }
  269. #region 13.0 教材信息导入
  270. [HttpGet]
  271. public ActionResult Import(string errorFile, string operationTips)
  272. {
  273. ViewBag.ErrorFile = errorFile;
  274. if (string.IsNullOrEmpty(operationTips))
  275. {
  276. operationTips = "错误数据下载";
  277. }
  278. ViewBag.operationTips = operationTips;
  279. return View();
  280. }
  281. [HttpPost]
  282. public ActionResult Import(HttpPostedFileBase file)
  283. {
  284. try
  285. {
  286. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  287. {
  288. throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
  289. }
  290. var excel = new NpoiExcelHelper();
  291. #region 表单头
  292. Dictionary<string, string> cellheader = new Dictionary<string, string>
  293. {
  294. { "TeachingMaterialCode", "教材编号" },
  295. { "CoursematerialName", "课程名称" },
  296. { "TeachingMaterialName", "教材名称" },
  297. { "PublishTime", "版本时间" },
  298. { "PublishName", "出版单位" }, { "Author", "作者" },
  299. { "ISBN", "ISBN" },
  300. { "Price", "单价" }, { "TeachingMaterialTypeName", "教材类型" },
  301. { "WnningLevelName", "获奖级别" }, { "Desc", "备注" }, { "ErrorMessage", "错误信息" }
  302. };
  303. #endregion
  304. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  305. string sourceWebPath = FileUploadHelper.UploadFile(file);
  306. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  307. List<TeachingMaterialPoolImportView> errList = new List<TeachingMaterialPoolImportView>();
  308. List<TeachingMaterialPoolImportView> dataList = new List<TeachingMaterialPoolImportView>();
  309. int errCount = 0;
  310. int OkCount = 0;
  311. TeachingMaterialPoolServices.TeachingMaterialPoolImport(cellheader, out errCount, out errList, out OkCount, sourcePhysicalPath);
  312. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  313. if (errCount > 0)
  314. {
  315. var errorPhysicalPath = sourcePhysicalPath;
  316. var errorWebPaths = sourceWebPath;
  317. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教材操作失败文件", errorWebPaths));
  318. ViewBag.ErrorFile = errorWebPath;
  319. string Errinfo = string.Format("提示:成功导入{0}条记录,失败{1}条,详情请点击错误数据下载查看。", OkCount < 1 ? 0 : OkCount, errCount < 1 ? 0 : errCount);
  320. ViewBag.operationTips = Errinfo;
  321. // //return RedirectToAction("Import", new { errorFile = errorWebPath, operationTips = Errinfo });
  322. return RedirectToAction("MsgShow", "Common", new
  323. {
  324. WindowID = "none",
  325. msg = "导入失败!",
  326. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  327. });
  328. }
  329. else
  330. {
  331. return RedirectToAction("MsgShow", "Common", new
  332. {
  333. WindowID = Request["WindowID"],
  334. msg = "导入成功!",
  335. url = Url.Action("List").AddMenuParameter()
  336. });
  337. }
  338. }
  339. catch (Exception ex)
  340. {
  341. return RedirectToAction("MsgShow", "Common", new
  342. {
  343. WindowID = Request["WindowID"],
  344. msg = "导入失败,原因:" + ex.Message + "!",
  345. url = Url.Action("List").AddMenuParameter()
  346. });
  347. }
  348. #endregion
  349. }
  350. }
  351. }