StaffController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web.Mvc;
  5. using Bowin.Common.Data;
  6. using Bowin.Common.Exceptions;
  7. using Bowin.Common.Utility;
  8. using Bowin.Web.Controls.Mvc;
  9. using EMIS.CommonLogic.AdministrativeOrgan;
  10. using EMIS.CommonLogic.SystemServices;
  11. using EMIS.CommonLogic.TeacherManagement;
  12. using EMIS.Utility;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.TeacherManagement;
  15. using EMIS.Web.Controls;
  16. using System.Web;
  17. using System.IO;
  18. using System.Text;
  19. using Bowin.Common.DataTime;
  20. namespace EMIS.Web.Controllers.UserManagement
  21. {
  22. [Authorization]
  23. public class StaffController : Controller
  24. {
  25. public Lazy<IStaffServices> staffServices { get; set; }
  26. public Lazy<IUserServices> userServices { get; set; }
  27. public Lazy<ICampusServices> campusServices { get; set; }
  28. public Lazy<ICollegeServices> collegeServices { get; set; }
  29. public Lazy<IDepartmentServices> departmentServices { get; set; }
  30. /// <summary>
  31. /// 教师信息页面
  32. /// </summary>
  33. /// <returns></returns>
  34. public ActionResult List()
  35. {
  36. return View();
  37. }
  38. /// <summary>
  39. /// 列表查询
  40. /// </summary>
  41. /// <param name="pararms"></param>
  42. /// <returns></returns>
  43. [HttpPost]
  44. public ActionResult List(QueryParamsModel pararms)
  45. {
  46. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  47. var userID = pararms.getExtraGuid("SaffDropdown");
  48. var campusID = pararms.getExtraGuid("CampusDropdown");
  49. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  50. var departmentID = pararms.getExtraGuid("DepartmentDropdown");
  51. var isphotoUrl = pararms.getExtraInt("PhotoUrltmentDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("PhotoUrltmentDropdown");
  52. return base.Json(staffServices.Value.GetStaffViewGrid(configuretView, campusID, collegeID, departmentID, isphotoUrl, userID, (int)pararms.page, (int)pararms.rows));
  53. }
  54. /// <summary>
  55. /// 列表查询
  56. /// </summary>
  57. /// <param name="pararms"></param>
  58. /// <returns></returns>
  59. [HttpPost]
  60. public ActionResult ListWithNoDataRange(QueryParamsModel pararms)
  61. {
  62. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  63. var userID = pararms.getExtraGuid("SaffDropdown");
  64. var campusID = pararms.getExtraGuid("CampusDropdown");
  65. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  66. var departmentID = pararms.getExtraGuid("DepartmentDropdown");
  67. var isphotoUrl = pararms.getExtraInt("PhotoUrltmentDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("PhotoUrltmentDropdown");
  68. return base.Json(staffServices.Value.GetStaffViewGridWithNoDataRange(configuretView, campusID, collegeID, departmentID, isphotoUrl, userID, (int)pararms.page, (int)pararms.rows));
  69. }
  70. /// <summary>
  71. ///
  72. /// </summary>
  73. /// <param name="pararms"></param>
  74. /// <returns></returns>
  75. [HttpPost]
  76. public ActionResult ListForTeacherEdit(QueryParamsModel pararms)
  77. {
  78. var campusID = pararms.getExtraGuid("CampusDropdown");
  79. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  80. var loginID = pararms.getExtraString("LoginID");
  81. var name = pararms.getExtraString("Name");
  82. return base.Json(staffServices.Value.GetStaffViewGrid(campusID, collegeID, loginID, name, (int)pararms.page, (int)pararms.rows));
  83. }
  84. /// <summary>
  85. /// 编辑页面
  86. /// </summary>
  87. /// <returns></returns>
  88. [HttpGet]
  89. public ActionResult Edit(Guid? userID)
  90. {
  91. ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
  92. StaffView staffView = new StaffView();
  93. if (userID.HasValue)
  94. staffView = staffServices.Value.GetStaffView(userID.Value);
  95. return View(staffView);
  96. }
  97. /// <summary>
  98. /// 新增
  99. /// </summary>
  100. /// <param name="facultymajorView"></param>
  101. /// <returns></returns>
  102. [HttpPost]
  103. public ActionResult Edit(StaffView staffView)
  104. {
  105. try
  106. {
  107. var accepts = new List<string> { ".jpg" };
  108. var postedFile = Request.Files["PhotoUrl"];
  109. if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
  110. {
  111. throw new Exception("只允许上传.jpg格式的文件。");
  112. }
  113. string photoUrl = FileUploadHelper.UploadFile(postedFile);
  114. staffServices.Value.StaffAdd(staffView, photoUrl);
  115. return RedirectToAction("MsgShow", "Common", new
  116. {
  117. WindowID = Request["WindowID"],
  118. msg = "保存成功。",
  119. url = Url.Action("List").AddMenuParameter()
  120. });
  121. }
  122. catch (Exception ex)
  123. {
  124. return RedirectToAction("MsgShow", "Common", new
  125. {
  126. WindowID = Request["WindowID"],
  127. msg = "保存失败,原因:" + ex.Message + "。",
  128. url = Url.Action("List").AddMenuParameter()
  129. });
  130. }
  131. }
  132. /// <summary>
  133. /// 编辑页面
  134. /// </summary>
  135. /// <returns></returns>
  136. [HttpGet]
  137. public ActionResult Edits(Guid? userID)
  138. {
  139. ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
  140. StaffView staffView = new StaffView();
  141. if (userID.HasValue)
  142. staffView = staffServices.Value.GetStaffView(userID.Value);
  143. return View(staffView);
  144. }
  145. /// <summary>
  146. /// 新增
  147. /// </summary>
  148. /// <param name="facultymajorView"></param>
  149. /// <returns></returns>
  150. [HttpPost]
  151. public ActionResult Edits(StaffView staffView)
  152. {
  153. try
  154. {
  155. var accepts = new List<string> { ".jpg" };
  156. var postedFile = Request.Files["PhotoUrl"];
  157. if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
  158. {
  159. throw new Exception("只允许上传.jpg格式的文件。");
  160. }
  161. string photoUrl = FileUploadHelper.UploadFile(postedFile);
  162. staffServices.Value.StaffAdd(staffView, photoUrl);
  163. return RedirectToAction("MsgShow", "Common", new
  164. {
  165. WindowID = Request["WindowID"],
  166. msg = "保存成功。",
  167. url = Url.Action("List").AddMenuParameter()
  168. });
  169. }
  170. catch (Exception ex)
  171. {
  172. return RedirectToAction("MsgShow", "Common", new
  173. {
  174. WindowID = Request["WindowID"],
  175. msg = "保存失败,原因:" + ex.Message + "。",
  176. url = Url.Action("List").AddMenuParameter()
  177. });
  178. }
  179. }
  180. /// <summary>
  181. /// 删除
  182. /// </summary>
  183. /// <param name="facultymajorView"></param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. public ActionResult Delete(string userIDs)
  187. {
  188. try
  189. {
  190. List<Guid> list = new List<Guid>();
  191. for (int i = 0; i < userIDs.Split(',').Length; i++)
  192. {
  193. string id = userIDs.Split(',')[i];
  194. if (!string.IsNullOrEmpty(id))
  195. {
  196. Guid userID = new Guid(id);
  197. list.Add(userID);
  198. }
  199. }
  200. staffServices.Value.StaffDelete(list);
  201. return base.Json("删除成功。");
  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. mge = "请先删除所有关联的数据,如:班级信息、课程信息等";
  211. }
  212. return base.Json("删除失败,原因:" + mge + "。");
  213. }
  214. }
  215. /// <summary>
  216. /// 添加更新前验证
  217. /// </summary>
  218. /// <param name="universityID"></param>
  219. /// <param name="code"></param>
  220. /// <returns></returns>
  221. [HttpPost]
  222. public ActionResult Verification(Guid? userID, string Code, Guid? CollegeID, Guid? DepartmentID)
  223. {
  224. return Json(staffServices.Value.GetVerification(userID, Code, CollegeID, DepartmentID));
  225. }
  226. [HttpPost]
  227. public ActionResult DeletePhoto(Guid userID)
  228. {
  229. try
  230. {
  231. this.staffServices.Value.DeletePhoto(userID);
  232. return Json(new ReturnMessage()
  233. {
  234. IsSuccess = true,
  235. Message = "删除成功。"
  236. });
  237. }
  238. catch (Exception ex)
  239. {
  240. return Json(new ReturnMessage()
  241. {
  242. IsSuccess = false,
  243. Message = "删除失败:" + ex.Message
  244. });
  245. }
  246. }
  247. /// <summary>
  248. /// 获取教师信息
  249. /// </summary>
  250. [HttpPost]
  251. public ActionResult GetStaffDataBind(DropdownListBindType? bindType, Guid? userID)
  252. {
  253. List<DropdownListItem> list = null;
  254. if (userID == null)
  255. list = new List<DropdownListItem>();
  256. else
  257. list = staffServices.Value.GetListStaffView(userID).Select(x => new DropdownListItem { Text = x.Name, Value = x.UserID.ToString() }).ToList();
  258. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  259. DropdownList.FormatDropdownItemList(dbt, list);
  260. return base.Json(list);
  261. }
  262. /// <summary>
  263. /// 获取教师信息
  264. /// </summary>
  265. [HttpPost]
  266. public ActionResult GetAllStaffDataBind(QueryParamsModel pararms)
  267. {
  268. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  269. return base.Json(staffServices.Value.GetAllStaffView(configuretView, (int)pararms.page, (int)pararms.rows));
  270. }
  271. /// <summary>
  272. /// 获取教师信息
  273. /// </summary>
  274. [HttpPost]
  275. public ActionResult GetDepartmentStaffDataBind(DropdownListBindType? bindType, Guid? departmentID)
  276. {
  277. List<DropdownListItem> list = null;
  278. if (departmentID == null)
  279. list = new List<DropdownListItem>();
  280. else
  281. list = staffServices.Value.GetStaffViewList(new ConfiguretView(), null, null, departmentID, null)
  282. .Select(x => new DropdownListItem { Text = x.Name, Value = x.UserID.ToString() }).ToList();
  283. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  284. DropdownList.FormatDropdownItemList(dbt, list);
  285. return base.Json(list);
  286. }
  287. /// <summary>
  288. /// 教师信息Excel导入
  289. /// </summary>
  290. /// <param name="errorFile"></param>
  291. /// <param name="operationTips"></param>
  292. /// <returns></returns>
  293. [HttpGet]
  294. public ActionResult Import(string errorFile, string operationTips)
  295. {
  296. ViewBag.ErrorFile = errorFile;
  297. if (string.IsNullOrEmpty(operationTips))
  298. {
  299. operationTips = "错误数据下载";
  300. }
  301. ViewBag.operationTips = operationTips;
  302. return View();
  303. }
  304. [HttpPost]
  305. public ActionResult Import(HttpPostedFileBase file)
  306. {
  307. try
  308. {
  309. //1.0 HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls
  310. //2.0 XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx
  311. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  312. {
  313. throw new Exception("只允许上传xls和xlsx格式的Excel文件!");
  314. }
  315. StringBuilder errorMsg = new StringBuilder(); // 错误信息
  316. string sourceWebPath = FileUploadHelper.UploadFile(file);
  317. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  318. List<StaffView> errList = new List<StaffView>();
  319. int errCount = 0;//失败条数
  320. int OkCount = 0;//成功条数
  321. string errorWebPath = "";
  322. string Errinfo = "";
  323. staffServices.Value.StaffImport(out errCount, out errList, out OkCount, sourcePhysicalPath,sourceWebPath,out errorWebPath,out Errinfo);
  324. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  325. if (errCount > 0)
  326. {
  327. ViewBag.ErrorFile = errorWebPath;
  328. ViewBag.operationTips = Errinfo;
  329. return RedirectToAction("MsgShow", "Common", new
  330. {
  331. WindowID = "none",
  332. msg = "导入失败!",
  333. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  334. });
  335. }
  336. else
  337. {
  338. return RedirectToAction("MsgShow", "Common", new
  339. {
  340. WindowID = Request["WindowID"],
  341. msg = "导入成功!",
  342. url = Url.Action("List").AddMenuParameter()
  343. });
  344. }
  345. }
  346. catch (Exception ex)
  347. {
  348. return RedirectToAction("MsgShow", "Common", new
  349. {
  350. WindowID = Request["WindowID"],
  351. msg = "导入失败,原因:" +ex.Message + "!",
  352. url = Url.Action("List").AddMenuParameter()
  353. });
  354. }
  355. }
  356. /// <summary>
  357. /// Excel导出
  358. /// </summary>
  359. /// <param name="pararms"></param>
  360. /// <returns></returns>
  361. [HttpPost]
  362. public ActionResult Excel()
  363. {
  364. NpoiExcelHelper neh = new NpoiExcelHelper();
  365. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  366. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  367. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  368. var departmentID = Request.Form["DepartmentDropdown"].ParseStrTo<Guid>();
  369. var isphotoUrl = Request.Form["ChekBoxPhotoUrl"].ParseStrTo<int>();
  370. var dt = staffServices.Value.GetStaffViewList(configuretView, campusID, collegeID, departmentID, isphotoUrl).Select(x => new
  371. {
  372. x.StaffCode,
  373. x.Name,
  374. x.CampusCode,
  375. x.CampusName,
  376. x.CollegeNo,
  377. x.CollegeName,
  378. x.DepartmentCode,
  379. x.DepartmentName,
  380. BirthDate = x.BirthDate.HasValue == true ? x.BirthDate.Value.ToString("yyyy-MM-dd") : "",
  381. x.SexName,
  382. x.UsedName,
  383. x.NationName,
  384. x.Place,
  385. x.EducationCodeName,
  386. x.Telephone,
  387. x.OfficeTelephone,
  388. x.Mobile,
  389. x.Email,
  390. x.QQ,
  391. x.Nationality,
  392. x.HealthStateName,
  393. x.HousePhone,
  394. x.Address,
  395. x.Postcode,
  396. x.HomeAddress,
  397. x.NowAddress,
  398. x.Residence,
  399. x.Speciality,
  400. x.WeChatNum,
  401. x.ReligionName,
  402. x.TeacherTypeName,
  403. x.IncumbencyStateName,
  404. x.CertificatesTypeName,
  405. x.CertificatesNum,
  406. x.SituationName,
  407. x.LiteracyLevelsName,
  408. x.DegreeStateName,
  409. x.LearnPositionName,
  410. x.TitleName,
  411. x.PaymentLevelName,
  412. x.IsDualTeacherName,
  413. WorkDate = x.WorkDate.HasValue == true ? x.WorkDate.Value.ToString("yyyy-MM") : "",
  414. ComeSchoolDate = x.ComeSchoolDate.HasValue == true ? x.ComeSchoolDate.Value.ToString("yyyy-MM") : "",
  415. TeachingDate = x.TeachingDate.HasValue == true ? x.TeachingDate.Value.ToString("yyyy-MM") : "",
  416. x.Profile,
  417. x.Remarks
  418. }).ToTable();
  419. string[] liststring = { "教职工号", "姓名", RSL.Get("CampusCode"), RSL.Get("CampusName"), RSL.Get("CollegeCode"),
  420. RSL.Get("College"), "所在教研室代码", "所在教研室", "出生日期", "性别",
  421. "曾用名", "民族", "籍贯", "学历", "家庭电话", "办公室电话", "移动电话", "电子邮箱", "QQ",
  422. "国籍","健康状况", "住宅电话", "通信地址", "邮政编码", "家庭住址", "现住地址", "户口所在地",
  423. "特长", "微信号", "宗教信仰","教师类别", "在职状态", "证件类型", "证件号码", "任课状况",
  424. "文化程度", "学位状况", "授予学位", "职称", "课酬级别", "是否双师型教师", "参加工作年月",
  425. "来校日期", "从教年月", "简介", "备注" };
  426. neh.Export(dt, liststring, "教职工信息" + DateTime.Now.ToString("yyyyMMdd"));
  427. return Json(new ReturnMessage()
  428. {
  429. IsSuccess = true,
  430. Message = "导出成功。"
  431. });
  432. }
  433. }
  434. }