LibraryController.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Bowin.Common.Utility;
  7. using Bowin.Common.Data;
  8. using Bowin.Web.Controls.Mvc;
  9. using EMIS.Web.Controls;
  10. using EMIS.Utility;
  11. using EMIS.ViewModel;
  12. using EMIS.ViewModel.TeachingMaterial;
  13. using EMIS.CommonLogic.TeachingMaterial;
  14. using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan;
  15. namespace EMIS.Web.Controllers.TeachingMaterial
  16. {
  17. [Authorization]
  18. public class LibraryController : Controller
  19. {
  20. public ILibraryServices LibraryServices { get; set; }
  21. public ICampusServices CampusServices { get; set; }
  22. /// <summary>
  23. /// 书库信息页面
  24. /// </summary>
  25. /// <returns></returns>
  26. [HttpGet]
  27. public ActionResult List()
  28. {
  29. return View();
  30. }
  31. /// <summary>
  32. /// 列表查询
  33. /// </summary>
  34. /// <param name="pararms"></param>
  35. /// <returns></returns>
  36. [HttpPost]
  37. public ActionResult List(QueryParamsModel pararms)
  38. {
  39. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  40. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  41. return base.Json(LibraryServices.GetLibraryViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
  42. }
  43. [HttpPost]
  44. public ActionResult Excel(QueryParamsModel pararms)
  45. {
  46. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  47. if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
  48. NpoiExcelHelper neh = new NpoiExcelHelper();
  49. var dt = LibraryServices.GetLibraryViewExcel(configuretView).Select(x => new
  50. {
  51. x.LibraryCode,
  52. x.LibraryName,
  53. x.CampusName,
  54. x.HeadPeople,
  55. x.ContectTelNumber,
  56. x.CreateTime,
  57. x.CreateUserName
  58. }).ToTable();
  59. string[] liststring = { "书库编号", "书库名称", RSL.Get("CampusName"), "负责人", "联系电话", "创建时间", "创建人" };
  60. neh.Export(dt, liststring, "书库信息");
  61. return RedirectToAction("MsgShow", "Common", new
  62. {
  63. msg = "导出成功!",
  64. url = Url.Content("~/ Library/List").AddMenuParameter()
  65. });
  66. }
  67. /// <summary>
  68. /// 编辑页面
  69. /// </summary>
  70. /// <returns></returns>
  71. [HttpGet]
  72. public ActionResult Edit(Guid? libraryID)
  73. {
  74. LibraryView libraryView;
  75. if (libraryID != null && libraryID != Guid.Empty)
  76. {
  77. libraryView = LibraryServices.GetSingleLibrary(libraryID.Value);
  78. }
  79. else
  80. {
  81. libraryView = new LibraryView()
  82. {
  83. LibraryID = Guid.Empty
  84. };
  85. }
  86. return View(libraryView);
  87. }
  88. /// <summary>
  89. /// 新增
  90. /// </summary>
  91. /// <returns></returns>
  92. [HttpPost]
  93. public ActionResult Edit(LibraryView libraryView)
  94. {
  95. try
  96. {
  97. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  98. LibraryServices.EditLibrary(libraryView, user.UserID);
  99. return Json(new ReturnMessage()
  100. {
  101. IsSuccess = true,
  102. Message = "保存成功!"
  103. });
  104. }
  105. catch (Exception ex)
  106. {
  107. return Json(new ReturnMessage()
  108. {
  109. IsSuccess = false,
  110. Message = "保存失败,原因:" + ex.Message + "!"
  111. });
  112. }
  113. }
  114. /// <summary>
  115. /// 删除
  116. /// </summary>
  117. /// <param name="roleID"></param>
  118. /// <returns></returns>
  119. [HttpPost]
  120. public ActionResult Delete(string libraryIDs)
  121. {
  122. try
  123. {
  124. var libraryIDList = libraryIDs.Split(',').Select(x => (Guid)new Guid(x)).ToList();
  125. LibraryServices.DeleteLibrary(libraryIDList);
  126. return base.Json("删除成功");
  127. }
  128. catch (Exception ex)
  129. {
  130. return base.Json("删除失败,原因:" + ex.Message + "。");
  131. }
  132. }
  133. [HttpPost]
  134. public ActionResult GetCampusCodeByCampusID(Guid campusID)
  135. {
  136. string campusCode = string.Empty;
  137. var campus = CampusServices.GetCampusList()
  138. .Where(x => x.CampusID == campusID).SingleOrDefault();
  139. if (campus != null)
  140. {
  141. campusCode = campus.No;
  142. }
  143. return base.Json(campusCode);
  144. }
  145. }
  146. }