using Bowin.Common.Data; using Bowin.Common.Exceptions; using Bowin.Common.Utility; using Bowin.Web.Controls.Mvc; using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan; using EMIS.Utility; using EMIS.ViewModel; using EMIS.ViewModel.UniversityManage.AdministrativeOrgan; using EMIS.Web.Controls; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace EMIS.Web.Controllers.UniversityManage.AdministrativeOrgan { [Authorization] public class CollegeController : Controller { public ICollegeServices CollegeServices { get; set; } /// /// 院系所信息页面 /// /// public ActionResult List() { return View(); } /// /// 院系所信息列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory"); return base.Json(CollegeServices.GetCollegeViewGrid(configuretView, campusID, unitCategoryID, (int)pararms.page, (int)pararms.rows)); } /// /// 院系所信息列表查询(只显示院、系、部类别的院系所) /// /// /// [HttpPost] public ActionResult ListOnlyCollege(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); return base.Json(CollegeServices.GetOnlyCollegeViewList(configuretView, campusID, (int)pararms.page, (int)pararms.rows)); } /// /// 查询院系所信息View(无数据范围) /// /// /// [HttpPost] public ActionResult ListWithoutRange(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var campusID = pararms.getExtraGuid("CampusDropdown"); return base.Json(CollegeServices.GetCollegeViewWithoutRange(configuretView, campusID, (int)pararms.page, (int)pararms.rows)); } /// /// 根据校区获取学院(带数据范围) /// /// /// /// [HttpPost] public ActionResult CollegeDropdownListBanid(DropdownListBindType? bindType, Guid? campusID) { List list = CollegeServices.GetCollegeList(campusID) .Select(x => new DropdownListItem { Text = x.Name, Value = x.CollegeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 根据校区获取学院(无数据范围) /// /// /// /// [HttpPost] public ActionResult AllCollegeDropdownListBanid(DropdownListBindType? bindType, Guid? campusID) { List list = CollegeServices.GetAllCollegeList(campusID) .Select(x => new DropdownListItem { Text = x.Name, Value = x.CollegeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 院系所下拉列表 /// /// /// [HttpPost] public ActionResult CollegeDropdownListBanids(DropdownListBindType? bindType) { List list = new List(); list = CollegeServices.GetCollegeList() .Select(x => new DropdownListItem { Text = x.Name, Value = x.CollegeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 院系所下拉列表(只显示院、系、部类别的院系所) /// /// /// [HttpPost] public ActionResult CollegeDropdownListOnlyCollege(DropdownListBindType? bindType) { List list = new List(); list = CollegeServices.GetOnlyCollegeList() .Select(x => new DropdownListItem { Text = x.Name, Value = x.CollegeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 获取学院(无数据范围限制) /// [HttpPost] public ActionResult CollegeDropdownListBanidsWithoutRange(DropdownListBindType? bindType) { List list = new List(); list = CollegeServices.GetCollegeViewListWithoutDataRange() .Select(x => new DropdownListItem { Text = x.Name, Value = x.CollegeID.ToString() }).ToList(); DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value; DropdownList.FormatDropdownItemList(dbt, list); return base.Json(list); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid collegeID) { CollegeView collegeView = new CollegeView(); collegeView = CollegeServices.GetCollegeView(collegeID); return View("Edit", collegeView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(CollegeView collegeView) { collegeView.CollegeID = Guid.Empty; return this.Edit(collegeView); } /// /// 编辑(新增、修改,业务主键:院系所代码或院系所名称) /// /// /// [HttpGet] public ActionResult Edit(Guid? collegeID) { CollegeView collegeView = new CollegeView(); if (collegeID.HasValue && collegeID != Guid.Empty) { collegeView = CollegeServices.GetCollegeView(collegeID); } else { collegeView.UnitCategoryID = (int)CF_UnitCategory.College; } return View(collegeView); } /// /// 编辑(新增、修改,业务主键:院系所代码或院系所名称) /// /// /// [HttpPost] public ActionResult Edit(CollegeView collegeView) { try { CollegeServices.CollegeEdit(collegeView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string collegeIDs) { try { List list = collegeIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); CollegeServices.CollegeDelete(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 }); } } /// /// Excel导入 /// /// /// /// [HttpGet] public ActionResult Import(string errorFile, string operationTips) { ViewBag.ErrorFile = errorFile; if (string.IsNullOrEmpty(operationTips)) { operationTips = "点击查看失败原因..."; } ViewBag.operationTips = operationTips; return View(); } /// /// Excel导入 /// /// /// [HttpPost] public ActionResult Import(HttpPostedFileBase file) { try { if (!NpoiExcelHelper.GetIsCompatible(file.FileName)) { throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。"); } Dictionary cellheader = new Dictionary { { "No", RSL.Get("CollegeCode") }, { "Name", RSL.Get("CollegeName") }, { "SimpleName", "简称" }, { "EnglishName", "英文名称" }, { "CampusNo", RSL.Get("CampusCode") }, { "PoliticalManagerName", "党务负责人" }, { "AdministrativeManagerName", "行政负责人" }, { "UnitCategoryStr", "单位类别" }, { "FoundDateStr", "建立年月" }, { "Officephone", "办公电话" }, { "Remark", "备注" }, { "ErrorMessage", "未导入原因" } }; StringBuilder errorMsg = new StringBuilder(); // 错误信息 string sourceWebPath = FileUploadHelper.UploadFile(file); var sourcePhysicalPath = Server.MapPath(sourceWebPath); List errList = new List(); List dataList = new List(); int? inCount = 0; //导入个数 int? upCount = 0; //更新个数 int? errCount = 0; //失败个数 //导入 CollegeServices.CollegeImport(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, RSL.Get("College") + "导入失败文件", sourcePhysicalPath)); ViewBag.ErrorFile = errorWebPath; string Errinfo = string.Format("提示:{0}条" + RSL.Get("College") + "导入成功,{1}条" + RSL.Get("College") + "更新成功,{2}条" + RSL.Get("College") + "导入失败,点击查看。", 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}条" + RSL.Get("College") + "导入成功,{1}条" + RSL.Get("College") + "更新成功。", 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"] }); } } /// /// 院系所对应的教研室 /// /// public ActionResult DepartmentList() { return View(); } /// /// 院系所对应的教研室 /// /// /// [HttpPost] public ActionResult DepartmentList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var collegeID = Request["collegeID"].ParseStrTo(); return Json(CollegeServices.GetDepartmentListViewGrid(configuretView, collegeID, (int)pararms.page, (int)pararms.rows)); } /// /// 院系所对应的教研室信息Excel导出 /// /// [HttpPost] public ActionResult DepartmentListExcel() { return null; } /// /// 院系所对应的教师信息 /// /// public ActionResult StaffList() { return View(); } /// /// 院系所对应的教师信息 /// /// /// [HttpPost] public ActionResult StaffList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var collegeID = Request["collegeID"].ParseStrTo(); var departmentID = pararms.getExtraGuid("DepartmentDropdown"); var isPhotoUrl = pararms.getExtraInt("IsPhotoUrlDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsPhotoUrlDropdown"); var teacherTypeID = pararms.getExtraInt("DictionaryTeacherType") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTeacherType"); var incumbencyState = pararms.getExtraInt("DictionaryIncumbencyState") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryIncumbencyState"); var titleID = pararms.getExtraInt("DictionaryTitle") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryTitle"); var isDualTeacher = pararms.getExtraInt("IsDualTeacherDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsDualTeacherDropdown"); return base.Json(CollegeServices.GetStaffListViewGrid(configuretView, collegeID, departmentID, isPhotoUrl, teacherTypeID, incumbencyState, titleID, isDualTeacher, (int)pararms.page, (int)pararms.rows)); } /// /// 院系所对应的教师信息Excel导出 /// /// [HttpPost] public ActionResult StaffListExcel() { return null; } /// /// 院系所对应的院系专业 /// /// public ActionResult FacultymajorList() { return View(); } /// /// 院系所对应的院系专业 /// /// /// [HttpPost] public ActionResult FacultymajorList(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); var collegeID = Request["collegeID"].ParseStrTo(); var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard"); var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation"); var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform"); var learnSystem = pararms.getExtraString("DictionaryLearnSystem"); var scienceclassID = pararms.getExtraInt("DictionaryScienceclass") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryScienceclass"); //在校状态 var inSchoolStatus = pararms.getExtraInt("DictionaryInschoolStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryInschoolStatus"); return Json(CollegeServices.GetFacultymajorListViewGrid(configuretView, collegeID, standardID, educationID, learningformID, learnSystem, scienceclassID, inSchoolStatus, (int)pararms.page, (int)pararms.rows)); } /// /// 院系所对应的院系专业信息Excel导出 /// /// [HttpPost] public ActionResult FacultymajorListExcel() { return null; } /// /// Excel导出 /// /// /// [HttpPost] public ActionResult Excel(CollegeView pararms) { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var campusID = Request.Form["CampusDropdown"].ParseStrTo(); var unitCategoryID = Request.Form["DictionaryUnitCategory"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryUnitCategory"].ParseStrTo(); var dt = CollegeServices.GetCollegeViewList(configuretView, campusID, unitCategoryID) .Select(x => new { x.No, x.Name, x.SimpleName, x.CampusNo, x.CampusName, x.PoliticalManagerName, x.AdministrativeManagerName, x.UnitCategoryName, FoundDate = x.FoundDate == null ? null : x.FoundDate.Value.ToString("yyyy-MM-dd"), x.Officephone, x.DepartmentCount, x.StaffCount, x.FacultymajorCount, x.Remark, }).ToTable(); string[] liststring = { RSL.Get("CollegeCode"), RSL.Get("CollegeName"), "简称", RSL.Get("CampusCode"), RSL.Get("CampusName"), "党务负责人", "行政负责人", "单位类别", "建立年月","办公电话", "教研室数", "教师人数", "院系专业数", "备注" }; neh.Export(dt, liststring, RSL.Get("College") + "信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }