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 CampusController : Controller
{
public ICampusServices CampusServices { get; set; }
///
/// 校区信息页面
///
///
public ActionResult List()
{
return View();
}
///
/// 校区信息列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
return base.Json(CampusServices.GetCampusViewGrid(configuretView, (int)pararms.page, (int)pararms.rows));
}
///
/// 校区信息下拉查询
///
///
///
[HttpPost]
public ActionResult CampusDropdownListBanid(DropdownListBindType? bindType)
{
List list = CampusServices.GetCampusList().Select(x => new DropdownListItem
{
Text = x.Name,
Value = x.CampusID.ToString()
}).ToList();
DropdownList.FormatDropdownItemList(bindType.Value, list);
return base.Json(list);
}
///
/// 复制新增
///
///
///
public ActionResult CopyAdd(Guid campusID)
{
CampusView campusView = new CampusView();
campusView = CampusServices.GetCampusView(campusID);
return View("Edit", campusView);
}
///
/// 复制新增
///
///
///
[HttpPost]
public ActionResult CopyAdd(CampusView campusView)
{
campusView.CampusID = Guid.Empty;
return this.Edit(campusView);
}
///
/// 编辑(新增、修改,业务主键:校区代码或校区名称)
///
///
///
[HttpGet]
public ActionResult Edit(Guid? campusID)
{
//ViewBag.Type = Request.Params["Type"];//临时性加参数控制、屏蔽列表进入无保存按钮权限
CampusView campusView = new CampusView();
if (campusID.HasValue && campusID != Guid.Empty)
{
campusView = CampusServices.GetCampusView(campusID);
}
return View(campusView);
}
///
/// 编辑(新增、修改,业务主键:校区代码或校区名称)
///
///
///
[HttpPost]
public ActionResult Edit(CampusView campusView)
{
try
{
CampusServices.CampusEdit(campusView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public JsonResult Delete(string campusIDs)
{
try
{
List list = campusIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
CampusServices.CampusDelete(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("College") + "等。";
}
}
return base.Json(new ReturnMessage { IsSuccess = false, Message = "删除失败,原因:" + mge });
}
}
///
/// 校区对应的院系所信息
///
///
public ActionResult CollegeList()
{
return View();
}
///
/// 校区对应的院系所信息
///
///
///
[HttpPost]
public ActionResult CollegeList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = Request["campusID"].ParseStrTo();
var unitCategoryID = pararms.getExtraInt("DictionaryUnitCategory") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryUnitCategory");
return Json(CampusServices.GetCollegeListViewGrid(configuretView, campusID, unitCategoryID, (int)pararms.page, (int)pararms.rows));
}
///
/// 校区对应的院系所信息Excel导出
///
///
[HttpPost]
public ActionResult CollegeListExcel()
{
return null;
}
///
/// Excel导出
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var dt = CampusServices.GetCampusViewList(configuretView)
.Select(x => new
{
x.No,
x.Name,
x.SimpleName,
x.EnglishName,
x.UniversityCode,
x.UniversityName,
x.GeneralsuperName,
x.RecruitstudentsName,
x.PlacesuperName,
x.TeachingsuperName,
x.StudentchargeName,
x.ZIPCode,
x.Officephone,
x.FAX,
x.Email,
x.Evolution,
x.CollegeCount,
x.Remark
}).ToTable();
string[] liststring = {
RSL.Get("CampusCode"), RSL.Get("CampusName"), RSL.Get("CampusSimpleName"),
"英文名称", "学校代码", "学校名称", "总负责人", "招生负责人", "学籍负责人",
"教学负责人", "学生负责人", "邮政编码", "办公电话",
"传真", "电子邮箱", "历史沿革", RSL.Get("CollegeCount"), "备注"
};
neh.Export(dt, liststring, RSL.Get("CampusName") + "信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
}
}