ClassroomController.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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.Web.Controls;
  12. using EMIS.Utility;
  13. using EMIS.ViewModel;
  14. using EMIS.ViewModel.UniversityManage.ClassroomManage;
  15. using EMIS.CommonLogic.UniversityManage.ClassroomManage;
  16. namespace EMIS.Web.Controllers.UniversityManage.ClassroomManage
  17. {
  18. [Authorization]
  19. public class ClassroomController : Controller
  20. {
  21. public IClassroomServices ClassroomServices { 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 buildingsID = pararms.getExtraGuid("BuildingsDropdown");
  41. //教室名称
  42. var classroomName = pararms.getExtraString("ClassroomNameDropdown");
  43. //教室类型
  44. var classroomTypeID = pararms.getExtraInt("ClassroomTypeDictionary") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ClassroomTypeDictionary");
  45. //所属院系所
  46. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  47. //可否多班教学
  48. var isConcurrentUse = pararms.getExtraInt("IsConcurrentUseDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsConcurrentUseDropdown");
  49. //是否预留
  50. var isReserve = pararms.getExtraInt("IsReserveDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsReserveDropdown");
  51. //是否可用
  52. var isAvailable = pararms.getExtraInt("IsAvailableDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsAvailableDropdown");
  53. return base.Json(ClassroomServices.GetClassroomViewGrid(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
  54. }
  55. /// <summary>
  56. /// 教室信息页面列表查询
  57. /// </summary>
  58. /// <param name="pararms"></param>
  59. /// <returns></returns>
  60. [HttpPost]
  61. public ActionResult ListIsEnable(QueryParamsModel pararms)
  62. {
  63. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  64. var campusID = pararms.getExtraGuid("CampusDropdown");
  65. var buildingsID = pararms.getExtraGuid("BuildingsDropdown");
  66. //教室名称
  67. var classroomName = pararms.getExtraString("ClassroomNameDropdown");
  68. //教室类型
  69. var classroomTypeID = pararms.getExtraInt("ClassroomTypeDictionary") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ClassroomTypeDictionary");
  70. //所属院系所
  71. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  72. //可否多班教学
  73. var isConcurrentUse = pararms.getExtraInt("IsConcurrentUseDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsConcurrentUseDropdown");
  74. //是否预留
  75. var isReserve = pararms.getExtraInt("IsReserveDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsReserveDropdown");
  76. //是否可用
  77. var isAvailable = (int)SYS_STATUS.USABLE;
  78. return base.Json(ClassroomServices.GetClassroomViewGrid(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
  79. }
  80. /// <summary>
  81. /// 查询对应的教室信息下拉(带数据范围)
  82. /// </summary>
  83. /// <param name="bindType"></param>
  84. /// <returns></returns>
  85. [HttpPost]
  86. public ActionResult DropDown(DropdownListBindType? bindType, int? classroomType)
  87. {
  88. var allClassroomList = ClassroomServices.GetClassroomViewList(new ConfiguretView(), null, null, null, classroomType, null, null, null, null);
  89. List<DropdownListItem> list = allClassroomList.Select(x => new DropdownListItem { Text = x.Name, Value = x.ClassroomID }).ToList();
  90. DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
  91. DropdownList.FormatDropdownItemList(dbt, list);
  92. return base.Json(list);
  93. }
  94. /// <summary>
  95. /// 复制新增
  96. /// </summary>
  97. /// <param name="classroomID"></param>
  98. /// <returns></returns>
  99. public ActionResult CopyAdd(Guid classroomID)
  100. {
  101. ClassroomView classroomView = new ClassroomView();
  102. classroomView = ClassroomServices.GetClassroomView(classroomID);
  103. return View("Edit", classroomView);
  104. }
  105. /// <summary>
  106. /// 复制新增
  107. /// </summary>
  108. /// <param name="classroomView"></param>
  109. /// <returns></returns>
  110. [HttpPost]
  111. public ActionResult CopyAdd(ClassroomView classroomView)
  112. {
  113. classroomView.ClassroomID = Guid.Empty;
  114. return this.Edit(classroomView);
  115. }
  116. /// <summary>
  117. /// 编辑(新增、修改,业务主键:教室编号唯一)
  118. /// </summary>
  119. /// <param name="classroomID"></param>
  120. /// <returns></returns>
  121. [HttpGet]
  122. public ActionResult Edit(Guid? classroomID)
  123. {
  124. ClassroomView classroomView = new ClassroomView();
  125. if (classroomID.HasValue && classroomID != Guid.Empty)
  126. {
  127. classroomView = ClassroomServices.GetClassroomView(classroomID);
  128. }
  129. else
  130. {
  131. classroomView.RoomUseID = (int)CF_RoomUse.Classroom;
  132. classroomView.IsAvailable = true;
  133. }
  134. return View(classroomView);
  135. }
  136. /// <summary>
  137. /// 编辑(新增、修改,业务主键:教室编号唯一)
  138. /// </summary>
  139. /// <param name="classroomView"></param>
  140. /// <returns></returns>
  141. [HttpPost]
  142. public ActionResult Edit(ClassroomView classroomView)
  143. {
  144. try
  145. {
  146. ClassroomServices.ClassroomEdit(classroomView);
  147. return Json(new ReturnMessage()
  148. {
  149. IsSuccess = true,
  150. Message = "保存成功。"
  151. });
  152. }
  153. catch (Exception ex)
  154. {
  155. return Json(new ReturnMessage()
  156. {
  157. IsSuccess = false,
  158. Message = "保存失败,原因:" + ex.Message
  159. });
  160. }
  161. }
  162. /// <summary>
  163. /// 删除
  164. /// </summary>
  165. /// <param name="classroomIDs"></param>
  166. /// <returns></returns>
  167. [HttpPost]
  168. public ActionResult Delete(string classroomIDs)
  169. {
  170. try
  171. {
  172. List<Guid?> list = classroomIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  173. ClassroomServices.ClassroomDelete(list);
  174. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  175. }
  176. catch (Exception ex)
  177. {
  178. string mge = ex.Message;
  179. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  180. if (num != null)
  181. {
  182. if (num.Number == 547)
  183. {
  184. mge = "请先删除所有关联的数据,如:教师课表、学生课表等。";
  185. }
  186. }
  187. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  188. }
  189. }
  190. /// <summary>
  191. /// 根据教室信息ID查询对应的教室类型List
  192. /// </summary>
  193. /// <param name="classroomID"></param>
  194. /// <returns></returns>
  195. [HttpPost]
  196. public ActionResult GetClassroomModeType(Guid? classroomID)
  197. {
  198. List<string> list = new List<string>();
  199. if (classroomID.HasValue && classroomID != Guid.Empty)
  200. {
  201. list = ClassroomServices.GetClassroomTypeList(classroomID).Select(x => x.ToString()).ToList();
  202. }
  203. else
  204. {
  205. list.Add(((int)EMIS.ViewModel.CF_ClassroomType.Classroom).ToString());
  206. }
  207. return base.Json(list);
  208. }
  209. /// <summary>
  210. /// Excel导入
  211. /// </summary>
  212. /// <param name="errorFile"></param>
  213. /// <param name="operationTips"></param>
  214. /// <returns></returns>
  215. [HttpGet]
  216. public ActionResult Import(string errorFile, string operationTips)
  217. {
  218. ViewBag.ErrorFile = errorFile;
  219. if (string.IsNullOrEmpty(operationTips))
  220. {
  221. operationTips = "点击查看失败原因...";
  222. }
  223. ViewBag.operationTips = operationTips;
  224. return View();
  225. }
  226. /// <summary>
  227. /// Excel导入
  228. /// </summary>
  229. /// <param name="file"></param>
  230. /// <returns></returns>
  231. [HttpPost]
  232. public ActionResult Import(HttpPostedFileBase file)
  233. {
  234. try
  235. {
  236. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  237. {
  238. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  239. }
  240. Dictionary<string, string> cellheader = new Dictionary<string, string>
  241. {
  242. { "Code", "教室编号" },
  243. { "Name", "教室名称" },
  244. { "BuildingsInfoCode", "建筑编号" },
  245. { "CollegeCode", RSL.Get("CollegeCode") },
  246. { "ClassroomTypeIDListStr", "教室类型" },
  247. //{ "LayoutTypeStr", "布局类型" },
  248. { "RoomUseStr", "房间用途" },
  249. { "FloorLevelStr", "所在楼层" },
  250. { "AcreageStr", "面积" },
  251. { "RowCoutStr", "行数" },
  252. { "ColumnCountStr", "列数" },
  253. { "TotalseatingStr", "总座位数" },
  254. { "EffectiveseatingStr", "有效座位数" },
  255. { "ExaminationseatingStr", "考试座位数" },
  256. { "IsWrittenExamStr", "可否笔试" },
  257. { "IsMachinetestStr", "可否机试" },
  258. { "IsConcurrentUseStr", "可否多班教学" },
  259. { "IsAvailableStr", "是否可用" },
  260. { "Remark", "备注" },
  261. { "ErrorMessage", "未导入原因" }
  262. };
  263. StringBuilder errorMsg = new StringBuilder();
  264. string sourceWebPath = FileUploadHelper.UploadFile(file);
  265. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  266. List<ClassroomView> errList = new List<ClassroomView>();
  267. List<ClassroomView> dataList = new List<ClassroomView>();
  268. int? inCount = 0; //导入个数
  269. int? upCount = 0; //更新个数
  270. int? errCount = 0; //失败个数
  271. //导入
  272. ClassroomServices.ClassroomImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  273. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  274. if (errList.Count() > 0)
  275. {
  276. //获取错误数据文件路径
  277. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "教室信息导入失败文件", sourcePhysicalPath));
  278. ViewBag.ErrorFile = errorWebPath;
  279. string Errinfo = string.Format("提示:{0}条教室信息导入成功,{1}条教室信息更新成功,{2}条教室信息导入失败,点击查看。", inCount, upCount, errCount);
  280. ViewBag.operationTips = Errinfo;
  281. return RedirectToAction("MsgShow", "Common", new
  282. {
  283. WindowID = "none",
  284. msg = Errinfo,
  285. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  286. });
  287. }
  288. else
  289. {
  290. string successInfo = string.Format("提示:{0}条教室信息导入成功,{1}条教室信息更新成功。", inCount, upCount);
  291. return RedirectToAction("MsgShow", "Common", new
  292. {
  293. WindowID = Request["WindowID"],
  294. msg = successInfo,
  295. url = Url.Action("List").AddMenuParameter()
  296. });
  297. }
  298. }
  299. catch (Exception ex)
  300. {
  301. return RedirectToAction("MsgShow", "Common", new
  302. {
  303. WindowID = "none",
  304. msg = "导入失败,原因:" + ex.Message,
  305. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  306. });
  307. }
  308. }
  309. /// <summary>
  310. /// 查询教室信息对应的排课分配院系所信息List(无数据范围)
  311. /// </summary>
  312. /// <returns></returns>
  313. public ActionResult ClassroomCollegeList()
  314. {
  315. return View();
  316. }
  317. /// <summary>
  318. /// 查询教室信息对应的排课分配院系所信息List(无数据范围)
  319. /// </summary>
  320. /// <param name="pararms"></param>
  321. /// <returns></returns>
  322. [HttpPost]
  323. public ActionResult ClassroomCollegeList(QueryParamsModel pararms)
  324. {
  325. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  326. var classroomID = Request["classroomID"].ParseStrTo<Guid>();
  327. var campusID = pararms.getExtraGuid("CampusDropdown");
  328. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  329. var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory");
  330. return base.Json(ClassroomServices.GetClassroomCollegeViewGrid(configuretView, classroomID, campusID, collegeID, unitCategoryID, (int)pararms.page, (int)pararms.rows));
  331. }
  332. /// <summary>
  333. /// 教室信息对应的排课分配院系所信息Excel导出
  334. /// </summary>
  335. /// <returns></returns>
  336. [HttpPost]
  337. public ActionResult Excel_ClassroomCollege()
  338. {
  339. try
  340. {
  341. NpoiExcelHelper neh = new NpoiExcelHelper();
  342. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  343. var classroomID = Request["classroomID"].ParseStrTo<Guid>();
  344. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  345. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  346. var unitCategoryID = Request.Form["DictionaryUnitCategory"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryUnitCategory"].ParseStrTo<int>();
  347. var dt = ClassroomServices.GetClassroomCollegeViewList(configuretView, classroomID, campusID, collegeID, unitCategoryID)
  348. .Select(x => new
  349. {
  350. x.Code,
  351. x.Name,
  352. x.BuildingsInfoCode,
  353. x.BuildingsInfoName,
  354. x.CampusCode,
  355. x.CampusName,
  356. x.ClassroomTypeName,
  357. x.RoomUseName,
  358. x.FloorLevel,
  359. x.Acreage,
  360. x.RowCout,
  361. x.ColumnCount,
  362. x.Totalseating,
  363. x.Effectiveseating,
  364. x.Examinationseating,
  365. x.CollegeCode,
  366. x.CollegeName,
  367. x.UnitCategoryName,
  368. x.CollegeCampusCode,
  369. x.CollegeCampusName,
  370. x.IsWrittenExamName,
  371. x.IsMachinetestName,
  372. x.IsConcurrentUseName,
  373. x.IsReserveName,
  374. x.IsAvailableName,
  375. x.Remark
  376. }).ToTable();
  377. string[] liststring = {
  378. "教室编号", "教室名称", "建筑物编号", "建筑物名称", RSL.Get("CampusCode"),
  379. RSL.Get("Campus"), "教室类型", "房间用途", "所在楼层","面积", "行数", "列数",
  380. "总座位数", "有效座位数", "考试座位数", "分配" + RSL.Get("CollegeCode"),
  381. "分配" + RSL.Get("College"), "单位类别", "分配" + RSL.Get("CampusCode"),
  382. "分配" + RSL.Get("Campus"), "可否笔试", "可否机试", "可否多班教学", "是否预留",
  383. "是否可用", "备注"
  384. };
  385. neh.Export(dt, liststring, "教室信息排课分配院系明细信息" + DateTime.Now.ToString("yyyyMMdd"));
  386. return Json(new ReturnMessage()
  387. {
  388. IsSuccess = true,
  389. Message = "导出成功。"
  390. });
  391. }
  392. catch (Exception ex)
  393. {
  394. return Json(new ReturnMessage()
  395. {
  396. IsSuccess = false,
  397. Message = "导出失败,原因:" + ex.Message
  398. });
  399. }
  400. }
  401. /// <summary>
  402. /// Excel导出
  403. /// </summary>
  404. /// <param name="pararms"></param>
  405. /// <returns></returns>
  406. [HttpPost]
  407. public ActionResult Excel()
  408. {
  409. try
  410. {
  411. NpoiExcelHelper neh = new NpoiExcelHelper();
  412. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  413. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  414. var buildingsID = Request.Form["BuildingsDropdown"].ParseStrTo<Guid>();
  415. //教室名称
  416. var classroomName = Request.Form["ClassroomNameDropdown"].ToString();
  417. //教室类型
  418. var classroomTypeID = Request.Form["ClassroomTypeDictionary"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["ClassroomTypeDictionary"].ParseStrTo<int>();
  419. //所属院系所
  420. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  421. //可否多班教学
  422. var isConcurrentUse = Request.Form["IsConcurrentUseDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsConcurrentUseDropdown"].ParseStrTo<int>();
  423. //是否预留
  424. var isReserve = Request.Form["IsReserveDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsReserveDropdown"].ParseStrTo<int>();
  425. //是否可用
  426. var isAvailable = Request.Form["IsAvailableDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsAvailableDropdown"].ParseStrTo<int>();
  427. var dt = ClassroomServices.GetClassroomViewList(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable)
  428. .Select(x => new
  429. {
  430. x.Code,
  431. x.Name,
  432. x.BuildingsInfoCode,
  433. x.BuildingsInfoName,
  434. x.CampusCode,
  435. x.CampusName,
  436. x.ClassroomTypeName,
  437. x.RoomUseName,
  438. x.FloorLevel,
  439. x.Acreage,
  440. x.RowCout,
  441. x.ColumnCount,
  442. x.Totalseating,
  443. x.Effectiveseating,
  444. x.Examinationseating,
  445. x.CollegeCode,
  446. x.CollegeName,
  447. x.CollegeCampusCode,
  448. x.CollegeCampusName,
  449. x.IsWrittenExamName,
  450. x.IsMachinetestName,
  451. x.IsConcurrentUseName,
  452. x.IsReserveName,
  453. x.ScheduleCollegeCount,
  454. x.IsAvailableName,
  455. x.Remark
  456. }).ToTable();
  457. string[] liststring = {
  458. "教室编号", "教室名称", "建筑物编号", "建筑物名称", RSL.Get("CampusCode"),
  459. RSL.Get("Campus"), "教室类型", "房间用途", "所在楼层","面积", "行数", "列数",
  460. "总座位数", "有效座位数", "考试座位数", "所属" + RSL.Get("CollegeCode"),
  461. "所属" + RSL.Get("College"), "所属" + RSL.Get("CampusCode"), "所属" + RSL.Get("Campus"),
  462. "可否笔试", "可否机试", "可否多班教学", "是否预留", "排课院系个数", "是否可用", "备注"
  463. };
  464. neh.Export(dt, liststring, "教室信息" + DateTime.Now.ToString("yyyyMMdd"));
  465. return Json(new ReturnMessage()
  466. {
  467. IsSuccess = true,
  468. Message = "导出成功。"
  469. });
  470. }
  471. catch (Exception ex)
  472. {
  473. return Json(new ReturnMessage()
  474. {
  475. IsSuccess = false,
  476. Message = "导出失败,原因:" + ex.Message
  477. });
  478. }
  479. }
  480. }
  481. }