using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.CommonLogic.ExaminationApply;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using EMIS.ViewModel.ExaminationApply;
using Bowin.Common.Exceptions;
namespace EMIS.Web.Controllers.ExaminationApply
{
[Authorization]
public class ExaminationTypeController : Controller
{
public IExaminationTypeServices ExaminationTypeServices { get; set; }
///
/// 考试类型页面
///
///
public ActionResult List()
{
return View();
}
public ActionResult Edit(Guid? ExaminationTypeID)
{
ExaminationTypeView examinationTypeView = new ExaminationTypeView();
if (ExaminationTypeID != null && ExaminationTypeID != Guid.Empty)
{
examinationTypeView = ExaminationTypeServices.GetExaminationTypeViewInfo(ExaminationTypeID);
}
return View(examinationTypeView);
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(ExaminationTypeServices.GetExaminationTypeViewList(configuretView, (int)pararms.page, (int)pararms.rows));
}
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
if (configuretView.Attribute == Bowin.Web.Controls.Mvc.DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
var dt = ExaminationTypeServices.GetExaminationTypeViewList(configuretView).Select(x => new
{
x.Name,
x.IsTimesLimitDesc
}).ToTable();
string[] liststring = { "考试类型", "是否要求次数限定" };
neh.Export(dt, liststring, "考试类型信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/ExaminationType/List").AddMenuParameter()
});
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string examinationTypeIDs)
{
try
{
var examinationTypeIDList = examinationTypeIDs.Split(',').Select(x => (Guid?)new Guid(x)).ToList();
ExaminationTypeServices.Delete(examinationTypeIDList);
return base.Json("删除成功");
}
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("删除失败,原因:" + mge + "!");
}
}
///
/// 修改
///
///
[HttpPost]
public ActionResult Edit(ExaminationTypeView examinationTypeView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
ExaminationTypeServices.Save(examinationTypeView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败:" + ex.Message
});
}
}
[HttpPost]
public ActionResult DropdownList(DropdownListBindType? bindType)
{
List list = ExaminationTypeServices.GetExaminationTypeViewList(new ConfiguretView())
.Select(x => new DropdownListItem { Text = x.Name, Value = x.ExaminationTypeID.ToString() }).ToList();
DropdownListBindType dbt = bindType == null ? DropdownListBindType.SelectAll : bindType.Value;
Bowin.Web.Controls.Mvc.DropdownList.FormatDropdownItemList(dbt, list);
return base.Json(list);
}
}
}