BuildingsController.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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 BuildingsController : Controller
  20. {
  21. public IBuildingsInfoServices BuildingsInfoServices { 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. //建筑类型
  42. var buildingsTypeID = pararms.getExtraInt("DictionaryBuildingsType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryBuildingsType");
  43. //是否可用
  44. var isSpecial = pararms.getExtraInt("IsSpecialDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsSpecialDropdown");
  45. return base.Json(BuildingsInfoServices.GetBuildingsInfoViewGrid(configuretView, campusID, collegeID, buildingsTypeID, isSpecial, (int)pararms.page, (int)pararms.rows));
  46. }
  47. /// <summary>
  48. /// 建筑信息页面列表查询(只查询是否可用为是的信息)
  49. /// </summary>
  50. /// <param name="pararms"></param>
  51. /// <returns></returns>
  52. [HttpPost]
  53. public ActionResult BuildingsList(QueryParamsModel pararms)
  54. {
  55. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  56. //是否可用
  57. var isSpecial = (int)CF_GeneralPurpose.IsYes;
  58. return base.Json(BuildingsInfoServices.GetBuildingsInfoViewGrid(configuretView, null, null, null, isSpecial, (int)pararms.page, (int)pararms.rows));
  59. }
  60. /// <summary>
  61. /// 查询全部建筑信息
  62. /// </summary>
  63. /// <returns></returns>
  64. [HttpPost]
  65. public ActionResult BuildingsDataBind()
  66. {
  67. ConfiguretView configuretView = new ConfiguretView();
  68. List<BuildingsInfoView> list = BuildingsInfoServices.GetBuildingsInfoViewList(configuretView, null, null, null, null).ToList();
  69. return base.Json(list);
  70. }
  71. /// <summary>
  72. /// 复制新增
  73. /// </summary>
  74. /// <param name="BuildingsInfoID"></param>
  75. /// <returns></returns>
  76. public ActionResult CopyAdd(Guid BuildingsInfoID)
  77. {
  78. BuildingsInfoView buildingsInfoView = new BuildingsInfoView();
  79. buildingsInfoView = BuildingsInfoServices.GetBuildingsInfoView(BuildingsInfoID);
  80. return View("Edit", buildingsInfoView);
  81. }
  82. /// <summary>
  83. /// 复制新增
  84. /// </summary>
  85. /// <param name="buildingsInfoView"></param>
  86. /// <returns></returns>
  87. [HttpPost]
  88. public ActionResult CopyAdd(BuildingsInfoView buildingsInfoView)
  89. {
  90. buildingsInfoView.BuildingsInfoID = Guid.Empty;
  91. return this.Edit(buildingsInfoView);
  92. }
  93. /// <summary>
  94. /// 编辑(新增、修改,业务主键:建筑编号唯一)
  95. /// </summary>
  96. /// <param name="buildingsInfoID"></param>
  97. /// <returns></returns>
  98. [HttpGet]
  99. public ActionResult Edit(Guid? buildingsInfoID)
  100. {
  101. BuildingsInfoView buildingsInfoView = new BuildingsInfoView();
  102. if (buildingsInfoID.HasValue && buildingsInfoID != Guid.Empty)
  103. {
  104. buildingsInfoView = BuildingsInfoServices.GetBuildingsInfoView(buildingsInfoID);
  105. }
  106. else
  107. {
  108. buildingsInfoView.BuildingsTypeID = (int)CF_BuildingsType.Buildings;
  109. buildingsInfoView.BuildingsStatusID = (int)CF_BuildingsStatus.Normal;
  110. buildingsInfoView.IsSpecial = true;
  111. }
  112. return View(buildingsInfoView);
  113. }
  114. /// <summary>
  115. /// 编辑(新增、修改,业务主键:建筑编号唯一)
  116. /// </summary>
  117. /// <param name="buildingsInfoView"></param>
  118. /// <returns></returns>
  119. [HttpPost]
  120. public ActionResult Edit(BuildingsInfoView buildingsInfoView)
  121. {
  122. try
  123. {
  124. BuildingsInfoServices.BuildingsInfoEdit(buildingsInfoView);
  125. return Json(new ReturnMessage()
  126. {
  127. IsSuccess = true,
  128. Message = "保存成功。"
  129. });
  130. }
  131. catch (Exception ex)
  132. {
  133. return Json(new ReturnMessage()
  134. {
  135. IsSuccess = false,
  136. Message = "保存失败,原因:" + ex.Message
  137. });
  138. }
  139. }
  140. /// <summary>
  141. /// 删除
  142. /// </summary>
  143. /// <param name="buildingsInfoIDs"></param>
  144. /// <returns></returns>
  145. [HttpPost]
  146. public ActionResult Delete(string buildingsInfoIDs)
  147. {
  148. try
  149. {
  150. List<Guid?> list = buildingsInfoIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
  151. BuildingsInfoServices.BuildingsInfoDelete(list);
  152. return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
  153. }
  154. catch (Exception ex)
  155. {
  156. string mge = ex.Message;
  157. System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
  158. if (num != null)
  159. {
  160. if (num.Number == 547)
  161. {
  162. mge = "请先删除所有关联的数据,如:教室信息等。";
  163. }
  164. }
  165. return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
  166. }
  167. }
  168. /// <summary>
  169. /// Excel导入
  170. /// </summary>
  171. /// <param name="errorFile"></param>
  172. /// <param name="operationTips"></param>
  173. /// <returns></returns>
  174. [HttpGet]
  175. public ActionResult Import(string errorFile, string operationTips)
  176. {
  177. ViewBag.ErrorFile = errorFile;
  178. if (string.IsNullOrEmpty(operationTips))
  179. {
  180. operationTips = "点击查看失败原因...";
  181. }
  182. ViewBag.operationTips = operationTips;
  183. return View();
  184. }
  185. /// <summary>
  186. /// Excel导入
  187. /// </summary>
  188. /// <param name="file"></param>
  189. /// <returns></returns>
  190. [HttpPost]
  191. public ActionResult Import(HttpPostedFileBase file)
  192. {
  193. try
  194. {
  195. if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
  196. {
  197. throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
  198. }
  199. Dictionary<string, string> cellheader = new Dictionary<string, string>
  200. {
  201. { "Code", "建筑编号" },
  202. { "Name", "建筑名称" },
  203. { "CampusCode", RSL.Get("CampusCode") },
  204. { "CollegeCode", RSL.Get("CollegeCode") },
  205. { "BuildingsTypeStr", "建筑类型" },
  206. { "BuildingsStatusStr", "建筑状况" },
  207. { "BuildingsLevelStr", "建筑层数" },
  208. { "BuildingsAreaStr", "建筑面积" },
  209. { "UseAreaStr", "使用面积" },
  210. { "Position", "地址" },
  211. { "IsSpecialStr", "是否可用" },
  212. { "Remark", "备注" },
  213. { "ErrorMessage", "未导入原因" }
  214. };
  215. StringBuilder errorMsg = new StringBuilder();
  216. string sourceWebPath = FileUploadHelper.UploadFile(file);
  217. var sourcePhysicalPath = Server.MapPath(sourceWebPath);
  218. List<BuildingsInfoView> errList = new List<BuildingsInfoView>();
  219. List<BuildingsInfoView> dataList = new List<BuildingsInfoView>();
  220. int? inCount = 0; //导入个数
  221. int? upCount = 0; //更新个数
  222. int? errCount = 0; //失败个数
  223. //导入
  224. BuildingsInfoServices.BuildingsInfoImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
  225. System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
  226. if (errList.Count() > 0)
  227. {
  228. //获取错误数据文件路径
  229. string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "建筑信息导入失败文件", sourcePhysicalPath));
  230. ViewBag.ErrorFile = errorWebPath;
  231. string Errinfo = string.Format("提示:{0}条建筑信息导入成功,{1}条建筑信息更新成功,{2}条建筑信息导入失败,点击查看。", inCount, upCount, errCount);
  232. ViewBag.operationTips = Errinfo;
  233. return RedirectToAction("MsgShow", "Common", new
  234. {
  235. WindowID = "none",
  236. msg = Errinfo,
  237. url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
  238. });
  239. }
  240. else
  241. {
  242. string successInfo = string.Format("提示:{0}条建筑信息导入成功,{1}条建筑信息更新成功。", inCount, upCount);
  243. return RedirectToAction("MsgShow", "Common", new
  244. {
  245. WindowID = Request["WindowID"],
  246. msg = successInfo,
  247. url = Url.Action("List").AddMenuParameter()
  248. });
  249. }
  250. }
  251. catch (Exception ex)
  252. {
  253. return RedirectToAction("MsgShow", "Common", new
  254. {
  255. WindowID = "none",
  256. msg = "导入失败,原因:" + ex.Message,
  257. url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
  258. });
  259. }
  260. }
  261. /// <summary>
  262. /// 查询建筑信息对应的教室信息页面
  263. /// </summary>
  264. /// <returns></returns>
  265. public ActionResult ClassroomList()
  266. {
  267. return View();
  268. }
  269. /// <summary>
  270. /// 查询建筑信息对应的教室信息页面
  271. /// </summary>
  272. /// <param name="pararms"></param>
  273. /// <returns></returns>
  274. [HttpPost]
  275. public ActionResult ClassroomList(QueryParamsModel pararms)
  276. {
  277. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
  278. var buildingsInfoID = Request["buildingsInfoID"].ParseStrTo<Guid>();
  279. //教室名称
  280. var classroomName = pararms.getExtraString("ClassroomNameDropdown");
  281. //教室类型
  282. var classroomTypeID = pararms.getExtraInt("ClassroomTypeDictionary") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ClassroomTypeDictionary");
  283. //所属院系所
  284. var collegeID = pararms.getExtraGuid("CollegeDropdown");
  285. //可否多班教学
  286. var isConcurrentUse = pararms.getExtraInt("IsConcurrentUseDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsConcurrentUseDropdown");
  287. //是否预留
  288. var isReserve = pararms.getExtraInt("IsReserveDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsReserveDropdown");
  289. //是否可用
  290. var isAvailable = pararms.getExtraInt("IsAvailableDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsAvailableDropdown");
  291. return base.Json(BuildingsInfoServices.GetClassroomViewGrid(configuretView, buildingsInfoID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
  292. }
  293. /// <summary>
  294. /// 建筑信息中对应教室信息Excel导出
  295. /// </summary>
  296. /// <param name="pararms"></param>
  297. /// <returns></returns>
  298. [HttpPost]
  299. public ActionResult Excel_Classroom()
  300. {
  301. try
  302. {
  303. NpoiExcelHelper neh = new NpoiExcelHelper();
  304. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  305. var buildingsInfoID = Request["buildingsInfoID"].ParseStrTo<Guid>();
  306. //教室名称
  307. var classroomName = Request.Form["ClassroomNameDropdown"].ToString();
  308. //教室类型
  309. var classroomTypeID = Request.Form["ClassroomTypeDictionary"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["ClassroomTypeDictionary"].ParseStrTo<int>();
  310. //所属院系所
  311. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  312. //可否多班教学
  313. var isConcurrentUse = Request.Form["IsConcurrentUseDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsConcurrentUseDropdown"].ParseStrTo<int>();
  314. //是否预留
  315. var isReserve = Request.Form["IsReserveDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsReserveDropdown"].ParseStrTo<int>();
  316. //是否可用
  317. var isAvailable = Request.Form["IsAvailableDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsAvailableDropdown"].ParseStrTo<int>();
  318. var dt = BuildingsInfoServices.GetClassroomViewList(configuretView, buildingsInfoID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable)
  319. .Select(x => new
  320. {
  321. x.Code,
  322. x.Name,
  323. x.BuildingsInfoCode,
  324. x.BuildingsInfoName,
  325. x.CampusCode,
  326. x.CampusName,
  327. x.ClassroomTypeName,
  328. x.RoomUseName,
  329. x.FloorLevel,
  330. x.Acreage,
  331. x.RowCout,
  332. x.ColumnCount,
  333. x.Totalseating,
  334. x.Effectiveseating,
  335. x.Examinationseating,
  336. x.CollegeCode,
  337. x.CollegeName,
  338. x.CollegeCampusCode,
  339. x.CollegeCampusName,
  340. x.IsWrittenExamName,
  341. x.IsMachinetestName,
  342. x.IsConcurrentUseName,
  343. x.IsReserveName,
  344. x.ScheduleCollegeCount,
  345. x.IsAvailableName,
  346. x.Remark
  347. }).ToTable();
  348. string[] liststring = {
  349. "教室编号", "教室名称", "建筑物编号", "建筑物名称", RSL.Get("CampusCode"),
  350. RSL.Get("Campus"), "教室类型", "房间用途", "所在楼层","面积", "行数", "列数",
  351. "总座位数", "有效座位数", "考试座位数", "所属" + RSL.Get("CollegeCode"),
  352. "所属" + RSL.Get("College"), "所属" + RSL.Get("CampusCode"), "所属" + RSL.Get("Campus"),
  353. "可否笔试", "可否机试", "可否多班教学", "是否预留", "排课院系个数", "是否可用", "备注"
  354. };
  355. neh.Export(dt, liststring, "建筑信息教室明细" + DateTime.Now.ToString("yyyyMMdd"));
  356. return Json(new ReturnMessage()
  357. {
  358. IsSuccess = true,
  359. Message = "导出成功。"
  360. });
  361. }
  362. catch (Exception ex)
  363. {
  364. return Json(new ReturnMessage()
  365. {
  366. IsSuccess = false,
  367. Message = "导出失败,原因:" + ex.Message
  368. });
  369. }
  370. }
  371. /// <summary>
  372. /// Excel导出
  373. /// </summary>
  374. /// <param name="pararms"></param>
  375. /// <returns></returns>
  376. [HttpPost]
  377. public ActionResult Excel()
  378. {
  379. try
  380. {
  381. NpoiExcelHelper neh = new NpoiExcelHelper();
  382. ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
  383. var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
  384. var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
  385. //建筑类型
  386. var buildingsTypeID = Request.Form["DictionaryBuildingsType"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryBuildingsType"].ParseStrTo<int>();
  387. //是否启用
  388. var isSpecial = Request.Form["IsSpecialDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsSpecialDropdown"].ParseStrTo<int>();
  389. var dt = BuildingsInfoServices.GetBuildingsInfoViewList(configuretView, campusID, collegeID, buildingsTypeID, isSpecial)
  390. .Select(x => new
  391. {
  392. x.Code,
  393. x.Name,
  394. x.CampusCode,
  395. x.CampusName,
  396. x.BuildingsTypeName,
  397. x.BuildingsStatusName,
  398. x.BuildingsLevel,
  399. x.BuildingsArea,
  400. x.UseArea,
  401. x.Position,
  402. x.CollegeCode,
  403. x.CollegeName,
  404. x.CollegeCampusCode,
  405. x.CollegeCampusName,
  406. x.ClassroomCount,
  407. x.IsSpecialName,
  408. x.Remark
  409. }).ToTable();
  410. string[] liststring = {
  411. "建筑编号", "建筑名称", RSL.Get("CampusCode"), RSL.Get("CampusName"),
  412. "建筑类型", "建筑状况", "建筑层数", "建筑面积", "使用面积", "地址",
  413. "所属" + RSL.Get("CollegeCode"), "所属" + RSL.Get("CollegeName"),
  414. "所属" + RSL.Get("CampusCode"), "所属" + RSL.Get("CampusName"), "教室间数", "是否可用", "备注"
  415. };
  416. neh.Export(dt, liststring, "建筑物信息" + DateTime.Now.ToString("yyyyMMdd"));
  417. return Json(new ReturnMessage()
  418. {
  419. IsSuccess = true,
  420. Message = "导出成功。"
  421. });
  422. }
  423. catch (Exception ex)
  424. {
  425. return Json(new ReturnMessage()
  426. {
  427. IsSuccess = false,
  428. Message = "导出失败,原因:" + ex.Message
  429. });
  430. }
  431. }
  432. }
  433. }