DepartmentController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using Bowin.Common.Data;
  8. using Bowin.Common.Exceptions;
  9. using Bowin.Common.Utility;
  10. using Bowin.Web.Controls.Mvc;
  11. using EMIS.Utility;
  12. using EMIS.Web.Controls;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.UniversityManage.AdministrativeOrgan;
  15. using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan;
  16. namespace EMIS.Web.Controllers.UniversityManage.AdministrativeOrgan
  17. {
  18. [Authorization]
  19. public class DepartmentController : Controller
  20. {
  21. public IDepartmentServices DepartmentServices { 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 collegeID = pararms.getExtraGuid("CollegeDropdown");
  41. return base.Json(DepartmentServices.GetDepartmentViewGrid(configuretView, campusID, collegeID, (int)pararms.page, (int)pararms.rows));
  42. }
  43. /// <summary>
  44. /// 查询教研室信息View(无数据范围)
  45. /// </summary>
  46. /// <param name="pararms"></param>
  47. /// <returns></returns>
  48. [HttpPost]
  49. public ActionResult ListGridResultSet(QueryParamsModel pararms)
  50. {
  51. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  52. var campusID = pararms.getExtraGuid("CampusDropdown");
  53. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  54. return base.Json(DepartmentServices.GetDepartmentViewWithoutRange(configuretView, campusID, collegeID, (int)pararms.page, (int)pararms.rows));
  55. }
  56. /// <summary>
  57. /// 根据院系所信息ID获取教研室信息(带数据范围)
  58. /// </summary>
  59. /// <param name="bindType"></param>
  60. /// <param name="collegeID"></param>
  61. /// <returns></returns>
  62. [HttpPost]
  63. public ActionResult DepartmentDropdownListBanid(DropdownListBindType? bindType, Guid? collegeID)
  64. {
  65. List<DropdownListItem> list = null;
  66. if (collegeID == null)
  67. {
  68. list = new List<DropdownListItem>();
  69. }
  70. else
  71. {
  72. list = DepartmentServices.GetDepartmentList(collegeID)
  73. .Select(x => new DropdownListItem
  74. {
  75. Text = x.Name,
  76. Value = x.DepartmentID.ToString()
  77. }).ToList();
  78. }
  79. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  80. DropdownList.FormatDropdownItemList(dbt, list);
  81. return base.Json(list);
  82. }
  83. /// <summary>
  84. /// 查询全部部门信息DepartmentView(带数据范围)
  85. /// </summary>
  86. /// <param name="bindType"></param>
  87. /// <param name="collegeID"></param>
  88. /// <returns></returns>
  89. [HttpPost]
  90. public ActionResult DepartmentDropdownAllBanid(DropdownListBindType? bindType)
  91. {
  92. List<DropdownListItem> list = DepartmentServices.GetDepartmentList()
  93. .Select(x => new DropdownListItem
  94. {
  95. Text = x.Name,
  96. Value = x.DepartmentID.ToString()
  97. }).ToList();
  98. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  99. DropdownList.FormatDropdownItemList(dbt, list);
  100. return base.Json(list);
  101. }
  102. /// <summary>
  103. /// 根据学院ID获取部门绑定到combogrid控件
  104. /// </summary>
  105. /// <param name="pararms"></param>
  106. /// <param name="collegeID"></param>
  107. /// <returns></returns>
  108. [HttpPost]
  109. public ActionResult DepartmentComBoGrid(QueryParamsModel pararms, Guid? collegeID)
  110. {
  111. collegeID = collegeID == null ? Guid.Empty : collegeID;
  112. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  113. return base.Json(DepartmentServices.GetDepartmentViewGrid(configuretView, Guid.Empty, (Guid)collegeID, (int)pararms.page, (int)pararms.rows));
  114. }
  115. /// <summary>
  116. /// 期末、补考设定教研室查询
  117. /// </summary>
  118. /// <param name="ClassmajorID"></param>
  119. /// <param name="CoursematerialID"></param>
  120. /// <returns></returns>
  121. [HttpPost]
  122. public ActionResult ListForExamination(Guid? ClassmajorID, Guid? CoursematerialID)
  123. {
  124. return base.Json(DepartmentServices.GetDepartmentListForExamination(ClassmajorID, CoursematerialID));
  125. }
  126. /// <summary>
  127. /// 复制新增
  128. /// </summary>
  129. /// <param name="departmentID"></param>
  130. /// <returns></returns>
  131. public ActionResult CopyAdd(Guid departmentID)
  132. {
  133. DepartmentView departmentView = new DepartmentView();
  134. departmentView = DepartmentServices.GetDepartmentView(departmentID);
  135. return View("Edit", departmentView);
  136. }
  137. /// <summary>
  138. /// 复制新增
  139. /// </summary>
  140. /// <param name="departmentView"></param>
  141. /// <returns></returns>
  142. [HttpPost]
  143. public ActionResult CopyAdd(DepartmentView departmentView)
  144. {
  145. departmentView.DepartmentID = Guid.Empty;
  146. return this.Edit(departmentView);
  147. }
  148. /// <summary>
  149. /// 编辑(新增、修改,业务主键:部门代码或部门名称)
  150. /// </summary>
  151. /// <param name="departmentID"></param>
  152. /// <returns></returns>
  153. [HttpGet]
  154. public ActionResult Edit(Guid? departmentID)
  155. {
  156. DepartmentView departmentView = new DepartmentView();
  157. if (departmentID.HasValue && departmentID != Guid.Empty)
  158. {
  159. departmentView = DepartmentServices.GetDepartmentView(departmentID);
  160. }
  161. return View(departmentView);
  162. }
  163. /// <summary>
  164. /// 编辑(新增、修改,业务主键:部门代码或部门名称)
  165. /// </summary>
  166. /// <param name="departmentView"></param>
  167. /// <returns></returns>
  168. [HttpPost]
  169. public ActionResult Edit(DepartmentView departmentView)
  170. {
  171. try
  172. {
  173. DepartmentServices.DepartmentEdit(departmentView);
  174. return Json(new ReturnMessage()
  175. {
  176. IsSuccess = true,
  177. Message = "保存成功。"
  178. });
  179. }
  180. catch (Exception ex)
  181. {
  182. return Json(new ReturnMessage()
  183. {
  184. IsSuccess = false,
  185. Message = "保存失败,原因:" + ex.Message
  186. });
  187. }
  188. }
  189. /// <summary>
  190. /// 删除
  191. /// </summary>
  192. /// <param name="departmentIDs"></param>
  193. /// <returns></returns>
  194. [HttpPost]
  195. public ActionResult Delete(string departmentIDs)
  196. {
  197. try
  198. {
  199. List<Guid?> list = departmentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  200. DepartmentServices.DepartmentDelete(list);
  201. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  202. }
  203. catch (Exception ex)
  204. {
  205. string mge = ex.Message;
  206. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  207. if (num != null)
  208. {
  209. if (num.Number == 547)
  210. {
  211. mge = "请先删除所有关联的数据,如教师信息等。";
  212. }
  213. }
  214. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  215. }
  216. }
  217. /// <summary>
  218. /// Excel导入
  219. /// </summary>
  220. /// <param name="errorFile"></param>
  221. /// <param name="operationTips"></param>
  222. /// <returns></returns>
  223. [HttpGet]
  224. public ActionResult Import(string errorFile, string operationTips)
  225. {
  226. ViewBag.ErrorFile = errorFile;
  227. if (string.IsNullOrEmpty(operationTips))
  228. {
  229. operationTips = "点击查看失败原因...";
  230. }
  231. ViewBag.operationTips = operationTips;
  232. return View();
  233. }
  234. /// <summary>
  235. /// Excel导入
  236. /// </summary>
  237. /// <param name="file"></param>
  238. /// <returns></returns>
  239. [HttpPost]
  240. public ActionResult Import(HttpPostedFileBase file)
  241. {
  242. try
  243. {
  244. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  245. {
  246. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  247. }
  248. Dictionary<string, string> cellheader = new Dictionary<string, string>
  249. {
  250. { "No", "教研室代码" },
  251. { "Name", "教研室名称" },
  252. { "SimpleName", "教研室简称" },
  253. { "EnglishName", "英文名称" },
  254. { "CollegeCode", RSL.Get("CollegeCode") },
  255. { "DirectorName", "主任姓名" },
  256. { "DeputyDirectorName", "副主任姓名" },
  257. { "FoundDateStr", "创建年月" },
  258. { "Remark", "备注" },
  259. { "ErrorMessage", "未导入原因" }
  260. };
  261. StringBuilder errorMsg = new StringBuilder();
  262. string sourceWebPath = FileUploadHelper.UploadFile(file);
  263. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  264. List<DepartmentView> errList = new List<DepartmentView>();
  265. List<DepartmentView> dataList = new List<DepartmentView>();
  266. int? inCount = 0; //导入个数
  267. int? upCount = 0; //更新个数
  268. int? errCount = 0; //失败个数
  269. //导入
  270. DepartmentServices.DepartmentImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  271. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  272. if (errList.Count() > 0)
  273. {
  274. //获取错误数据文件路径
  275. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教研室信息导入失败文件", sourcePhysicalPath));
  276. ViewBag.ErrorFile = errorWebPath;
  277. string Errinfo = string.Format("提示:{0}条教研室信息导入成功,{1}条教研室信息更新成功,{2}条教研室信息导入失败,点击查看。", inCount, upCount, errCount);
  278. ViewBag.operationTips = Errinfo;
  279. return RedirectToAction("MsgShow", "Common", new
  280. {
  281. WindowID = "none",
  282. msg = Errinfo,
  283. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  284. });
  285. }
  286. else
  287. {
  288. string successInfo = string.Format("提示:{0}条教研室信息导入成功,{1}条教研室信息更新成功。", inCount, upCount);
  289. return RedirectToAction("MsgShow", "Common", new
  290. {
  291. WindowID = Request["WindowID"],
  292. msg = successInfo,
  293. url = Url.Action("List").AddMenuParameter()
  294. });
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. return RedirectToAction("MsgShow", "Common", new
  300. {
  301. WindowID = "none",
  302. msg = "导入失败,原因:" + ex.Message,
  303. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  304. });
  305. }
  306. }
  307. /// <summary>
  308. /// 教研室对应的教师信息
  309. /// </summary>
  310. /// <returns></returns>
  311. public ActionResult StaffList()
  312. {
  313. return View();
  314. }
  315. /// <summary>
  316. /// 教研室对应的教师信息
  317. /// </summary>
  318. /// <param name="pararms"></param>
  319. /// <returns></returns>
  320. [HttpPost]
  321. public ActionResult StaffList(QueryParamsModel pararms)
  322. {
  323. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  324. var departmentID = Request["departmentID"].ParseStrTo<Guid>();
  325. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  326. var isPhotoUrl = pararms.getExtraInt("IsPhotoUrlDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsPhotoUrlDropdown");
  327. var teacherTypeID = pararms.getExtraInt("DictionaryTeacherType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTeacherType");
  328. var incumbencyState = pararms.getExtraInt("DictionaryIncumbencyState") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIncumbencyState");
  329. var titleID = pararms.getExtraInt("DictionaryTitle") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTitle");
  330. var isDualTeacher = pararms.getExtraInt("IsDualTeacherDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsDualTeacherDropdown");
  331. return base.Json(DepartmentServices.GetStaffListViewGrid(configuretView, collegeID, departmentID, isPhotoUrl, teacherTypeID, incumbencyState, titleID, isDualTeacher, (int)pararms.page, (int)pararms.rows));
  332. }
  333. /// <summary>
  334. /// 教研室对应的教师信息Excel导出
  335. /// </summary>
  336. /// <returns></returns>
  337. [HttpPost]
  338. public ActionResult StaffListExcel()
  339. {
  340. return null;
  341. }
  342. /// <summary>
  343. /// Excel导出
  344. /// </summary>
  345. /// <returns></returns>
  346. [HttpPost]
  347. public ActionResult Excel()
  348. {
  349. NpoiExcelHelper neh = new NpoiExcelHelper();
  350. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  351. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  352. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  353. var dt = DepartmentServices.GetDepartmentViewList(configuretView, campusID, collegeID)
  354. .Select(x => new
  355. {
  356. x.No,
  357. x.Name,
  358. x.SimpleName,
  359. x.CollegeCode,
  360. x.CollegeName,
  361. x.DirectorName,
  362. x.DeputyDirectorName,
  363. FoundDate = x.FoundDate == null ? null : x.FoundDate.Value.ToString("yyyy-MM-dd"),
  364. x.StaffCount,
  365. x.Remark
  366. }).ToTable();
  367. string[] liststring = {
  368. "教研室代码", "教研室名称", "教研室简称",
  369. RSL.Get("CollegeCode"), RSL.Get("CollegeName"),
  370. "主任姓名", "副主任", "创建年月", "教师人数", "备注"
  371. };
  372. neh.Export(dt, liststring, "教研室信息" + DateTime.Now.ToString("yyyyMMdd"));
  373. return Json(new ReturnMessage()
  374. {
  375. IsSuccess = true,
  376. Message = "导出成功。"
  377. });
  378. }
  379. }
  380. }