CollegeController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.Web.Controls;
  7. using Bowin.Common.JSON;
  8. using EMIS.Entities;
  9. using Bowin.Common.Linq.Entity;
  10. using EMIS.CommonLogic.AdministrativeOrgan;
  11. using EMIS.ViewModel;
  12. using EMIS.CommonLogic.SystemServices;
  13. using Bowin.Web.Controls.Mvc;
  14. using Bowin.Common.Utility;
  15. using System.Data;
  16. using Bowin.Common.Data;
  17. using Bowin.Common.Exceptions;
  18. using EMIS.Utility;
  19. using System.Text;
  20. using EMIS.CommonLogic.DataCenterSynch;
  21. namespace EMIS.Web.Controllers.AdministrativeOrgan
  22. {
  23. [Authorization]
  24. public class CollegeController : Controller
  25. {
  26. public ICollegeServices CollegeServices { get; set; }
  27. public ICollegeSynchServices CollegeSynchServices { get; set; }
  28. /// <summary>
  29. /// 院系所信息页面
  30. /// </summary>
  31. /// <returns></returns>
  32. public ActionResult List()
  33. {
  34. return View();
  35. }
  36. /// <summary>
  37. /// 院系所信息列表查询
  38. /// </summary>
  39. /// <param name="pararms"></param>
  40. /// <returns></returns>
  41. [HttpPost]
  42. public ActionResult List(QueryParamsModel pararms)
  43. {
  44. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  45. var campusID = pararms.getExtraGuid("CampusDropdown");
  46. var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory");
  47. return base.Json(CollegeServices.GetCollegeViewGrid(configuretView, campusID, unitCategoryID, (int)pararms.page, (int)pararms.rows));
  48. }
  49. /// <summary>
  50. /// 院系所信息列表查询(只显示院、系、部类别的院系所)
  51. /// </summary>
  52. /// <param name="pararms"></param>
  53. /// <returns></returns>
  54. [HttpPost]
  55. public ActionResult ListOnlyCollege(QueryParamsModel pararms)
  56. {
  57. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  58. var campusID = pararms.getExtraGuid("CampusDropdown");
  59. return base.Json(CollegeServices.GetOnlyCollegeViewList(configuretView, campusID, (int)pararms.page, (int)pararms.rows));
  60. }
  61. /// <summary>
  62. /// 查询院系所信息View(无数据范围)
  63. /// </summary>
  64. /// <param name="pararms"></param>
  65. /// <returns></returns>
  66. [HttpPost]
  67. public ActionResult ListWithoutRange(QueryParamsModel pararms)
  68. {
  69. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  70. var campusID = pararms.getExtraGuid("CampusDropdown");
  71. return base.Json(CollegeServices.GetCollegeViewWithoutRange(configuretView, campusID, (int)pararms.page, (int)pararms.rows));
  72. }
  73. /// <summary>
  74. /// 根据校区获取学院(带数据范围)
  75. /// </summary>
  76. /// <param name="bindType"></param>
  77. /// <param name="campusID"></param>
  78. /// <returns></returns>
  79. [HttpPost]
  80. public ActionResult CollegeDropdownListBanid(DropdownListBindType? bindType, Guid? campusID)
  81. {
  82. List<DropdownListItem> list = null;
  83. list = CollegeServices.GetCollegeList(campusID)
  84. .Select(x => new DropdownListItem
  85. {
  86. Text = x.Name,
  87. Value = x.CollegeID.ToString()
  88. }).ToList();
  89. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  90. DropdownList.FormatDropdownItemList(dbt, list);
  91. return base.Json(list);
  92. }
  93. /// <summary>
  94. /// 根据校区获取学院(无数据范围)
  95. /// </summary>
  96. /// <param name="bindType"></param>
  97. /// <param name="campusID"></param>
  98. /// <returns></returns>
  99. [HttpPost]
  100. public ActionResult AllCollegeDropdownListBanid(DropdownListBindType? bindType, Guid? campusID)
  101. {
  102. List<DropdownListItem> list = CollegeServices.GetAllCollegeList(campusID)
  103. .Select(x => new DropdownListItem
  104. {
  105. Text = x.Name,
  106. Value = x.CollegeID.ToString()
  107. }).ToList();
  108. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  109. DropdownList.FormatDropdownItemList(dbt, list);
  110. return base.Json(list);
  111. }
  112. /// <summary>
  113. /// 院系所下拉列表
  114. /// </summary>
  115. /// <param name="bindType"></param>
  116. /// <returns></returns>
  117. [HttpPost]
  118. public ActionResult CollegeDropdownListBanids(DropdownListBindType? bindType)
  119. {
  120. List<DropdownListItem> list = new List<DropdownListItem>();
  121. list = CollegeServices.GetCollegeList()
  122. .Select(x => new DropdownListItem
  123. {
  124. Text = x.Name,
  125. Value = x.CollegeID.ToString()
  126. }).ToList();
  127. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  128. DropdownList.FormatDropdownItemList(dbt, list);
  129. return base.Json(list);
  130. }
  131. /// <summary>
  132. /// 院系所下拉列表(只显示院、系、部类别的院系所)
  133. /// </summary>
  134. /// <param name="bindType"></param>
  135. /// <returns></returns>
  136. [HttpPost]
  137. public ActionResult CollegeDropdownListOnlyCollege(DropdownListBindType? bindType)
  138. {
  139. List<DropdownListItem> list = new List<DropdownListItem>();
  140. list = CollegeServices.GetOnlyCollegeList()
  141. .Select(x => new DropdownListItem
  142. {
  143. Text = x.Name,
  144. Value = x.CollegeID.ToString()
  145. }).ToList();
  146. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  147. DropdownList.FormatDropdownItemList(dbt, list);
  148. return base.Json(list);
  149. }
  150. /// <summary>
  151. /// 获取学院(无数据范围限制)
  152. /// </summary>
  153. [HttpPost]
  154. public ActionResult CollegeDropdownListBanidsWithoutRange(DropdownListBindType? bindType)
  155. {
  156. List<DropdownListItem> list = new List<DropdownListItem>();
  157. list = CollegeServices.GetCollegeViewListWithoutDataRange()
  158. .Select(x => new DropdownListItem
  159. {
  160. Text = x.Name,
  161. Value = x.CollegeID.ToString()
  162. }).ToList();
  163. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  164. DropdownList.FormatDropdownItemList(dbt, list);
  165. return base.Json(list);
  166. }
  167. /// <summary>
  168. /// 复制新增
  169. /// </summary>
  170. /// <param name="collegeID"></param>
  171. /// <returns></returns>
  172. public ActionResult CopyAdd(Guid collegeID)
  173. {
  174. CollegeView collegeView = new CollegeView();
  175. collegeView = CollegeServices.GetCollegeView(collegeID);
  176. return View("Edit", collegeView);
  177. }
  178. /// <summary>
  179. /// 复制新增
  180. /// </summary>
  181. /// <param name="collegeView"></param>
  182. /// <returns></returns>
  183. [HttpPost]
  184. public ActionResult CopyAdd(CollegeView collegeView)
  185. {
  186. collegeView.CollegeID = Guid.Empty;
  187. return this.Edit(collegeView);
  188. }
  189. /// <summary>
  190. /// 编辑(新增、修改,业务主键:院系所代码或院系所名称)
  191. /// </summary>
  192. /// <param name="collegeID"></param>
  193. /// <returns></returns>
  194. [HttpGet]
  195. public ActionResult Edit(Guid? collegeID)
  196. {
  197. //临时性加参数控制、屏蔽列表进入无保存按钮权限
  198. ViewBag.Type = Request.Params["Type"];
  199. CollegeView collegeView = new CollegeView();
  200. if (collegeID.HasValue && collegeID != Guid.Empty)
  201. {
  202. collegeView = CollegeServices.GetCollegeView(collegeID);
  203. }
  204. else
  205. {
  206. collegeView.UnitCategoryID = (int)CF_UnitCategory.College;
  207. }
  208. return View(collegeView);
  209. }
  210. /// <summary>
  211. /// 编辑(新增、修改,业务主键:院系所代码或院系所名称)
  212. /// </summary>
  213. /// <param name="collegeView"></param>
  214. /// <returns></returns>
  215. [HttpPost]
  216. public ActionResult Edit(CollegeView collegeView)
  217. {
  218. try
  219. {
  220. CollegeServices.CollegeEdit(collegeView);
  221. return Json(new ReturnMessage()
  222. {
  223. IsSuccess = true,
  224. Message = "保存成功。"
  225. });
  226. }
  227. catch (Exception ex)
  228. {
  229. return Json(new ReturnMessage()
  230. {
  231. IsSuccess = false,
  232. Message = "保存失败,原因:" + ex.Message
  233. });
  234. }
  235. }
  236. /// <summary>
  237. /// 删除
  238. /// </summary>
  239. /// <param name="collegeIDs"></param>
  240. /// <returns></returns>
  241. [HttpPost]
  242. public ActionResult Delete(string collegeIDs)
  243. {
  244. try
  245. {
  246. List<Guid?> list = collegeIDs.Split(',').Where(x => !string.IsNullOrEmpty(x))
  247. .Select(x => (Guid?)new Guid(x)).ToList();
  248. CollegeServices.CollegeDelete(list);
  249. return base.Json("删除成功。");
  250. }
  251. catch (Exception ex)
  252. {
  253. string mge = ex.Message;
  254. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  255. if (num != null)
  256. {
  257. if (num.Number == 547)
  258. {
  259. mge = "请先删除与其关联的数据,如:教研室等";
  260. }
  261. }
  262. return base.Json("删除失败,原因:" + mge);
  263. }
  264. }
  265. /// <summary>
  266. /// Excel导出
  267. /// </summary>
  268. /// <param name="pararms"></param>
  269. /// <returns></returns>
  270. [HttpPost]
  271. public ActionResult Excel(CollegeView pararms)
  272. {
  273. NpoiExcelHelper neh = new NpoiExcelHelper();
  274. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  275. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  276. var unitCategoryID = Request.Form["DictionaryUnitCategory"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryUnitCategory"].ParseStrTo<int>();
  277. var dt = CollegeServices.GetCollegeViewList(configuretView, campusID, unitCategoryID)
  278. .Select(x => new
  279. {
  280. x.No,
  281. x.Name,
  282. x.SimpleName,
  283. x.CampusNo,
  284. x.CampusName,
  285. x.PoliticalManagerName,
  286. x.AdministrativeManagerName,
  287. x.UnitCategoryName,
  288. x.FoundDate,
  289. x.Officephone,
  290. x.Remark,
  291. }).ToTable();
  292. string[] liststring = {
  293. RSL.Get("CollegeCode"), RSL.Get("CollegeName"), "简称",
  294. RSL.Get("CampusCode"), RSL.Get("CampusName"), "党务负责人",
  295. "行政负责人", "单位类别", "建立年月","办公电话", "备注"
  296. };
  297. neh.Export(dt, liststring, RSL.Get("College") + "信息" + DateTime.Now.ToString("yyyyMMdd"));
  298. return Json(new ReturnMessage()
  299. {
  300. IsSuccess = true,
  301. Message = "导出成功。"
  302. });
  303. }
  304. /// <summary>
  305. /// Excel导入
  306. /// </summary>
  307. /// <param name="errorFile"></param>
  308. /// <param name="operationTips"></param>
  309. /// <returns></returns>
  310. [HttpGet]
  311. public ActionResult Import(string errorFile, string operationTips)
  312. {
  313. ViewBag.ErrorFile = errorFile;
  314. if (string.IsNullOrEmpty(operationTips))
  315. {
  316. operationTips = "点击查看失败原因...";
  317. }
  318. ViewBag.operationTips = operationTips;
  319. return View();
  320. }
  321. /// <summary>
  322. /// Excel导入
  323. /// </summary>
  324. /// <param name="file"></param>
  325. /// <returns></returns>
  326. [HttpPost]
  327. public ActionResult Import(HttpPostedFileBase file)
  328. {
  329. try
  330. {
  331. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  332. {
  333. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  334. }
  335. Dictionary<string, string> cellheader = new Dictionary<string, string>
  336. {
  337. { "No", RSL.Get("CollegeCode") },
  338. { "Name", RSL.Get("CollegeName") },
  339. { "SimpleName", "简称" },
  340. { "EnglishName", "英文名称" },
  341. { "CampusNo", RSL.Get("CampusCode") },
  342. { "PoliticalManagerName", "党务负责人" },
  343. { "AdministrativeManagerName", "行政负责人" },
  344. { "UnitCategoryStr", "单位类别" },
  345. { "FoundDateStr", "建立年月" },
  346. { "Officephone", "办公电话" },
  347. { "Remark", "备注" },
  348. { "ErrorMessage", "未导入原因" }
  349. };
  350. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  351. string sourceWebPath = FileUploadHelper.UploadFile(file);
  352. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  353. List<CollegeView> errList = new List<CollegeView>();
  354. List<CollegeView> dataList = new List<CollegeView>();
  355. int? inCount = 0; //导入个数
  356. int? upCount = 0; //更新个数
  357. int? errCount = 0; //失败个数
  358. //导入
  359. CollegeServices.CollegeImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  360. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  361. if (errList.Count() > 0)
  362. {
  363. //获取错误数据文件路径
  364. string errorWebPath = string.Format("{0}", NpoiExcelHelper
  365. .EntityListToExcel2003(cellheader, errList, RSL.Get("College") + "导入失败文件", sourcePhysicalPath));
  366. ViewBag.ErrorFile = errorWebPath;
  367. string Errinfo = string.Format("提示:{0}条" + RSL.Get("College") + "导入成功,{1}条" + RSL.Get("College") + "更新成功,{2}条" + RSL.Get("College") + "导入失败,点击查看。",
  368. inCount, upCount, errCount);
  369. ViewBag.operationTips = Errinfo;
  370. return RedirectToAction("MsgShow", "Common", new
  371. {
  372. WindowID = "none",
  373. msg = Errinfo,
  374. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips="
  375. + Errinfo + "&WindowID=" + Request["WindowID"]
  376. });
  377. }
  378. else
  379. {
  380. string successInfo = string.Format("提示:{0}条" + RSL.Get("College") + "导入成功,{1}条" + RSL.Get("College") + "更新成功。", inCount, upCount);
  381. return RedirectToAction("MsgShow", "Common", new
  382. {
  383. WindowID = Request["WindowID"],
  384. msg = successInfo,
  385. url = Url.Action("List").AddMenuParameter()
  386. });
  387. }
  388. }
  389. catch (Exception ex)
  390. {
  391. return RedirectToAction("MsgShow", "Common", new
  392. {
  393. WindowID = "none",
  394. msg = "导入失败,原因:" + ex.Message,
  395. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  396. });
  397. }
  398. }
  399. [HttpPost]
  400. public ActionResult Synchr()
  401. {
  402. try
  403. {
  404. CollegeSynchServices.Synchr();
  405. return Json(new ReturnMessage { IsSuccess = true, Message = "同步成功。" });
  406. }
  407. catch (Exception ex)
  408. {
  409. return Json(new ReturnMessage { IsSuccess = false, Message = "同步失败:" + ex.Message + ex.InnerException?.Message ?? "" + ex.StackTrace });
  410. }
  411. }
  412. }
  413. }