using System; using System.Collections.Generic; using System.Linq; 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.Utility; using EMIS.Web.Controls; using EMIS.ViewModel; using EMIS.ViewModel.UniversityManage.AdministrativeOrgan; using EMIS.CommonLogic.UniversityManage.AdministrativeOrgan; namespace EMIS.Web.Controllers.UniversityManage.AdministrativeOrgan { [Authorization] public class UniversityController : Controller { public IUniversityServices UniversityServices { get; set; } /// /// 学校信息页面 /// /// public ActionResult List() { return View(); } /// /// 学校信息列表查询 /// /// /// [HttpPost] public ActionResult List(QueryParamsModel pararms) { ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms); return base.Json(UniversityServices.GetUniversityViewGrid(configuretView, (int)pararms.page, (int)pararms.rows)); } /// /// 学校信息下拉查询 /// /// /// [HttpPost] public ActionResult DropdownListBanid() { List list = UniversityServices.GetUniversityList().Select(x => new DropdownListItem { Text = x.Name, Value = x.UniversityID.ToString() }).ToList(); return base.Json(list); } /// /// 复制新增 /// /// /// public ActionResult CopyAdd(Guid universityID) { UniversityView universityView = new UniversityView(); universityView = UniversityServices.GetUniversityView(universityID); return View("Edit", universityView); } /// /// 复制新增 /// /// /// [HttpPost] public ActionResult CopyAdd(UniversityView universityView) { universityView.UniversityID = Guid.Empty; return this.Edit(universityView); } /// /// 编辑(新增、修改,业务主键:学校代码或学校名称) /// /// /// [HttpGet] public ActionResult Edit(Guid? universityID) { UniversityView universityView = new UniversityView(); if (universityID != null && universityID != Guid.Empty) { universityView = UniversityServices.GetUniversityView(universityID); } return View(universityView); } /// /// 编辑(新增、修改,业务主键:学校代码或学校名称) /// /// /// [HttpPost] public ActionResult Edit(UniversityView universityView) { try { UniversityServices.UniversityEdit(universityView); return Json(new ReturnMessage() { IsSuccess = true, Message = "保存成功。" }); } catch (Exception ex) { return Json(new ReturnMessage() { IsSuccess = false, Message = "保存失败,原因:" + ex.Message }); } } /// /// 删除 /// /// /// [HttpPost] public ActionResult Delete(string universityIDs) { try { List list = universityIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList(); UniversityServices.UniversityDelete(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 = "请先删除与其有关联的数据,如:" + RSL.Get("Campus") + "、" + RSL.Get("College") + "等。"; } } return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge }); } } /// /// Excel导出 /// /// /// [HttpPost] public ActionResult Excel(UniversityView pararms) { NpoiExcelHelper neh = new NpoiExcelHelper(); ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null); var dt = UniversityServices.GetUniversityViewList(configuretView) .Select(x => new { x.Code, x.Name, x.SimpleName, x.EnglishName, x.ProvinceName, x.CityName, x.HeadMasterName, x.PartyManageName, x.Telephone, x.ZIPCode, x.FAX, x.Email, x.BuildDate, x.SchoolMotto, x.HistoryEvolution, x.HomePage, x.Address, x.EnglishAddress, x.Remark }).ToTable(); string[] liststring = { "学校代码", "学校名称", "学校简称", "英文名称", "所属省份", "所属市", "校长", "党务负责人", "联系电话", "邮政编码", "传真", "电子邮件", "创校日期", "校训", "历史沿革", "主页地址", "学校地址" , "学校英文地址", "备注" }; neh.Export(dt, liststring, "学校信息" + DateTime.Now.ToString("yyyyMMdd")); return Json(new ReturnMessage() { IsSuccess = true, Message = "导出成功。" }); } } }