123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- using Bowin.Common.Data;
- using Bowin.Common.Exceptions;
- using Bowin.Common.Utility;
- using Bowin.Web.Controls.Mvc;
- using EMIS.Web.Controls;
- using EMIS.Utility;
- using EMIS.ViewModel;
- using EMIS.ViewModel.UniversityManage.ClassroomManage;
- using EMIS.CommonLogic.UniversityManage.ClassroomManage;
- namespace EMIS.Web.Controllers.UniversityManage.ClassroomManage
- {
- [Authorization]
- public class BuildingsController : Controller
- {
- public IBuildingsInfoServices BuildingsInfoServices { get; set; }
- /// <summary>
- /// 建筑信息页面
- /// </summary>
- /// <returns></returns>
- public ActionResult List()
- {
- return View();
- }
- /// <summary>
- /// 建筑信息页面列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult List(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- //建筑类型
- var buildingsTypeID = pararms.getExtraInt("DictionaryBuildingsType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryBuildingsType");
- //是否可用
- var isSpecial = pararms.getExtraInt("IsSpecialDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsSpecialDropdown");
- return base.Json(BuildingsInfoServices.GetBuildingsInfoViewGrid(configuretView, campusID, collegeID, buildingsTypeID, isSpecial, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 建筑信息页面列表查询(只查询是否可用为是的信息)
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult BuildingsList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- //是否可用
- var isSpecial = (int)CF_GeneralPurpose.IsYes;
- return base.Json(BuildingsInfoServices.GetBuildingsInfoViewGrid(configuretView, null, null, null, isSpecial, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 查询全部建筑信息
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult BuildingsDataBind()
- {
- ConfiguretView configuretView = new ConfiguretView();
- List<BuildingsInfoView> list = BuildingsInfoServices.GetBuildingsInfoViewList(configuretView, null, null, null, null).ToList();
- return base.Json(list);
- }
- /// <summary>
- /// 复制新增
- /// </summary>
- /// <param name="BuildingsInfoID"></param>
- /// <returns></returns>
- public ActionResult CopyAdd(Guid BuildingsInfoID)
- {
- BuildingsInfoView buildingsInfoView = new BuildingsInfoView();
- buildingsInfoView = BuildingsInfoServices.GetBuildingsInfoView(BuildingsInfoID);
- return View("Edit", buildingsInfoView);
- }
- /// <summary>
- /// 复制新增
- /// </summary>
- /// <param name="buildingsInfoView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult CopyAdd(BuildingsInfoView buildingsInfoView)
- {
- buildingsInfoView.BuildingsInfoID = Guid.Empty;
- return this.Edit(buildingsInfoView);
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:建筑编号唯一)
- /// </summary>
- /// <param name="buildingsInfoID"></param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edit(Guid? buildingsInfoID)
- {
- BuildingsInfoView buildingsInfoView = new BuildingsInfoView();
- if (buildingsInfoID.HasValue && buildingsInfoID != Guid.Empty)
- {
- buildingsInfoView = BuildingsInfoServices.GetBuildingsInfoView(buildingsInfoID);
- }
- else
- {
- buildingsInfoView.BuildingsTypeID = (int)CF_BuildingsType.Buildings;
- buildingsInfoView.BuildingsStatusID = (int)CF_BuildingsStatus.Normal;
- buildingsInfoView.IsSpecial = true;
- }
- return View(buildingsInfoView);
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:建筑编号唯一)
- /// </summary>
- /// <param name="buildingsInfoView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(BuildingsInfoView buildingsInfoView)
- {
- try
- {
- BuildingsInfoServices.BuildingsInfoEdit(buildingsInfoView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败,原因:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="buildingsInfoIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string buildingsInfoIDs)
- {
- try
- {
- List<Guid?> list = buildingsInfoIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
- BuildingsInfoServices.BuildingsInfoDelete(list);
- return base.Json(new ReturnMessage { IsSuccess = true, Message = "删除成功。" });
- }
- catch (Exception ex)
- {
- string mge = ex.Message;
- System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
- if (num != null)
- {
- if (num.Number == 547)
- {
- mge = "请先删除所有关联的数据,如:教室信息等。";
- }
- }
- return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
- }
- }
- /// <summary>
- /// Excel导入
- /// </summary>
- /// <param name="errorFile"></param>
- /// <param name="operationTips"></param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Import(string errorFile, string operationTips)
- {
- ViewBag.ErrorFile = errorFile;
- if (string.IsNullOrEmpty(operationTips))
- {
- operationTips = "点击查看失败原因...";
- }
- ViewBag.operationTips = operationTips;
- return View();
- }
- /// <summary>
- /// Excel导入
- /// </summary>
- /// <param name="file"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Import(HttpPostedFileBase file)
- {
- try
- {
- if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
- {
- throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
- }
- Dictionary<string, string> cellheader = new Dictionary<string, string>
- {
- { "Code", "建筑编号" },
- { "Name", "建筑名称" },
- { "CampusCode", RSL.Get("CampusCode") },
- { "CollegeCode", RSL.Get("CollegeCode") },
- { "BuildingsTypeStr", "建筑类型" },
- { "BuildingsStatusStr", "建筑状况" },
- { "BuildingsLevelStr", "建筑层数" },
- { "BuildingsAreaStr", "建筑面积" },
- { "UseAreaStr", "使用面积" },
- { "Position", "地址" },
- { "IsSpecialStr", "是否可用" },
- { "Remark", "备注" },
- { "ErrorMessage", "未导入原因" }
- };
- StringBuilder errorMsg = new StringBuilder();
- string sourceWebPath = FileUploadHelper.UploadFile(file);
- var sourcePhysicalPath = Server.MapPath(sourceWebPath);
- List<BuildingsInfoView> errList = new List<BuildingsInfoView>();
- List<BuildingsInfoView> dataList = new List<BuildingsInfoView>();
- int? inCount = 0; //导入个数
- int? upCount = 0; //更新个数
- int? errCount = 0; //失败个数
- //导入
- BuildingsInfoServices.BuildingsInfoImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
- System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
- if (errList.Count() > 0)
- {
- //获取错误数据文件路径
- string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "建筑信息导入失败文件", sourcePhysicalPath));
- ViewBag.ErrorFile = errorWebPath;
- string Errinfo = string.Format("提示:{0}条建筑信息导入成功,{1}条建筑信息更新成功,{2}条建筑信息导入失败,点击查看。", inCount, upCount, errCount);
- ViewBag.operationTips = Errinfo;
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = "none",
- msg = Errinfo,
- url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
- });
- }
- else
- {
- string successInfo = string.Format("提示:{0}条建筑信息导入成功,{1}条建筑信息更新成功。", inCount, upCount);
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = Request["WindowID"],
- msg = successInfo,
- url = Url.Action("List").AddMenuParameter()
- });
- }
- }
- catch (Exception ex)
- {
- return RedirectToAction("MsgShow", "Common", new
- {
- WindowID = "none",
- msg = "导入失败,原因:" + ex.Message,
- url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
- });
- }
- }
- /// <summary>
- /// 查询建筑信息对应的教室信息页面
- /// </summary>
- /// <returns></returns>
- public ActionResult ClassroomList()
- {
- return View();
- }
- /// <summary>
- /// 查询建筑信息对应的教室信息页面
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ClassroomList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var buildingsInfoID = Request["buildingsInfoID"].ParseStrTo<Guid>();
- //教室名称
- var classroomName = pararms.getExtraString("ClassroomNameDropdown");
- //教室类型
- var classroomTypeID = pararms.getExtraInt("ClassroomTypeDictionary") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ClassroomTypeDictionary");
- //所属院系所
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- //可否多班教学
- var isConcurrentUse = pararms.getExtraInt("IsConcurrentUseDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsConcurrentUseDropdown");
- //是否预留
- var isReserve = pararms.getExtraInt("IsReserveDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsReserveDropdown");
- //是否可用
- var isAvailable = pararms.getExtraInt("IsAvailableDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsAvailableDropdown");
- return base.Json(BuildingsInfoServices.GetClassroomViewGrid(configuretView, buildingsInfoID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 建筑信息中对应教室信息Excel导出
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel_Classroom()
- {
- try
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var buildingsInfoID = Request["buildingsInfoID"].ParseStrTo<Guid>();
- //教室名称
- var classroomName = Request.Form["ClassroomNameDropdown"].ToString();
- //教室类型
- var classroomTypeID = Request.Form["ClassroomTypeDictionary"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["ClassroomTypeDictionary"].ParseStrTo<int>();
- //所属院系所
- var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
- //可否多班教学
- var isConcurrentUse = Request.Form["IsConcurrentUseDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsConcurrentUseDropdown"].ParseStrTo<int>();
- //是否预留
- var isReserve = Request.Form["IsReserveDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsReserveDropdown"].ParseStrTo<int>();
- //是否可用
- var isAvailable = Request.Form["IsAvailableDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsAvailableDropdown"].ParseStrTo<int>();
- var dt = BuildingsInfoServices.GetClassroomViewList(configuretView, buildingsInfoID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable)
- .Select(x => new
- {
- x.Code,
- x.Name,
- x.BuildingsInfoCode,
- x.BuildingsInfoName,
- x.CampusCode,
- x.CampusName,
- x.ClassroomTypeName,
- x.RoomUseName,
- x.FloorLevel,
- x.Acreage,
- x.RowCout,
- x.ColumnCount,
- x.Totalseating,
- x.Effectiveseating,
- x.Examinationseating,
- x.CollegeCode,
- x.CollegeName,
- x.CollegeCampusCode,
- x.CollegeCampusName,
- x.IsWrittenExamName,
- x.IsMachinetestName,
- x.IsConcurrentUseName,
- x.IsReserveName,
- x.ScheduleCollegeCount,
- x.IsAvailableName,
- x.Remark
- }).ToTable();
- string[] liststring = {
- "教室编号", "教室名称", "建筑物编号", "建筑物名称", RSL.Get("CampusCode"),
- RSL.Get("Campus"), "教室类型", "房间用途", "所在楼层","面积", "行数", "列数",
- "总座位数", "有效座位数", "考试座位数", "所属" + RSL.Get("CollegeCode"),
- "所属" + RSL.Get("College"), "所属" + RSL.Get("CampusCode"), "所属" + RSL.Get("Campus"),
- "可否笔试", "可否机试", "可否多班教学", "是否预留", "排课院系个数", "是否可用", "备注"
- };
- neh.Export(dt, liststring, "建筑信息教室明细" + DateTime.Now.ToString("yyyyMMdd"));
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "导出成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "导出失败,原因:" + ex.Message
- });
- }
- }
- /// <summary>
- /// Excel导出
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel()
- {
- try
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
- var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
- //建筑类型
- var buildingsTypeID = Request.Form["DictionaryBuildingsType"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryBuildingsType"].ParseStrTo<int>();
- //是否启用
- var isSpecial = Request.Form["IsSpecialDropdown"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["IsSpecialDropdown"].ParseStrTo<int>();
- var dt = BuildingsInfoServices.GetBuildingsInfoViewList(configuretView, campusID, collegeID, buildingsTypeID, isSpecial)
- .Select(x => new
- {
- x.Code,
- x.Name,
- x.CampusCode,
- x.CampusName,
- x.BuildingsTypeName,
- x.BuildingsStatusName,
- x.BuildingsLevel,
- x.BuildingsArea,
- x.UseArea,
- x.Position,
- x.CollegeCode,
- x.CollegeName,
- x.CollegeCampusCode,
- x.CollegeCampusName,
- x.ClassroomCount,
- x.IsSpecialName,
- x.Remark
- }).ToTable();
- string[] liststring = {
- "建筑编号", "建筑名称", RSL.Get("CampusCode"), RSL.Get("CampusName"),
- "建筑类型", "建筑状况", "建筑层数", "建筑面积", "使用面积", "地址",
- "所属" + RSL.Get("CollegeCode"), "所属" + RSL.Get("CollegeName"),
- "所属" + RSL.Get("CampusCode"), "所属" + RSL.Get("CampusName"), "教室间数", "是否可用", "备注"
- };
- neh.Export(dt, liststring, "建筑物信息" + DateTime.Now.ToString("yyyyMMdd"));
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "导出成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "导出失败,原因:" + ex.Message
- });
- }
- }
- }
- }
|