123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512 |
- 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 ClassroomController : Controller
- {
- public IClassroomServices ClassroomServices { 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 buildingsID = pararms.getExtraGuid("BuildingsDropdown");
- //教室名称
- 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(ClassroomServices.GetClassroomViewGrid(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 教室信息页面列表查询
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ListIsEnable(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var buildingsID = pararms.getExtraGuid("BuildingsDropdown");
- //教室名称
- 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 = (int)SYS_STATUS.USABLE;
- return base.Json(ClassroomServices.GetClassroomViewGrid(configuretView, campusID, buildingsID, classroomName, classroomTypeID, collegeID, isConcurrentUse, isReserve, isAvailable, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 查询对应的教室信息下拉(带数据范围)
- /// </summary>
- /// <param name="bindType"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult DropDown(DropdownListBindType? bindType, int? classroomType)
- {
- var allClassroomList = ClassroomServices.GetClassroomViewList(new ConfiguretView(), null, null, null, classroomType, null, null, null, null);
- List<DropdownListItem> list = allClassroomList.Select(x => new DropdownListItem { Text = x.Name, Value = x.ClassroomID }).ToList();
- DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
- DropdownList.FormatDropdownItemList(dbt, list);
- return base.Json(list);
- }
- /// <summary>
- /// 复制新增
- /// </summary>
- /// <param name="classroomID"></param>
- /// <returns></returns>
- public ActionResult CopyAdd(Guid classroomID)
- {
- ClassroomView classroomView = new ClassroomView();
- classroomView = ClassroomServices.GetClassroomView(classroomID);
- return View("Edit", classroomView);
- }
- /// <summary>
- /// 复制新增
- /// </summary>
- /// <param name="classroomView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult CopyAdd(ClassroomView classroomView)
- {
- classroomView.ClassroomID = Guid.Empty;
- return this.Edit(classroomView);
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:教室编号唯一)
- /// </summary>
- /// <param name="classroomID"></param>
- /// <returns></returns>
- [HttpGet]
- public ActionResult Edit(Guid? classroomID)
- {
- ClassroomView classroomView = new ClassroomView();
- if (classroomID.HasValue && classroomID != Guid.Empty)
- {
- classroomView = ClassroomServices.GetClassroomView(classroomID);
- }
- else
- {
- classroomView.RoomUseID = (int)CF_RoomUse.Classroom;
- classroomView.IsAvailable = true;
- }
- return View(classroomView);
- }
- /// <summary>
- /// 编辑(新增、修改,业务主键:教室编号唯一)
- /// </summary>
- /// <param name="classroomView"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Edit(ClassroomView classroomView)
- {
- try
- {
- ClassroomServices.ClassroomEdit(classroomView);
- return Json(new ReturnMessage()
- {
- IsSuccess = true,
- Message = "保存成功。"
- });
- }
- catch (Exception ex)
- {
- return Json(new ReturnMessage()
- {
- IsSuccess = false,
- Message = "保存失败,原因:" + ex.Message
- });
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="classroomIDs"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Delete(string classroomIDs)
- {
- try
- {
- List<Guid?> list = classroomIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
- ClassroomServices.ClassroomDelete(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>
- /// 根据教室信息ID查询对应的教室类型List
- /// </summary>
- /// <param name="classroomID"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult GetClassroomModeType(Guid? classroomID)
- {
- List<string> list = new List<string>();
- if (classroomID.HasValue && classroomID != Guid.Empty)
- {
- list = ClassroomServices.GetClassroomTypeList(classroomID).Select(x => x.ToString()).ToList();
- }
- else
- {
- list.Add(((int)EMIS.ViewModel.CF_ClassroomType.Classroom).ToString());
- }
- return base.Json(list);
- }
- /// <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", "教室名称" },
- { "BuildingsInfoCode", "建筑编号" },
- { "CollegeCode", RSL.Get("CollegeCode") },
- { "ClassroomTypeIDListStr", "教室类型" },
- //{ "LayoutTypeStr", "布局类型" },
- { "RoomUseStr", "房间用途" },
- { "FloorLevelStr", "所在楼层" },
- { "AcreageStr", "面积" },
- { "RowCoutStr", "行数" },
- { "ColumnCountStr", "列数" },
- { "TotalseatingStr", "总座位数" },
- { "EffectiveseatingStr", "有效座位数" },
- { "ExaminationseatingStr", "考试座位数" },
- { "IsWrittenExamStr", "可否笔试" },
- { "IsMachinetestStr", "可否机试" },
- { "IsConcurrentUseStr", "可否多班教学" },
- { "IsAvailableStr", "是否可用" },
- { "Remark", "备注" },
- { "ErrorMessage", "未导入原因" }
- };
- StringBuilder errorMsg = new StringBuilder();
- string sourceWebPath = FileUploadHelper.UploadFile(file);
- var sourcePhysicalPath = Server.MapPath(sourceWebPath);
- List<ClassroomView> errList = new List<ClassroomView>();
- List<ClassroomView> dataList = new List<ClassroomView>();
- int? inCount = 0; //导入个数
- int? upCount = 0; //更新个数
- int? errCount = 0; //失败个数
- //导入
- ClassroomServices.ClassroomImport(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>
- /// 查询教室信息对应的排课分配院系所信息List(无数据范围)
- /// </summary>
- /// <returns></returns>
- public ActionResult ClassroomCollegeList()
- {
- return View();
- }
- /// <summary>
- /// 查询教室信息对应的排课分配院系所信息List(无数据范围)
- /// </summary>
- /// <param name="pararms"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult ClassroomCollegeList(QueryParamsModel pararms)
- {
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
- var classroomID = Request["classroomID"].ParseStrTo<Guid>();
- var campusID = pararms.getExtraGuid("CampusDropdown");
- var collegeID = pararms.getExtraGuid("CollegeDropdown");
- var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory");
- return base.Json(ClassroomServices.GetClassroomCollegeViewGrid(configuretView, classroomID, campusID, collegeID, unitCategoryID, (int)pararms.page, (int)pararms.rows));
- }
- /// <summary>
- /// 教室信息对应的排课分配院系所信息Excel导出
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Excel_ClassroomCollege()
- {
- try
- {
- NpoiExcelHelper neh = new NpoiExcelHelper();
- ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
- var classroomID = Request["classroomID"].ParseStrTo<Guid>();
- var campusID = Request.Form["CampusDropdown"].ParseStrTo<Guid>();
- var collegeID = Request.Form["CollegeDropdown"].ParseStrTo<Guid>();
- var unitCategoryID = Request.Form["DictionaryUnitCategory"].ParseStrTo<int>() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryUnitCategory"].ParseStrTo<int>();
- var dt = ClassroomServices.GetClassroomCollegeViewList(configuretView, classroomID, campusID, collegeID, unitCategoryID)
- .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.UnitCategoryName,
- x.CollegeCampusCode,
- x.CollegeCampusName,
- x.IsWrittenExamName,
- x.IsMachinetestName,
- x.IsConcurrentUseName,
- x.IsReserveName,
- 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 buildingsID = Request.Form["BuildingsDropdown"].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 = ClassroomServices.GetClassroomViewList(configuretView, campusID, buildingsID, 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
- });
- }
- }
- }
- }
|