UniversityController.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.Data;
  7. using Bowin.Common.Exceptions;
  8. using Bowin.Common.Utility;
  9. using Bowin.Web.Controls.Mvc;
  10. using EMIS.Utility;
  11. using EMIS.Web.Controls;
  12. using EMIS.ViewModel;
  13. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  14. using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan;
  15. namespace EMIS.Web.Controllers.UniversityManage.AdministrativeOrgan
  16. {
  17. [Authorization]
  18. public class UniversityController : Controller
  19. {
  20. public IUniversityServices UniversityServices { get; set; }
  21. /// <summary>
  22. /// 学校信息页面
  23. /// </summary>
  24. /// <returns></returns>
  25. public ActionResult List()
  26. {
  27. return View();
  28. }
  29. /// <summary>
  30. /// 学校信息列表查询
  31. /// </summary>
  32. /// <param name="pararms"></param>
  33. /// <returns></returns>
  34. [HttpPost]
  35. public ActionResult List(QueryParamsModel pararms)
  36. {
  37. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  38. return base.Json(UniversityServices.GetUniversityViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
  39. }
  40. /// <summary>
  41. /// 学校信息下拉查询
  42. /// </summary>
  43. /// <param name="pararms"></param>
  44. /// <returns></returns>
  45. [HttpPost]
  46. public ActionResult DropdownListBanid()
  47. {
  48. List<DropdownListItem> list = UniversityServices.GetUniversityList().Select(x => new DropdownListItem
  49. {
  50. Text = x.Name,
  51. Value = x.UniversityID.ToString()
  52. }).ToList();
  53. return base.Json(list);
  54. }
  55. /// <summary>
  56. /// 复制新增
  57. /// </summary>
  58. /// <param name="universityID"></param>
  59. /// <returns></returns>
  60. public ActionResult CopyAdd(Guid universityID)
  61. {
  62. UniversityView universityView = new UniversityView();
  63. universityView = UniversityServices.GetUniversityView(universityID);
  64. return View("Edit", universityView);
  65. }
  66. /// <summary>
  67. /// 复制新增
  68. /// </summary>
  69. /// <param name="universityView"></param>
  70. /// <returns></returns>
  71. [HttpPost]
  72. public ActionResult CopyAdd(UniversityView universityView)
  73. {
  74. universityView.UniversityID = Guid.Empty;
  75. return this.Edit(universityView);
  76. }
  77. /// <summary>
  78. /// 编辑(新增、修改,业务主键:学校代码或学校名称)
  79. /// </summary>
  80. /// <param name="universityID"></param>
  81. /// <returns></returns>
  82. [HttpGet]
  83. public ActionResult Edit(Guid? universityID)
  84. {
  85. UniversityView universityView = new UniversityView();
  86. if (universityID != null && universityID != Guid.Empty)
  87. {
  88. universityView = UniversityServices.GetUniversityView(universityID);
  89. }
  90. return View(universityView);
  91. }
  92. /// <summary>
  93. /// 编辑(新增、修改,业务主键:学校代码或学校名称)
  94. /// </summary>
  95. /// <param name="pararms"></param>
  96. /// <returns></returns>
  97. [HttpPost]
  98. public ActionResult Edit(UniversityView universityView)
  99. {
  100. try
  101. {
  102. UniversityServices.UniversityEdit(universityView);
  103. return Json(new ReturnMessage()
  104. {
  105. IsSuccess = true,
  106. Message = "保存成功。"
  107. });
  108. }
  109. catch (Exception ex)
  110. {
  111. return Json(new ReturnMessage()
  112. {
  113. IsSuccess = false,
  114. Message = "保存失败,原因:" + ex.Message
  115. });
  116. }
  117. }
  118. /// <summary>
  119. /// 删除
  120. /// </summary>
  121. /// <param name="universityID"></param>
  122. /// <returns></returns>
  123. [HttpPost]
  124. public ActionResult Delete(string universityIDs)
  125. {
  126. try
  127. {
  128. List<Guid?> list = universityIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  129. UniversityServices.UniversityDelete(list);
  130. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  131. }
  132. catch (Exception ex)
  133. {
  134. string mge = ex.Message;
  135. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  136. if (num != null)
  137. {
  138. if (num.Number == 547)
  139. {
  140. mge = "请先删除与其有关联的数据,如:" + RSL.Get("Campus") + "、" + RSL.Get("College") + "等。";
  141. }
  142. }
  143. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  144. }
  145. }
  146. /// <summary>
  147. /// Excel导出
  148. /// </summary>
  149. /// <param name="pararms"></param>
  150. /// <returns></returns>
  151. [HttpPost]
  152. public ActionResult Excel(UniversityView pararms)
  153. {
  154. NpoiExcelHelper neh = new NpoiExcelHelper();
  155. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  156. var dt = UniversityServices.GetUniversityViewList(configuretView)
  157. .Select(x => new
  158. {
  159. x.Code,
  160. x.Name,
  161. x.SimpleName,
  162. x.EnglishName,
  163. x.ProvinceName,
  164. x.CityName,
  165. x.HeadMasterName,
  166. x.PartyManageName,
  167. x.Telephone,
  168. x.ZIPCode,
  169. x.FAX,
  170. x.Email,
  171. x.BuildDate,
  172. x.SchoolMotto,
  173. x.HistoryEvolution,
  174. x.HomePage,
  175. x.Address,
  176. x.EnglishAddress,
  177. x.Remark
  178. }).ToTable();
  179. string[] liststring = {
  180. "学校代码", "学校名称", "学校简称", "英文名称", "所属省份", "所属市", "校长",
  181. "党务负责人", "联系电话", "邮政编码", "传真", "电子邮件", "创校日期", "校训",
  182. "历史沿革", "主页地址", "学校地址" , "学校英文地址", "备注"
  183. };
  184. neh.Export(dt, liststring, "学校信息" + DateTime.Now.ToString("yyyyMMdd"));
  185. return Json(new ReturnMessage()
  186. {
  187. IsSuccess = true,
  188. Message = "导出成功。"
  189. });
  190. }
  191. }
  192. }