CollegeController.cs 22 KB

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